boxes-details.js 5.06 KB
// packageA/pages/details_serviceCard/details_serviceCard.js
const app = getApp();
// const os = app.globalData.setting;
let self = null;
// 防抖函数用定时器
let timer;
const {
  barcode,
  qrcode
} = require('../../../utils/index.js');

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		// is_summit_ing: 0,
		
		showQr: false,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		self = this;
		this.setData({
			options,
		});
		// this.data.options = options;
		app.isLogin().then(function(data) {
			self.setData({
				userInfo: data,
			});
			wx.setNavigationBarTitle({
				title: options.title,
			});
			// self.getConfig();
		});
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		// console.log('show~~~');
		if (app.globalData.userInfo) {
			if (!this.data.isLogin) {
				this.setData({
					userInfo: app.globalData.userInfo,
					imghost: app.globalData.setting.imghost,
					isLogin: true,
				});

				let url = '/api/weshop/serviceCard/listWriteoffWare'
				let data = {
					store_id: app.globalData.setting.stoid,
					user_id: this.data.userInfo.user_id,
					Id: this.data.options.formlistid,
				};

				// 请求数据
				app.request.promiseGet(url, {
					data: data,
				}).then(res => {
					if (res.data.code == 0) {
						// console.log('请求成功', res);
						this.setData({
							details: res.data.data,
							writeOffCode: res.data.data[0].WriteOffCode
						});
					} else {
						throw (res);
					};
				}).catch(err => {
					// wx.showToast({
					// 	title: err.data.data,
					// 	icon: 'error',
					// });
				});
				
						
			};
		};
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

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

	},

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

	},

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

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
        getApp().globalData.no_clear=1
	},



	// 图片异常时加载默认图片
	// bind_bnerr(e) {
	// 	var errImg = e.currentTarget.dataset.errorimg;
	// 	var errObj = {};
	// 	errObj[errImg] = 'public/images/default_goods_image_240.gif';
	// 	this.setData(errObj); // this.setData({ details.list[0].img_url});    
	// },

	
	showQr() {
		// wx.showLoading({
		// 	title:'生成核销码中',
		// });
		
		let writeOffCode = this.data.details[0].WriteOffCode;
		self.qrcode(writeOffCode);
		self.setData({
			showQr: true,
		});
		
		// let store_id = app.globalData.setting.stoid;
		// let id = this.data.options.id;
		// let url = `/api/weshop/rechargeServicelist/update/${store_id}/${id}`;
		
		// app.request.put(url, {
		//   data: {},
		//   success: function(res) {
		// 		wx.hideLoading();
		// 		if(res.data.code == 0) {
		// 			let verify_code = res.data.data.verify_code;
		// 			self.qrcode(verify_code);
		// 			self.setData({
		// 				verify_code,
		// 				showQr: true,
		// 			});
		// 		};
		// 	}
		// });
	},
	
	// showQr() {
	// 	// this.debounce(this.createQr, 300)();
	// },
	
	
	closeQr() {
		this.setData({
			showQr: false,
		});
		
		// 关闭二维码弹窗后,检测核销情况,改变按钮状态
		wx.showLoading({
			title: '刷新中',
			mask: true,
		});
		
		// let store_id = app.globalData.setting.stoid;
		// let id = this.data.options.id;
		let url = '/api/weshop/serviceCard/listWriteoffWare';
		
		app.request.promiseGet(url, {
			data: {
				store_id: app.globalData.setting.stoid,
				user_id: this.data.userInfo.user_id,
				Id: this.data.options.formlistid,
			},
		}).then(res => {
			wx.hideLoading();
			if (res.data.code == 0) {

				let posNo = res.data.data[0].PosNo;
				if(posNo != '') {
					self.setData({
						['options.usestate']: 1,
					});
				} else {
					self.setData({
						['options.usestate']: 0,
					});
				};
				
			} else {
				throw (res);
			};
		}).catch(err => {
			// wx.showToast({
			// 	title: err.data.data,
			// 	icon: 'error',
			// });
		});
		
		
		
		// app.promiseGet(url, {
		//   data: {
		// 		store_id: app.globalData.setting.stoid,
		// 		user_id: self.data.userInfo.user_id,
		// 		Id: self.data.options.formlistid,
		// 	},
		//   success: function(res) {
		// 		wx.hideLoading();
		// 		if(res.data.code == 0) {
		// 			console.log('xxx000', res.data.data);
		// 			// let posNo = res.data.data[0].PosNo;
		// 			// if(posNo != '') {
		// 			// 	self.setData({
		// 			// 		['options.usestate']: 1,
		// 			// 	});
		// 			// } else {
		// 			// 	self.setData({
		// 			// 		['options.usestate']: 0,
		// 			// 	});
		// 			// };
					
		// 		};
		// 	}
		// });
		
		
		
	},
	
	/**
	 * 生成二维码
	 * by sty
	 */
	qrcode(val) {
	  barcode('barcode', val, 600,140);
	  qrcode('qrcode', val, 300, 300);
	},
	
	touchMove() {},
	
	// 函数防抖
	debounce(func, wait) { 
		return () => {
			clearTimeout(timer);
			timer = setTimeout(func, wait);
		};
	},
	
	








})