shish 4 лет назад
Родитель
Сommit
dc7ac1ffc1

+ 43 - 38
ghsApp/src/admin/staff/add.vue

@@ -30,7 +30,7 @@
 
           <tui-list-cell class="line-cell" :hover="false">
               <div class="tui-title required">验证码</div>
-              <input v-model="form.authCode" type="number" style="width:330upx;" placeholder-class="phcolor" placeholder-style="color:#CCCCCC" class="tui-input" name="authCode" placeholder="请填写" />
+              <input v-model="form.authCode" type="number" style="width:330upx;" placeholder-class="phcolor" placeholder-style="color:#CCCCCC" class="tui-input" name="authCode" placeholder="员工收到的验证码" />
               <button v-if="hasGet == false" class="admin-button-com blue middle" @click="requestAuthCode()">获取</button>
               <button v-else class="admin-button-com default middle" >{{count}}</button>
           </tui-list-cell>
@@ -61,9 +61,9 @@
 import TuiListCell from "@/components/plugin/list-cell";
 import AppAvatarModule from "@/components/module/app-avatar";
 const form = require("@/utils/formValidation.js");
-import { getRoleList, getStaffDet as getDet, updateStaff as update } from "@/api/staff";
+import { getRoleList, getStaffDet as getDet } from "@/api/staff";
 import { getDet as getMemberDet } from "@/api/member";
-import { prepareBind } from "@/api/shop-admin";
+import { getStaffAuthCode,createStaff } from "@/api/staff";
 export default {
   name: "staff-add",
   components: {
@@ -78,7 +78,8 @@ export default {
         password: "",
         status: 1,
         remark: "",
-        name:''
+        name:'',
+        mobile:''
       },
       roleList: [],
       roleSelData: {},
@@ -86,18 +87,38 @@ export default {
       showMiniCodeArea: false,
       miniCodeSrc:'',
       memberData: {},
-      hasGet:false
+      hasGet:false,
+      INT:null,
+      count:0
     };
   },
   onLoad() {},
   onShow() {
-    if (this.option.id) {
-      uni.setNavigationBarTitle({ title: `修改员工` })
-    } else {
-      uni.setNavigationBarTitle({ title: `添加员工` })
-    }
   },
   methods: {
+    requestAuthCode(){
+      let that = this
+      let mobile = this.form.mobile
+      if(this.$util.checkMobile(mobile) == false){
+        this.$msg('请输入正确手机号')
+        return
+      }
+      getStaffAuthCode({mobile}).then(res=>{
+        if(res.code == 1){
+          that.hasGet = true
+          that.count = 120
+          that.INT = setInterval(function(){
+            if(that.count <= 0){
+              clearInterval(that.INT)
+              that.hasGet = false
+              that.count = 120
+              return
+            }
+            that.count--
+          },1000)
+        }
+      })
+    },
     init() {
       let data = uni.getStorageSync("addStaffData");
       if (data) {
@@ -167,41 +188,25 @@ export default {
     statusChangeFn(e) {
       this.form.status = e.detail.value ? 1 : 0;
     },
-    confirmFn() {
-      let hostFn = this.option.id ? update : prepareBind;
-      if (this.option.id) {
-        this.form.id = this.option.id;
-      }
-      hostFn(this.form).then(res => {
-        if(typeof(this.option.id) == 'undefined'){
-          this.showMiniCodeArea = true;
-          this.miniCodeSrc = res.data.miniCode;
-          this.showStaffArea = false;
-        }else{
-          let promptText = this.option.id ? "修改成功!" : "添加成功!";
-          this.$msg(promptText);
-          setTimeout(() => {
-            this.$util.pageTo(1);
-          }, 1000);
-        }
-        
-      });
-    },
     complete(){
       this.$util.pageTo(1)
     },
     formSubmit(e) {
-      let rules = [
-        {
-          name: "roleId",
-          rule: ["required"],
-          msg: ["请选择角色"]
-        }
-      ];
+      let that = this
+      let rules = [{ name: "roleId", rule: ["required"], msg: ["请选择角色"] }]
       let formData = e.detail.value;
       let checkRes = form.validation(formData, rules);
       if (!checkRes) {
-        this.confirmFn();
+        uni.showLoading({mask:true});
+        createStaff(that.form).then(res => {
+          uni.hideLoading()
+          if(res.code == 1){
+            that.$msg('添加成功')
+            setTimeout(() => {
+              uni.navigateBack()
+            }, 1000)
+          }
+        })
       } else {
         this.$msg(checkRes);
       }

+ 9 - 35
ghsApp/src/admin/staff/detail.vue

@@ -40,9 +40,8 @@
 import TuiListCell from "@/components/plugin/list-cell";
 import AppAvatarModule from "@/components/module/app-avatar";
 const form = require("@/utils/formValidation.js");
-import { getRoleList, getStaffDet as getDet, updateStaff as update } from "@/api/staff";
+import { getRoleList, getStaffDet as getDet, updateStaff} from "@/api/staff";
 import { getDet as getMemberDet } from "@/api/member";
-import { prepareBind } from "@/api/shop-admin";
 export default {
   name: "staff-add",
   components: {
@@ -68,11 +67,6 @@ export default {
   },
   onLoad() {},
   onShow() {
-    if (this.option.id) {
-      uni.setNavigationBarTitle({ title: `修改员工` })
-    } else {
-      uni.setNavigationBarTitle({ title: `添加员工` })
-    }
   },
   methods: {
     init() {
@@ -144,41 +138,21 @@ export default {
     statusChangeFn(e) {
       this.form.status = e.detail.value ? 1 : 0;
     },
-    confirmFn() {
-      let hostFn = this.option.id ? update : prepareBind;
-      if (this.option.id) {
-        this.form.id = this.option.id;
-      }
-      hostFn(this.form).then(res => {
-        if(typeof(this.option.id) == 'undefined'){
-          this.showMiniCodeArea = true;
-          this.miniCodeSrc = res.data.miniCode;
-          this.showStaffArea = false;
-        }else{
-          let promptText = this.option.id ? "修改成功!" : "添加成功!";
-          this.$msg(promptText);
-          setTimeout(() => {
-            this.$util.pageTo(1);
-          }, 1000);
-        }
-        
-      });
-    },
     complete(){
       this.$util.pageTo(1)
     },
     formSubmit(e) {
-      let rules = [
-        {
-          name: "roleId",
-          rule: ["required"],
-          msg: ["请选择角色"]
-        }
-      ];
+      let rules = [{ name: "roleId", rule: ["required"], msg: ["请选择角色"] }]
       let formData = e.detail.value;
       let checkRes = form.validation(formData, rules);
       if (!checkRes) {
-        this.confirmFn();
+        this.form.id = this.option.id;
+        updateStaff(this.form).then(res => {
+            this.$msg('修改成功');
+            setTimeout(() => {
+              this.$util.pageTo(1);
+            }, 1000)
+        })
       } else {
         this.$msg(checkRes);
       }

+ 1 - 1
ghsApp/src/api/common/index.js

@@ -51,4 +51,4 @@ export const initSocket = async clientId => {
 export const appLogin = data => https.get("/auth/app-login", data);
 
 //app重新获取登陆信息
-export const appReGetLoginInfo = data => https.get("/admin/app-re-get-login-info", data);
+export const autoLogin = data => https.get("/admin/auto-login", data);

+ 3 - 6
ghsApp/src/api/shop-admin/index.js

@@ -1,14 +1,11 @@
 import https from '@/plugins/luch-request_0.0.7/request'
-/** *
- * 准备创建管理员的数据
- */
+
+//准备创建管理员的数据
 export const prepareBind = data => {
 	return https.post('/shop-admin/prepare-bind', data)
 }
 
-/** *
- * 创建管理员
- */
+//创建管理员
 export const generateAdmin = data => {
 	return https.post('/shop-admin/generate-admin', data)
 }

+ 10 - 0
ghsApp/src/api/staff/index.js

@@ -69,3 +69,13 @@ export const delRole = data => {
 export const getLogList = data => {
 	return https.get('/admin-log/list', data)
 }
+
+//获取员工的验证码
+export const getStaffAuthCode = data => {
+	return https.get('/shop-admin/get-staff-auth-code', data)
+}
+
+//添加员工
+export const createStaff = data => {
+	return https.post('/shop-admin/add-staff', data)
+}

+ 32 - 8
ghsApp/src/mixins/globalMixins.js

@@ -3,7 +3,7 @@ import { mapGetters,mapActions } from 'vuex'
 import { pageTo, isLogin } from '@/utils/util.js'
 import { getUser, wxMiniLogin } from '@/utils/auth'
 import { postWxCode, getDictionaries } from '@/api/mini'
-import { getStaffApi,appReGetLoginInfo } from '@/api/common'
+import { getStaffApi,autoLogin } from '@/api/common'
 import { allProduct } from '@/api/product'
 import { codePay} from "@/api/order/index";
 
@@ -59,13 +59,37 @@ export default {
       var pages = getCurrentPages()
 			let currentRoute  = pages[pages.length-1].route;
       let token = uni.getStorageSync('token')
-      if(currentRoute == 'admin/home/workbench' && this.$util.isEmpty(token)){
-        wxMiniLogin(true).then(res => {
-          let token = res.token || ''
-          if (!this.$util.isEmpty(token)) {
-            getUser(true)
-            this.setUserShopAll()
+      if(this.$util.isEmpty(token)){
+        if(currentRoute == 'admin/home/workbench'){
+          wxMiniLogin(true).then(res => {
+            let token = res.token || ''
+            if (!this.$util.isEmpty(token)) {
+              getUser(true)
+              this.setUserShopAll()
+            }
+            if (this.init) {
+              this.init()
+            }
+          })
+        }
+      }else{
+        let that = this
+        autoLogin().then(subRes=>{
+          if(subRes.code != 1){
+            return
           }
+					getDictionaries({ token: subRes.data.token }).then(res => {
+						if (!that.$util.isEmpty(res)) {
+              store.commit('setDictionariesInfo', { ...res.data.dict, ...res.data })
+              store.commit('setMyShopInfo', { ...res.data.shop, ...res.data })
+						}
+					})
+          store.commit('setLoginInfo', { ...subRes.data.admin, ...subRes.data })
+          this.skCustomId = subRes.data.skCustomId
+          // #ifdef APP-PLUS
+          this.listenPDAkd()
+          // #endif
+          this.setUserShopAll()
           if (this.init) {
             this.init()
           }
@@ -78,7 +102,7 @@ export default {
       const appToken = uni.getStorageSync('token')
       if(!this.$util.isEmpty(appToken)){
         let that = this
-        appReGetLoginInfo().then(subRes=>{
+        autoLogin().then(subRes=>{
           if(subRes.code != 1){
             return
           }