Page({
	data: {
		mch_list: [],
		order: {},
    id: '',
    car_appoint_id: ''
	},
	onLoad(e){
		console.log('传过来的数据',e)
		let id = e.id
		let that = this
		if(id != ('' || null || 'undefined' || undefined)){
			that.setData({
				id: id
			})
			this.getGoods()
		}
	},
	// 获取商品详情
	getGoods: function(){
    let id = this.data.id;
    let that = this
    let data = {
      id: id
    }
    if(typeof(id) != ('undefined' || undefined || null || '')){
			data.id = id
		}
		getApp().request({
      url: getApp().api.order.offline_goods_detail,
      data: data,
      success: function (t) {
        if (0 == t.code) {
          let e = t.data.attr_group_list;
          let mch_list = []
          let goods_list = []
          let attr_list = null;
          let attr = [];
          goods_list.push({
              goods_id: t.data.id,
              num: 1,
              attr: attr
          });
          mch_list.push({
            mch_id: 0,
            goods_list: goods_list
          })
          for(let i in e){
              for (let s in e[i].attr_list){
                  attr_list = {
                      attr_id: e[i].attr_list[s].attr_id,
                      attr_name: e[i].attr_list[s].attr_name
                  }
              }
              attr.push({
                  attr_group_id: e[i].attr_group_id,
                  attr_id: attr_list.attr_id
              })
          }
          var d = t.data;
          that.setData({
            order: d,
            attr_group_list: t.data.attr_group_list,
            btn: !0,
            mch_list: mch_list
          }),
          console.log(mch_list)
          that.newSubmitPreview()
        }
        1 == t.code && getApp().core.showModal({
          title: "提示",
          content: t.msg,
          showCancel: !1,
          success: function (t) {
            t.confirm && getApp().core.switchTab({
              url: "/pages/index/index"
            })
          }
        })
      }
    })
	},
	newSubmitPreview: function(t){

    let data = {
      mch_list:[]
    }
    let good_list = {
    	attr:[]
    }
    data.mch_list = JSON.stringify(this.data.mch_list)
    console.log('预约接口数据',data)
    let that = this
    getApp().request({
      url: getApp().api.order.new_submit_preview,
      method: "POST",
      data: data,
      success: function (res) {
        console.log(res,'下单')
        if(res.code == 0){
          res.data.mch_list[0].show = false
          res.data.mch_list[0].show_length = 0
          res.data.mch_list[0].offline = 0
          that.setData({
            mch_list: res.data.mch_list
          })
        }else{
          wx.showToast({
            icon: 'none',
            title: res.msg,
          })
          setTimeout(()=>{
            wx.navigateBack()
          },2000)
        }
      }
    })
  },
	pay: function(){
    let o = {
      mch_list:[]
    }
    o.mch_list = JSON.stringify(this.data.mch_list)
    o.payment = 3
    getApp().request({
      url: getApp().api.order.new_submit,
      method: "POST",
      data: o,
      success: function (res) {
        console.log(res,'下单sssss')
        getApp().request({
          url: getApp().api.order.pay_data,
          data: {
            order_id: res.data.order_id,
            pay_type: "WECHAT_PAY"
          },
          complete: function () {
            getApp().core.hideLoading()
          },
          success: function (t) {
            0 == t.code && getApp().core.requestPayment({
              _res: t,
              timeStamp: t.data.timeStamp,
              nonceStr: t.data.nonceStr,
              package: t.data.package,
              signType: t.data.signType,
              paySign: t.data.paySign,
              success: function (t) {},
              fail: function (t) {},
              complete: function (t) {
                "requestPayment:fail" != t.errMsg && "requestPayment:fail cancel" != t.errMsg ? getApp().core.redirectTo({
                  url: "/pages/order/order?status=2"
                }) : getApp().core.showModal({
                  title: "提示",
                  content: "订单尚未支付",
                  showCancel: !1,
                  confirmText: "确认",
                  success: function (t) {
                    t.confirm && getApp().core.redirectTo({
                      url: "/pages/order/order?status=0"
                    })
                  }
                })
              }
            }), 1 == t.code && getApp().core.showToast({
              title: t.msg,
              image: "/images/icon-warning.png"
            })
          }
        })
      }
    })
  },
});
