liyongli 3 years ago
parent
commit
ea3902ac64
5 changed files with 132 additions and 66 deletions
  1. 12 0
      src/api/index.js
  2. 6 1
      src/utils/request.js
  3. 32 42
      src/views/Apply.vue
  4. 11 6
      src/views/Appointment.vue
  5. 71 17
      src/views/Queue.vue

+ 12 - 0
src/api/index.js

@@ -60,6 +60,18 @@ export function skip(data) {
   });
 }
 
+/**
+ * 下一个
+ * @returns {AxjxPromise}
+ */
+export function nextone(data) {
+  return ajax({
+    url: "/orders/finish",
+    method: "GET",
+    data,
+  });
+}
+
 /**
  * 预约时段
  * @returns {AxjxPromise}

+ 6 - 1
src/utils/request.js

@@ -1,4 +1,6 @@
 import config from "../config/index.js";
+import { Toast } from "vant";
+import "vant/lib/toast/style/index";
 
 function getdata(data) {
   let text = "";
@@ -35,7 +37,10 @@ export default function (ori) {
         reject(err);
       }
       if (data.code === 0) resolve(data.data);
-      else reject(data);
+      else {
+        Toast("请求失败");
+        reject(data);
+      }
     };
   });
 }

+ 32 - 42
src/views/Apply.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="apply">
-    <van-nav-bar title="预定" left-arrow />
+    <van-nav-bar title="预定" :left-arrow="back" @click-left="$router.go(-1)" />
     <van-form @submit="onSubmit">
       <van-field
         v-model="username"
@@ -32,14 +32,6 @@
         readonly
         :rules="[{ required: true, message: '请选择预定时间' }]"
       />
-      <!-- <van-field
-        @click="() => (dateInput = true)"
-        v-model="selectTime"
-        label="预定时间"
-        placeholder="预定时间"
-        readonly
-        :rules="[{ required: true, message: '请选择预定时间' }]"
-      /> -->
       <div style="margin: 16px">
         <van-button
           color="#2a7ef4"
@@ -52,7 +44,8 @@
         </van-button>
       </div>
     </van-form>
-    <div style="margin: 16px" v-if="back">
+    <div style="margin: 16px">
+      <!-- <div style="margin: 16px" v-if="!back"> -->
       <van-button round block type="default" @click="toAppointment">
         查看预约
       </van-button>
@@ -60,15 +53,6 @@
 
     <!-- #2a7ef4 -->
     <van-popup v-model="dateInput" position="bottom">
-      <!-- <van-datetime-picker
-        :filter="filter"
-        type="datetime"
-        :min-date="minDate"
-        :max-date="maxDate"
-        title="选择预定时间"
-        @cancel="dateInput = false"
-        @confirm="onConfirm"
-      /> -->
       <van-picker
         title="选择预约时间"
         @cancel="dateInput = false"
@@ -102,9 +86,6 @@ import "vant/lib/picker/style/index";
 
 import { goodsList, apply, applyrang } from "../api/index";
 
-// import { formatDate } from "../utils/tool";
-
-// let selecttime = null;
 export default {
   name: "Apply",
   data() {
@@ -126,24 +107,38 @@ export default {
     };
   },
   mounted() {
-    this.back = !!location.href.split("?")[1];
+    this.userphone = this.$route.query.phone || "";
+    this.username = this.$route.query.userName || "";
+    this.back = !location.href.split("?")[1];
     goodsList().then(res => {
       this.goodsLi = res || [];
       this.radio = (this.goodsLi[0] || {}).id;
     });
-    applyrang()
-      .then(res => {
-        console.log(res);
-        this.tagList = res || [];
-      })
-      .catch(err => {
-        console.log(err);
-      });
+    applyrang().then(res => {
+      let l = res || [],
+        nl = [],
+        o = {};
+      for (let i = 0; i < l.length; i++) {
+        const v = l[i];
+        let keys = v.startTime.split(" "),
+          key = keys[0],
+          val = keys[1];
+        v.startTime = val;
+        if (o[key] >= 0) {
+          nl[o[key]].children.push(v);
+        } else {
+          o[key] = nl.length;
+          nl[o[key]] = {
+            startTime: key,
+            children: [v],
+          };
+        }
+      }
+      this.tagList = nl;
+    });
   },
   computed: {
     selectTime() {
-      //   if (!this.date.D || !this.date.D.length) return "";
-      //   return this.date.D.join("-") + " " + this.date.T.join(":");
       return this.date;
     },
   },
@@ -155,26 +150,21 @@ export default {
       return options;
     },
     toAppointment() {
-      this.$router.push({ name: "Appointment", params: { a: 0 } });
+      this.$router.push({ name: "Appointment", query: { phone: this.userphone } });
     },
     onSubmit() {
       apply({
         userName: this.username,
         userPhone: this.userphone,
         goodsId: this.radio,
-        orderTime: this.date
-        // orderTime: this.date.D.join("-") + " " + this.date.T.join(":") + ":00",
-      }).then(res => {
-        console.log(res);
+        orderTime: this.date,
+      }).then(() => {
         this.toAppointment();
       });
     },
     onConfirm(date) {
       this.dateInput = false;
-      //   selecttime = date;
-      console.log(date);
-      //   this.date = formatDate(date);
-      this.date = date.startTime;
+      this.date = date.join(" ");
     },
   },
   beforeUnmount: function () {},

+ 11 - 6
src/views/Appointment.vue

@@ -1,5 +1,6 @@
 <template>
   <div class="Appointment">
+    <van-nav-bar title="预约信息" left-arrow @click-left="$router.go(-1)" />
     <div class="main">
       <van-cell title="预约时间" value="姓名" />
       <van-cell v-for="(item, i) in mainList" :key="i" :title="item.orderTime">
@@ -7,6 +8,7 @@
           {{ item.userName }}
           <van-icon
             name="close"
+            color="#fb5f5c"
             @click="() => removequeue(item.id, i)"
             v-if="item.self"
           />
@@ -25,6 +27,7 @@ import {
   Sidebar as vanSidebar,
   SidebarItem as vanSidebarItem,
   Cell as vanCell,
+  NavBar as vanNavBar,
   Icon as vanIcon,
   Dialog,
 } from "vant";
@@ -32,12 +35,14 @@ import "vant/lib/sidebar/style/index";
 import "vant/lib/cell/style/index";
 import "vant/lib/icon/style/index";
 import "vant/lib/dialog/style/index";
+import "vant/lib/nav-bar/style/index";
 import "vant/lib/sidebar-item/style/index";
 
 // import { formatDate } from "../utils/tool";
 import { orderList, cancel } from "../api/index";
 
-let group = {};
+let group = {},
+  phone = "";
 export default {
   name: "Appointment",
   data() {
@@ -48,8 +53,9 @@ export default {
     };
   },
   mounted() {
+    phone = this.$route.query.phone || "";
     orderList({
-      userPhone: "123123123",
+      userPhone: phone,
     }).then(res => {
       const li = res || [];
       let l = [];
@@ -77,7 +83,6 @@ export default {
       this.mainList = group[this.dataList[this.activeKey]];
     },
     removequeue(id, i) {
-      console.log(id);
       Dialog.confirm({
         title: "取消预约",
         message: "确定要取消该预约?",
@@ -86,9 +91,8 @@ export default {
         // on confirm
         cancel({
           id,
-        }).then(res => {
-          console.log(res);
-          group[this.dataList[this.activeKey]].spice(i,1)
+        }).then(() => {
+          group[this.dataList[this.activeKey]].splice(i, 1);
         });
       });
     },
@@ -99,6 +103,7 @@ export default {
     vanCell,
     vanSidebarItem,
     vanIcon,
+    vanNavBar,
   },
 };
 </script>

+ 71 - 17
src/views/Queue.vue

@@ -7,12 +7,33 @@
       left-arrow
     />
     <van-cell-group>
-      <van-cell v-for="(item,i) in queueList" :key="i">
-        <template #title> {{[i , item.userName , item.orderTime].join(" ")}} </template>
+      <van-cell v-for="(item, i) in queueList" :key="i">
+        <template #title>
+          {{ [i + 1 + ".", item.orderTime + "  ", item.userName].join(" ") }}
+        </template>
         <template #default>
-          <van-button type="default" size="small" @click="()=>skipUser(item.id)"> 跳过 </van-button>
-          <van-button type="info" size="small" @click="()=>skipUser(item.id)">下一个</van-button>
-          <van-button type="warning" size="small" @click="()=>skipUser(item.id)">删除</van-button>
+          <van-button
+            v-if="i === 0"
+            type="default"
+            size="small"
+            @click="skipUser"
+          >
+            跳过
+          </van-button>
+          <van-button
+            v-if="i === 0"
+            type="info"
+            size="small"
+            @click="nextItem"
+          >
+            完成
+          </van-button>
+          <van-button
+            type="warning"
+            size="small"
+            @click="() => removequeue(item.id, i)"
+            >删除</van-button
+          >
         </template>
       </van-cell>
     </van-cell-group>
@@ -26,13 +47,15 @@ import {
   CellGroup as vanCellGroup,
   Button as vanButton,
   NavBar as vanNavBar,
+  Dialog,
 } from "vant";
 import "vant/lib/cell/style/index";
 import "vant/lib/cell-group/style/index";
+import "vant/lib/dialog/style/index";
 import "vant/lib/button/style/index";
 import "vant/lib/nav-bar/style/index";
 
-import { orderList, skip } from "../api/index";
+import { orderList, skip, nextone, cancel } from "../api/index";
 
 export default {
   name: "Queue",
@@ -42,23 +65,54 @@ export default {
     };
   },
   mounted() {
-    orderList().then(res => {
-      console.log(res);
-      this.queueList = res || [];
-    });
+    this.reloadOrder();
   },
   computed: {},
   methods: {
+    reloadOrder() {
+      orderList().then(res => {
+        this.queueList = res || [];
+      });
+    },
     toAdmin() {
       this.$router.push({ name: "Apply", params: { a: 0 } });
     },
-    skipUser(id){
-        skip({
-            userId: id 
-        }).then(res=>{
-            console.log(res)
-        })
-    }
+    skipUser() {
+      Dialog.confirm({
+        message: "是否跳过该用户?",
+        confirmButtonColor: "#2a7ef4",
+      }).then(() => {
+        skip().then(() => {
+          this.reloadOrder();
+        });
+      });
+    },
+    nextItem() {
+      Dialog.confirm({
+        message: "该服务是否已完成?",
+        confirmButtonColor: "#2a7ef4",
+      }).then(() => {
+        nextone().then(() => {
+          this.reloadOrder();
+        });
+      });
+    },
+    removequeue(id, i) {
+      console.log(id);
+      Dialog.confirm({
+        message: "确定要删除该预约?",
+        confirmButtonColor: "#2a7ef4",
+      }).then(() => {
+        // on confirm
+        cancel({
+          id,
+        }).then(() => {
+          let queueList = JSON.parse(JSON.stringify(this.queueList));
+          queueList.splice(i, 1);
+          this.queueList = queueList;
+        });
+      });
+    },
   },
   beforeUnmount: function () {},
   components: {