index.js 5.15 KB

const app = getApp();
let self = null;

let imgDraw = {
	"width": "650px",
	"height": "843px",
	"background": "https://mshopimg.yolipai.net/miniapp/images/zhg/bg-zuhegou.jpg",
	"views": [
		{ // 头像
			"type": "image",
			"url": "https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/0F/08/ChMkJlauzXWIDrXBAAdCg2xP7oYAAH9FQOpVAIAB0Kb342.jpg",
			"css": {
				"width": "100px",
				"height": "100px",
				"top": "20px",
				"left": "275px",
				"borderRadius": "100px",
				"mode": "scaleToFill",
				"borderWidth": "2px",
				"borderColor": "#fff",
			}
		},
		{ //昵称
			"type": "text",
			"text": "我是店铺名称名称名称名称名称名称名称名称名称名称名称名称名称名称",
			"css": {
				"width": "400px",
				"color": "#fff",
				"top": "136px",
				"left": "137px",
				"fontSize": "26px",
				"maxLines": "1",
			}
		},
		{ //10元任选3件
			"type": "text",
			"text": "10元任选3件",
			"css": {
				"color": "#fff",
				"width": "650px",
				"top": "270px",
				"fontSize": "70px",
				"maxLines": "1",
				"textAlign": "center",
				"fontWeight": "bold",
			}
		},
		{ //活动时间
			"type": "text",
			"text": "活动时间:2021.07.06 - 2021.07.08",
			"css": {
				"color": "#333",
				"width": "650px",
				"top": "440px",
				"fontSize": "26px",
				"fontWeight": "normal",
				"maxLines": "1",
				"textAlign": "center"
			}
		},
		{	// 码
			"type": "qrcode",
			"content": "二维码地址",
			"css": {
				"color": "#000",
				"width": "200px",
				"height": "200px",
				"top": "525px",
				"left": "225px",
			}
		},
		{ // 扫码提示
			"type": "text",
			"text": "长按扫码即可参与活动",
			"css": {
				"color": "#666",
				"width": "650px",
				"top": "750px",
				"fontSize": "26px",
				"textAlign": "center"
			}
		},
	]
};


Page({

  /**
   * 页面的初始数据
   */
  data: {
		showRule: false,
		showMask: false,
		showNum: false,
		haveAdded: false,
		imgDraw: imgDraw,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		self = this;
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
	
	/**
	 * 点击规则详情,弹出规则
	 */
	showRule() {
		this.setData({
			type: 0, //控制显示规则详情还是提示信息,0规则详情,1提示信息
			showRule: true,
			showMask: true,
		});
	},
	
	/**
	 * 点击关闭按钮关闭规则详情弹窗
	 */
	closeRule() {
		this.setData({
			showRule: false,
			showMask: false,
		});
	},
	
	/**
	 * 点击提示信息
	 */
	showInfo() {
		this.setData({
			type: 1,
			showRule: true,
			showMask: true,
		});
	},
	
	/**
	 * 加入购物车
	 */
	addToCart() {
		let haveAdded = !this.data.haveAdded;
		let title = '';
		if(haveAdded) {
			title = '加入购物车成功';
			this.setData({
				num: 1,
				showNum: true,
				haveAdded,
			});
			wx.showToast({
				title: title,
				icon: 'success',
			});
		} else {
			wx.showModal({
			  title: '温馨提示',
			  content: '确定将该商品移出购物车?',
			  success (res) {
			    if (res.confirm) {
			      console.log('用户点击确定');
						title = '移除购物车成功';
						self.setData({
							showNum: false,
							haveAdded: false,
						});
						wx.showToast({
							title: title,
							icon: 'success',
						});
			    } else if (res.cancel) {
			      console.log('用户点击取消')
						self.setData({
							haveAdded: true,
						});
			    }
			  }
			})
			
		}
		
	},
	
	/**
	 * 增加数量
	 */
	add() {
		this.setData({
			num: ++this.data.num,
		});
	},
	
	/**
	 * 减少数量
	 */
	sub() {
		let num = this.data.num;
		if(num >= 2) {
			this.setData({
				num: --this.data.num,
			});
		};
		if(num == 1) {
			// this.setData({
			// 	showNum: false,
			// 	haveAdded: false,
			// });
			wx.showModal({
			  title: '温馨提示',
			  content: '确定将该商品移出购物车?',
			  success (res) {
			    if (res.confirm) {
			      console.log('用户点击确定');
						// title = '移除购物车成功';
						self.setData({
							showNum: false,
							haveAdded: false,
						});
						wx.showToast({
							title: '移除购物车成功',
							icon: 'success',
						});
			    } else if (res.cancel) {
			      console.log('用户点击取消')
						self.setData({
							haveAdded: true,
						});
			    }
			  }
			})
		}
	},
	
	/**
	 * 分享
	 */
	share() {
		this.setData({
			showMask: true,
			showPoster: true,
		});
	},
	
	/**
	 * 关闭海报
	 */
	closePoster() {
		this.setData({
			showMask: false,
			showPoster: false,
		});
	},
	
	onImgOK(e) {
		console.log(e.detail.path);
		this.setData({
			myimg: e.detail.path,
		});
	},
})