123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- const app = getApp();
- Page({
- cashdialog: null,
- isOpenView: false,
- pid: '',
- pg: 1,
- data: {
- isShowNull: false
- },
- onReady: function(){
- },
- onLoad: function (options) {
- //产品详情路径附带参数,用于来源分享的参数scene=encodeURIComponent(uid, product_id)
- if (options != null && typeof options.scene != 'undefined') {
- let str = decodeURIComponent(options.scene);
- let arr = str.split(',');
- let uid = arr[0];
- this.pid = arr[1];
- app.saveInviteUid(uid);
- //跳转详情页
- this.isOpenView = true;
- }else{
- this.isOpenView = false;
- }
- var that = this;
- wx.login({
- success: function (res) {
- if (res.code) {
- app.request("passport.applet.bind", {
- code: res.code
- }, {
- success: function (data, res) {
- that.getHomeData(that);
- if (that.isOpenView){
- app.location('view/index?id=' + that.pid);
- }
- }
- })
- }
- }
- })
- },
- /**
- * 获取首页数据
- */
- getHomeData: function(that){
- if (that.pg == 1) {
- app.showLoading();
- }
- that.cashdialog = that.selectComponent("#cashdialog");
- app.set(that, 'loadMoreText', '正在加载');
- app.request('product.api.home', {
- pg: that.pg
- }, {
- success: function (data, res) {
- if (data.product.length > 0) {
- if (that.pg > 1) {
- app.setList(that, data.product, true);
- } else {
- app.setList(that, data.product);
- }
- that.pg++;
- app.set(that, 'isShowNull', false);
- } else {
- app.set(that, 'isShowNull', true);
- }
- app.hideLoading();
- },
- complete: function(res){
- app.hideLoading();
- }
- });
- },
- /**
- * 查看商品详情
- */
- view: function (event) {
- let id = app.getData(event).id;
- app.location('view/index?id=' + id);
- },
- /**
- * 礼品卡兑换
- */
- cash: function(){
- var that = this;
- app.isAuth('scope.userInfo', function(res){
- if(res){
- that.cashdialog.setErrMsg('');
- that.cashdialog.showDialog();
- }else{
- app.location('login/index');
- }
- });
- },
- /**
- * 跳转兑换页面
- */
- toCash: function(){
- var that = this;
- var cashCode = this.cashdialog.getCashCode();
- if (cashCode.length <= 0) {
- that.cashdialog.setErrMsg('请输入兑换码!');
- return ;
- }
- app.request('product.api.checkCode', {
- code: cashCode
- }, {
- success: function (data, res) {
- that.cashdialog.hideDialog();
- app.location('cash/index?code=' + cashCode);
- },
- fail: function (res) {
- that.cashdialog.setErrMsg(res.data.msg);
- }
- });
- },
- /**
- * 页面下拉事件的处理函数
- */
- onPullDownRefresh: function () {
- this.pg = 1;
- app.startPullDown(this);
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- app.startPullDown(this);
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (options) {
- //打开好友列表
- wx.showShareMenu({
- withShareTicket: true,
- success: function (res) {
- console.log('wx.showShareMenu success', res.data);
- },
- fail: function (res) {
- console.log('wx.showShareMenu fail', res.data);
- }
- })
- return {
- title: '',
- desc: '',
- path: '/template/home/index'
- }
- }
- })
|