From acc7ee230ce5fe24f0e2b4283cf92032aac82fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E9=B9=8F?= <1242402566@qq.com> Date: Mon, 25 May 2020 23:36:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8E=A8=E8=8D=90=EF=BC=8C=E6=96=B0=E5=A2=9E=E9=AA=8C?= =?UTF-8?q?=E5=85=89=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/cart/cart.vue | 124 ++++------------ src/pages/newOpticsData/newOpticsData.vue | 238 ++++++++++++++++++++---------- src/pages/user/user.vue | 1 + src/store/modules/cart.js | 11 +- 4 files changed, 191 insertions(+), 183 deletions(-) diff --git a/src/pages/cart/cart.vue b/src/pages/cart/cart.vue index 2e6b207..b2329a8 100644 --- a/src/pages/cart/cart.vue +++ b/src/pages/cart/cart.vue @@ -93,8 +93,8 @@ export default { computed: { cartList() { - // console.log('cart-list', this.$store.state.cart.cartList); - return this.$store.state.cart.cartList + // console.log('cart-list', this.$store.state.cart.cartList); + return this.$store.state.cart.cartList }, childIsOpen() { const temp = [] @@ -107,97 +107,24 @@ export default { } }, onLoad: function() { - // 判断是否授权 - // uni.getSetting({ - // success(res) { - // console.log('authSetting',res.authSetting) - // if(res.authSetting['scope.userInfo'] !== true) { - - // uni.switchTab({ - // url:'/pages/user/user' - // }) - // }else { - // } - // } - // }) - - // console.log('usr-my',this.$store.state.user.userInfo) - // store.dispatch('cart/addCart',{ - // "num":1, - // "pid": 7,//产品id - // "uid":1, - // "sk_id": 72, - // "price": 120, - // "mp_id":1, - // "checkedSKU":{ - // "discount": "45", - // "in_price": "6000", - // "kc": "0", - // "model_pic": null, - // "out_price": 191.8, - // "pic": "https://glass.xiuyetang.com//upload_jk/7/7_22AE0C.jpg", - // "pid": "7", - // "real_price": 99, - // "sk_id": "89", - // "sku_name": "1.56非球面防蓝光_黑", - // "sku_shop_value": "", - // "sku_value": "58_61", - // "status": "1", - // }, - // }); + // store.dispatch('cart/addCart', { + // uid: this.$store.state.user.userInfo.uid, + // openid: this.$store.state.user.userInfo.openid, + // mp_id: 7, + // sk_id: 7, + // num: 1, + // pid: 8, + // price: 128, + // checkedSKU:{}, + // }) store.dispatch('cart/getCartList', { - uid: 1 // 用户id + uid: this.$store.state.user.userInfo.uid // 用户id }) + }, methods: { - // 跳转到对应的选购页面 - // toshop(id,type){ - // console.log('===',id,type) - // switch(type){ - // case 1: - // uni.navigateTo({ - // url: `../detailsChoiceArgs/detailsChoiceArgs?oderId=`+id+`&goodType=`+type, - // success: res => {}, - // fail: () => {}, - // complete: () => {} - // }); - // break; - // case 2: - // uni.navigateTo({ - // url: `../detailStandard/detailStandard_k?oderId=`+id+`&goodType=`+type, - // success: res => {}, - // fail: () => {}, - // complete: () => {} - // }); - // break; - // case 3||4: - // uni.navigateTo({ - // url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type, - // success: res => {}, - // fail: () => {}, - // complete: () => {} - // }); - // break; - // // case 4: - // // uni.navigateTo({ - // // url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type, - // // success: res => {}, - // // fail: () => {}, - // // complete: () => {} - // // }); - // case 5: - // uni.navigateTo({ - // url: `../purchaseLenses/purchaseLenses?oderId=`+id+`&goodType=`+type, - // success: res => {}, - // fail: () => {}, - // complete: () => {} - // }); - // break; - // default : - // break - // } - // }, + toGoods(id, type) { uni.navigateTo({ url: '../frameDetail/frameDetail?oderId=' + id, @@ -254,9 +181,12 @@ export default { } else { this.addDisabled = true // 修改num + if(this.childIsOpen[index]){ + this.totalPrice = this.totalPrice + this.$store.state.cart.cartList[index].nowPrice + } store.dispatch('cart/modiCart', { - uid: 1, - // openid: '', + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, mp_id: mp_id, sk_id: sk_id, cart_id: cart_id, @@ -274,9 +204,12 @@ export default { } else { this.desDisabled = false // post 请求修改相关参数 + if(this.childIsOpen[index]){ + this.totalPrice = this.totalPrice - this.$store.state.cart.cartList[index].nowPrice + } store.dispatch('cart/modiCart', { - uid: 1, - // openid: '', + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, mp_id: mp_id, sk_id: sk_id, cart_id: cart_id, @@ -289,6 +222,9 @@ export default { this.desDisabled = true } } + // store.dispatch('cart/getCartList', { + // uid: this.$store.state.user.userInfo.uid // 用户id + // }) }, Change(isopen, indexC) { @@ -340,8 +276,8 @@ export default { if (res.confirm) { // this.$store.state.cart.cartList.splice(index,1) store.dispatch('cart/delCart', { - uid: 1, // 用户id - openid: '', + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, cart_id: cart_id, // 要修改的购物车id arg: index // 由于action 传参是能接收两参数,因此将index放入对象 }) diff --git a/src/pages/newOpticsData/newOpticsData.vue b/src/pages/newOpticsData/newOpticsData.vue index afec571..48d352a 100644 --- a/src/pages/newOpticsData/newOpticsData.vue +++ b/src/pages/newOpticsData/newOpticsData.vue @@ -161,13 +161,14 @@ confirm: false, // 用户是否确认 tabicon:['/static/detail-button.png','/static/detail-button-unselected.png'], name: '夏小花', + oldname:'',// 用于判读用户是否改变名字 pickerInfoChioce:{ - "leftSph": 0, - "rightSph": 0, - "leftCyl": 0, - "rightCyl": 0, - "leftAxi": 0, - "rightAxi": 0, + "leftSph": '', + "rightSph": '', + "leftCyl": '', + "rightCyl": '', + "leftAxi": '', + "rightAxi": '', "time":{ "year":0, "month": 0, @@ -175,6 +176,7 @@ } }, pd: '',// 瞳距 + oldpd: '',// 用于判断用户是否改变瞳距 kinds:Number, // kinds=1,提交为新增验光,2为修改 mp_id: Number }; @@ -225,6 +227,8 @@ this.name=loveList[option.index].name this.pd=loveList[option.index].pd this.mp_id=loveList[option.index].mp_id + this.oldname=loveList[option.index].name + this.oldpd=loveList[option.index].pd // 将kinds =2时的值传到该页面 this.pickerInfoList[0].nameArray1.unshift(loveList[option.index].leftSph) this.pickerInfoList[0].nameArray2.unshift(loveList[option.index].rightSph) @@ -258,7 +262,7 @@ uni.showToast({ title:"请输入有效数据;示例:89", icon: "none", - duration: 3000, + duration: 2000, }) this.pd = '' } @@ -270,88 +274,158 @@ uni.showToast({ title:"请输入验光单取名", icon: "none", - duration: 3000, + duration: 2000, }) - } - if(this.pd==''){ - uni.showToast({ - title:"请输入瞳距", - icon: "none", - duration: 3000, - }) - } - if(this.confirm){ - if(this.kinds==1){ - // 添加用户验光单 - console.log('kinds====>',this.kinds) - store.dispatch('myLoveList/addMylove', { - - uid: this.$store.state.user.userInfo.uid, - openid: this.$store.state.user.userInfo.openid, - // mp_name: this.$store.state.user.userInfo.mp_name, - leftSph: this.pickerInfoChioce.leftSph, - rightSph: this.pickerInfoChioce.rightSph, - leftCyl: this.pickerInfoChioce.leftCyl, - rightCyl: this.pickerInfoChioce.rightCyl, - leftAxi: this.pickerInfoChioce.leftAxi, - rightAxi: this.pickerInfoChioce.rightAxi, - pd: this.pd,// 瞳距 - mp_name:this.name, - // time: this.pickerInfoChioce.time, - // img_url2: "http://localhost:8087/images/shop_1/1/", - }); - store.dispatch('myLoveList/getLoveList', { - uid: this.$store.state.user.userInfo.uid, - }); - uni.navigateBack({ - delta:1, - animationDuration:2000 - }) - } - if(this.kinds==2){ - // console.log('kinds====>',this.kinds) - // console.log('pickerindex=====>',this.pickerInfoList[0].nameIndex1) - // console.log('this.pickerInfoChioce====>',type(this.pickerInfoChioce)) - const leftList = ["leftSph","leftCyl","leftAxi"]; - const rightList = ["rightSph", "rightCyl", "rigthAxi"]; - for (let j=0; j<3; j++) { - if(this.pickerInfoList[j].nameIndex1!=0){ + }else{ + + if(this.pd==''){ + uni.showToast({ + title:"请输入瞳距", + icon: "none", + duration: 2000, + }) + }else{ + + if(this.kinds==1){ + // 添加用户验光单 + console.log('kinds====>',this.pickerInfoChioce.leftSph) + console.log('kinds====>',this.pickerInfoChioce.leftSph==Number) + console.log('kinds====>',this.pickerInfoChioce.rightSph==Number) + if(this.pickerInfoChioce.rightSph==''||this.pickerInfoChioce.leftSph==''|| + this.pickerInfoChioce.leftCyl==''||this.pickerInfoChioce.rightCyl==''|| + this.pickerInfoChioce.leftAxi==''||this.pickerInfoChioce.rightAxi=='' + ){ + uni.showToast({ + title:"请输入您的验光数据", + icon: "none", + duration: 2000, + }) + }else{ + if(this.confirm){ + store.dispatch('myLoveList/addMylove', { + + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, + // mp_name: this.$store.state.user.userInfo.mp_name, + leftSph: this.pickerInfoChioce.leftSph, + rightSph: this.pickerInfoChioce.rightSph, + leftCyl: this.pickerInfoChioce.leftCyl, + rightCyl: this.pickerInfoChioce.rightCyl, + leftAxi: this.pickerInfoChioce.leftAxi, + rightAxi: this.pickerInfoChioce.rightAxi, + pd: this.pd,// 瞳距 + mp_name:this.name, + // time: this.pickerInfoChioce.time, + // img_url2: "http://localhost:8087/images/shop_1/1/", + }); + store.dispatch('myLoveList/getLoveList', { + uid: this.$store.state.user.userInfo.uid, + }); + uni.navigateBack({ + delta:1, + animationDuration:2000 + }) + + } else{ + uni.showToast({ + title:"请确认您的验光数据", + icon: "none", + duration: 3000, + }) + } - store.dispatch('myLoveList/updateMylove', { - uid: this.$store.state.user.userInfo.uid, - openid: this.$store.state.user.userInfo.openid, - mp_id: this.mp_id, - keyname: leftList[j], - keyvalue: this.pickerInfoList[j].nameArray1[this.pickerInfoList[j].nameIndex1], - }); - } - if(this.pickerInfoList[j].nameIndex2 !=0) { - store.dispatch('myLoveList/updateMylove', { - uid: this.$store.state.user.userInfo.uid, - openid: this.$store.state.user.userInfo.openid, - mp_id: this.mp_id, - keyname: rightList[j], - keyvalue: this.pickerInfoList[j].nameArray2[this.pickerInfoList[j].nameIndex2] - }); } + } - store.dispatch('myLoveList/getLoveList', { - uid: this.$store.state.user.userInfo.uid, - }); - uni.navigateBack({ - delta:1, - animationDuration:2000 - }) + if(this.kinds==2){ + // console.log('kinds====>',this.kinds) + // console.log('pickerindex=====>',this.pickerInfoList[0].nameIndex1) + // console.log('this.pickerInfoChioce====>',type(this.pickerInfoChioce)) + if(this.confirm){ + const leftList = ["leftSph","leftCyl","leftAxi"]; + const rightList = ["rightSph", "rightCyl", "rightAxi"]; + let flag=0; + if(this.name!=this.oldname){ + store.dispatch('myLoveList/updateMylove', { + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, + mp_id: this.mp_id, + keyname: 'name', + keyvalue: this.name, + }); + flag=1 + } + if(this.pd!=this.oldpd){ + store.dispatch('myLoveList/updateMylove', { + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, + mp_id: this.mp_id, + keyname: 'pd', + keyvalue: this.pd, + }); + flag=1 + } + // 先验证是否有改动项, + for (let j=0; j<3; j++) { + if(this.pickerInfoList[j].nameIndex1!=0||this.pickerInfoList[j].nameIndex2!=0){ + if(this.pickerInfoList[j].nameArray1[this.pickerInfoList[j].nameIndex1]!=''&& + this.pickerInfoList[j].nameArray2[this.pickerInfoList[j].nameIndex2]!=''){ + if(this.pickerInfoList[j].nameIndex1!=0){ + store.dispatch('myLoveList/updateMylove', { + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, + mp_id: this.mp_id, + keyname: leftList[j], + keyvalue: this.pickerInfoList[j].nameArray1[this.pickerInfoList[j].nameIndex1], + }); + } + if(this.pickerInfoList[j].nameIndex2!=0){ + store.dispatch('myLoveList/updateMylove', { + uid: this.$store.state.user.userInfo.uid, + openid: this.$store.state.user.userInfo.openid, + mp_id: this.mp_id, + keyname: rightList[j], + keyvalue: this.pickerInfoList[j].nameArray2[this.pickerInfoList[j].nameIndex2] + }); + } + flag=1; + } else{ + flag=0; + uni.showToast({ + title:"请输入您的验光数据", + icon: "none", + duration: 2000, + }) + + } + } + + } + if(flag!=0){ + store.dispatch('myLoveList/getLoveList', { + uid: this.$store.state.user.userInfo.uid, + }); + uni.navigateBack({ + delta:1, + animationDuration:2000 + }) + } + } else{ + uni.showToast({ + title:"请确认您的验光数据", + icon: "none", + duration: 3000, + }) + } + + } + + } - - } else{ - uni.showToast({ - title:"请确认你的验光数据", - icon: "none", - duration: 3000, - }) + } + }, changeConfirm() { this.confirm = !this.confirm diff --git a/src/pages/user/user.vue b/src/pages/user/user.vue index 2b94d97..4a2cacd 100644 --- a/src/pages/user/user.vue +++ b/src/pages/user/user.vue @@ -572,6 +572,7 @@ export default { display: flex; justify-content: space-between; flex-wrap: wrap; + height: 400px; .product { width: 48%; margin: 0 0 20rpx 0; diff --git a/src/store/modules/cart.js b/src/store/modules/cart.js index c5d9c21..002986c 100644 --- a/src/store/modules/cart.js +++ b/src/store/modules/cart.js @@ -20,11 +20,7 @@ const mutations = { MODI: (state, args) => { console.log('the num', state.cartList[args.index].num) console.log('mutations====>isadd', args) - if (args.isadd) { - state.cartList[args.index].num = args.num - } else { - state.cartList[args.index].num = args.num - } + state.cartList[args.index].num = args.num console.log('the num', state.cartList[args.index].num) } @@ -53,14 +49,15 @@ const actions = { }, modiCart({ commit }, param) { - const args = Object.assign({ num: param.num }, param.args) + const arg = Object.assign({ num: param.num }, param.args) delete param.args request({ url: cartModi, data: param, success: (res) => { + console.log('modiCart-res=====>',res.data) console.log('modi-parm', param) - commit('MODI', args) + commit('MODI', arg) }, fail: (res) => { console.log('fail status === > ', res) -- 2.0.0