|
|
|
// pages/manager-invitation/editor.js
|
|
|
|
import util from '../../utils/util';
|
|
|
|
import App from '../../utils/api';
|
|
|
|
import TP from '../../utils/tpls';
|
|
|
|
const {regeneratorRuntime} = global
|
|
|
|
import PubSub from '../../utils/PubSub'
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
pickerValue:[-1,0,0],
|
|
|
|
pickerData:[[],[],[]],
|
|
|
|
hasSubmit:false,
|
|
|
|
form:{
|
|
|
|
name:'',
|
|
|
|
room:'',
|
|
|
|
addr:'',
|
|
|
|
sid:'',
|
|
|
|
time:'',
|
|
|
|
image:'',
|
|
|
|
latitude:'',
|
|
|
|
longitude:'',
|
|
|
|
},
|
|
|
|
defImage:'http://qn.colorcun.com/manager-invitation/wx/upload2.jpg',
|
|
|
|
tpl:{},
|
|
|
|
timeStr:'',
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
pickerData:[],
|
|
|
|
tpl:{},
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.tpl=TP.tpls(options.tplid);
|
|
|
|
this.pickerData=TP.pickerData();
|
|
|
|
let pd=TP.pickerData();
|
|
|
|
pd[2]=pd[2][this.data.pickerValue[1]];
|
|
|
|
this.initData(options)
|
|
|
|
this.setData({
|
|
|
|
pickerData:pd,
|
|
|
|
tpl:this.tpl,
|
|
|
|
options:options,
|
|
|
|
})
|
|
|
|
PubSub.on(
|
|
|
|
'quick',
|
|
|
|
data=>{
|
|
|
|
console.log('quick.msg',data)
|
|
|
|
this.setData({
|
|
|
|
[`form.sid`]:data.id,
|
|
|
|
[`form.name`]:data.name,
|
|
|
|
[`form.addr`]:data.address,
|
|
|
|
[`form.latitude`]:data.lat,
|
|
|
|
[`form.longitude`]:data.long,
|
|
|
|
})
|
|
|
|
this.checkHasSubmit();
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
initData(options){
|
|
|
|
if(options.rid){
|
|
|
|
App.Invitation.Detail({id:options.rid}).then(res=>{
|
|
|
|
this.setData({
|
|
|
|
form:{
|
|
|
|
sid:res.data.seller_name,
|
|
|
|
name:res.data.seller_name,
|
|
|
|
room:res.data.room_name,
|
|
|
|
addr:res.data.seller_address,
|
|
|
|
sid:res.data.sid,
|
|
|
|
time:res.data.arrival_time,
|
|
|
|
image:res.data.image_url,
|
|
|
|
latitude:res.data.lat,
|
|
|
|
longitude:res.data.long,
|
|
|
|
},
|
|
|
|
timeStr:util.unixtoTime(res.data.arrival_time,this.data.tpl.timeStr)
|
|
|
|
})
|
|
|
|
this.checkHasSubmit();
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
App.Invitation.GetSellerList({
|
|
|
|
openid:getApp().openid
|
|
|
|
}).then(res=>{
|
|
|
|
if(res.data.length>0){
|
|
|
|
let defi=0;
|
|
|
|
for(let i=0;i<res.data.length;i++){
|
|
|
|
if(res.data[i].is_default==1){
|
|
|
|
defi=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let sel=res.data[defi];
|
|
|
|
this.setData({
|
|
|
|
form:{
|
|
|
|
sid:sel.id,
|
|
|
|
name:sel.name,
|
|
|
|
addr:sel.address,
|
|
|
|
latitude:sel.lat,
|
|
|
|
longitude:sel.long,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
bindMultiPickerColumnChange(e){
|
|
|
|
//console.log(e);
|
|
|
|
if(e.detail.column==1){
|
|
|
|
this.setData({
|
|
|
|
[`pickerValue[1]`]:e.detail.value,
|
|
|
|
[`pickerData[2]`]:this.pickerData[2][e.detail.value],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bindMultiPickerChange(e){
|
|
|
|
console.log(e);
|
|
|
|
this.setData({
|
|
|
|
pickerValue:e.detail.value,
|
|
|
|
timeStr:util.unixtoTime(this.getTimeStr(e.detail.value),this.data.tpl.timeStr)
|
|
|
|
})
|
|
|
|
this.checkHasSubmit()
|
|
|
|
},
|
|
|
|
checkHasSubmit(){
|
|
|
|
let form=this.data.form;
|
|
|
|
let flag=false;
|
|
|
|
console.log(
|
|
|
|
form.name
|
|
|
|
, (this.data.pickerValue[0]>-1 || form.time>0)
|
|
|
|
, form.room
|
|
|
|
, form.addr
|
|
|
|
, form.latitude>0
|
|
|
|
, (!this.tpl.hasImage || (this.tpl.hasImage && form.image))
|
|
|
|
|
|
|
|
)
|
|
|
|
if(
|
|
|
|
form.name
|
|
|
|
&& (this.data.pickerValue[0]>-1 || form.time>0)
|
|
|
|
&& form.room
|
|
|
|
&& form.addr
|
|
|
|
&& form.latitude>0
|
|
|
|
&& (!this.tpl.hasImage || (this.tpl.hasImage && form.image))//带图模板
|
|
|
|
){
|
|
|
|
flag=true;
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
hasSubmit:flag
|
|
|
|
})
|
|
|
|
return flag;
|
|
|
|
},
|
|
|
|
input(e){
|
|
|
|
let key=util.attr(e,'key');
|
|
|
|
if(key=='addr' && !(this.data.form.latitude>0)){
|
|
|
|
return this.onChangeAddress()
|
|
|
|
}
|
|
|
|
let val=util.val(e).trim();
|
|
|
|
let form=this.data.form;
|
|
|
|
form[key]=val;
|
|
|
|
this.setData({
|
|
|
|
form:form,
|
|
|
|
})
|
|
|
|
this.checkHasSubmit()
|
|
|
|
},
|
|
|
|
getTimeStr(pickerValue=''){
|
|
|
|
if(pickerValue.length<1){
|
|
|
|
pickerValue=this.data.pickerValue;
|
|
|
|
}
|
|
|
|
if(pickerValue[0]>-1){
|
|
|
|
let d=new Date();
|
|
|
|
let y=d.getFullYear();
|
|
|
|
let md=this.data.pickerData[0][pickerValue[0]].substr(0,5);
|
|
|
|
let t=this.data.pickerData[2][pickerValue[2]];
|
|
|
|
console.log(y+'-'+md+' '+t+':00')
|
|
|
|
return util.timetouUnix(y+'-'+md+' '+t+':00');
|
|
|
|
}else{
|
|
|
|
return this.data.form.time;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
submit(){
|
|
|
|
if(!this.checkHasSubmit()){
|
|
|
|
let msg='请完善邀请函信息';
|
|
|
|
if(this.data.form.latitude<1){
|
|
|
|
msg='请标注店铺位置'
|
|
|
|
}else if(!this.data.form.image){
|
|
|
|
msg='请上传或等待图片完成'
|
|
|
|
}
|
|
|
|
return util.toast(msg,'none')
|
|
|
|
}
|
|
|
|
let opt=this.data.options
|
|
|
|
let param={
|
|
|
|
openid:getApp().openid,
|
|
|
|
template_id:opt.tplid,
|
|
|
|
sid:this.data.form.sid,
|
|
|
|
sname:this.data.form.name,
|
|
|
|
seller_address:this.data.form.addr,
|
|
|
|
room_name:this.data.form.room,
|
|
|
|
arrival_time:this.getTimeStr(),
|
|
|
|
lat:this.data.form.latitude,
|
|
|
|
long:this.data.form.longitude,
|
|
|
|
}
|
|
|
|
if(opt.rid){
|
|
|
|
param.id=opt.rid
|
|
|
|
}
|
|
|
|
if(this.data.form.image){
|
|
|
|
param.image_url=this.data.form.image
|
|
|
|
}
|
|
|
|
App.Invitation.SetInvitationInfo(param).then(res=>{
|
|
|
|
wx.redirectTo({
|
|
|
|
url:util.http_build_query({
|
|
|
|
rid:res.data.id,
|
|
|
|
...this.data.options,
|
|
|
|
},'./review')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
chooseImage(){
|
|
|
|
wx.chooseImage({
|
|
|
|
count:1,
|
|
|
|
sizeType:'compressed',
|
|
|
|
//sourceType:'album',
|
|
|
|
success:res=>{
|
|
|
|
const tempFilePaths = res.tempFilePaths[0]
|
|
|
|
this.setData({
|
|
|
|
defImage:tempFilePaths,
|
|
|
|
})
|
|
|
|
wx.uploadFile({
|
|
|
|
url:util.cgi('App.Examples_Upload.UploadQn'),
|
|
|
|
filePath:tempFilePaths,
|
|
|
|
name:'file',
|
|
|
|
success:upres=>{
|
|
|
|
try{
|
|
|
|
upres=JSON.parse(upres.data)
|
|
|
|
console.log('upres',upres)
|
|
|
|
if(upres.ret==200){
|
|
|
|
util.toast('图片上传完成','none')
|
|
|
|
this.setData({
|
|
|
|
[`form.image`]:upres.data,
|
|
|
|
})
|
|
|
|
this.checkHasSubmit()
|
|
|
|
}else{
|
|
|
|
util.toast(upres.msg||'上传出错','none')
|
|
|
|
}
|
|
|
|
}catch (e){
|
|
|
|
util.toast('上传出错','none')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onChangeAddress(){
|
|
|
|
wx.chooseLocation({
|
|
|
|
success: (res)=> {
|
|
|
|
console.log(res);
|
|
|
|
this.setData({
|
|
|
|
[`form.latitude`]:res.latitude,
|
|
|
|
[`form.longitude`]:res.longitude,
|
|
|
|
[`form.addr`]:res.name,
|
|
|
|
})
|
|
|
|
this.checkHasSubmit()
|
|
|
|
},
|
|
|
|
fail: function (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|