222 lines
5.5 KiB
JavaScript
222 lines
5.5 KiB
JavaScript
import _ from '../../commons/js/commons'
|
||
const app = getApp()
|
||
Page({
|
||
data: {
|
||
tabs_id:'',
|
||
tab:[],
|
||
isEdit:false,
|
||
},
|
||
onLoad: function (options) {
|
||
for (let key in options) {
|
||
this.setData({
|
||
[key]: options[key]
|
||
})
|
||
}
|
||
this.getAppBizSituation_tabs()
|
||
},
|
||
onShow: function () {
|
||
|
||
},
|
||
//店铺概况_tab
|
||
getAppBizSituation_tabs(){
|
||
_.apiQuery.getAppBizSituation_tabs().then(res => {
|
||
this.setData({
|
||
tab:res.data,
|
||
tabs_id:this.data.tabs_id==''?res.data[0].id:this.data.tabs_id,
|
||
})
|
||
|
||
this.getAppBizSituation()
|
||
wx.stopPullDownRefresh()
|
||
|
||
});
|
||
},
|
||
//店铺概况
|
||
getAppBizSituation(){
|
||
let params = {};
|
||
params['tabs_id'] = this.data.tabs_id;
|
||
_.apiQuery.getAppBizSituation(params).then(res => {
|
||
let info = res.data
|
||
info.forEach((item1,i) => {
|
||
if(item1.type=='select'){
|
||
item1.optionsArr=[]
|
||
item1.list.forEach((item2,k) => {
|
||
item1.optionsArr.push(item2.name)
|
||
if(item1.value==item2.id){
|
||
item1.index=k
|
||
}
|
||
})
|
||
}
|
||
})
|
||
this.setData({
|
||
isEdit:false,
|
||
info:res.data,
|
||
})
|
||
});
|
||
},
|
||
//切换tab
|
||
changeTab(e){
|
||
let that = this
|
||
if(that.data.tabs_id!=that.data.tab[e.currentTarget.dataset.index].id){
|
||
if(that.data.isEdit){
|
||
wx.showModal({
|
||
title:'修改还没保存哦~!',
|
||
confirmText:'保存修改',
|
||
cancelText:'不保存',
|
||
confirmColor: "#36afa2",
|
||
cancelColor: "#666",
|
||
success(res) {
|
||
if (res.confirm) {
|
||
that.postAppBizSituation()
|
||
} else if (res.cancel) {
|
||
that.setData({
|
||
tabs_id:that.data.tab[e.currentTarget.dataset.index].id,
|
||
})
|
||
that.getAppBizSituation()
|
||
}
|
||
}
|
||
})
|
||
}else{
|
||
that.setData({
|
||
tabs_id:that.data.tab[e.currentTarget.dataset.index].id,
|
||
})
|
||
that.getAppBizSituation()
|
||
}
|
||
}
|
||
},
|
||
// 输入
|
||
inputTx(e) {
|
||
this.data.info[e.currentTarget.dataset.i].value = e.detail.value
|
||
this.setData({
|
||
isEdit:true,
|
||
info:this.data.info,
|
||
})
|
||
},
|
||
//选择
|
||
pickerChange(e){
|
||
this.data.info[e.currentTarget.dataset.i].index = e.detail.value
|
||
this.data.info[e.currentTarget.dataset.i].value = this.data.info[e.currentTarget.dataset.i].list[e.detail.value].id
|
||
this.setData({
|
||
isEdit:true,
|
||
info:this.data.info,
|
||
})
|
||
if(this.data.info[e.currentTarget.dataset.i].field=='county_id'){
|
||
this.getAppBizStreet(this.data.info[e.currentTarget.dataset.i].value)
|
||
}
|
||
|
||
},
|
||
//获取乡镇
|
||
getAppBizStreet(id){
|
||
let params = {};
|
||
params['id'] = id;
|
||
_.apiQuery.getAppBizStreet(params).then(res => {
|
||
let info = this.data.info
|
||
let list = res.data
|
||
info.forEach((item1,i) => {
|
||
if(item1.field=='street_id'){
|
||
let optionsArr=[]
|
||
list.forEach((item2,k) => {
|
||
optionsArr.push(item2.name)
|
||
})
|
||
item1.list = list
|
||
item1.optionsArr = optionsArr
|
||
item1.index = 0
|
||
}
|
||
})
|
||
this.setData({
|
||
info,
|
||
})
|
||
});
|
||
},
|
||
//门店照片
|
||
imgUpload(e) {
|
||
let that = this
|
||
wx.chooseImage({
|
||
count: 1, //
|
||
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
||
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
||
success(res1) {
|
||
wx.showLoading({
|
||
title: '图片上传中',
|
||
})
|
||
|
||
//上传图片
|
||
wx.uploadFile({
|
||
url:_.config.api.upImg,
|
||
filePath:res1.tempFilePaths[0],
|
||
name: 'img',
|
||
formData: {
|
||
'app': 'liche'
|
||
},
|
||
success: (resp) => {
|
||
resp.data = JSON.parse(resp.data);
|
||
wx.hideLoading();
|
||
if (resp.data.code == 200) {
|
||
that.data.info[e.currentTarget.dataset.i].list[e.currentTarget.dataset.j].value=resp.data.data.url
|
||
that.data.info[e.currentTarget.dataset.i].list[e.currentTarget.dataset.j].src=resp.data.data.full_url
|
||
that.setData({
|
||
isEdit:true,
|
||
info:that.data.info,
|
||
})
|
||
}else{
|
||
wx.showToast({
|
||
title: '上传失败',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
},
|
||
})
|
||
|
||
},
|
||
fail: res => {
|
||
wx.showToast({
|
||
title: '文件选择失败',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
//店铺概况保存
|
||
postAppBizSituation() {
|
||
let that = this
|
||
that.setData({
|
||
submitFlag: true,
|
||
})
|
||
let info = that.data.info;
|
||
let newInfo = [];
|
||
info.forEach((item,i) => {
|
||
if(item.type=="img"){
|
||
newInfo.push({
|
||
field:item.field,
|
||
list:item.list,
|
||
})
|
||
}else{
|
||
newInfo.push({
|
||
field:item.field,
|
||
value:item.value,
|
||
})
|
||
}
|
||
})
|
||
let params = {};
|
||
params['tabs_id'] = that.data.tabs_id;
|
||
params['info'] = newInfo;
|
||
_.apiQuery.postAppBizSituation(params).then(res => {
|
||
wx.showToast({
|
||
title: '保存成功',
|
||
icon: 'success',
|
||
duration: 2500
|
||
});
|
||
that.setData({
|
||
isEdit:false,
|
||
submitFlag: false,
|
||
})
|
||
}).catch(res=>{
|
||
that.setData({
|
||
submitFlag: false,
|
||
})
|
||
});
|
||
},
|
||
|
||
}) |