From b37bca8f7a6cdae798e74f14b51936e3a6a9637c Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期四, 29 八月 2024 22:42:14 +0800 Subject: [PATCH] update 售后问题 --- store/index.js | 916 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 526 insertions(+), 390 deletions(-) diff --git a/store/index.js b/store/index.js index 8a6aef8..71274a5 100644 --- a/store/index.js +++ b/store/index.js @@ -6,413 +6,549 @@ Vue.use(Vuex) const store = new Vuex.Store({ - state: { - hasLogin: false, - isUniverifyLogin: false, - loginProvider: "", - openid: null, - testvuex: false, - colorIndex: 0, - colorList: ['#FF0000', '#00FF00', '#0000FF'], - noMatchLeftWindow: true, - active: 'componentPage', - leftWinActive: '/pages/component/view/view', - activeOpen: '', - menu: [], - univerifyErrorMsg: '', - currentInfo: {}, //个人用户信息 - cache_address: {}, - // remoteip:'',//服务器ip - sign: { - 'enterprise': 0, - 'info': 0, - 'flower': 0, - 'shopping': 0, - 'follow': 0 - }, - defaultaddress: {} - }, - mutations: { + state: { + hasLogin: false, + isUniverifyLogin: false, + loginProvider: "", + openid: null, + testvuex: false, + colorIndex: 0, + colorList: ['#FF0000', '#00FF00', '#0000FF'], + noMatchLeftWindow: true, + active: 'componentPage', + leftWinActive: '/pages/component/view/view', + activeOpen: '', + menu: [], + univerifyErrorMsg: '', + currentInfo: {}, //个人用户信息 + cache_address: {}, + // remoteip:'',//服务器ip + sign: { + 'enterprise': 0, + 'info': 0, + 'flower': 0, + 'shopping': 0, + 'follow': 0, + 'delivery': 0, + 'order': 0, + 'shopnum': 0, + }, + defaultaddress: {} + }, + mutations: { - updateLogin(state, provider) { - console.log('updateLogin', provider) - state.hasLogin = provider && true || false; - if (!state.hasLogin) { - storage.removeItem('token') - } - }, - login(state, provider) { - state.hasLogin = true; - state.loginProvider = provider; - }, - logout(state) { - state.hasLogin = false - state.openid = null - state.currentInfo = {} - storage.removeItem('token') - message.showToast('退出登录成功') - // #ifdef APP - var KeepAliveModule = uni.requireNativePlugin("yh-nl") //保活组件 - - let ret = KeepAliveModule.stopLocation(); - console.log('ret', ret) - // #endif - uni.redirectTo({ - url: '/views/login/login' - }) - }, - setOpenid(state, openid) { - state.openid = openid - }, - setDefaultAddress(state, defaultaddress) { - state.defaultaddress = defaultaddress - }, - setTestTrue(state) { - state.testvuex = true - }, - setTestFalse(state) { - state.testvuex = false - }, - setColorIndex(state, index) { - state.colorIndex = index - }, - setActive(state, tabPage) { - state.active = tabPage - }, - setActiveOpen(state, activeOpen) { - state.activeOpen = activeOpen - }, - setMenu(state, menu) { - state.menu = menu - }, - setUniverifyLogin(state, payload) { - typeof payload !== 'boolean' ? payload = !!payload : ''; - state.isUniverifyLogin = payload; - }, - setUniverifyErrorMsg(state, payload = '') { - state.univerifyErrorMsg = payload - } - }, - getters: { - currentColor(state) { - return state.colorList[state.colorIndex] - } - }, - actions: { - sign_add: async function ({ - commit, - state - }, key) { - console.log('sign_add', key) - state.sign[key] = 1 - }, - sign_clear: async function ({ - commit, - state - }, key) { - console.log('sign_clear', key) - state.sign[key] = 0 - }, - // lazy loading openid - logout: async function ({ - commit, - state - }) { - commit('logout') - }, - getUserOpenId: async function ({ - commit, - state - }) { - return await new Promise((resolve, reject) => { - if (state.openid) { - resolve(state.openid) - } else { - uni.login({ - success: (data) => { - commit('login') - setTimeout(function () { //模拟异步请求服务器获取 openid - const openid = '123456789' - console.log( - 'uni.request mock openid[' + - openid + ']'); - commit('setOpenid', openid) - resolve(openid) - }, 1000) - }, - fail: (err) => { - console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', - err) - reject(err) - } - }) - } - }) - }, - getCurrentInfo: async function ({ - commit, - state - }) { - //把权限获取到 - // console.log('getCurrentInfo,getCurrentInfo') - const currentInfo = await http.request('get', '/api/current/user', {}) - if (currentInfo && currentInfo.code == 0) { - // state.cMenu = cMenu - // state.roles = currentInfo.data.roles || [] - state.currentInfo = currentInfo.data || {} - state.type = currentInfo.data.type || '' - state.spacecode = currentInfo.data.spacecode || '' - // if(reload){ - // location.reload() - // } - commit("updateLogin", true) - } else { - commit("updateLogin", false) - //这种情况就是要跳转到登录页面 - } - }, - loginwx: async function ({ - dispatch, - commit, - state - }, data) { - var code = data.code - let inviter = data.inviter || '' - console.log('') - const resp = await http.request('post', '/api/login/wechat', { - data: { - code: code, - imgurl: data.imgurl || '', - nickname: data.nickname || '', - inviter: inviter - }, - // params:{ - // code:code - // } - }) - if (resp && resp.code == 0) { - state.isBind = true - storage.setItem("token", resp.data.access_token || "") - state.hasLogin = true - if (inviter) { - storage.removeItem('inviter'); - storage.removeItem('inviterTime'); - storage.removeItem('inviterName'); - } - await dispatch('getCurrentInfo') - } else { - message.showToast('登录失败.' + (resp && resp.msg)) - storage.removeItem('openid'); - storage.removeItem('tel'); - storage.removeItem('token'); - } - return resp - }, - regUser: async function ({ - commit, - dispatch, - state - }, data) { - { - const resp = await http.request('post', '/api/register/' + data.type, { - data: { - username: data.username, - password: data.password, - tel: data.phoneNumber || data.tel, - smsCode: data.smsCode || '', - dto: data.dto || undefined - }, - params: { - clientType: data.clientType || 'app' - } - }) - console.log('resp', resp) - if (resp && resp.code == 0) { + updateLogin(state, provider) { + console.log('updateLogin', provider) + state.hasLogin = provider && true || false; + if (!state.hasLogin) { + state.currentInfo = {} + storage.removeItem('token') + } + }, + login(state, provider) { + state.hasLogin = true; + state.loginProvider = provider; + }, + logout(state) { + state.hasLogin = false + state.openid = null + state.currentInfo = {} + storage.removeItem('token') + message.showToast('退出登录成功') + + }, + setOpenid(state, openid) { + state.openid = openid + }, + setDefaultAddress(state, defaultaddress) { + state.defaultaddress = defaultaddress + }, + setTestTrue(state) { + state.testvuex = true + }, + setTestFalse(state) { + state.testvuex = false + }, + setColorIndex(state, index) { + state.colorIndex = index + }, + setActive(state, tabPage) { + state.active = tabPage + }, + setActiveOpen(state, activeOpen) { + state.activeOpen = activeOpen + }, + setMenu(state, menu) { + state.menu = menu + }, + setUniverifyLogin(state, payload) { + typeof payload !== 'boolean' ? payload = !!payload : ''; + state.isUniverifyLogin = payload; + }, + setUniverifyErrorMsg(state, payload = '') { + state.univerifyErrorMsg = payload + } + }, + getters: { + currentColor(state) { + return state.colorList[state.colorIndex] + } + }, + actions: { + sign_add: async function({ + commit, + state + }, key) { + console.log('sign_add', key) + state.sign[key] = 1 + }, + // sign_add_value: async function({ + // commit, + // state + // }, { + // key, + // value + // }) { + // console.log('sign_add', key) + // state.sign[key] = value || 0 + // }, + sign_clear: async function({ + commit, + state + }, key) { + console.log('sign_clear', key) + state.sign[key] = 0 + }, + // lazy loading openid + logout: async function({ + commit, + state + }) { + commit('logout') + }, + getUserOpenId: async function({ + commit, + state + }) { + return await new Promise((resolve, reject) => { + if (state.openid) { + resolve(state.openid) + } else { + uni.login({ + success: (data) => { + commit('login') + setTimeout(function() { //模拟异步请求服务器获取 openid + const openid = '123456789' + console.log( + 'uni.request mock openid[' + + openid + ']'); + commit('setOpenid', openid) + resolve(openid) + }, 1000) + }, + fail: (err) => { + console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', + err) + reject(err) + } + }) + } + }) + }, + getCurrentInfo: async function({ + commit, + state + }) { + //把权限获取到 + // console.log('getCurrentInfo,getCurrentInfo') + const currentInfo = await http.request('get', '/api/current/user', {}) + if (currentInfo && currentInfo.code == 0) { + // state.cMenu = cMenu + // state.roles = currentInfo.data.roles || [] + state.currentInfo = currentInfo.data || {} + state.type = currentInfo.data.type || '' + state.spacecode = currentInfo.data.spacecode || '' + // if(reload){ + // location.reload() + // } + commit("updateLogin", true) + } else { + commit("updateLogin", false) + //这种情况就是要跳转到登录页面 + } + }, + loginwx: async function({ + dispatch, + commit, + state + }, data) { + var code = data.code + let inviter = data.inviter || '' + console.log('') + const resp = await http.request('post', '/api/login/wechat', { + data: { + code: code, + imgurl: data.imgurl || '', + nickname: data.nickname || '', + inviter: inviter + }, + // params:{ + // code:code + // } + }) + if (resp && resp.code == 0) { + state.isBind = true + storage.setItem("token", resp.data.access_token || "") + state.hasLogin = true + if (inviter) { + storage.removeItem('inviter'); + storage.removeItem('inviterTime'); + storage.removeItem('inviterName'); + } + await dispatch('getCurrentInfo') + } else { + message.showToast('登录失败.' + (resp && resp.msg)) + storage.removeItem('openid'); + storage.removeItem('tel'); + storage.removeItem('token'); + } + return resp + }, + regUser: async function({ + commit, + dispatch, + state + }, data) { + { + const resp = await http.request('post', '/api/register/' + data.type, { + data: { + username: data.username, + password: data.password, + tel: data.phoneNumber || data.tel, + smsCode: data.smsCode || '', + dto: data.dto || undefined, + wxcode: data.wxcode || undefined + }, + params: { + clientType: data.clientType || 'app' + } + }) + console.log('resp', resp) + if (resp && resp.code == 0) { - } else { + } else { - } - return resp - } + } + return resp + } - }, - loginPartner: async function ({ - commit, - dispatch, - state - }, data) { - { - const resp = await http.request('post', '/api/login/partner' + ((data - .phoneNumber || data.tel) ? '/phone' : ''), { - data: { - username: (data.phoneNumber || data.tel) ? (data.phoneNumber || - data.tel) : data.username, - password: data.password, - tel: data.phoneNumber || data.tel, - smsCode: data.smsCode || '' - }, - params: { - clientType: data.clientType || 'app' - } - }) - console.log('resp', resp) - if (resp && resp.code == 0) { - // await getCurrentInfo() - // // this.$message.showToast('登录成功') - // console.log(resp) - storage.setItem('token', resp.data.access_token) - commit("updateLogin", true) - await dispatch('getCurrentInfo') + }, + loginPartner: async function({ + commit, + dispatch, + state + }, data) { + { + const resp = await http.request('post', '/api/login/partner' + ((data + .phoneNumber || data.tel) ? '/phone' : ''), { + data: { + username: (data.phoneNumber || data.tel) ? (data.phoneNumber || + data.tel) : data.username, + password: data.password, + tel: data.phoneNumber || data.tel, + smsCode: data.smsCode || '' + }, + params: { + clientType: data.clientType || 'app' + } + }) + if (resp && resp.code == 0) { + storage.setItem('token', resp.data.access_token) + commit("updateLogin", true) + await dispatch('getCurrentInfo') + uni.reLaunch({ + url: '/pages/home/supplier-home' + }) + } else {} + return resp + } + }, + loginAdmin: async function({ + commit, + dispatch, + state + }, data) { + { + // + ((data + // .phoneNumber || data.tel) ? '/phone' : '') + const resp = await http.request('post', '/api/login/admin/wx', { + data: { + username: (data.phoneNumber || data.tel) ? (data.phoneNumber || + data.tel) : data.username, + password: data.password, + tel: data.phoneNumber || data.tel, + smsCode: data.smsCode || '' + }, + params: { + clientType: data.clientType || 'app' + } + }) + if (resp && resp.code == 0) { + storage.setItem('token', resp.data.access_token) + commit("updateLogin", true) + await dispatch('getCurrentInfo') + uni.reLaunch({ + url: '/sub_pages/partner/delivery/delivery-home' + }) + } else {} + return resp + } + }, + loginSupplier: async function({ + commit, + dispatch, + state + }, data) { + { + const resp = await http.request('post', '/api/login/supplier' + ((data + .phoneNumber || data.tel) ? '/phone' : ''), { + data: { + username: (data.phoneNumber || data.tel) ? (data.phoneNumber || + data.tel) : data.username, + password: data.password, + tel: data.phoneNumber || data.tel, + smsCode: data.smsCode || '' + }, + params: { + clientType: data.clientType || 'app' + } + }) + console.log('resp', resp) + if (resp && resp.code == 0) { + // await getCurrentInfo() + // // this.$message.showToast('登录成功') + // console.log(resp) + storage.setItem('token', resp.data.access_token) + commit("updateLogin", true) + await dispatch('getCurrentInfo') - console.log('login,reLaunch') - // #ifdef APP - var KeepAliveModule = uni.requireNativePlugin("yh-nl") //保活组件 + console.log('login,reLaunch') + // #ifdef APP + var KeepAliveModule = uni.requireNativePlugin("yh-nl") //保活组件 - KeepAliveModule && KeepAliveModule.startLocation({ - intervalTime: 5000, //定位间隔时间 - gaodeApiKey: "0eef1axxxxxx7964", //高德地图Key,已停用,引入插件配置 - locationMode: 1, //定位模式 - purpose: 0, //定位场景 - ifUpload: true, //是否上报服务器 - uploadUrl: "http://bio51-api.fixbug.fun/api/current/employee/location", //上报接口 - params: "{'lat':'1','lng':'3'}", //其他参数 - headers: "{'authorization1':'Bearer xOHeJhg'}", - }, function (res) { - console.log("启用结果:", res); - let ret = KeepAliveModule.getCurrentLocation(); - console.log("启用结果2:", ret); - }); - // #endif - // uni.redirectTo({ - // url: '/views/app/app-home/app-home' - // }) - uni.reLaunch({ - url: '/pages/home/supplier-home' - }) - } else { - // this.$message.showToast('登录失败') + KeepAliveModule && KeepAliveModule.startLocation({ + intervalTime: 5000, //定位间隔时间 + gaodeApiKey: "0eef1axxxxxx7964", //高德地图Key,已停用,引入插件配置 + locationMode: 1, //定位模式 + purpose: 0, //定位场景 + ifUpload: true, //是否上报服务器 + uploadUrl: "http://bio51-api.fixbug.fun/api/current/employee/location", //上报接口 + params: "{'lat':'1','lng':'3'}", //其他参数 + headers: "{'authorization1':'Bearer xOHeJhg'}", + }, function(res) { + console.log("启用结果:", res); + let ret = KeepAliveModule.getCurrentLocation(); + console.log("启用结果2:", ret); + }); + // #endif + + uni.reLaunch({ + url: '/pages/home/supplier-home' + }) + } else { + // this.$message.showToast('登录失败') - } - return resp - } + } + return resp + } - }, - loginSupplier: async function ({ - commit, - dispatch, - state - }, data) { - { - const resp = await http.request('post', '/api/login/supplier' + ((data - .phoneNumber || data.tel) ? '/phone' : ''), { - data: { - username: (data.phoneNumber || data.tel) ? (data.phoneNumber || - data.tel) : data.username, - password: data.password, - tel: data.phoneNumber || data.tel, - smsCode: data.smsCode || '' - }, - params: { - clientType: data.clientType || 'app' - } - }) - console.log('resp', resp) - if (resp && resp.code == 0) { - // await getCurrentInfo() - // // this.$message.showToast('登录成功') - // console.log(resp) - storage.setItem('token', resp.data.access_token) - commit("updateLogin", true) - await dispatch('getCurrentInfo') + }, - console.log('login,reLaunch') - // #ifdef APP - var KeepAliveModule = uni.requireNativePlugin("yh-nl") //保活组件 + loginCustomer: async function({ + commit, + dispatch, + state + }, data) { + { + const resp = await http.request('post', '/api/login/customer' + ((data.phoneNumber || data + .tel) ? '/phone' : ''), { + data: { + username: (data.phoneNumber || data.tel) ? (data.phoneNumber || + data.tel) : data.username, + password: data.password, + tel: data.phoneNumber || data.tel, + smsCode: data.smsCode || '' + }, + params: { + clientType: data.clientType || 'app' + } + }) + console.log('resp', resp) + if (resp && resp.code === 0) { + storage.setItem('token', resp.data.access_token) + commit("updateLogin", true) + await dispatch('getCurrentInfo') + //todo 登录后可能需要进行绑定 + try { + var sharePartnerUserId = storage.getItem('cache_sharePartnerUserId') + if (sharePartnerUserId) { + //试图绑定 + storage.removeItem('cache_sharePartnerUserId') + if (state.currentInfo.customerDTO && !state.currentInfo.customerDTO.partnerId) { + message.showLoading() + const bindres = await http.request('post', '/api/customer/bind/partner', { + data: { + partnerUserId: sharePartnerUserId + } + }) + message.hideLoading() + if (bindres.code == 0) { + message.showToast(`绑定合伙人成功`) + await dispatch('getCurrentInfo') + } + } - KeepAliveModule && KeepAliveModule.startLocation({ - intervalTime: 5000, //定位间隔时间 - gaodeApiKey: "0eef1axxxxxx7964", //高德地图Key,已停用,引入插件配置 - locationMode: 1, //定位模式 - purpose: 0, //定位场景 - ifUpload: true, //是否上报服务器 - uploadUrl: "http://bio51-api.fixbug.fun/api/current/employee/location", //上报接口 - params: "{'lat':'1','lng':'3'}", //其他参数 - headers: "{'authorization1':'Bearer xOHeJhg'}", - }, function (res) { - console.log("启用结果:", res); - let ret = KeepAliveModule.getCurrentLocation(); - console.log("启用结果2:", ret); - }); - // #endif - // uni.redirectTo({ - // url: '/views/app/app-home/app-home' - // }) - uni.reLaunch({ - url: '/pages/home/supplier-home' - }) - } else { - // this.$message.showToast('登录失败') + } + } catch (e) { + console.error('login ', e) + } - } - return resp - } - - }, - - loginCustomer: async function ({ - commit, - dispatch, - state - }, data) { - { - const resp = await http.request('post', '/api/login/customer' + (data - .phoneNumber ? '/phone' : ''), { - data: { - username: (data.phoneNumber || data.tel) ? (data.phoneNumber || - data.tel) : data.username, - password: data.password, - tel: data.phoneNumber || data.tel, - smsCode: data.smsCode || '' - }, - params: { - clientType: data.clientType || 'app' - } - }) - console.log('resp', resp) - if (resp && resp.code === 0) { - storage.setItem('token', resp.data.access_token) - commit("updateLogin", true) - await dispatch('getCurrentInfo') - uni.reLaunch({ - url: '/pages/home/home' - }) - } else { + uni.reLaunch({ + url: '/pages/home/home' + }) + } else { - } - return resp - } + } + return resp + } - }, - submitShopping: async function ({commit, dispatch}, data) { - const resp = await http.request('post', '/api/customer/flower/cart/change-num', { - data: { - id: data.id, - num: 1 - } - } - ) - if (resp && resp.code === 0) { - message.showToast('添加购物车成功') - dispatch('sign_add', 'shopping') - } else { + }, + submitShopping: async function({ + commit, + dispatch, + state + }, data) { + if (!state.currentInfo.id) { + message.showToast('请先登录') + return + } + //输入要添加多少个 + // const res = await message.confirm('', { + // editable: true, + // title: '请输入购买数目' + // }) + // if (res.content && res.confirm) { + // var t = res.content + var t = 1 + if (!isNaN(parseInt(t)) && t >= 0) { + if ((t) === 0) { + message.showLoading() + const resp = await http.request('get', '/api/customer/flower/cart/delete', { + params: { + id: data.id, + } + }) + message.hideLoading() + if (resp && resp.code === 0) { + message.showToast('操作成功') + dispatch('sign_add', 'shopping') + return { + code: 0, + data: 0 + } + } + } else { + if (parseInt(t) <= 0) { - } - return resp - }, + } else { + //提示没有库存 + if (!data.stock) { + message.showToast('没有库存了,更新失败') - } + return { + code: 1, + data: parseInt(t) + } + } else { + if (data.stock == 0) { + message.showToast('库存为0,更新失败') + + return { + code: 1, + data: parseInt(t) + } + } else if (data.stock > 0 && data.stock < ( + parseInt(t))) { + message.showToast('超过库存,更新失败') + + return { + code: 1, + data: parseInt(t) + } + } + } + // console.log('data',) + } + message.showLoading() + + const resp = await http.request('post', '/api/customer/flower/cart/change-num', { + data: { + id: data.id, + num: parseInt(t) + } + }) + message.hideLoading() + + if (resp && resp.code === 0) { + message.showToast('添加购物车成功') + dispatch('sign_add', 'shopping') + return { + code: 0, + data: parseInt(t) + } + } + } + + // return { + // code: 1, + // data: 0 + // } + } + // else { + // console.log('res.content', res.content) + // message.showToast('输入数目需要大于0') + // } + + + return { + code: 1, + data: 0 + } + }, + countShopping: async function({ + commit, + dispatch, + state + }, data) { + if (state.currentInfo.id) { + const resp = await http.request('get', '/api/customer/flower/cart/flower/count', { + params: { + // flowerId: data || null + } + }) + if (resp && resp.code === 0) { + return resp.data || 0 + } else { + return 0 + } + } + return 0 + }, + + + } }) export default store \ No newline at end of file -- Gitblit v1.9.3