审查视图

pages/kind/detail_1/detail_1.js 7.8 KB
lihongjuan authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// pages/kind/detail_1/detail_1.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    index: 1,
    showModal: false,
    hide: false,
    num: 1,
    detail_id: null,
    detailCon: {},
    assess: [],
lihongjuan authored
16
    id: '',
lihongjuan authored
17 18 19 20
    days: 0,
    hours: 0,
    minutes: 0,
    seconds: 0,
lihongjuan authored
21 22 23 24
    over: true,
    short: [],
    seemore: true,
    images: []
lihongjuan authored
25 26 27 28 29
  },

  /**
   * 生命周期函数--监听页面加载
   */
lihongjuan authored
30
  onLoad: function(options) {
lihongjuan authored
31 32 33
    console.log(options)
    this.setData({
      detail_id: options.id,
lihongjuan authored
34
      id: options.id
lihongjuan authored
35 36
    })
    this.detaiFun(options.id)
lihongjuan authored
37
lihongjuan authored
38
  },
lihongjuan authored
39 40
  slectpic(e) {
    let that = this;
lihongjuan authored
41
    console.log(e)
lihongjuan authored
42
    let idx = e.currentTarget.dataset.idx;
lihongjuan authored
43
    let newassess = that.data.assess;
lihongjuan authored
44 45 46 47 48 49
    for (var i = 0; i < newassess.length; i++) {
      if (i == idx) {
        that.setData({
          images: newassess[i].img
        })
      }
lihongjuan authored
50 51 52 53 54 55 56

    }

    console.log(that.data.images)
  },

  // 图片预览
lihongjuan authored
57
  previewImage: function(e) {
lihongjuan authored
58 59 60 61 62 63 64 65 66 67 68 69 70

    let that = this;
    console.log(e)
    let idx = e.currentTarget.dataset.idx;
    let newassess = that.data.assess;
    for (var i = 0; i < newassess.length; i++) {
      if (i == idx) {
        that.setData({
          images: newassess[i].img
        })
      }

    }
lihongjuan authored
71
lihongjuan authored
72 73 74 75 76 77
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.images
    })
  },
lihongjuan authored
78 79

  //已成团
lihongjuan authored
80
  group() {
lihongjuan authored
81 82
    wx.showToast({
      title: '商品已成团,无法继续购买',
lihongjuan authored
83
      icon: "none"
lihongjuan authored
84 85
    })
  },
lihongjuan authored
86 87
  //结束
  gameover() {
lihongjuan authored
88 89
    wx.showToast({
      title: '活动已结束',
lihongjuan authored
90
      icon: "none"
lihongjuan authored
91 92
    })
  },
lihongjuan authored
93
  moresee() {
lihongjuan authored
94 95
    let that = this;
    that.setData({
lihongjuan authored
96
      seemore: false
lihongjuan authored
97
    })
lihongjuan authored
98
lihongjuan authored
99
lihongjuan authored
100 101 102 103 104 105 106 107 108 109 110
    let url = "home/index/shopMessage";
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    let params = {
      shop_id: that.data.detail_id,
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      let masarr = []
lihongjuan authored
111
lihongjuan authored
112 113 114
      that.setData({
        // short: masarr,
        //assess: res.data
lihongjuan authored
115
        assess: res.data
lihongjuan authored
116 117 118 119
      })
    }).catch((err) => {
      console.log(err)
    })
lihongjuan authored
120 121
  },
lihongjuan authored
122 123

lihongjuan authored
124
  goFirm_order1(e) {
lihongjuan authored
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    let that = this;
    let url = '/user/index/checkNum',
      params = {
        num: that.data.num,
        shop_id: that.data.id

      }
    let header = {
      'XX-Token': wx.getStorageSync("token"),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params).then((res) => {
      console.log(res);
      if (res.msg.msg == "可以购买") {
        wx.navigateTo({
          url: '../firm_order1/firm_order1?id=' + e.currentTarget.dataset.id + "&&num=" + this.data.num,
        })
      }else{
        wx.showToast({
          title: '库存不足',
          icon:"none"
        })
      }



    }).catch((err) => {
lihongjuan authored
153
    })
lihongjuan authored
154 155

lihongjuan authored
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  },

  // 商品详情数据
  detaiFun(id) {
    let that = this;
    let url = "home/index/shopEdit";
    let params = {
      shop_id: that.data.id
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res.data.content)
      that.setData({
        detailCon: res.data,
        content: res.content
      })
lihongjuan authored
176
lihongjuan authored
177 178 179 180 181 182 183 184 185 186 187
      // WxParse.wxParse('content', 'html', this.data.content, this, 5);
      WxParse.wxParse('article', 'html', res.data.content, that, 5)
      console.log(that.data.detailCon);

      let number = res.data.end_time - res.data.now_time;
      console.log(number)
      // let number = res.over_time;
      // 时间戳处理
      var totalSecond = number;
      console.log(totalSecond)
lihongjuan authored
188
      var interval = setInterval(function() {
lihongjuan authored
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
        // 秒数
        var second = totalSecond;
        // 天数位
        var day = Math.floor(second / 3600 / 24);
        var dayStr = day.toString();
        if (dayStr.length == 1) dayStr = '0' + dayStr;
        // 小时位
        var hr = Math.floor((second - day * 3600 * 24) / 3600);
        var hrStr = hr.toString();
        if (hrStr.length == 1) hrStr = '0' + hrStr;
        // 分钟位
        var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
        var minStr = min.toString();
        if (minStr.length == 1) minStr = '0' + minStr;
        // 秒位
        var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
        var secStr = sec.toString();
        if (secStr.length == 1) secStr = '0' + secStr;
lihongjuan authored
207
lihongjuan authored
208 209 210
        that.setData({
          days: dayStr,
          hours: hrStr,
lihongjuan authored
211
          minutes: minStr,
lihongjuan authored
212 213 214
          seconds: secStr,
        });
        totalSecond--;
lihongjuan authored
215
lihongjuan authored
216 217
        if (totalSecond <= 0) {
          that.setData({
lihongjuan authored
218
            over: false
lihongjuan authored
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
          })
          console.log(that.data.over)
          clearInterval(interval);
          // wx.showToast({
          //   title: '已结束',
          //   icon: 'none'
          // });
          // 倒计时结束
          //that.countDown();
          that.setData({
            days: '00',
            hours: '00',
            minutes: '00',
            seconds: '00',
          });
        }
      }.bind(this), 1000);
lihongjuan authored
236
lihongjuan authored
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254

    }).catch((err) => {
      console.log(err)
    })
  },
  // 商品评价页面
  assessFun() {
    let that = this;
    let url = "home/index/shopMessage";
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    let params = {
      shop_id: that.data.detail_id,
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
lihongjuan authored
255 256 257
      let masarr = []
      for (var i = 0; i < res.data.length; i++) {
        if (i < 5) {
lihongjuan authored
258 259
          masarr.push(res.data[i])
        }
lihongjuan authored
260
lihongjuan authored
261 262
      }
      that.setData({
lihongjuan authored
263 264 265
        // short: masarr,
        //assess: res.data
        assess: masarr
lihongjuan authored
266
      })
lihongjuan authored
267 268

      console.log(that.data.assess)
lihongjuan authored
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
    }).catch((err) => {
      console.log(err)
    })
  },
  // 加入收藏
  addFun() {
    let that = this;
    let url = "home/index/shopCollect";
    let params = {
      shop_id: that.data.detail_id,
    };
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    };
    app.post(url, params, header).then((res) => {
      console.log(res)
      // if(res.code == 20000){
      wx.showToast({
        title: '收藏成功',
        icon: "none",
        duration: 1500
      })
lihongjuan authored
293
      setTimeout(function() {
lihongjuan authored
294
        that.detaiFun()
lihongjuan authored
295
      }, 1500)
lihongjuan authored
296 297 298 299 300 301

      // }     
    }).catch((err) => {
      console.log(err)
      wx.showToast({
        title: err.msg,
lihongjuan authored
302
        icon: 'none'
lihongjuan authored
303 304
      })
lihongjuan authored
305
      setTimeout(function() {
lihongjuan authored
306 307 308 309 310 311 312 313
        that.detaiFun()
      }, 1500)
    })
  },
  goy(e) {
    this.setData({
      index: e.currentTarget.dataset.id,
    })
lihongjuan authored
314
    if (e.currentTarget.dataset.id == 2) {
lihongjuan authored
315 316
      console.log(9909)
      this.assessFun()
lihongjuan authored
317
    } else {
lihongjuan authored
318 319 320
      this.detaiFun()
    }
  },
lihongjuan authored
321
  goConfirm: function() {
lihongjuan authored
322 323 324 325
    this.setData({
      showModal: true,
    })
  },
lihongjuan authored
326
  m_close: function() {
lihongjuan authored
327 328 329 330 331
    this.setData({
      showModal: false,
    })
  },
  // 点击加减
lihongjuan authored
332
  bindMinus: function() {
lihongjuan authored
333 334 335 336 337 338 339 340 341
    var num = this.data.num;
    if (num > 1) {
      num--;
    }
    this.setData({
      num: num,
    });
  },
  // 点击加
lihongjuan authored
342
  bindPlus: function() {
lihongjuan authored
343 344 345 346 347 348 349 350 351
    var num = this.data.num;
    num++;
    this.setData({
      num: num,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
lihongjuan authored
352
  onReady: function() {
lihongjuan authored
353 354 355 356 357 358

  },

  /**
   * 生命周期函数--监听页面显示
   */
lihongjuan authored
359
  onShow: function() {
lihongjuan authored
360 361 362 363 364 365

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
lihongjuan authored
366
  onHide: function() {
lihongjuan authored
367 368 369 370 371 372

  },

  /**
   * 生命周期函数--监听页面卸载
   */
lihongjuan authored
373
  onUnload: function() {
lihongjuan authored
374 375 376 377 378 379

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
lihongjuan authored
380
  onPullDownRefresh: function() {
lihongjuan authored
381 382 383 384 385 386

  },

  /**
   * 页面上拉触底事件的处理函数
   */
lihongjuan authored
387
  onReachBottom: function() {
lihongjuan authored
388 389 390 391 392 393

  },

  /**
   * 用户点击右上角分享
   */
lihongjuan authored
394
  onShareAppMessage: function() {
lihongjuan authored
395 396 397

  }
})