// pages/usercenter/apply-shop/index.js Page({ /** * 页面的初始数据 */ data: { shopInfo: { ShopBusinessCategoryGuid: "", ShopName: "", ShopIntro: "", ShopLogo: [], ShopBusinessLicense: [], }, }, // 提交 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); }, 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 上 // // }); // }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })