diff --git a/pages/usercenter/apply-shop/index.js b/pages/usercenter/apply-shop/index.js index 7564ce1..a741233 100644 --- a/pages/usercenter/apply-shop/index.js +++ b/pages/usercenter/apply-shop/index.js @@ -5,22 +5,175 @@ Page({ * 页面的初始数据 */ data: { - logo: [], + shopInfo: { + ShopBusinessCategoryGuid: "", + ShopName: "", + ShopIntro: "", + ShopLogo: [], + ShopBusinessLicense: [], + }, }, - submit(){ - console.log(this.data.logo); + // 提交 + submit() { + console.log(this.data.shopInfo); + let data = this.data.shopInfo + data.ShopLogo = data.ShopLogo.map(item => item.url).join(',') + data.ShopBusinessLicense = data.ShopBusinessLicense.map(item => item.url).join(',') + console.log(data); }, - onCustomEvent(event) { - // console.log(event.detail,"获取子组件传递的值"); - // const receivedData = event.detail; // 获取子组件传递的值 - // this.setData({ - // fileList: receivedData // 将子组件传递的值绑定到父组件的 data 属性 fileList 上 - // }); + onChangeShopName(e) { + this.setData({ + "shopInfo.ShopName": e.detail.value + }) }, + onChangeShopIntro(e) { + this.setData({ + "shopInfo.ShopIntro": e.detail.value + }) + }, + + + // 上传Logo + handleAddLogo(e) { + const { + files + } = e.detail; + + // 每次选择图片都上传,展示每次上传图片的进度 + files.forEach(file => this.onUploadLogo(file)) + }, + + // 移除Logo + handleRemoveLogo(e) { + const { + index + } = e.detail; + const { + ShopLogo + } = this.data.shopInfo; + + ShopLogo.splice(index, 1); + this.setData({ + "shopInfo.ShopLogo": ShopLogo, + }); + }, + + // 上传ShopBusinessLicense + handleAddShopBusinessLicense(e) { + const { + files + } = e.detail; + + // 每次选择图片都上传,展示每次上传图片的进度 + files.forEach(file => this.onUploadShopBusinessLicense(file, this.data.shopInfo.ShopBusinessLicense)) + }, + + // 移除营业执照 + handleRemoveShopBusinessLicense(e) { + const { + index + } = e.detail; + const { + ShopBusinessLicense + } = this.data.shopInfo; + + ShopBusinessLicense.splice(index, 1); + this.setData({ + "shopInfo.ShopBusinessLicense": ShopBusinessLicense, + }); + }, + + + // 上传Logo方法 + onUploadLogo(file) { + let { + ShopLogo + } = this.data.shopInfo + + this.setData({ + "shopInfo.ShopLogo": [...ShopLogo, { + ...file, + status: 'loading' + }], + }); + const { + length + } = ShopLogo; + + const task = wx.uploadFile({ + url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 仅为示例,非真实的接口地址 + filePath: file.url, + name: 'file', + formData: { + fileDir: 'Shops' + }, + success: (res) => { + this.setData({ + [`shopInfo.ShopLogo[${length}].url`]: JSON.parse(res.data).data.url, + [`shopInfo.ShopLogo[${length}].status`]: 'done', + }); + // this.triggerEventToParent() + }, + }); + task.onProgressUpdate((res) => { + this.setData({ + [`shopInfo.ShopLogo[${length}].percent`]: res.progress, + }); + }); + }, + + + // 上传营业执照方法 + onUploadShopBusinessLicense(file) { + let { + ShopBusinessLicense + } = this.data.shopInfo + + this.setData({ + "shopInfo.ShopBusinessLicense": [...ShopBusinessLicense, { + ...file, + status: 'loading' + }], + }); + const { + length + } = ShopBusinessLicense; + + const task = wx.uploadFile({ + url: 'http://192.168.1.102:8888/api/Common/UploadFile', // 仅为示例,非真实的接口地址 + filePath: file.url, + name: 'file', + formData: { + fileDir: 'Shops' + }, + success: (res) => { + this.setData({ + [`shopInfo.ShopBusinessLicense[${length}].url`]: JSON.parse(res.data).data.url, + [`shopInfo.ShopBusinessLicense[${length}].status`]: 'done', + }); + // this.triggerEventToParent() + }, + }); + task.onProgressUpdate((res) => { + this.setData({ + [`shopInfo.ShopBusinessLicense[${length}].percent`]: res.progress, + }); + }); + }, + + + // onCustomEvent(event) { + // // console.log(event.detail,"获取子组件传递的值"); + // // const receivedData = event.detail; // 获取子组件传递的值 + // // this.setData({ + // // fileList: receivedData // 将子组件传递的值绑定到父组件的 data 属性 fileList 上 + // // }); + // }, + /** * 生命周期函数--监听页面加载 */ diff --git a/pages/usercenter/apply-shop/index.json b/pages/usercenter/apply-shop/index.json index 1ebd33f..da0ed45 100644 --- a/pages/usercenter/apply-shop/index.json +++ b/pages/usercenter/apply-shop/index.json @@ -2,8 +2,8 @@ "usingComponents": { "t-input": "tdesign-miniprogram/input/input", "t-textarea": "tdesign-miniprogram/textarea/textarea", - "upload": "/components/upload/index", "t-button": "tdesign-miniprogram/button/button", + "t-upload": "tdesign-miniprogram/upload/upload", "van-button": "@vant/weapp/button/index" }, "navigationBarTitleText": "申请开店" diff --git a/pages/usercenter/apply-shop/index.wxml b/pages/usercenter/apply-shop/index.wxml index 1fa30b0..24a76e5 100644 --- a/pages/usercenter/apply-shop/index.wxml +++ b/pages/usercenter/apply-shop/index.wxml @@ -3,30 +3,41 @@ - + - + - + + 营业执照 + + + diff --git a/services/usercenter/fetchUsercenter.js b/services/usercenter/fetchUsercenter.js index d4bc4c9..0a40089 100644 --- a/services/usercenter/fetchUsercenter.js +++ b/services/usercenter/fetchUsercenter.js @@ -4,10 +4,10 @@ import { import { getStorage } from '~/utils/storage' -const userData = getStorage('userInfo'); /** 获取个人中心信息 */ export function fetchUserCenter() { + const userData = getStorage('userInfo'); return new Promise((resolve, reject) => { request({ url: `CustomerApi/getCustomerDetails?CustomerGuid=` + userData?.customerGuid,