detail_owner_invitation_new.js 10.4 KB
// pages/customer/detail_owner_invitation_new.js
var mta = require('mta-wechat-analysis')
import util from '../../utils/util';
import App from '../../utils/api';
import TP from '../../utils/tpls';
import RS from '../../utils/reserveStatus'
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		options: {
			tplid: ''
		},
		tableNum:0,
		detail:{},
		staffinfo:{},
		between: false,
		id: null,
		msgTpl: '',
		chef: {},
		marketing: {},
		home: {},
		reserve: {},
		signboard: {},
		store: {},
		recharge_data:{},
		coupon_data:{},
		homeColor: '',
		stringifyUse:'',
		current: 0,
		theme: 'blackGold', //blue green blackGold
		seller: {
			name: '',
			room: '',
			date: '',
			addr: ''
		},
		priceInfo:'',
		scoreInfo:'',
		discount:'',
		dataStr:Date.now()*1/1000,
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.id = options.id
		let param = {
			options: options,
			hasOwner: options.hasSellerShare == 1, //是否为发起人
		}
		param.tpls = [TP.tpls(options.tplid)]
		console.log(param);
		console.log(options);
		this.setData(param)
		mta.Page.init({
			"appID": "500667280",
			"eventID": "500667287",
			"statPullDownFresh": true,
			"statShareApp": true,
			"statReachBottom": true,
			"lauchOpts": options, //渠道分析
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {
		this.getDetail();
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {
		return this.sharesetting();
	},
	onShareTimeline() {
		return this.sharesetting();
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
	},
	cli() {
		if(this.data.staffinfo.wechat){
			wx.setClipboardData({
				data: this.data.staffinfo.wechat,
				success(res) {
					wx.getClipboardData({
						success(res) {
							console.log(res.data) // data
						}
					})
				}
			})
		}else{
			console.log('无微信号')
		}
	},
	call() {
		wx.reportMonitor('1012', 1)
		wx.makePhoneCall({
			phoneNumber: this.data.staffinfo.phone
		})
	},
	looklocation: function () {
		wx.reportMonitor('1015', 1)
		wx.openLocation({
			latitude: Number(this.data.seller.lat),
			longitude: Number(this.data.seller.long),
			scale: 17,
			address: this.data.seller.addr,
			success: function (res) {
				console.log(res)
			}
		})
	},
	getDetail() {
		App.Reserve.Detail({
			openid: getApp().openid,
			rid: this.data.options.id
		}).then(res => {
			let tables = [], //桌子信息
				regions = [],//区域名称
				tableNum =0;
			res.data.tables.forEach(t => {
				tables.push(t.name);
				tableNum+=t.table_pnum*1
				if (regions.indexOf('t.rname') == -1) {
					regions.push(t.rname);
				}
			})
			console.log(tableNum);
			let reserev = RS.reserve(res.data)
			let dateSmart
			if (res.data.type == 1) {
				dateSmart = util.unixtoTime(reserev.ddate, this.data.tpls[this.data.current].timeStrSmart[0])
				if (res.data.is_set_ddate == 1) {
					dateSmart += ' ' + util.unixtoTime(reserev.ddate, this.data.tpls[this.data.current].timeStrSmart[1])
				} else {
					dateSmart += ' ' + reserev.soltName
				}
			} else {
				dateSmart = util.unixtoTime(reserev.ddate, this.data.tpls[this.data.current].timeStr)
			}
			this.setData({
				detail: this.formatDatail(reserev, dateSmart),
				tableNum,
				seller: {
					name: reserev.seller.sellername,
					sid:reserev.sid,
					room: tables.join('、'),
					date: dateSmart,
					region: regions.join('、'),
					addr: reserev.seller.real_address || reserev.seller.map_address,
					image: reserev.image_url,
					hasOwner: true,
					type: reserev.type,
					is_set_ddate: reserev.is_set_ddate,
					hasUpTime: reserev.type == 1 && reserev.hasRunning && reserev.status != 2,
					tel: reserev.seller.seller_tel.split(',')[0],
					soltName: reserev.soltName,
					lat:reserev.seller.lat,
					long:reserev.seller.long,
				}
			})
			console.log('reserevreserevreserevreserevreserev',reserev);
			console.log('sellersellersellerseller',this.data.seller);
			console.log('detaildetaildetaildetail',this.data.detail);
			setTimeout(() => {
				this.getSellerTemplateConfFun(reserev.sid);
				this.getstaffinfo(res.data.uid)
			}, 0);
		}).catch(res=>{
			console.log(res,'详情请求失败');
		})
	},
	getstaffinfo(uid){
		console.log('Baseinfo__uid',uid);
		console.log('sellerid',this.data.detail.seller.id);
		App.Activity.GetCustomerActivityBaseinfo({sellerid:this.data.detail.seller.id,uid}).then((json)=>{
			if(json.ret==200){
				console.log('staffinfostaffinfostaffinfo',json.data)
				this.setData({
					staffinfo:json.data
				})
			}
		})  
	},
	cookbook() {
		if (this.data.detail.order && this.data.detail.order.cookbooklist.length > 0) {
			wx.navigateTo({
				url: util.http_build_query({
					rid: this.id,
					oid: this.data.detail.order.id,
					identity: 1
				}, '/pack-cookbook/pages/success')
			});
		} else {
			App.Advance.CreateOrder({
				rid: this.id,
				openid: getApp().openid,
			}).then(res => {
				if (res.ret != 200) {
					return util.toast(res.msg, 'none')
				}
				console.log(this.id,res.data.id,res.data.sellerid);
				wx.navigateTo({
					url: util.http_build_query({
						rid: this.id,
						oid: res.data.id,
						identity: 1,
						sid: res.data.sellerid,
						sellerName:this.data.seller.name
					}, '/pack-cookbook/pages/index_new')
				});
			})
		}
	},
	sharesetting() {
		wx.reportMonitor('1017', 1)
		let parmdata = {
			id: this.id,
			fromid: getApp().openid,
			hasInvitation: 1,
			tplid: this.data.options.tplid
		}
		if (this.data.options.uid) {
			parmdata.uid = this.data.options.uid;
		}
		console.log('seller_imageseller_imageseller_imageseller_imageseller_image',this.data.detail.seller.seller_image);
		return {
			title: '邀请您于'+this.data.seller.date+'一起共进'+this.data.seller.soltName+'。点击查看详情',
			path: util.http_build_query(parmdata, '/pages/customer/index'),
			imageUrl: this.data.detail.seller.seller_image,
		}
	},
	formatDatail(detail, dateSmart) {
		detail.rdateStr = dateSmart;
		detail.tableFirst = detail.tables[0].name;
		if (detail.tables.length > 1) {
			detail.tableSubInfo = '等' + (detail.tables.length) + '个' +
				(detail.tables[0].tid == 2 ? '包间' : '');
		}
		if (detail.rname && detail.sex != 3) {
			detail.rnameStr = detail.rname.substr(0, 1) + (detail.sex == 1 ? '先生' : '女士')
		} else {
			detail.rnameStr = detail.rname
		}
		detail.eatStr = '邀请您共进晚餐';
		let hi = util.unixtoTime(detail.ddate, 'HHII');
		if (hi < '10:00') {
			detail.eatStr = '邀请您共进早餐';
		} else if (hi < '15:00') {
			detail.eatStr = '邀请您共进午餐';
		}
		return detail;
	},
	getSellerTemplateConfFun(sid) {
		console.log(sid,'sidsidsidsid');
		App.Seller.GetSellerTemplateConf({
			sid
		}).then(res => {
			let data=res.data
			console.log('data',data);
			let home,chef,marketing,reserve,signboard,store,homeColor,coupon_data,priceInfo,scoreInfo,recharge_list,stringifyUse;
			chef = data.chef ? JSON.parse(data.chef) : '';
			reserve = data.reserve ? JSON.parse(data.reserve) : '';
			marketing = data.marketing ? JSON.parse(data.marketing) : '';
			signboard = data.signboard ? JSON.parse(data.signboard) : '';
			store = data.store ? JSON.parse(data.store) : '';
			home = data.home ? JSON.parse(data.home) : '';
			console.log('chef', chef);
			console.log('reserve', reserve);
			console.log('marketing', marketing);
			console.log('signboard', signboard);
			console.log('store', store);
			console.log('home', home);
			if(marketing.coupon_data){
				coupon_data=marketing.coupon_data;
				stringifyUse=JSON.stringify(marketing.coupon_data.use)
			}
			console.log('coupon_data', coupon_data);
			console.log('stringifyUse', stringifyUse);
			if(marketing.is_recharge=='1' && marketing.recharge_data){
				let recharge_data=marketing.recharge_data
				recharge_list=marketing.recharge_data.recharge_list
				if(recharge_list.is_price=='1')	priceInfo='会员充值满'+recharge_data.recharge_money+'元赠送'+recharge_list.price+'元余额';
				if(recharge_list.is_score=='1') scoreInfo='会员充值满'+recharge_data.recharge_money+'元赠送'+recharge_list.score+'积分';
				console.log('scoreInfo',scoreInfo);
				console.log('priceInfo',priceInfo);
				this.setData({
					recharge_data:marketing.recharge_data
				})
				console.log('recharge_data',recharge_data);
			}
			this.setData({
				coupon_data,
				stringifyUse
			})
			// is_cash 代金券  is_discount折扣券  is_dish菜品券 只有代金券有几折显示
			if(marketing.is_coupon=='1' && coupon_data && (!coupon_data.use.is_cash || coupon_data.use.is_cash=='1')){
				let cash=coupon_data.use.cash;
				let price=coupon_data.price*1;
				let discount=((price/cash)*10).toFixed(2);
				console.log('cash',cash);
				console.log('price',price);
				console.log('discount',discount);
				this.setData({
					discount
				})
			}
			if(store && store.images.length>0) store.images =store.images?JSON.parse(store.images):'';
			if(signboard && signboard.images) signboard.images = signboard.images?JSON.parse(signboard.images):'';
			if (marketing && marketing.is_online_book=='1' && marketing.is_transpond =='1') {
				this.setData({
					between: true
				})
			}
			if(home && home.red && home.green && home.blue && home.alpha){
				homeColor=home.red + ',' + home.green + ',' + home.blue + ',' + home.alpha
			}else{
				homeColor ='67,142,147,1'
			}
			console.log('homeColor',homeColor);
			this.setData({
				chef,
				marketing,
				home,
				reserve,
				signboard,
				store,
				homeColor, //home主题颜色
				priceInfo,
				scoreInfo
			})
			if (home && home.red == '1' && home.green == '67' && home.blue == '163') {
				this.setData({
					theme: 'blue'
				})
			}
			if (home && home.red == '67' && home.green == '142' && home.blue == '147') {
				this.setData({
					theme: 'green'
				})
			}
			if (home && home.red == '12' && home.green == '15' && home.blue == '14') {
				this.setData({
					theme: 'blackGold'
				})
			}
		}).catch(res=>{
			this.setData({
				theme:'green',
				homeColor:'67,142,147,1'
			})
			console.log(this.data.homeColor,'GetSellerTemplateConf请求失败');
		})
	},
	// 再次预订
	secondbook() {
		wx.reportMonitor('1013', 1)
		wx.redirectTo({
			url: '../reserve/detail?id=' + this.data.detail.seller.id
		})
	},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},
})