From 2744a8492dbbee8afc5f1be87017390edbe6828a Mon Sep 17 00:00:00 2001 From: donqi Date: Tue, 17 May 2022 16:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9D=80=E5=A2=9E=E5=88=A0=E6=94=B9?= =?UTF-8?q?=E6=9F=A5=EF=BC=8C=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=EF=BC=88?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E5=89=8D=EF=BC=89=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/globalData.js | 2 +- common/js/request.js | 146 +++++++++++++++++++++++------------ pages/my/edit-address.vue | 110 +++++++++++++++++++++----- pages/my/my-address.vue | 67 ++++++++++------ pages/order/order-detail.vue | 27 +++++-- pages/order/pay-result.vue | 12 ++- 6 files changed, 260 insertions(+), 104 deletions(-) diff --git a/common/js/globalData.js b/common/js/globalData.js index b134ea7..96de592 100644 --- a/common/js/globalData.js +++ b/common/js/globalData.js @@ -1,5 +1,5 @@ export default { - deptId: 1, + deptId: 101, initPageNum: 1, initPageSize: 5 } \ No newline at end of file diff --git a/common/js/request.js b/common/js/request.js index 78c996b..ad87764 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -6,6 +6,8 @@ export default { uni.addInterceptor('request', { invoke(args) { // request 触发前拼接 url + // args.url = 'https://www.opsoul.com' + args.url; + // args.url = 'http://192.168.2.3:80' + args.url; args.url = 'http://127.0.0.1:80' + args.url; // console.log("停止触发"); // return false; @@ -60,52 +62,56 @@ export default { }) }, async login() { - // 从缓存中获取登录信息 - let userInfo = uni.getStorageSync('userProfile'); - if (userInfo) { - return true; - } - - // 获取微信登录凭证 - const wxLoginRes = await wx.login(); - console.log(wxLoginRes) - const wxAuthRes = await uni.request({ - url: '/wx/auth', - header: { - code: wxLoginRes.code - } - }) - console.log(wxAuthRes) - // TODO:调用小程序服务端确认是否是授权登录过的用户 - let loginRes = { - logined: false, - userInfo: {} - }; - // 未登录过的获取微信用户信息 - if (!loginRes || !loginRes.logined) { - userInfo = await wx.getUserProfile({ - desc: '用于小程序登录' - }); - // 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回 - loginRes = { - logined: true, - userInfo: { - userId: 1, - wxLoginCode: wxLoginRes.code, - openId: wxAuthRes[1].data.data.openid - } - }; - } - userInfo = loginRes.userInfo; - if (!userInfo) { - uni.showToast({ - icon: 'error', - title: '用户信息获取失败,请退出小程序重试' - }) - return false; - } - // 页面存储用户登录有效信息,以便其他页面调用 - uni.setStorageSync('userProfile', userInfo); + // 从缓存中获取登录信息 + let userInfo = uni.getStorageSync('userProfile'); + if (userInfo) { + return true; + } + + // TODO:调用小程序服务端确认是否是授权登录过的用户 + let loginRes = { + logined: false, + userInfo: {} + }; + // 未登录过的获取微信用户信息 + if (!loginRes.logined) { + userInfo = await wx.getUserProfile({ + desc: '用于小程序登录' + }); + // 获取微信登录凭证 + const wxLoginRes = await wx.login(); + console.log(wxLoginRes) + // 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回 + loginRes = { + logined: true, + userInfo: { + ...userInfo, + userId: 1, + wxLoginCode: wxLoginRes.code + } + }; + + const wxAuthRes = await uni.request({ + url: '/wx/auth', + header: { + code: wxLoginRes.code + } + }) + console.log(wxAuthRes) + loginRes.userInfo.openId = wxAuthRes[1].data.data.openid; + loginRes.userInfo.customerId = 2; + } + userInfo = loginRes.userInfo; + + if (!userInfo) { + uni.showToast({ + icon: 'error', + title: '微信用户信息获取失败,请退出小程序重试' + }) + return false; + } + // 页面存储用户登录有效信息,以便其他页面调用 + uni.setStorageSync('userProfile', userInfo); return true; }, wxLogin() { @@ -113,7 +119,6 @@ export default { }, getCurUserInfo() { let userProfile = uni.getStorageSync('userProfile'); - console.log("curUser:" + userProfile) return userProfile; }, getProductCategories(params = {}) { @@ -152,5 +157,50 @@ export default { } }) return res[1].data; - }, + }, + async getAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/list', + method: 'POST', + data: params + }) + return res[1].data; + }, + async addAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/insert', + method: 'POST', + data: params + }) + return res[1].data; + }, + async editAddressList(params = {}) { + let res = await uni.request({ + url: '/customer/address/update', + method: 'POST', + data: params + }) + return res[1].data; + }, + async delAddressList(customerAddressId) { + let res = await uni.request({ + url: '/customer/address/delete', + method: 'POST', + data: { + customerAddressId: customerAddressId + }, + header: { + 'content-type': 'application/x-www-form-urlencoded' + } + }) + return res[1].data; + }, + async areaListByStep(params = { parentCode: null }) { + let res = await uni.request({ + url: '/system/area/list', + method: 'POST', + data: params + }) + return res[1].data; + } } diff --git a/pages/my/edit-address.vue b/pages/my/edit-address.vue index 9c70a0a..e0a9160 100644 --- a/pages/my/edit-address.vue +++ b/pages/my/edit-address.vue @@ -10,30 +10,31 @@
联系人 - + 手机号码 - + 地址选择 - + - {{areaList[0][multiIndex[0]].name}},{{areaList[1][multiIndex[1]].name}},{{areaList[2][multiIndex[2]].name}} + {{formData.area && formData.area.length ? formData.area[0].areaName + '-' + formData.area[1].areaName + '-' + formData.area[2].areaName : '请选择'}} 详细地址 - + - 默认地址 + 默认地址 + + :checked="formData.isDefault?true:false" name="isDefault" :value="formData.isDefault" v-model="formData.isDefault"> @@ -52,7 +53,7 @@ multiIndex: [0, 0, 0], formData: { }, - mode: 1 // 1为新增,0 + mode: 1 // 1为新增,0为修改 } }, onLoad(options) { @@ -67,10 +68,24 @@ }, methods: { async loadData() { - this.areaList = await this.$api.data('areaList'); + // this.areaList = await this.$api.data('areaList'); + this.loadAreaList(); }, fillForm(addressInfo) { this.formData = addressInfo && Object.keys(addressInfo).length > 0 ? addressInfo : this.formData; + }, + async loadAreaList(idArr) { + let areaList = await this.$request.areaListByStep(); + areaList = areaList.data; + let col1Code = idArr ? idArr[0] : areaList[0].areaCode; + let subAreaList = await this.$request.areaListByStep({ parentCode: col1Code }); + subAreaList = subAreaList.data; + let col2Code = idArr ? idArr[1] : subAreaList[0].areaCode; + let subSubAreaList = await this.$request.areaListByStep({ parentCode: col2Code }); + subSubAreaList = subSubAreaList.data; + this.areaList.push(areaList); + this.areaList.push(subAreaList); + this.areaList.push(subSubAreaList); }, regionChange(e) { this.multiIndex = e.detail.value; @@ -78,15 +93,44 @@ for(let i = 0; i < this.areaList.length; i++) { chosenArea.push(this.areaList[i][this.multiIndex[i]]); } - this.formData.area = chosenArea; + this.formData.area = chosenArea; + this.formData.provinceId = chosenArea[1].areaId; + this.formData.cityId = chosenArea[2].areaId; + this.formData.countryId = chosenArea[0].areaId; + }, + async regionColChange(e) { + let colObj = e.detail; + if (colObj.column == 0) { + let subSubAreaList = []; + // 通过一级查询二级,通过二级查三级 + let subAreaList = await this.$request.areaListByStep({parentCode: this.areaList[0][colObj.value].areaCode}); + subAreaList = subAreaList.data; + if (subAreaList && subAreaList.length) { + subSubAreaList = await this.$request.areaListByStep({parentCode: subAreaList[0].areaCode}); + subSubAreaList = subSubAreaList.data; + } + this.areaList.pop(); + this.areaList.pop(); + this.areaList.push(subAreaList); + this.areaList.push(subSubAreaList); + this.multiIndex = [colObj.value, 0, 0]; + } else if (colObj.column == 1) { + // 通过二级查三级 + let subSubAreaList = await this.$request.areaListByStep({parentCode: subAreaList[0].areaCode}); + subSubAreaList = subSubAreaList.data; + this.areaList.pop(); + this.areaList.push(subSubAreaList); + this.multiIndex = [this.multiIndex[0], colObj.value, 0]; + } }, isDefaultChange(e) { this.formData.isDefault = e.detail.value; }, validateForm(addressInfo) { - let valid = Boolean(addressInfo.person2Contact) && + let valid = Boolean(addressInfo.name) && Boolean(addressInfo.phone) && - Boolean(addressInfo.address); + Boolean(addressInfo.address) && + Boolean(addressInfo.area) && addressInfo.area.length > 0 if (!valid) { uni.showToast({ @@ -104,15 +148,43 @@ } return valid; }, - submit(e) { + async submit(e) { const confirmFormData = Object.assign({}, this.formData, e.detail.value) let formValid = this.validateForm(confirmFormData); - if (formValid) { - uni.showToast({ - title: '保存成功', - icon: 'success', - mask: true - }) + if (formValid) { + let isSuccess = false; + if (this.mode === 1) { + let res = await this.$request.addAddressList({ + ...this.formData, + customerId: this.$request.getCurUserInfo().customerId, + isDefault: this.formData.isDefault ? 1 : 0 + }); + if (res.code === 0) { + isSuccess = true; + } + } else if (this.mode === 0) { + let res = await this.$request.editAddressList({ + ...this.formData, + customerId: this.$request.getCurUserInfo().customerId, + isDefault: this.formData.isDefault ? 1 : 0 + }); + if (res.code === 0) { + isSuccess = true; + } + } + if (isSuccess) { + uni.showToast({ + title: '保存成功', + icon: 'success', + mask: true + }) + } else { + uni.showToast({ + title: '保存失败', + icon: 'error', + mask: true + }) + } } } } diff --git a/pages/my/my-address.vue b/pages/my/my-address.vue index f5789a6..4b54316 100644 --- a/pages/my/my-address.vue +++ b/pages/my/my-address.vue @@ -11,39 +11,28 @@ 默认 - - {{areaObj.name}} + {{item.countryName}} + {{item.provinceName}} + {{item.cityName}} {{item.address}} - {{item.person2Contact}} + {{item.name}} {{item.phone}} - + - + - - - - 是否删除该地址? - - - 取消 - 确定 - - - - + @@ -54,7 +43,6 @@ myAddressList: [], modalName: '', delAddressInfo: {}, - delAddressIndex: 0, chooseMode: false } }, @@ -62,15 +50,21 @@ if (Boolean(options)) { this.chooseMode = options.chooseMode === 'true' ? true : false; } - this.loadData(); this.bindEvent(); }, + onShow() { + this.loadData(); + }, onUnload() { this.offBindEvent(); }, methods: { async loadData() { - this.myAddressList = await this.$api.data('myAddressList'); + // this.myAddressList = await this.$api.data('myAddressList'); + let res = await this.$request.getAddressList({ + customerId: this.$request.getCurUserInfo().customerId + }); + this.myAddressList = res.data; }, bindEvent() { uni.$on(this.$globalFun.CONFIRM, this.delAddress); @@ -83,6 +77,16 @@ let params = null; if (addressInfo) { // 修改 + addressInfo.area = [{ + areaId: addressInfo.countryId, + areaName: addressInfo.countryName + }, { + areaId: addressInfo.provinceId, + areaName: addressInfo.provinceName + }, { + areaId: addressInfo.cityId, + areaName: addressInfo.cityName + }] params = { addressInfo: addressInfo, mode: 0 @@ -97,13 +101,26 @@ url: '/pages/my/edit-address?params=' + encodeURIComponent(JSON.stringify(params)) }) }, - confirm2DelAddress(addressInfo, index) { + confirm2DelAddress(addressInfo) { this.delAddressInfo = addressInfo; - this.delAddressIndex = index; this.$refs.confirmModal.showModal(); }, - delAddress() { - this.myAddressList = this.myAddressList.slice(0, this.delAddressIndex).concat(this.myAddressList.slice(++this.delAddressIndex)); + async delAddress() { + let res = await this.$request.delAddressList(this.delAddressInfo.customerAddressId); + if (res.code === 0) { + uni.showToast({ + title: '删除成功', + icon: 'success', + mask: true + }) + this.loadData(); + } else { + uni.showToast({ + title: '删除失败', + icon: 'error', + mask: true + }) + } }, showModal(e) { this.modalName = typeof e === 'string' ? e : e.currentTarget.dataset.target diff --git a/pages/order/order-detail.vue b/pages/order/order-detail.vue index 1bc794d..ca5c653 100644 --- a/pages/order/order-detail.vue +++ b/pages/order/order-detail.vue @@ -9,14 +9,14 @@ - - - {{areaObj.name}} - + + {{formInfo.defaultAddress.countryName}} + {{formInfo.defaultAddress.provinceName}} + {{formInfo.defaultAddress.cityName}} {{formInfo.defaultAddress.address}} - {{formInfo.defaultAddress.person2Contact}} + {{formInfo.defaultAddress.name}} {{formInfo.defaultAddress.phone}} @@ -95,7 +95,10 @@ - 是否需要发票 + + 是否需要发票 + 需开具发票请在下面备注发票信息 +