let Parse = getApp().Parse; const company = getApp().globalData.company const qiniuUploader = require("../../../../../../utils/qiniuUploader"); Page({ /** * 页面的初始数据 */ data: { imageList: [],//商店首页 licenseList: [],//店铺图片 merchant: null, store: null, stores: null, perCapita: null, cover: '', image: [], storeName: null, perCapita: null, desc: null, name: null, workingTime: null, uploadURL: null, domain: null, uptokenURL: null, html: null, content: null, id: null, address:'', locations:null, }, getHtml(e) { //从组件获取值 let html = e.detail.content.html console.log(html); // this.setData({ html: html }) // let field = event.currentTarget.dataset.field; // let html = event.detail.content.html; this.setData({ html: html }) }, insertImage() { //图片上传插入示例 let that = this wx.chooseImage({ count: 1, success(res) { // 本地测试图片插入 // this.selectComponent('#hf_editor').insertSrc(res.tempFilePaths[0]); // console.log(res.tempFilePaths[0]); let tempFilePaths = res.tempFilePaths[0]; console.log(tempFilePaths); qiniuUploader.upload( tempFilePaths, (res) => { let img = res.imageURL; that.selectComponent('#hf_editor').insertSrc(img); //调用组件insertSrc方法 }, (error) => { console.log("error: " + error); }, { region: "SCN", uploadURL: that.data.uploadURL, domain: that.data.domain, uptoken: that.data.uptokenURL, } ); } }) }, changeFile(e) { if (e.detail && e.detail.length > 0) { this.setData({ cover: [e.detail[0].url] }) } else { this.setData({ cover: [] // cover:this.data.imageList[0].url }) } }, changeFiles(e) { if (e.detail && e.detail.length > 0) { this.setData({ image: e.detail }) console.log('图片',this.data.image); } else { this.setData({ image: [] }) } }, blur(e) { let name = e.currentTarget.dataset.name this.setData({ [name]: e.detail.value }) }, mobile() { let id = this.data.store.objectId console.log(id); wx.navigateTo({ url: '../account/mobile/index?id=' + id }); }, password() { let id = this.data.store.objectId console.log(id); wx.navigateTo({ url: '../account/password/index?id=' + id }); }, async determine() { let image = [] if(this.data.image[0].url){ for (let index = 0; index < this.data.image.length; index++) { let item = this.data.image[index]; image.push(item.url) } // 设置图片格式判断 console.log('店铺图片',image); }else{ image=this.data.image } console.log(this.data.name, image, this.data.storeName, this.data.perCapita, this.data.desc, this.data.workingTime, this.data.html); let query = new Parse.Query("ShopStore") let ShopStore = await query.get(this.data.id) // ShopStore.set("perCapita", this.data.perCapita) ShopStore.set("name", this.data.name) ShopStore.set("cover", this.data.cover) ShopStore.set("image", image) if(this.data.locations){ ShopStore.set("location", this.data.locations) }else{ wx.showToast({ title: '请选择民宿地址', icon: 'none' }) return } ShopStore.set("storeName", this.data.storeName) if(Number(this.data.perCapita)){ ShopStore.set("perCapita", Number(this.data.perCapita)) }else{ wx.showToast({ title: '请输入正确人均消费', icon: 'none' }) return } ShopStore.set("desc", this.data.desc) ShopStore.set("workingTime", this.data.workingTime) ShopStore.set("content", this.data.html) ShopStore.save().then(res => { console.log(res) wx.showToast({ title: '修改成功', icon: 'none' }) setTimeout(()=>{ wx.navigateBack({ delta: 1 }); },1000) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: async function(options) { let merchant = wx.getStorageSync('merchant'); //用户 let ShopStore = new Parse.Query('ShopStore') ShopStore.notEqualTo('isDeleted', "true") ShopStore.equalTo('company',company) ShopStore.include('user') ShopStore.equalTo('user',merchant.objectId) let store = await ShopStore.first() store = store.toJSON() console.log(store); let imageList = [] let licenseList = [] // store.cover[0].forEach(i => { imageList.push({ url: store.cover }) // }) console.log(imageList); store.image.forEach(i => { licenseList.push({ url: i }) }) this.setData({ imageList: imageList, store: store, cover: store.cover, image: store.image, // perCapita: store.perCapita, storeName: store.storeName, perCapita: store.perCapita, desc: store.desc, name: store.name, workingTime: store.workingTime, html: store.content, id: store.objectId, licenseList: licenseList, }) console.log('首页',this.data.perCapita); this.selectComponent('#hf_editor').setHtml(this.data.html); this.getQiniuOption() }, async getQiniuOption() { let uploadData = await this.getUptoken() if (uploadData) { this.setData({ uploadURL: uploadData.zoneUrl, domain: uploadData.domain, uptokenURL: uploadData.uptoken, }) } console.log(this.data.uploadURL, this.data.domain, this.data.uptokenURL); }, getUptoken() { return Parse.Cloud.run('qiniu_uptoken', { company: company }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, chooseGeoPoint() { wx.chooseLocation({ latitude: 0, longitude: 0, success: (res) => { let { latitude, longitude, address, name } = res; let locations = new Parse.GeoPoint(latitude, longitude) this.setData({ locations, address:address }) console.log(locations); console.log(address + name); // this.data.formData[field] = locations // this.data.formData['address'] = address + name // this.data.formData['address'] = address // this.setData({ // formData: this.data.formData, // }) } }) }, })