//获取应用实例
import { getDeviceScreen, CalcMethod } from '../../utils/comm.js'
const Calc = new CalcMethod(),
  app = getApp(),
  { hostname, business_id } = app.globalData
Page({
  data: {
    // hasLoadAllData: 0,
    // showLoading: 1,
    // scrollTop: 0,
    // showToTop: 0,
    // sortIndex: 0,
    // imgUrls: [
    // ],
    kindStatus: 1,
    videotatus: 1,
    acoStatus: 1,
    actStatus: 1,
    bookStatus: 1,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    serviceFlag: false,
    // indicatorColor: 'rgba(0,0,0,.3)',
    // indicatorActiveColor: '#ffffff',
    // goodsPage: 1,
    // catPage: 1,
    // goodsListHasMore: 1,
    // catListHasMore: 1
  },
  // 首次进入首页执行
  onLoad() {
    let that = this;
    that.getShopInfo(that);
    that.getVedio();
    app.getUserInfo()
  },
  //获取图片前缀
  // getImgBefore(that) {
  //   wx.request({
  //     url: app.globalData.hostname + 'shop/get_url',
  //     success(res) {
  //       let imgUrlBefore = res.data;
  //       wx.setStorageSync('imgUrlBefore', res.data);
  //       that.setData({
  //         imgUrlBefore: res.data
  //       })
  //     },
  //     complete() {
  //       that.getSwiper(that);
  //       that.getGoodsList(that);
  //       that.getSwtich(that);
  //       that.getIndexCat(that);
  //     }
  //   })
  // },
  //获取轮播
  getSwiper(that) {
    wx.request({
      url: app.globalData.hostname + 'Kaiguan/getChart',
      success(res) {
        that.setData({
          Swiper: res.data.data
        })
      }
    })
  },
  // 进入搜索页面
  // goSearch() {
  //   wx.navigateTo({
  //     url: '/pages/index/search/search'
  //   })
  // },
  // 分类跳转
  goKind(e) {
    let that = this,
      { key } = e.currentTarget.dataset;
    switch (key) {
      case 'seckill':
        wx.navigateTo({
          url: '/pages/Spike/Spike',
        })
        break;
      case 'bargain':
        wx.navigateTo({
          url: '/pages/bargain_goods_list/bargain_goods_list',
        })
        break;
      case 'group':
        wx.navigateTo({
          url: '/pages/group_goods/group_goods',
        })
        break;
      case 'nearby':
        wx.navigateTo({
          url: '/pages/nearby/nearby',
        })
        break;
      case 'integral':
        wx.navigateTo({
          url: '/pages/more/integral_goods/integral_goods',
        })
        break;
      case 'about':
        wx.navigateTo({
          url: '/pages/more/aboutus/aboutus',
        })
        break;
      case 'coupon':
        wx.navigateTo({
          url: '/pages/coupon/coupon',
        })
        break;
      case 'tuike':
        wx.navigateTo({
          url: '/pages/more/points_list/points_list',
        })
        break;
      case 'sign':
        wx.switchTab({
          url: '/pages/more/more',
        })
        break;
      case 'pay':
        wx.navigateTo({
          url: '/pages/pay/pay',
        })
        break;
      case 'about':
        wx.navigateTo({
          url: '/pages/more/aboutus/aboutus',
        })
        break;
      default:
        wx.navigateTo({
          url: '/pages/information/information',
        })
        break;
    }
  },
  // 获取首页分类及活动的开关信息
  getSwtich(that) {
    wx.request({
      url: app.globalData.hostname + 'shop/switch_list',
      success(res) {
        let swtich = res.data.data;
        that.setData({
          kindStatus: swtich[0].status,
          videotatus: swtich[14].status,
          isckillStatus: swtich[16].status,
          igroupStatus: swtich[17].status,
          ibookStatus: swtich[15].status,
          swtich
        })
      }
    })
  },
  //根据距离显示客服
  getService(e) {
    let that = this;
    if (e.detail.scrollTop > 300) {
      that.setData({
        serviceFlag: true
      })
    } else {
      that.setData({
        serviceFlag: false
      })
    }
  },
  // 获取首页商品列表
  getGoodsList(that) {
    wx.request({
      url: app.globalData.hostname + 'shop/index_goods',
      success(res) {
        that.setData({
          goodsList: res.data.data
        })
      }
    })
  },
  //预约表单提交
  // submit(e) {
  //   console.log(e)
  //   let that = this,
  //     myreg = /^[1][3,4,5,7,8][0-9]{9}$/,
  //     { name, phone } = e.detail.value,
  //     phoneValid = myreg.test(Number(phone));
  //   if (name == '') {
  //     wx.showToast({
  //       title: '姓名不能为空',
  //       image: '/images/error.png',
  //       duration: 1000
  //     })
  //   } else if (phone == '') {
  //     wx.showToast({
  //       title: '电话不能为空',
  //       image: '/images/error.png',
  //       duration: 1000
  //     })
  //   } else if (!phoneValid) {
  //     wx.showToast({
  //       title: '号码输入有误',
  //       image: '/images/error.png',
  //       duration: 1000
  //     })
  //   } else {
  //     wx.request({
  //       url: app.globalData.hostname + 'shop/send_yuyue',
  //       data: {
  //         name, phone
  //       },
  //       success(res) {
  //         if (res.data.code == 200) {
  //           wx.showToast({
  //             title: res.data.info,
  //             icon: 'success',
  //             duration: 1000
  //           })
  //         }
  //       },
  //       complete() {
  //         that.setData({
  //           name: '',
  //           phone: ''
  //         })
  //       }
  //     })
  //   }
  // },
  // 分类跳转
  goCate(e) {
    let { id } = e.currentTarget.dataset;
    app.globalData.id = id;
    wx.switchTab({
      url: '/pages/cate/cate'
    })
  },
  // 进入商品详情
  // goGoodsDetails(e) {
  //   let { id } = e.currentTarget.dataset;
  //   wx.navigateTo({
  //     url: '/pages/index/goodsdetail/goodsdetail?id=' + id
  //   })
  // },
  // 获取店铺信息
  getShopInfo(that) {
    wx.request({
      url: app.globalData.hostname + 'shop/index_info',
      success(res) {
        wx.setStorageSync("indexInfo", res.data.data)
        that.setData({
          indexInfo: res.data.data
        })
      }
    })
  },
  // 拨打客服电话
  callPhone() {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.indexInfo.phone
    })
  },


  // qi
  seeDownLine: function (e) {
    var that = this;
    var share_status = e.currentTarget.dataset.share_status;
    if (share_status != 1) {
      that.setData({
        showApply: true,
      })
      return;
    }
    wx.navigateTo({
      url: "downLine/downLine?withdraw=true"
    })
  },


  // 领取优惠券
  getCoupon(e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    wx.request({
      url: app.globalData.hostname + 'get_red',
      data: {
        user_id: wx.getStorageSync('openid'),
        activi_id: id
      },
      success: function (res) {
        if (res.data == 20000) {
          wx.showToast({
            title: '您已领取过了',
            image: '../../images/warning.png',
            duration: 1500,
            success: function () {
              setTimeout(function () {
                that.setData({
                  showApply: false,
                })
              }, 500)
            }
          })

        } else if (res.data == 10000) {
          wx.showToast({
            title: '领取成功',
            duration: 1500,
            success: function () {
              setTimeout(function () {
                that.setData({
                  showApply: false,
                })
              }, 500)
            }
          })

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  //获取优惠券列表
  getCouponList() {
    let that = this;
    wx.request({
      url: app.globalData.hostname + 'coupon_activi_list',
      data: {
        user_id: wx.getStorageSync("openid")
      },
      success(res) {

        that.setData({
          couponList: res.data.data
        })
      }
    })
  },


  // 获取首页分类
  getIndexCat(that) {
    wx.request({
      url: app.globalData.hostname + 'shop/index_cat',
      success(res) {
        that.setData({
          indexCat: res.data.data
        })
      }
    })
  },


  //获取视频
  getVedio() {
    let that = this;
    wx.request({
      url: app.globalData.hostname + 'Kaiguan/getVedio',
      data: {

      },
      success(res) {

      }
    })
  },
  
 
})
