liyongli 3 жил өмнө
parent
commit
d794419832

+ 7 - 0
public/index.html

@@ -8,6 +8,13 @@
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <script src="//cdn.bootcdn.net/ajax/libs/eruda/2.4.1/eruda.min.js"></script>
     <script>eruda.init();</script>
+    <script src="https://djweb.smcic.net/gouju/js/jquery-2.1.0.js"></script>
+    <!--导入原生js库-->
+    <script src="http://cmp/v1.0.0/js/cordova/__CMPSHELL_PLATFORM__/cordova.js"></script>
+    <script src="http://cmp/v1.0.0/js/cordova/cordova-plugins.js"></script>
+    <!--导入cmp.js-->
+    <script src="http://cmp/v/js/cmp-i18n.js"></script>
+    <script src="http://cmp/v/js/cmp.js"></script>
     <title>
         <%= htmlWebpackPlugin.options.title %>
     </title>

+ 24 - 0
src/api/index.js

@@ -103,3 +103,27 @@ export function getAPPUser(data) {
     data,
   });
 }
+
+/**
+ * 获取当前打烊规则
+ * @returns {AjaxPromise}
+ */
+export function getRule(data) {
+  return ajax({
+    url: "/stop-rule/list",
+    method: "POST",
+    data,
+  });
+}
+
+/**
+ * 更新当前打烊规则
+ * @returns {AjaxPromise}
+ */
+export function upRule(data) {
+  return ajax({
+    url: "/stop-rule/edit",
+    method: "POST",
+    data,
+  });
+}

+ 3 - 1
src/utils/request.js

@@ -14,15 +14,17 @@ function getdata(data) {
 
 export default function (ori) {
   let baseurl = config.base[ori.urlType || "defaultURl"];
-  let url = baseurl + ori.url + getdata(ori.data || {});
+  let url = baseurl + ori.url;
   return new Promise((resolve, reject) => {
     var xhttp;
     if (window.XMLHttpRequest) xhttp = new XMLHttpRequest();
     else if (window.ActiveXObject)
       xhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
     let method = ori.method.toUpperCase();
+    if (method === "GET") url +=  getdata(ori.data || {});
     xhttp.open(method, url, true);
     xhttp.setRequestHeader("Content-type", "application/json");
+    console.log(ori.data)
     method === "GET" ? xhttp.send() : xhttp.send(JSON.stringify(ori.data));
     xhttp.onreadystatechange = function () {
       if (this.readyState != 4) return;

+ 13 - 8
src/utils/tool.js

@@ -13,12 +13,17 @@ export function formatDate(T) {
   };
 }
 
-export function urlSearchData(){
-    let TextSearch = location ? location.search : "", search = {};
-    TextSearch = TextSearch.replace("?", "").split("&");
-    for (let i = 0; i < TextSearch.length; i++) {
-        const v = TextSearch[i].split("=");
-        search[v[0]] = v[1];
-    }
-    return search
+export function urlSearchData() {
+  let TextSearch = location ? location.href : "",
+    search = {};
+  const rex = new RegExp("https?://" + location.host + "/", "g");
+  TextSearch = TextSearch.replace(rex, "").split("?");
+  for (let i = 0; i < TextSearch.length; i++) {
+    if (!TextSearch[i]) continue;
+    const vs = TextSearch[i].split("=");
+    if (!vs[1]) continue;
+    const v = vs[1].split("#/")[0]
+    search[vs[0]] = v;
+  }
+  return search;
 }

+ 11 - 7
src/views/Appointment.vue

@@ -18,6 +18,7 @@
       <van-sidebar-item v-for="(item, i) in dataList" :key="i" :title="item" />
     </van-sidebar>
 
+    <div style="clear: both"></div>
     <div
       style="
         padding: 16px;
@@ -31,11 +32,12 @@
         round
         block
         type="info"
-        @click="toAppointment"
+        @click="test"
         native-type="submit"
       >
         去预约
       </van-button>
+      <!-- @click="toAppointment" -->
     </div>
   </div>
 </template>
@@ -57,8 +59,7 @@ import "vant/lib/icon/style/index";
 import "vant/lib/dialog/style/index";
 import "vant/lib/sidebar-item/style/index";
 
-// import { formatDate } from "../utils/tool";
-import { orderList, cancel, getAPPUser } from "../api/index";
+import { orderList, cancel } from "../api/index";
 import { urlSearchData } from "../utils/tool";
 
 export default {
@@ -75,10 +76,8 @@ export default {
   mounted() {
     this.phone = this.$route.query.phone || "";
     let search = urlSearchData();
+    console.log(search);
     document.title = "预定";
-    getAPPUser({ ticket: search.webviewId }).then(res => {
-      console.log(res);
-    });
     orderList({
       userPhone: this.phone,
     }).then(res => {
@@ -104,10 +103,12 @@ export default {
   },
   computed: {},
   methods: {
+    test() {
+      console.log(window.cmp);
+    },
     toAppointment() {
       this.$router.push({
         name: "Apply",
-        query: { phone: this.nextSearch.userphone },
       });
     },
     onChange() {
@@ -142,6 +143,7 @@ export default {
 <style>
 .Appointment {
   height: 100%;
+  box-sizing: border-box;
   background-color: #f7f8fa;
 }
 .Appointment .van-sidebar {
@@ -150,10 +152,12 @@ export default {
 .Appointment .main {
   width: calc(100% - 100px);
   height: 100%;
+  overflow-y: scroll;
   background-color: #fff;
   box-sizing: border-box;
   padding: 5px;
   float: right;
+  padding-bottom: 76px;
 }
 .Appointment .van-sidebar-item--select::before {
   background-color: #2a7ef4;

+ 99 - 23
src/views/Queue.vue

@@ -2,7 +2,7 @@
   <div class="queue">
     <van-nav-bar
       title="当前队列"
-      right-text="打烊"
+      right-text="营业规则"
       @click-left="toAdmin"
       @click-right="toOpen"
       left-text="添加预定"
@@ -38,10 +38,13 @@
     </van-cell-group>
 
     <van-popup closeable v-model="open" position="right" class="open">
-      <van-checkbox-group v-model="checkbox" v-if="showPopover.length">
+      <van-checkbox-group
+        v-model="checkbox"
+        v-if="showPopover.length"
+      >
         <van-row v-for="(item, i) in weeks" :key="i">
           <van-col span="8">
-            <van-checkbox name="1" style="height: 2em">
+            <van-checkbox :name="i" style="height: 2em">
               {{ item }}
             </van-checkbox>
           </van-col>
@@ -105,10 +108,9 @@
             </van-popover>
           </van-col>
         </van-row>
+        <br />
+        <van-button :loading="load" @click="upRulefun" round  type="info" loading-text="加载中..." block>保 存</van-button>
       </van-checkbox-group>
-      <br />
-      <van-button type="default" block round>打烊</van-button>
-      <van-button type="primary" block round>开始营业</van-button>
     </van-popup>
   </div>
 </template>
@@ -146,7 +148,15 @@ import "vant/lib/checkbox/style/index";
 import "vant/lib/checkbox-group/style/index";
 import "vant/lib/nav-bar/style/index";
 
-import { orderList, skip, nextone, cancel } from "../api/index";
+import {
+  orderList,
+  skip,
+  nextone,
+  cancel,
+  getRule,
+  upRule,
+} from "../api/index";
+
 export default {
   name: "Queue",
   data() {
@@ -157,32 +167,24 @@ export default {
       open: false,
       time: [],
       time2: [],
-      timerange: ["00:00 - 00:00"],
+      timerange: [],
       checkbox: [],
-      weeks: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
+      weeks: [],
+      load: false
     };
   },
   mounted() {
-    this.showPopover.fil;
-    let showPopover = new Array(this.weeks.length),
-      timerange = new Array(this.weeks.length);
-    showPopover.fill(false);
-    timerange.fill("00:00 - 00:00");
-    this.showPopover = showPopover;
-    this.time = new Array(this.weeks.length).fill("00:00");
-    this.time2 = new Array(this.weeks.length).fill("00:00");
-    this.timerange = timerange;
     this.reloadOrder();
     window.setInterval(() => {
-      console.log("---");
       this.reloadOrder();
     }, 60000);
   },
   computed: {},
   methods: {
     closeTime(t) {
-      console.log(t);
       const showP = JSON.parse(JSON.stringify(this.showPopover));
+      this.time[t] = this.timerange[t].split(" - ")[0];
+      this.time2[t] = this.timerange[t].split(" - ")[1];
       showP[t] = false;
       this.showPopover = showP;
     },
@@ -195,8 +197,83 @@ export default {
       this.timerange[t] = this.time[t] + " - " + this.time2[t];
       this.closeTime(t);
     },
+    upRulefun() {
+        this.load = true;
+      upRule({
+        week: this.formatRule()
+      }).then(r => {
+        console.log(r);
+        this.load = false;
+      }).catch(()=>{
+        this.load = false;
+      });
+    },
+    formatRule() {
+      let li = [],
+        week = {
+          周一: 1,
+          周二: 2,
+          周三: 3,
+          周四: 4,
+          周五: 5,
+          周六: 6,
+          周日: 7,
+        },
+        check = this.checkbox.join(",");
+      for (let i = 0; i < this.showPopover.length; i++) {
+        const time = this.time[i],
+          time2 = this.time2[i], rex = new RegExp(i);
+        li.push({
+          week: week[this.weeks[i]],
+          start: time,
+          end: time2,
+          status: rex.test(check) ? "OPEN" : "STOP",
+        });
+      }
+      return li;
+    },
     toOpen() {
-      this.open = true;
+      getRule().then(res => {
+        const li = res || [],
+          week = {
+            1: "一",
+            2: "二",
+            3: "三",
+            4: "四",
+            5: "五",
+            6: "六",
+            7: "日",
+          };
+        let W = [];
+        let showPopover = [],
+          timerange = [],
+          time = [],
+          time2 = [],
+          checkbox = [];
+        for (let i = 0; i < li.length; i++) {
+          const v = li[i];
+          let sT = v.start ? this.format(v.start) : "00:00";
+          let eT = v.end ? this.format(v.end) : "00:00";
+          W.push("周" + week[v.week]);
+          showPopover.push(false);
+          v.status === "OPEN" && checkbox.push(i);
+          timerange.push(sT + " - " + eT);
+          time.push(sT);
+          time2.push(eT);
+        }
+        this.weeks = W;
+        this.showPopover = showPopover;
+        this.time = time;
+        this.time2 = time2;
+        this.timerange = timerange;
+        this.checkbox = checkbox;
+        this.open = true;
+      });
+    },
+    format(T) {
+      let o = T.split(":");
+      o.splice(2, 1);
+      return o.join(":");
     },
     reloadOrder() {
       orderList().then(res => {
@@ -227,7 +304,6 @@ export default {
       });
     },
     removequeue(id, i) {
-      console.log(id);
       Dialog.confirm({
         message: "确定要删除该预约?",
         confirmButtonColor: "#2a7ef4",
@@ -263,7 +339,7 @@ export default {
 
 <style>
 .queue {
-  width: 990px;
+  width: 1200px;
   height: 100%;
   margin: 0 auto;
   background-color: #fff;