Browse Source

签到定位

ZhaoJing 2 years ago
parent
commit
0a9b04bb4d
2 changed files with 122 additions and 42 deletions
  1. 15 14
      index.html
  2. 107 28
      src/pages/stxkjs/index.vue

+ 15 - 14
index.html

@@ -1,18 +1,19 @@
 <!DOCTYPE html>
 <html lang="zh-CN">
+  <head>
+    <meta charset="UTF-8" />
+    <!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
+    <meta
+      name="viewport"
+      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"
+    />
+    <title>南马路</title>
+  </head>
 
-<head>
-  <meta charset="UTF-8" />
-  <!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
-  <meta name="viewport"
-    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
-  <title>南马路</title>
-</head>
-
-<body>
-  <div id="app"></div>
-  <script src="/config.js"></script>
-  <script type="module" src="/src/main.js"></script>
-</body>
-
+  <body>
+    <div id="app"></div>
+    <script src="/config.js"></script>
+    <script type="module" src="/src/main.js"></script>
+    <script src="https://mapapi.qq.com/web/mapComponents/geoLocation/v/geolocation.min.js"></script>
+  </body>
 </html>

+ 107 - 28
src/pages/stxkjs/index.vue

@@ -80,25 +80,33 @@
               >
               <div class="active">
                 <div class="teach-plan">
-                  <span class="cursor-pointer" @click="(planShow = true), (show = true), upPlan(c)"
+                  <span
+                    class="cursor-pointer"
+                    @click="(planShow = true), (show = true), upPlan(c)"
                     >上传教案</span
                   >
                 </div>
                 <div class="teach-signIn">
-                  <span class="cursor-pointer"
+                  <span
+                    class="cursor-pointer"
                     v-if="c.is_qd.kkq_zt == 0 || c.is_qd.kkq_zt == -1"
                     @click="apply(c)"
                     >申请</span
                   >
-                  <span class="cursor-pointer" v-if="c.is_qd.kkq_zt == 2" @click="applied()"
+                  <span
+                    class="cursor-pointer"
+                    v-if="c.is_qd.kkq_zt == 2"
+                    @click="applied()"
                     >已申请</span
                   >
-                  <span class="cursor-pointer"
+                  <span
+                    class="cursor-pointer"
                     v-if="c.is_qd.kkq_zt == 3"
                     @click="(signShow = true), (show = true), beginSign(c)"
                     >签到</span
                   >
-                  <span class="cursor-pointer"
+                  <span
+                    class="cursor-pointer"
                     v-if="c.is_qd.kkq_zt == 4"
                     @click="(signShow = true), (show = true), endSign(c)"
                     >已签到</span
@@ -206,9 +214,17 @@
             {{ signItem.kkbk_endtime }}
           </p>
           <div class="upload">
-            <div @click="getLoc" class="w-100px h-40px location">
+            <div
+              @click="(loading = true), getPosition()"
+              class="w-100px h-40px location"
+            >
               获取当前定位
             </div>
+            <van-loading v-if="loading" color="#1989fa" />
+            <div v-if="pos.province" class="position" id="demo">
+              当前位置在:{{ pos.province }}{{ pos.city }}{{ pos.district
+              }}{{ pos.addr }}
+            </div>
             <van-uploader
               v-if="sign"
               v-model="fileList"
@@ -250,7 +266,7 @@ import {
   stxkjs_qd,
   stxkjs_sc,
   stxkjs_sq,
-  qd_add
+  qd_add,
 } from "./api";
 import { user } from "../../store/user";
 import { ref, reactive, onMounted } from "vue";
@@ -304,7 +320,6 @@ getWeek();
 function getClass() {
   stxkjs_list(data).then((res) => {
     classWeek.value = res.data;
-    console.log(res.data);
   });
 }
 getClass();
@@ -357,10 +372,8 @@ function getlb() {
 let fileProxy = [];
 let kkj_fj;
 const upja = (fileList) => {
-  console.log(fileList.file);
   fileProxy = [];
   stxk_up({ file: fileList.file }).then((res) => {
-    console.log(res.data);
     fileProxy.push(res.data.file_name + "," + res.data.url);
     kkj_fj = {
       kkj_fj: fileProxy.join(";"),
@@ -397,13 +410,19 @@ function jaDelete(item) {
   });
 }
 let kkq_id = "";
+let kkbk_id = "";
+let kkb_id = "";
+let kkbk_sszt = "";
+let kkq_zt = "";
 let kkq_img = [];
 // 开始签到,缓存签到参数
 function beginSign(c) {
-  console.log(c);
   kkq_id = c.is_qd.kkq_id;
+  kkb_id = c.khfw_kcbgl.kkb_id;
+  kkbk_id = c.kkbk_id;
+  kkbk_sszt = c.kkbk_sszt;
+  kkq_zt = c.is_qd.kkq_zt;
   signItem.value = c;
-  // console.log(signItem.value);
   kkq_img = [];
   sign.value = true;
 }
@@ -417,10 +436,8 @@ function endSign(c) {
 const afterRead = (fileList) => {
   // 此时可以自行将文件上传至服务器
   const { file } = fileList;
-  console.log(kkq_img);
   file.status = "uploading";
   stxk_up({ file: file }).then((res) => {
-    // console.log(res.data);
     kkq_img.push(res.data.file_name + "," + res.data.url);
     file.status = "done";
   });
@@ -429,16 +446,67 @@ function beforeDelate(file, detail) {
   kkq_img.splice(detail.index, 1);
   return true;
 }
-function getLoc() {
-  
+
+// 获取定位
+// var geolocation = new qq.maps.Geolocation(
+//   "ZPTBZ-R4F6I-2IDG3-5TIDK-252R5-EQBH7",
+//   "myapp"
+// );
+let pos = ref({});
+let kkq_address = "";
+var positionNum = 0;
+var options = { timeout: 3000 };
+let loading = $ref(false);
+
+function showPosition(position) {
+  pos.value = position;
+  kkq_address =
+    pos.value.province + pos.value.city + pos.value.district + pos.value.addr;
+  console.log(kkq_address);
+  positionNum++;
+  loading = false;
+}
+function showErr() {
+  positionNum++;
+  loading = false;
+  showToast("获取定位失败!");
+  getPosition();
+}
+function getPosition() {
+  // console.log(pos.value);
+  pos.value = {};
+  var geolocation = new window.qq.maps.Geolocation(
+    "OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77",
+    "nml"
+  );
+  geolocation.getLocation(showPosition, showErr, options);
 }
+
 // signImg = ref([]);
 function submitSign(c) {
-  console.log(kkq_img);
-  if (kkq_img.length <= 0) {
-    showToast("请上传图片");
+  // if (kkq_img.length <= 0) {
+  //   showToast("请上传图片");
+  //   return;
+  // }
+  if (
+    !pos.value.province ||
+    !pos.value.city ||
+    !pos.value.district ||
+    !pos.value.addr
+  ) {
+    showToast("定位信息不完整!");
     return;
   }
+  let addData = {
+    khfw_kcbkb_qd: {
+      kkb_id,
+      kkbk_id,
+      kkq_zt: "4",
+      kkq_address,
+      kkq_lat: pos.value.lat,
+      kkq_lng: pos.value.lng,
+    },
+  };
   const data = {
     kkq_id,
     khfw_kcbkb_qd: {
@@ -446,10 +514,17 @@ function submitSign(c) {
       kkq_img: kkq_img.join(";"),
     },
   };
-  stxkjs_qd(data).then((res) => {
-    console.log(res);
-    sign.value = false;
-    getClass();
+
+  console.log(addData);
+  qd_add(addData).then((res) => {
+    console.log(res,1111111111111111);
+    if (res.code == 1) {
+      stxkjs_qd(data).then((item) => {
+        console.log(item,222222222222222);
+        sign.value = false;
+        getClass();
+      });
+    }
   });
 }
 let color = ref("");
@@ -639,15 +714,15 @@ getColor();
       padding-left: 0.2 * 13.3vw;
       margin-top: 0.35 * 13.3vw;
       line-height: 2 * 13.3vw;
-      .location{
-        height: .6*13.3vw;
-        line-height: .6 * 13.3vw;
+      .location {
+        height: 0.6 * 13.3vw;
+        line-height: 0.6 * 13.3vw;
         cursor: pointer;
         text-align: center;
         color: #003eee;
         border: 1px solid #003eee;
-        border-radius: .05*13.3vw;
-        margin-top: .1 *13.3vw;
+        border-radius: 0.05 * 13.3vw;
+        margin-top: 0.1 * 13.3vw;
       }
     }
     .signed {
@@ -667,6 +742,10 @@ getColor();
     }
   }
 }
+#demo {
+  line-height: 0.35 * 13.3vw;
+  transition: all, 1s;
+}
 ::v-deep .van-nav-bar {
   width: 100%;
   height: 1 * 13.3vw;