goods-detail.js 21.9 KB
Newer Older
D
devil_gong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
const app = getApp();
Page({
  data: {
    indicator_dots: false,
    indicator_color: 'rgba(0, 0, 0, .3)',
    indicator_active_color: '#e31c55',
    autoplay: true,
    circular: true,
    data_bottom_line_status: false,
    data_list_loding_status: 1,
    data_list_loding_msg: '',
    params: null,

    goods: null,
    goods_photo: [],
    goods_specifications_choose: [],
    goods_content_app: [],

    popup_status: false,
    goods_favor_text: '收藏',
    goods_favor_icon: '/images/goods-detail-favor-icon-0.png',
    temp_buy_number: 1,
    buy_event_type: 'buy',
    nav_submit_text: '立即购买',
    nav_submit_is_disabled: true,

    goods_spec_base_price: 0,
    goods_spec_base_original_price: 0,
    goods_spec_base_inventory: 0,
    goods_spec_base_images: '',
31 32

    show_field_price_text: null,
D
wx  
devil_gong 已提交
33 34

    goods_video_is_autoplay: false,
G
gongfuxiang 已提交
35
    common_app_is_use_mobile_detail: 1,
G
gongfuxiang 已提交
36 37

    popup_share_status: false,
G
gongfuxiang 已提交
38
    common_app_is_online_service: 0,
G
gongfuxiang 已提交
39 40 41 42 43 44

    // 限时秒杀插件
    common_app_is_limitedtimediscount: 0,
    plugins_limitedtimediscount_data: null,
    plugins_limitedtimediscount_is_show_time: true,
    plugins_limitedtimediscount_time_millisecond: 0,
D
devil_gong 已提交
45 46 47 48 49 50 51 52 53 54 55 56

    // 好物圈分享信息
    common_app_is_good_thing : 0,
    share_product: {
      "item_code": "",
      "title": "",
      "desc": "",
      "category_list": [],
      "image_list": [],
      "src_mini_program_path": "",
      "brand_info": {},
    },
57 58 59

    // 海报分享
    common_app_is_poster_share: 0,
D
devil_gong 已提交
60 61 62
  },
  on_error(e) {
    console.log(e)
D
devil_gong 已提交
63 64 65
  },

  onLoad(params) {
G
gongfuxiang 已提交
66
    //params['goods_id']=2;
D
devil_gong 已提交
67 68 69 70 71
    this.setData({params: params});
    this.init();
  },

  onShow() {
G
gongfuxiang 已提交
72
    wx.setNavigationBarTitle({title: (this.data.goods == null) ? app.data.common_pages_title.goods_detail : this.data.goods.title});
D
devil_gong 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  },

  // 获取数据列表
  init() {
    // 数据初始化
    this.setData({
      temp_attribute_active: {}
    });

    // 参数校验
    if((this.data.params.goods_id || null) == null)
    {
      wx.stopPullDownRefresh();
      this.setData({
        data_bottom_line_status: false,
        data_list_loding_status: 2,
        data_list_loding_msg: '商品ID有误',
      });
    } else {
      var self = this;

      // 加载loding
G
gongfuxiang 已提交
95
      wx.showLoading({title: '加载中...'});
D
devil_gong 已提交
96 97 98 99 100 101 102 103 104
      this.setData({
        data_list_loding_status: 1
      });

      wx.request({
        url: app.get_request_url("detail", "goods"),
        method: "POST",
        data: {goods_id: this.data.params.goods_id},
        dataType: "json",
D
devil_gong 已提交
105
        header: { 'content-type': 'application/x-www-form-urlencoded' },
D
devil_gong 已提交
106 107 108 109 110 111 112 113 114 115 116
        success: res => {
          wx.stopPullDownRefresh();
          wx.hideLoading();
          if (res.data.code == 0) {
            var data = res.data.data;
            self.setData({
              goods: data.goods,
              indicator_dots: (data.goods.photo.length > 1),
              autoplay: (data.goods.photo.length > 1),
              goods_photo: data.goods.photo,
              goods_specifications_choose: data.goods.specifications.choose || [],
G
gongfuxiang 已提交
117
              goods_content_app: data.goods.content_app || [],
118
              temp_buy_number: data.goods.buy_min_number || 1,
D
devil_gong 已提交
119
              goods_favor_text: (data.goods.is_favor == 1) ? '已收藏' : '收藏',
D
devil_gong 已提交
120 121 122 123 124 125 126 127 128
              goods_favor_icon: '/images/goods-detail-favor-icon-' + data.goods.is_favor+'.png',
              nav_submit_text: ((data.common_order_is_booking || 0) == 0) ? '立即购买' : '立即预约',
              data_bottom_line_status: true,
              data_list_loding_status: 3,
              nav_submit_is_disabled: (data.goods.is_shelves == 1 && data.goods.inventory > 0) ? false : true,

              goods_spec_base_price: data.goods.price,
              goods_spec_base_original_price: data.goods.original_price,
              goods_spec_base_inventory: data.goods.inventory,
129 130
              goods_spec_base_images: data.goods.images,

G
gongfuxiang 已提交
131
              show_field_price_text: (data.goods.show_field_price_text == '销售价') ? null : (data.goods.show_field_price_text.replace(/<[^>]+>/g, "") || null),
G
gongfuxiang 已提交
132 133
              common_app_is_use_mobile_detail: data.common_app_is_use_mobile_detail || 0,
              common_app_is_online_service: data.common_app_is_online_service || 0,
G
gongfuxiang 已提交
134 135 136

              common_app_is_limitedtimediscount: data.common_app_is_limitedtimediscount || 0,
              plugins_limitedtimediscount_data: data.plugins_limitedtimediscount_data || null,
D
devil_gong 已提交
137 138 139 140 141 142 143 144 145

              common_app_is_good_thing: data.common_app_is_good_thing || 0,
              'share_product.item_code': data.goods.id.toString(),
              'share_product.title': data.goods.title,
              'share_product.image_list': data.goods.photo.map(function (v) { return v.images;}),
              'share_product.desc': data.goods.simple_desc,
              'share_product.category_list': data.goods.category_names || [],
              'share_product.src_mini_program_path': '/pages/goods-detail/goods-detail?goods_id='+data.goods.id,
              'share_product.brand_info.name': data.goods.brand_name,
146 147

              common_app_is_poster_share: data.common_app_is_poster_share || 0,
D
devil_gong 已提交
148 149
            });

G
gongfuxiang 已提交
150 151 152 153 154
            // 限时秒杀倒计时
            if (this.data.common_app_is_limitedtimediscount == 1 && this.data.plugins_limitedtimediscount_data != null) {
              this.plugins_limitedtimediscount_countdown();
            }

D
1.6  
devil_gong 已提交
155 156 157
            // 标题
            wx.setNavigationBarTitle({ title: data.goods.title });

D
devil_gong 已提交
158 159 160 161 162
            // 不能选择规格处理
            this.goods_specifications_choose_handle_dont(0);

            if (data.goods.is_shelves != 1) {
              this.setData({
D
devil_gong 已提交
163
                nav_submit_text: '商品已下架',
D
devil_gong 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
                nav_submit_is_disabled: true,
              });
            } else {
              if(data.goods.inventory <= 0) {
                this.setData({
                  nav_submit_text: '商品卖光了',
                  nav_submit_is_disabled: true,
                });
              }
            }
          } else {
            self.setData({
              data_bottom_line_status: false,
              data_list_loding_status: 0,
              data_list_loding_msg: res.data.msg,
            });
          }
        },
        fail: () => {
          wx.stopPullDownRefresh();
          wx.hideLoading();
          self.setData({
            data_bottom_line_status: false,
            data_list_loding_status: 2,
            data_list_loding_msg: '服务器请求出错',
          });

G
gongfuxiang 已提交
191
          app.showToast("服务器请求出错");
D
devil_gong 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        }
      });
    }
  },

  // 不能选择规格处理
  goods_specifications_choose_handle_dont(key) {
    var temp_data = this.data.goods_specifications_choose || [];
    if(temp_data.length <= 0)
    {
      return false;
    }

    // 是否不能选择
    for(var i in temp_data)
    {
      for(var k in temp_data[i]['value'])
      {
        if(i > key)
        {
          temp_data[i]['value'][k]['is_dont'] = 'spec-dont-choose',
          temp_data[i]['value'][k]['is_disabled'] = '';
          temp_data[i]['value'][k]['is_active'] = '';
        }
216 217 218 219 220 221

        // 当只有一个规格的时候
        if(key == 0 && temp_data.length == 1)
        {
          temp_data[i]['value'][k]['is_disabled'] = ((temp_data[i]['value'][k]['is_only_level_one'] || null) != null && (temp_data[i]['value'][k]['inventory'] || 0) <= 0) ? 'spec-items-disabled' : '';
        }
D
devil_gong 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
      }
    }
    this.setData({goods_specifications_choose: temp_data});
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.init();
  },

  // 进入商品属性事件
  good_attribute_nav_event(e) {
    wx.navigateTo({
      url: "/pages/goods-attribute/goods-attribute?data="+JSON.stringify(this.data.goods_attribute_show)
    });
  },

G
gongfuxiang 已提交
239
  // 购买弹层关闭
D
devil_gong 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
  popup_close_event(e) {
    this.setData({popup_status: false});
  },

  // 进入店铺
  shop_event(e)
  {
    wx.switchTab({
      url: '/pages/index/index'
    });
  },

  // 加入购物车
  cart_submit_event(e) {
    this.setData({ popup_status: true, buy_event_type: 'cart' });
  },

  // 立即购买
  buy_submit_event(e) {
    this.setData({ popup_status: true, buy_event_type: 'buy'});
  },

  // 收藏事件
  goods_favor_event(e)
  {
G
gongfuxiang 已提交
265 266
    var user = app.get_user_cache_info(this, 'goods_favor_event');
    // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
267
    if (app.user_is_need_login(user)) {
G
gongfuxiang 已提交
268 269 270 271 272
      wx.navigateTo({
        url: "/pages/login/login?event_callback=init"
      });
      return false;
    } else {
G
gongfuxiang 已提交
273
      wx.showLoading({title: '处理中...'});
D
devil_gong 已提交
274

G
gongfuxiang 已提交
275 276 277 278 279 280 281 282 283 284 285 286
      wx.request({
        url: app.get_request_url('favor', 'goods'),
        method: 'POST',
        data: {"id": this.data.goods.id},
        dataType: 'json',
        success: (res) => {
          wx.hideLoading();
          if(res.data.code == 0)
          {
            var status = (this.data.goods.is_favor == 1) ? 0 : 1;
            this.setData({
              'goods.is_favor': status,
D
devil_gong 已提交
287
              goods_favor_text: (status == 1) ? '已收藏' : '收藏',
G
gongfuxiang 已提交
288
              goods_favor_icon: '/images/goods-detail-favor-icon-'+status+'.png'
D
devil_gong 已提交
289
            });
G
gongfuxiang 已提交
290 291 292
            app.showToast(res.data.msg, "success");
          } else {
            app.showToast(res.data.msg);
D
devil_gong 已提交
293
          }
G
gongfuxiang 已提交
294 295 296 297 298 299 300
        },
        fail: () => {
          wx.hideLoading();

          app.showToast('服务器请求出错');
        }
      });
D
devil_gong 已提交
301 302 303 304 305
    }
  },

  // 加入购物车事件
  goods_cart_event(e, spec) {
G
gongfuxiang 已提交
306 307
    var user = app.get_user_cache_info(this, 'goods_cart_event');
    // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
308
    if (app.user_is_need_login(user)) {
G
gongfuxiang 已提交
309 310 311 312 313
      wx.navigateTo({
        url: "/pages/login/login?event_callback=init"
      });
      return false;
    } else {
G
gongfuxiang 已提交
314
      wx.showLoading({title: '处理中...' });
G
gongfuxiang 已提交
315 316 317 318 319 320 321 322 323 324 325 326
      wx.request({
        url: app.get_request_url('save', 'cart'),
        method: 'POST',
        data: { "goods_id": this.data.goods.id, "stock": this.data.temp_buy_number, "spec": JSON.stringify(spec) },
        dataType: 'json',
        success: (res) => {
          wx.hideLoading();
          if (res.data.code == 0) {
            this.popup_close_event();
            app.showToast(res.data.msg, "success");
          } else {
            app.showToast(res.data.msg);
D
devil_gong 已提交
327
          }
G
gongfuxiang 已提交
328 329 330 331 332 333 334
        },
        fail: () => {
          wx.hideLoading();

          app.showToast('服务器请求出错');
        }
      });
D
devil_gong 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
    }
  },

  // 规格事件
  goods_specifications_event(e) {
    var key = e.currentTarget.dataset.key || 0;
    var keys = e.currentTarget.dataset.keys || 0;
    var temp_data = this.data.goods_specifications_choose;
    var temp_images = this.data.goods_spec_base_images;

    // 不能选择和禁止选择跳过
    if((temp_data[key]['value'][keys]['is_dont'] || null) == null && (temp_data[key]['value'][keys]['is_disabled'] || null) == null)
    {
      // 规格选择
      for(var i in temp_data)
      {
        for(var k in temp_data[i]['value'])
        {
          if((temp_data[i]['value'][k]['is_dont'] || null) == null && (temp_data[i]['value'][k]['is_disabled'] || null) == null)
          {
            if(key == i)
            {
              if(keys == k && (temp_data[i]['value'][k]['is_active'] || null) == null)
              {
                temp_data[i]['value'][k]['is_active'] = 'spec-active';
                if((temp_data[i]['value'][k]['images'] || null) != null)
                {
                  temp_images = temp_data[i]['value'][k]['images'];
                }
              } else {
                temp_data[i]['value'][k]['is_active'] = '';
              }
            }
          }
        }
      }
D
devil_gong 已提交
371
      this.setData({ goods_specifications_choose: temp_data, goods_spec_base_images: temp_images, temp_buy_number: this.data.goods.buy_min_number || 1});
D
devil_gong 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453

      // 不能选择规格处理
      this.goods_specifications_choose_handle_dont(key);

      // 获取下一个规格类型
      this.get_goods_specifications_type(key);

      // 获取规格详情
      this.get_goods_specifications_detail();
    }
  },

  // 获取下一个规格类型
  get_goods_specifications_type(key) {
    var temp_data = this.data.goods_specifications_choose;
    var active_index = key+1;
    var sku_count = temp_data.length;

    if(active_index <= 0 || active_index >= sku_count)
    {
      return false;
    }

    // 获取规格值
    var spec = [];
    for(var i in temp_data)
    {
      for(var k in temp_data[i]['value'])
      {
        if((temp_data[i]['value'][k]['is_active'] || null) != null)
        {
          spec.push({"type": temp_data[i]['name'], "value": temp_data[i]['value'][k]['name']});
          break;
        }
      }
    }
    if(spec.length <= 0)
    {
      return false;
    }

    // 获取数据
    wx.request({
      url: app.get_request_url('spectype', 'goods'),
      method: 'POST',
      data: { "id": this.data.goods.id, "spec": JSON.stringify(spec) },
      dataType: 'json',
      success: (res) => {
        if (res.data.code == 0) {
          var spec_count = spec.length;
          var index = (spec_count > 0) ? spec_count : 0;
          if(index < sku_count)
          {
            for(var i in temp_data)
            {
              for(var k in temp_data[i]['value'])
              {
                if(index == i)
                {
                  temp_data[i]['value'][k]['is_dont'] = '';
                  var temp_value = temp_data[i]['value'][k]['name'];
                  var temp_status = false;
                  for(var t in res.data.data)
                  {
                    if(res.data.data[t] == temp_value)
                    {
                      temp_status = true;
                      break;
                    }
                  }
                  if(temp_status == true)
                  {
                    temp_data[i]['value'][k]['is_disabled'] = '';
                  } else {
                    temp_data[i]['value'][k]['is_disabled'] = 'spec-items-disabled';
                  }
                }
              }
            }
            this.setData({goods_specifications_choose: temp_data});
          }
        } else {
G
gongfuxiang 已提交
454
          app.showToast(res.data.msg);
D
devil_gong 已提交
455 456 457
        }
      },
      fail: () => {
G
gongfuxiang 已提交
458
        app.showToast("服务器请求出错");
D
devil_gong 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
      }
    });
  },

  // 获取规格详情
  get_goods_specifications_detail() {
    // 是否全部选中
    var temp_data = this.data.goods_specifications_choose;
    var sku_count = temp_data.length;
    var active_count = 0;

    // 获取规格值
    var spec = [];
    for(var i in temp_data)
    {
      for(var k in temp_data[i]['value'])
      {
        if((temp_data[i]['value'][k]['is_active'] || null) != null)
        {
          active_count++;
          spec.push({"type": temp_data[i]['name'], "value": temp_data[i]['value'][k]['name']});
          break;
        }
      }
    }
    if(spec.length <= 0 || active_count < sku_count)
    {
      this.setData({
        goods_spec_base_price: this.data.goods.price,
        goods_spec_base_original_price: this.data.goods.original_price,
        goods_spec_base_inventory: this.data.goods.inventory,
      });
      return false;
    }

    // 获取数据
    wx.request({
      url: app.get_request_url('specdetail', 'goods'),
      method: 'POST',
      data: { "id": this.data.goods.id, "spec": JSON.stringify(spec) },
      dataType: 'json',
      success: (res) => {
        if (res.data.code == 0) {
          this.setData({
            goods_spec_base_price: res.data.data.price,
            goods_spec_base_original_price: res.data.data.original_price,
            goods_spec_base_inventory: res.data.data.inventory,
          });
        } else {
G
gongfuxiang 已提交
508
          app.showToast(res.data.msg);
D
devil_gong 已提交
509 510 511
        }
      },
      fail: () => {
G
gongfuxiang 已提交
512
        app.showToast("服务器请求出错");
D
devil_gong 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
      }
    });
  },

  // 数量输入事件
  goods_buy_number_blur(e) {
    var buy_number = parseInt(e.detail.value) || 1;
    this.setData({temp_buy_number: buy_number});
    this.goods_buy_number_func(buy_number);
  },

  // 数量操作事件
  goods_buy_number_event(e) {
    var type = parseInt(e.currentTarget.dataset.type) || 0;
    var temp_buy_number = parseInt(this.data.temp_buy_number);
    if(type == 0)
    {
      var buy_number = temp_buy_number - 1;
    } else {
      var buy_number = temp_buy_number + 1;
    }
    this.goods_buy_number_func(buy_number);
  },

  // 数量处理方法
  goods_buy_number_func(buy_number) {
    var buy_min_number = parseInt(this.data.goods.buy_min_number) || 1;
    var buy_max_number = parseInt(this.data.goods.buy_max_number) || 0;
541
    var inventory = parseInt(this.data.goods_spec_base_inventory);
D
devil_gong 已提交
542 543 544 545 546 547
    var inventory_unit = this.data.goods.inventory_unit;
    if(buy_number < buy_min_number)
    {
      buy_number = buy_min_number;
      if(buy_min_number > 1)
      {
548
        app.showToast('起购'+buy_min_number+inventory_unit);
D
devil_gong 已提交
549 550 551 552 553
      }
    }
    if(buy_max_number > 0 && buy_number > buy_max_number)
    {
      buy_number = buy_max_number;
G
gongfuxiang 已提交
554
      app.showToast('限购'+buy_max_number+inventory_unit);
D
devil_gong 已提交
555 556 557 558
    }
    if(buy_number > inventory)
    {
      buy_number = inventory;
G
gongfuxiang 已提交
559
      app.showToast('库存数量'+inventory+inventory_unit);
D
devil_gong 已提交
560 561 562 563 564 565
    }
    this.setData({temp_buy_number: buy_number});
  },

  // 确认
  goods_buy_confirm_event(e) {
G
gongfuxiang 已提交
566 567
    var user = app.get_user_cache_info(this, 'goods_buy_confirm_event');
    // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
568
    if (app.user_is_need_login(user)) {
G
gongfuxiang 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581
      wx.navigateTo({
        url: "/pages/login/login?event_callback=init"
      });
      return false;
    } else {
      // 属性
      var temp_data = this.data.goods_specifications_choose;
      var sku_count = temp_data.length;
      var active_count = 0;
      var spec = [];
      if(sku_count > 0)
      {
        for(var i in temp_data)
D
devil_gong 已提交
582
        {
G
gongfuxiang 已提交
583
          for(var k in temp_data[i]['value'])
D
devil_gong 已提交
584
          {
G
gongfuxiang 已提交
585
            if((temp_data[i]['value'][k]['is_active'] || null) != null)
D
devil_gong 已提交
586
            {
G
gongfuxiang 已提交
587 588
              active_count++;
              spec.push({"type": temp_data[i]['name'], "value": temp_data[i]['value'][k]['name']});
D
devil_gong 已提交
589 590 591
            }
          }
        }
G
gongfuxiang 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
        if(active_count < sku_count)
        {
          app.showToast('请选择属性');
          return false;
        }
      }
      
      // 操作类型
      switch (this.data.buy_event_type) {
        case 'buy' :
          // 进入订单确认页面
          var data = {
            "buy_type": "goods",
            "goods_id": this.data.goods.id,
            "stock": this.data.temp_buy_number,
            "spec": JSON.stringify(spec)
          };
          wx.navigateTo({
            url: '/pages/buy/buy?data=' + JSON.stringify(data)
          });
          this.popup_close_event();
          break;
D
devil_gong 已提交
614

G
gongfuxiang 已提交
615 616 617
        case 'cart' :
          this.goods_cart_event(e, spec);
          break;
D
devil_gong 已提交
618

G
gongfuxiang 已提交
619 620
        default :
          app.showToast("操作事件类型有误");
D
devil_gong 已提交
621 622 623 624 625 626 627 628 629 630
      }
    }
  },

  // 详情图片查看
  goods_detail_images_view_event(e) {
    var value = e.currentTarget.dataset.value || null;
    if(value != null)
    {
      wx.previewImage({
D
devil_gong 已提交
631
        current: value,
D
devil_gong 已提交
632 633 634 635 636 637 638
        urls: [value]
      });
    }
  },
  // 商品相册图片查看
  goods_photo_view_event(e) {
    var index = e.currentTarget.dataset.index;
G
gongfuxiang 已提交
639 640 641 642 643
    var all = [];
    for (var i in this.data.goods_photo)
    {
      all.push(this.data.goods_photo[i]['images']);
    }
D
devil_gong 已提交
644
    wx.previewImage({
D
devil_gong 已提交
645
      current: all[index],
G
gongfuxiang 已提交
646
      urls: all
D
devil_gong 已提交
647 648 649
    });
  },

D
wx  
devil_gong 已提交
650 651 652 653 654 655 656 657 658 659
  // 视频播放
  goods_video_play_event(e) {
    this.setData({ goods_video_is_autoplay: true});
  },

  // 视频关闭
  goods_video_close_event(e) {
    this.setData({ goods_video_is_autoplay: false });
  },

G
gongfuxiang 已提交
660 661 662 663 664 665 666 667 668 669
  // 分享开启弹层
  popup_share_event(e) {
    this.setData({ popup_share_status: true });
  },

  // 分享弹层关闭
  popup_share_close_event(e) {
    this.setData({ popup_share_status: false });
  },

G
gongfuxiang 已提交
670 671
  // 显示秒杀插件-倒计时
  plugins_limitedtimediscount_countdown() {
D
devil_gong 已提交
672 673
    var status = this.data.plugins_limitedtimediscount_data.time.status || 0;
    var msg = this.data.plugins_limitedtimediscount_data.time.msg || '';
G
gongfuxiang 已提交
674 675 676 677
    var hours = this.data.plugins_limitedtimediscount_data.time.hours || 0;
    var minutes = this.data.plugins_limitedtimediscount_data.time.minutes || 0;
    var seconds = this.data.plugins_limitedtimediscount_data.time.seconds || 0;
    var self = this;
D
devil_gong 已提交
678
    if (status == 1) {
G
gongfuxiang 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
      // 秒
      var timer = setInterval(function () {
        if (seconds <= 0) {
          if (minutes > 0) {
            minutes--;
            seconds = 59;
          } else if (hours > 0) {
            hours--;
            minutes = 59;
            seconds = 59;
          }
        } else {
          seconds--;
        }

        self.setData({
          'plugins_limitedtimediscount_data.time.hours': (hours < 10 && hours.length == 1) ? '0' + hours : hours,
          'plugins_limitedtimediscount_data.time.minutes': (minutes < 10 && minutes.length == 1) ? '0' + minutes : minutes,
          'plugins_limitedtimediscount_data.time.seconds': (seconds < 10 && seconds.length == 1) ? '0' + seconds : seconds,
        });

        if (hours <= 0 && minutes <= 0 && seconds <= 0) {
          // 停止时间
          clearInterval(timer);

          // 活动已结束
          self.setData({
            'plugins_limitedtimediscount_data.desc': '活动已结束',
            plugins_limitedtimediscount_is_show_time: false,
          });
        }
      }, 1000);

      // 毫秒
      var count = 0;
      var timers = setInterval(function () {
        count++;
        self.setData({ plugins_limitedtimediscount_time_millisecond: count});
        if(count > 9) {
          count = 0;
        }
D
百度  
devil_gong 已提交
720
        if (self.data.plugins_limitedtimediscount_is_show_time == false) {
G
gongfuxiang 已提交
721 722 723 724 725 726
          clearInterval(timers);
        }
      }, 100);
    } else {
      // 活动已结束
      self.setData({
D
devil_gong 已提交
727
        'plugins_limitedtimediscount_data.desc': msg,
G
gongfuxiang 已提交
728 729 730 731 732
        plugins_limitedtimediscount_is_show_time: false,
      });
    }
  },

D
devil_gong 已提交
733 734 735 736 737 738 739 740 741 742
  // 自定义分享
  onShareAppMessage() {
    return {
      title: app.data.application_title +'-'+ this.data.goods.title,
      desc: app.data.application_describe,
      path: '/pages/goods-detail/goods-detail?share=goods-detail&goods_id='+this.data.goods.id
    };
  },
  
});