goods-detail.js 25.8 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1
const app = getApp();
G
gongfuxiang 已提交
2
import parse from 'mini-html-parser2';
D
v1.2.0  
devil_gong 已提交
3
Page({
D
devil 已提交
4
  data: {    
D
v1.2.0  
devil_gong 已提交
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 31
    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: '',
32 33

    show_field_price_text: null,
D
devil 已提交
34
    goods_video_is_autoplay: false,    
D
devil_gong 已提交
35

D
devil 已提交
36 37
    // 购物车快捷导航
    quick_nav_cart_count: 0,
G
gongfuxiang 已提交
38

D
devil 已提交
39
    // 基础配置
D
devil 已提交
40
    currency_symbol: app.data.currency_symbol,
D
devil 已提交
41 42
    common_app_is_poster_share: 0,
    common_app_is_good_thing : 0,
D
devil_gong 已提交
43
    common_app_is_online_service: 0,
D
devil 已提交
44 45 46
    common_app_is_use_mobile_detail: 0,
    common_is_goods_detail_show_photo: 0,
    common_app_customer_service_tel: null,
D
devil_gong 已提交
47 48 49 50
    common_app_mini_alipay_tnt_inst_id: null,
    common_app_mini_alipay_scene: null,
    common_app_mini_alipay_openid: null,

G
gongfuxiang 已提交
51
    // 限时秒杀插件
D
devil 已提交
52
    plugins_limitedtimediscount_is_valid: 0,
G
gongfuxiang 已提交
53 54 55
    plugins_limitedtimediscount_data: null,
    plugins_limitedtimediscount_is_show_time: true,
    plugins_limitedtimediscount_time_millisecond: 0,
D
devil_gong 已提交
56 57
    plugins_limitedtimediscount_timer: null,
    plugins_limitedtimediscount_timers: null,
D
devil_gong 已提交
58 59 60

    // 优惠劵
    plugins_coupon_data: null,
D
devil_gong 已提交
61 62
    temp_coupon_receive_index: null,
    temp_coupon_receive_value: null,
D
v1.2.0  
devil_gong 已提交
63 64 65
  },

  onLoad(params) {
D
devil 已提交
66 67 68
    // 启动参数处理
    params = app.launch_params_handle(params);

G
gongfuxiang 已提交
69
    //params['goods_id']=2;
D
v1.2.0  
devil_gong 已提交
70 71 72 73
    this.setData({params: params});
  },

  onShow() {
G
gongfuxiang 已提交
74
    my.setNavigationBar({title: (this.data.goods == null) ? app.data.common_pages_title.goods_detail : this.data.goods.title});
D
devil 已提交
75 76 77 78 79 80 81 82 83 84 85 86

    // 数据加载
    this.init();

    // 初始化配置
    this.init_config();
  },

  // 初始化配置
  init_config(status) {
    if((status || false) == true) {
      this.setData({
D
devil 已提交
87
        currency_symbol: app.get_config('currency_symbol'),
D
devil 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
        common_app_is_use_mobile_detail: app.get_config('config.common_app_is_use_mobile_detail'),
        common_is_goods_detail_show_photo: app.get_config('config.common_is_goods_detail_show_photo'),
        common_app_is_online_service: app.get_config('config.common_app_is_online_service'),
        common_app_is_good_thing: app.get_config('config.common_app_is_good_thing'),
        common_app_is_poster_share: app.get_config('config.common_app_is_poster_share'),
        common_app_customer_service_tel: app.get_config('config.common_app_customer_service_tel'),
        common_app_mini_alipay_tnt_inst_id: app.get_config('config.common_app_mini_alipay_tnt_inst_id'),
        common_app_mini_alipay_scene: app.get_config('config.common_app_mini_alipay_scene'),
      });

      // 在线客服开启,获取用户openid
      if(this.data.common_app_is_online_service == 1)
      {
        this.setData({common_app_mini_alipay_openid: app.get_user_openid()});
      }
    } else {
      app.is_config(this, 'init_config');
    }
D
v1.2.0  
devil_gong 已提交
106 107
  },

D
devil 已提交
108
  // 获取数据
D
v1.2.0  
devil_gong 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  init() {
    // 参数校验
    if((this.data.params.goods_id || null) == null)
    {
      my.stopPullDownRefresh();
      this.setData({
        data_bottom_line_status: false,
        data_list_loding_status: 2,
        data_list_loding_msg: '商品ID有误',
      });
    } else {
      var self = this;

      // 加载loding
      my.showLoading({content: '加载中...'});
      this.setData({
        data_list_loding_status: 1
      });

D
1.6  
devil_gong 已提交
128
      my.request({
D
v1.2.0  
devil_gong 已提交
129 130 131 132
        url: app.get_request_url("detail", "goods"),
        method: "POST",
        data: {goods_id: this.data.params.goods_id},
        dataType: "json",
D
1.6  
devil_gong 已提交
133
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
134 135 136 137 138 139
        success: res => {
          my.stopPullDownRefresh();
          my.hideLoading();
          if (res.data.code == 0) {
            var data = res.data.data;
            self.setData({
D
devil 已提交
140 141
              data_bottom_line_status: true,
              data_list_loding_status: 3,
D
v1.2.0  
devil_gong 已提交
142 143 144 145 146
              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 已提交
147
              goods_content_app: data.goods.content_app || [],
148
              temp_buy_number: data.goods.buy_min_number || 1,
D
devil_gong 已提交
149
              goods_favor_text: (data.goods.is_favor == 1) ? '已收藏' : '收藏',
D
v1.2.0  
devil_gong 已提交
150 151
              goods_favor_icon: '/images/goods-detail-favor-icon-' + data.goods.is_favor+'.png',

D
devil 已提交
152 153 154 155 156
              nav_submit_text: data.nav_submit_text,
              nav_submit_is_disabled: data.nav_submit_is_disabled,
              common_site_type: data.common_site_type || 0,
              is_goods_site_type_consistent: data.is_goods_site_type_consistent || 0,
              
D
v1.2.0  
devil_gong 已提交
157 158 159
              goods_spec_base_price: data.goods.price,
              goods_spec_base_original_price: data.goods.original_price,
              goods_spec_base_inventory: data.goods.inventory,
160
              goods_spec_base_images: data.goods.images,
G
gongfuxiang 已提交
161
              show_field_price_text: (data.goods.show_field_price_text == '销售价') ? null : (data.goods.show_field_price_text.replace(/<[^>]+>/g, "") || null),
G
gongfuxiang 已提交
162 163

              plugins_limitedtimediscount_data: data.plugins_limitedtimediscount_data || null,
D
devil 已提交
164 165
              plugins_limitedtimediscount_is_valid: ((data.plugins_limitedtimediscount_data || null) != null && (data.plugins_limitedtimediscount_data.is_valid || 0) == 1) ? 1 : 0,

D
devil_gong 已提交
166
              plugins_coupon_data: data.plugins_coupon_data || null,
D
Devil 已提交
167
              quick_nav_cart_count: data.common_cart_total || 0,
D
v1.2.0  
devil_gong 已提交
168 169
            });

G
gongfuxiang 已提交
170
            // 限时秒杀倒计时
D
devil 已提交
171
            if (this.data.plugins_limitedtimediscount_is_valid == 1) {
G
gongfuxiang 已提交
172 173 174
              this.plugins_limitedtimediscount_countdown();
            }

D
1.6  
devil_gong 已提交
175 176 177
            // 标题
            my.setNavigationBar({title: data.goods.title});

D
1.6  
devil_gong 已提交
178 179 180 181 182 183 184 185 186 187 188
            // web内容转化
            if((data.goods.content_web || null) != null)
            {
              parse(data.goods.content_web, (err, nodes) => {
                if (!err) {
                  this.setData({
                    'goods.content_web': nodes,
                  });
                }
              });
            }
G
gongfuxiang 已提交
189

D
v1.2.0  
devil_gong 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
            // 不能选择规格处理
            this.goods_specifications_choose_handle_dont(0);
          } else {
            self.setData({
              data_bottom_line_status: false,
              data_list_loding_status: 0,
              data_list_loding_msg: res.data.msg,
            });
          }
        },
        fail: () => {
          my.stopPullDownRefresh();
          my.hideLoading();
          self.setData({
            data_bottom_line_status: false,
            data_list_loding_status: 2,
            data_list_loding_msg: '服务器请求出错',
          });
D
devil_gong 已提交
208
          app.showToast('服务器请求出错');
D
v1.2.0  
devil_gong 已提交
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        }
      });
    }
  },

  // 不能选择规格处理
  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'] = '';
        }
233 234 235 236 237 238

        // 当只有一个规格的时候
        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
v1.2.0  
devil_gong 已提交
239 240
      }
    }
241

D
v1.2.0  
devil_gong 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    this.setData({goods_specifications_choose: temp_data});
  },

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

  // 弹层关闭
  popup_close_event(e) {
    this.setData({popup_status: false});
  },

  // 进入店铺
  shop_event(e)
  {
    my.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)
  {
D
1.6  
devil_gong 已提交
276
    var user = app.get_user_info(this, 'goods_favor_event');
D
v1.2.0  
devil_gong 已提交
277 278
    if (user != false) {
      // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
279
      if (app.user_is_need_login(user)) {
D
v1.2.0  
devil_gong 已提交
280
        my.navigateTo({
D
devil_gong 已提交
281
          url: "/pages/login/login?event_callback=goods_favor_event"
D
v1.2.0  
devil_gong 已提交
282 283 284 285 286
        });
        return false;
      } else {
        my.showLoading({content: '处理中...'});

D
1.6  
devil_gong 已提交
287
        my.request({
D
v1.2.0  
devil_gong 已提交
288 289 290 291
          url: app.get_request_url('favor', 'goods'),
          method: 'POST',
          data: {"id": this.data.goods.id},
          dataType: 'json',
D
1.6  
devil_gong 已提交
292
          headers: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
293 294 295 296 297
          success: (res) => {
            my.hideLoading();
            if(res.data.code == 0)
            {
              this.setData({
D
devil_gong 已提交
298 299 300
                'goods.is_favor': res.data.data.status,
                goods_favor_text: res.data.data.text,
                goods_favor_icon: '/images/goods-detail-favor-icon-'+res.data.data.status+'.png'
D
v1.2.0  
devil_gong 已提交
301
              });
D
devil_gong 已提交
302
              app.showToast(res.data.msg, 'success');
D
v1.2.0  
devil_gong 已提交
303
            } else {
D
devil_gong 已提交
304
              if (app.is_login_check(res.data, this, 'goods_favor_event')) {
D
devil_gong 已提交
305 306
                app.showToast(res.data.msg);
              }
D
v1.2.0  
devil_gong 已提交
307 308 309 310
            }
          },
          fail: () => {
            my.hideLoading();
D
devil_gong 已提交
311
            app.showToast('服务器请求出错');
D
v1.2.0  
devil_gong 已提交
312 313 314 315 316 317 318 319
          }
        });
      }
    }
  },

  // 加入购物车事件
  goods_cart_event(e, spec) {
D
devil_gong 已提交
320
    var user = app.get_user_info(this, 'goods_buy_confirm_event');
D
v1.2.0  
devil_gong 已提交
321 322
    if (user != false) {
      // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
323
      if (app.user_is_need_login(user)) {
D
v1.2.0  
devil_gong 已提交
324 325 326 327 328 329
        my.navigateTo({
          url: "/pages/login/login?event_callback=init"
        });
        return false;
      } else {
        my.showLoading({ content: '处理中...' });
D
1.6  
devil_gong 已提交
330
        my.request({
D
v1.2.0  
devil_gong 已提交
331 332 333 334
          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',
D
1.6  
devil_gong 已提交
335
          headers: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
336 337 338
          success: (res) => {
            my.hideLoading();
            if (res.data.code == 0) {
D
Devil 已提交
339
              this.setData({ quick_nav_cart_count: res.data.data});
D
v1.2.0  
devil_gong 已提交
340
              this.popup_close_event();
D
devil_gong 已提交
341
              app.showToast(res.data.msg, 'success');
D
v1.2.0  
devil_gong 已提交
342
            } else {
D
devil_gong 已提交
343
              if (app.is_login_check(res.data, this, 'goods_buy_confirm_event')) {
D
devil_gong 已提交
344 345
                app.showToast(res.data.msg);
              }
D
v1.2.0  
devil_gong 已提交
346 347 348 349
            }
          },
          fail: () => {
            my.hideLoading();
D
devil_gong 已提交
350
            app.showToast('服务器请求出错');
D
v1.2.0  
devil_gong 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
          }
        });
      }
    }
  },

  // 规格事件
  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 已提交
390
      this.setData({goods_specifications_choose: temp_data, goods_spec_base_images: temp_images, temp_buy_number: this.data.goods.buy_min_number || 1});
D
v1.2.0  
devil_gong 已提交
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

      // 不能选择规格处理
      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;
    }

    // 获取数据
D
1.6  
devil_gong 已提交
433
    my.request({
D
v1.2.0  
devil_gong 已提交
434 435 436 437
      url: app.get_request_url('spectype', 'goods'),
      method: 'POST',
      data: { "id": this.data.goods.id, "spec": JSON.stringify(spec) },
      dataType: 'json',
D
1.6  
devil_gong 已提交
438
      headers: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
      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 {
D
devil_gong 已提交
474
          app.showToast(res.data.msg);
D
v1.2.0  
devil_gong 已提交
475 476 477
        }
      },
      fail: () => {
D
devil_gong 已提交
478
        app.showToast('服务器请求出错');
D
v1.2.0  
devil_gong 已提交
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 508 509 510 511 512 513 514
      }
    });
  },

  // 获取规格详情
  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;
    }

    // 获取数据
D
1.6  
devil_gong 已提交
515
    my.request({
D
v1.2.0  
devil_gong 已提交
516 517 518 519
      url: app.get_request_url('specdetail', 'goods'),
      method: 'POST',
      data: { "id": this.data.goods.id, "spec": JSON.stringify(spec) },
      dataType: 'json',
D
1.6  
devil_gong 已提交
520
      headers: { 'content-type': 'application/x-www-form-urlencoded' },
D
v1.2.0  
devil_gong 已提交
521 522 523 524 525 526 527 528
      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 {
D
devil_gong 已提交
529
          app.showToast(res.data.msg);
D
v1.2.0  
devil_gong 已提交
530 531 532
        }
      },
      fail: () => {
D
devil_gong 已提交
533
        app.showToast('服务器请求出错');
D
v1.2.0  
devil_gong 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
      }
    });
  },

  // 数量输入事件
  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;
562
    var inventory = parseInt(this.data.goods_spec_base_inventory);
D
v1.2.0  
devil_gong 已提交
563 564 565 566 567 568
    var inventory_unit = this.data.goods.inventory_unit;
    if(buy_number < buy_min_number)
    {
      buy_number = buy_min_number;
      if(buy_min_number > 1)
      {
D
devil_gong 已提交
569
        app.showToast('起购'+buy_min_number+inventory_unit);
D
v1.2.0  
devil_gong 已提交
570 571 572 573 574
      }
    }
    if(buy_max_number > 0 && buy_number > buy_max_number)
    {
      buy_number = buy_max_number;
D
devil_gong 已提交
575
      app.showToast('限购'+buy_max_number+inventory_unit);
D
v1.2.0  
devil_gong 已提交
576 577 578 579
    }
    if(buy_number > inventory)
    {
      buy_number = inventory;
D
devil_gong 已提交
580
      app.showToast('库存数量'+inventory+inventory_unit);
D
v1.2.0  
devil_gong 已提交
581 582 583 584 585 586
    }
    this.setData({temp_buy_number: buy_number});
  },

  // 确认
  goods_buy_confirm_event(e) {
D
1.6  
devil_gong 已提交
587
    var user = app.get_user_info(this, 'goods_buy_confirm_event');
D
v1.2.0  
devil_gong 已提交
588 589
    if (user != false) {
      // 用户未绑定用户则转到登录页面
D
1.6  
devil_gong 已提交
590
      if (app.user_is_need_login(user)) {
D
v1.2.0  
devil_gong 已提交
591
        my.navigateTo({
D
devil_gong 已提交
592
          url: "/pages/login/login?event_callback=goods_buy_confirm_event"
D
v1.2.0  
devil_gong 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
        });
        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)
          {
            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']});
              }
            }
          }
          if(active_count < sku_count)
          {
D
devil_gong 已提交
616
            app.showToast('请选择属性');
D
v1.2.0  
devil_gong 已提交
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
            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)
            };
            my.navigateTo({
              url: '/pages/buy/buy?data=' + JSON.stringify(data)
            });
            this.popup_close_event();
            break;

          case 'cart' :
            this.goods_cart_event(e, spec);
            break;

          default :
D
devil_gong 已提交
642
            app.showToast('操作事件类型有误');
D
v1.2.0  
devil_gong 已提交
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
        }
      }
    }
  },

  // 详情图片查看
  goods_detail_images_view_event(e) {
    var value = e.currentTarget.dataset.value || null;
    if(value != null)
    {
      my.previewImage({
        current: 0,
        urls: [value]
      });
    }
  },
  // 商品相册图片查看
  goods_photo_view_event(e) {
    var index = e.currentTarget.dataset.index;
G
gongfuxiang 已提交
662 663 664 665 666
    var all = [];
    for (var i in this.data.goods_photo)
    {
      all.push(this.data.goods_photo[i]['images']);
    }
D
v1.2.0  
devil_gong 已提交
667 668
    my.previewImage({
      current: index,
G
gongfuxiang 已提交
669
      urls: all
D
v1.2.0  
devil_gong 已提交
670 671 672
    });
  },

D
devil_gong 已提交
673 674 675 676 677 678 679 680 681 682
  // 视频播放
  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 已提交
683 684
  // 显示秒杀插件-倒计时
  plugins_limitedtimediscount_countdown() {
D
devil_gong 已提交
685 686 687 688 689
    // 销毁之前的任务
    clearInterval(this.data.plugins_limitedtimediscount_timer);
    clearInterval(this.data.plugins_limitedtimediscount_timers);

    // 定时参数
D
devil_gong 已提交
690 691
    var status = this.data.plugins_limitedtimediscount_data.time.status || 0;
    var msg = this.data.plugins_limitedtimediscount_data.time.msg || '';
D
devil_gong 已提交
692 693 694
    var hours = parseInt(this.data.plugins_limitedtimediscount_data.time.hours) || 0;
    var minutes = parseInt(this.data.plugins_limitedtimediscount_data.time.minutes) || 0;
    var seconds = parseInt(this.data.plugins_limitedtimediscount_data.time.seconds) || 0;
G
gongfuxiang 已提交
695
    var self = this;
D
devil_gong 已提交
696
    if (status == 1) {
G
gongfuxiang 已提交
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
      // 秒
      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({
D
devil_gong 已提交
713 714 715 716
          'plugins_limitedtimediscount_data.time.hours': (hours < 10) ? '0' + hours : hours,
          'plugins_limitedtimediscount_data.time.minutes': (minutes < 10) ? '0' + minutes : minutes,
          'plugins_limitedtimediscount_data.time.seconds': (seconds < 10) ? '0' + seconds : seconds,
          plugins_limitedtimediscount_timer: timer,
G
gongfuxiang 已提交
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
        });

        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 已提交
739
        if(self.data.plugins_limitedtimediscount_is_show_time == false) {
G
gongfuxiang 已提交
740 741 742
          clearInterval(timers);
        }
      }, 100);
D
devil_gong 已提交
743 744 745
      self.setData({
        plugins_limitedtimediscount_timers: timers,
      });
G
gongfuxiang 已提交
746 747 748
    } else {
      // 活动已结束
      self.setData({
D
devil_gong 已提交
749
        'plugins_limitedtimediscount_data.desc': msg,
G
gongfuxiang 已提交
750 751 752 753 754
        plugins_limitedtimediscount_is_show_time: false,
      });
    }
  },

D
devil_gong 已提交
755 756 757 758 759 760
  // 页面销毁时执行
  onUnload: function () {
    clearInterval(this.data.plugins_limitedtimediscount_timer);
    clearInterval(this.data.plugins_limitedtimediscount_timers);
  },

D
devil_gong 已提交
761 762
  // 优惠劵领取事件
  coupon_receive_event(e) {
D
devil_gong 已提交
763 764 765 766 767
    // 参数处理
    if((e || null) == null)
    {
      var index = this.data.temp_coupon_receive_index;
      var value = this.data.temp_coupon_receive_value;
D
devil_gong 已提交
768 769 770
    } else {
      var index = e.currentTarget.dataset.index;
      var value = e.currentTarget.dataset.value;
D
devil_gong 已提交
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
      this.setData({temp_coupon_receive_index: index, temp_coupon_receive_value: value});
    }

    // 登录校验
    var user = app.get_user_info(this, 'coupon_receive_event');
    if (user != false) {
      // 用户未绑定用户则转到登录页面
      if (app.user_is_need_login(user)) {
        my.navigateTo({
          url: "/pages/login/login?event_callback=coupon_receive_event"
        });
        return false;
      } else {
        var self = this;
        var temp_list = this.data.plugins_coupon_data.data;
        if (temp_list[index]['is_operable'] != 0) {
          my.showLoading({ title: "处理中..." });
          my.request({
D
devil 已提交
789
            url: app.get_request_url("receive", "coupon", "coupon"),
D
devil_gong 已提交
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
            method: "POST",
            data: { "coupon_id": value },
            dataType: "json",
            header: { 'content-type': 'application/x-www-form-urlencoded' },
            success: res => {
              my.hideLoading();
              if (res.data.code == 0) {
                app.showToast(res.data.msg, "success");
                if (self.data.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) {
                  temp_list[index]['is_operable'] = 0;
                  temp_list[index]['is_operable_name'] = '已领取';
                  self.setData({ 'plugins_coupon_data.data': temp_list });
                }
              } else {
                if (app.is_login_check(res.data, self, 'coupon_receive_event')) {
                  app.showToast(res.data.msg);
                }
D
devil_gong 已提交
807
              }
D
devil_gong 已提交
808 809 810 811
            },
            fail: () => {
              my.hideLoading();
              app.showToast("服务器请求出错");
D
devil_gong 已提交
812
            }
D
devil_gong 已提交
813 814
          });
        }
D
devil_gong 已提交
815 816 817 818
      }
    }
  },

D
devil_gong 已提交
819 820
  // 展示型事件
  exhibition_submit_event(e) {
D
devil 已提交
821
    app.call_tel(this.data.common_app_customer_service_tel);
D
devil_gong 已提交
822 823
  },

D
devil_gong 已提交
824

D
v1.2.0  
devil_gong 已提交
825 826
  // 自定义分享
  onShareAppMessage() {
D
Devil 已提交
827
    var user = app.get_user_cache_info() || null;
D
Devil 已提交
828
    var user_id = (user != null && (user.id || null) != null) ? user.id : 0;
D
v1.2.0  
devil_gong 已提交
829
    return {
D
v1.9.0  
devil 已提交
830
      title: this.data.goods.title+'-'+app.data.application_title,
D
v1.2.0  
devil_gong 已提交
831
      desc: app.data.application_describe,
D
Devil 已提交
832
      path: '/pages/goods-detail/goods-detail?goods_id='+this.data.goods.id +'&referrer='+user_id
D
v1.2.0  
devil_gong 已提交
833 834 835 836
    };
  },
  
});