From b07889e22f823fac80a66b503671e170668f4ee6 Mon Sep 17 00:00:00 2001 From: 陶杰 <1378534974@qq.com> Date: 星期二, 10 十二月 2024 10:10:25 +0800 Subject: [PATCH] 1.供应商子账号 --- store/index.js | 292 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 263 insertions(+), 29 deletions(-) diff --git a/store/index.js b/store/index.js index 0985520..16b907a 100644 --- a/store/index.js +++ b/store/index.js @@ -19,6 +19,7 @@ leftWinActive: '/pages/component/view/view', activeOpen: '', menu: [], + appMenu: [], univerifyErrorMsg: '', currentInfo: {}, //个人用户信息 cache_address: {}, @@ -29,9 +30,19 @@ 'flower': 0, 'shopping': 0, 'follow': 0, - 'delivery': 0 + 'delivery': 0, + 'order': 0, + 'shopnum': 0, + 'coupon': 0, + 'cache_topay':0, }, - defaultaddress: {} + cache: { + coupon: {}, + goods:[], + cache_coupon_select_cancel:0 + }, + defaultaddress: {}, + addressDesc:'', }, mutations: { @@ -39,6 +50,7 @@ console.log('updateLogin', provider) state.hasLogin = provider && true || false; if (!state.hasLogin) { + state.currentInfo = {} storage.removeItem('token') } }, @@ -50,23 +62,23 @@ state.hasLogin = false state.openid = null state.currentInfo = {} + state.appMenu=[] storage.removeItem('token') + storage.removeItem('appMenu'); 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 + }, + setAddressDesc(state, addressDesc) { + console.log('setAddressDesc',addressDesc) + state.addressDesc = addressDesc + storage.setItem("defaultaddress",addressDesc || "") + }, setTestTrue(state) { state.testvuex = true @@ -107,6 +119,16 @@ 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 @@ -114,6 +136,27 @@ console.log('sign_clear', key) state.sign[key] = 0 }, + cache_coupon_select: async function({ + commit, + state + }, dto) { + state.cache['coupon'] = dto || {} + }, + + cache_coupon_select_cancel: async function({ + commit, + state + }, val) { + state.cache['cache_coupon_select_cancel'] = val || 0 + }, + + cache_goods_select: async function({ + commit, + state + }, goods) { + state.cache['goods'] = goods || [] + }, + // lazy loading openid logout: async function({ commit, @@ -156,6 +199,7 @@ }) { //把权限获取到 // console.log('getCurrentInfo,getCurrentInfo') + const currentInfo = await http.request('get', '/api/current/user', {}) if (currentInfo && currentInfo.code == 0) { // state.cMenu = cMenu @@ -172,6 +216,80 @@ //这种情况就是要跳转到登录页面 } }, + + getSwitchSubAccount: async function({commit,state},payload) { + //把权限获取到 + // console.log('getCurrentInfo,getCurrentInfo') + + const currentInfo = await http.request('get', '/api/supplierSub/getSwitchById', { + params: { + id:payload.id + } + }) + if (currentInfo && currentInfo.code == 0) { + + state.currentInfo = currentInfo.data || {} + state.type = currentInfo.data.type || '' + state.spacecode = currentInfo.data.spacecode || '' + + commit("updateLogin", true) + } else { + commit("updateLogin", false) + //这种情况就是要跳转到登录页面 + } + + return currentInfo; + }, + + + getAppMenu: async function({ + commit, + state + }) { + //把权限获取到 + const menu = await http.request('get', '/api/app/menu/permission/menu', {}) + storage.setItem('appMenu', []); + if (menu && menu.code == 0) { + const appMenu = menu.data || [] + storage.setItem('appMenu', appMenu); + + // commit("updateLogin", true) + } else { + // commit("updateLogin", false) + //这种情况就是要跳转到登录页面 + } + }, + + getAppMenuSupplier: async function({ + commit, + state + }) { + //把权限获取到 + const menu = await http.request('get', '/api/app/menu/supplier/permission/menu', {}) + storage.setItem('appMenu', []); + if (menu && menu.code == 0) { + const appMenu = menu.data || [] + storage.setItem('appMenu', appMenu); + } else { + + } + }, + getAppMenuPartner: async function({ + commit, + state + }) { + //把权限获取到 + const menu = await http.request('get', '/api/app/menu/partner/permission/menu', {}) + storage.setItem('appMenu', []); + if (menu && menu.code == 0) { + const appMenu = menu.data || [] + storage.setItem('appMenu', appMenu); + } else { + + } + }, + + loginwx: async function({ dispatch, commit, @@ -262,6 +380,8 @@ storage.setItem('token', resp.data.access_token) commit("updateLogin", true) await dispatch('getCurrentInfo') + // 获取所有权限菜单 + await dispatch('getAppMenuPartner') uni.reLaunch({ url: '/pages/home/supplier-home' }) @@ -327,6 +447,8 @@ storage.setItem('token', resp.data.access_token) commit("updateLogin", true) await dispatch('getCurrentInfo') + // 获取所有供应商权限菜单 + await dispatch('getAppMenuSupplier') console.log('login,reLaunch') // #ifdef APP @@ -347,9 +469,7 @@ console.log("启用结果2:", ret); }); // #endif - // uni.redirectTo({ - // url: '/views/app/app-home/app-home' - // }) + uni.reLaunch({ url: '/pages/home/supplier-home' }) @@ -368,7 +488,8 @@ state }, data) { { - const resp = await http.request('post', '/api/login/customer' + ((data.phoneNumber || data.tel) ? '/phone' : ''), { + 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, @@ -385,6 +506,31 @@ 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') + } + } + + } + } catch (e) { + console.error('login ', e) + } + uni.reLaunch({ url: '/pages/home/home' }) @@ -398,29 +544,117 @@ }, submitShopping: async function({ commit, - dispatch + dispatch, + state }, 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 { - + if (!state.currentInfo.id) { + message.showToast('请先登录') + return } - return resp + //输入要添加多少个 + // 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) { + + } 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', {}) + 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 { -- Gitblit v1.9.3