const _Http = getApp().globalData.http;
Page({
  data: {
    skeletonShow: false,
    loading: false,
    sa_brandid: null,
    tradefield: null,
    brandList: [],
    domainList: []
  },
  onLoad(options) {
    console.log(options)
    _Http.basic({
      "id": 20230105144102,
      "content": {
        nocache: true,
        "sa_orderid": options.id
      }
    }).then(res => {
      console.log(res)
      this.setData({
        brandList: res.data.brands,
        domainList: res.data.tradefields,
      })
    })
  },
  /* 选择品牌 */
  onSelectBrand(e) {
    let {
      item
    } = e.currentTarget.dataset;
    if (this.data.sa_brandid == item.sa_brandid) return;
    this.setData({
      sa_brandid: item.sa_brandid
    })
  },
  /* 选择领域 */
  onSelect(e) {
    let {
      item
    } = e.currentTarget.dataset;
    if (this.data.tradefield == item.tradefield) return;
    this.setData({
      tradefield: item.tradefield
    })
  },
  submit() {
    if (this.data.loading) return;
    this.setData({
      loading: true
    })
    _Http.basic({
      "id": 20221108111402,
      content: {
        sa_orderid: 0,
        sa_accountclassid: 0,
        rec_contactsid: 0,
        pay_enterpriseid: 0,
        "sa_brandid": this.data.sa_brandid, //品牌ID
        "type": "标准订单", //订单类型
        "tradefield": this.data.tradefield, //必选
      }
    }).then(res => {
      this.setData({
        loading: false
      })
      console.log("创建标准订单", res);
      wx.showToast({
        title: res.msg != '成功' ? res.msg : '创建成功',
        icon: "none"
      });
      if (res.msg == '成功') setTimeout(() => {
        wx.redirectTo({
          url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
        });
      }, 500)
    })
  }
})