//这个页面是付尾款
var t = getApp(), app = t, a = t.request, e = require("../../../../utils/common.js"),
  s = require("../../../../utils/util.js"), ut = s, o = require("../../../../utils/md5.js"), to = getApp();
var oo = t.globalData.setting, os = oo;
var regeneratorRuntime = require('../../../../utils/runtime.js');
var util_pay = require("../../../../utils/pay.js");
const t_pay = require("../../../../utils/pay2.js");


Page({
  data: {
    url: t.globalData.setting.url,
    resourceUrl: t.globalData.setting.resourceUrl,
    imgUrl: t.globalData.setting.imghost,
    goods: null,
    order: null,
    orderPrices: null,
    coupons: null,
    coupon: null,
    invoiceToggle: !0,
    payWithUserMoney: !0,
    payWithPoints: !0,
    maxWord: 0,
    enterAddressPage: !1,
    firstEnter: !0,
    //页面获取的参数
    param: null,
    //提交订单的格式
    /*-----------当是购物车结算的时候-------------*/
    cartlist: null,
    old_cartlist: null,
    cartlist_y: null,  //购物车原始列表
    js_use_money: 0,  //是否使用余额
    is_all_zt: 1,      //是否全部都是自提

    /*----------------立即购买---------------------*/
    is_b_now: 0,    //0是购物车结算  1立即购买
    bn_goods: null, //立即购买时候的调用商品
    bn_use_money: 0,//是否使用余额
    bn_exp_type: 1, //0是物流 1自提
    bn_pick: 0,     //选择的门店
    bn_pickname: "", //选择的门店名称
    bn_t_exp_t: 0,    //判断商品和门店一起决定的物流自提的方式0 都可以 1自提 2物流

    bn_plus_cut_price: 0,  //显示等级卡会优惠多少钱
    /*------------------------*/
    user_addr: null,//物流
    userinfo: null, //获取会员
    /*----------物流选择--------*/
    wu_arr: null,
    index: 0,
    w_sele_index: 0,

    //判断页面是返回回来的还是 首次进入的
    isclose: 1,
    //申请提现的金额
    txmon: 0,
    yuer: 0,
    //提交中，不重复提交
    is_summit_ing: 0,
    //--更优惠券抵用有关，立即购买的，如果是购物车，就要把相应的值，写入cartlist数组中--
    ckeck_quan_price: 0,
    check_quan_price_list: '',
    check_quan_ware_list: '',
    ckeck_quan_price_scj: 0,  //优惠券用市场价进行获取

    isget_by_quan: {},       //是否调用了接口获取包邮券
    // 设计一个数组来存放已经选择了的券编号,coupon_no是券号，money是面值，coupon_price是真正优惠的价格，数组的下标是pickid
    //using_quan[11]={coupon_no:"1212121",money:"20",coupon_price:"45"}
    using_quan: {},
    open_quan: 0,
    //选择的券列表
    selected_quan_list: null,
    //选择的券的门店
    selected_quan_pick: null,
    is_close_quan: 0,
    disabled: 0,
    open_express: 0,//控制选择物流名列表 的属性

    is_express: 0,       //选中物流的属性
    expres_name: "",     //点击选定
    isopen: 0,           //券的说明
    is_coupon: null,     //选择券的控制属性
    is_shipping_code: "",//插入用户默认地址
    wu_arr_txt: "",      //要更新的物流的字段

    sales_rules: 1,         //默认是显示线上库存
    isget_by_quan: {},       //是否调用了接口获取包邮券
    get_by_quan_list: null,       //立即购买的
    get_by_quan_list_cart: {},    //购物车的
    by_quan_list_cart: null,   //点击选择的包邮列表

    //如果是全场包邮了，或者是全场不包邮了，就不要选包邮券
    is_no_by: {},
    is_by: {},
    is_quan_by: {},
    //--购买赠送的商品--
    buy_now_gift_goods: null,
    //--订单优惠--
    order_prom: {},
    //-- 购物车优惠活动 --
    prom_goods_map: {},
    //-- order_prom_list --
    order_prom_list_cart: null,

    ispt_goods: 0,       //是否平摊至单品，0要平摊 1不平摊

    rank_switch: 0,      //是不是开同等级卡
    show_card: null,     //显示的等级卡
    card_name: '',       //显示的卡的名称
    card_cut_price: null,//减价多少钱

    show_submit: 0,      //提交按钮变正常显示
    is_get_offline: 1,

    tabs: ['门店自提', '快递邮寄'],
    currentTabIndex: 1,

    order_sn: '',
    order_id: '',
    exp_price: 0,
    order_prom_amount: 0,
    paying: 0,
    same_ok: 1,  //同城配送按钮控制
    bconfig: null,
    showFold: true,

    is_fwk: 0,  //-- 是不是服务卡项的购买 -- 
    sameCityExp_off: 0, //未达到起送价
    sameCityExp_info: '',//未达到起送价提示信息
    first_entry: 0,//进入次数，如果是第一次进入，进行判断是否进行优惠券是否直接使用
    def_coupon1: null,//购物车优惠券列表
    def_coupon2: null,//直接购买优惠券列表
    def_coupon3: null,//购物车包邮券列表
    def_coupon4: null,//直接购买包邮券列表
  },



  onReady() {

    setTimeout(() => {
      wx.createSelectorQuery().selectAll(".showArea, .hideArea").boundingClientRect(res => {
        if (res.length != 0) {
          this.setData({
            showFold: res[0].height < res[1].height,
          });
        };

      }).exec();
    }, 1000);

  },

  clickCollapse() {
    this.setData({
      flag: !this.data.flag,
    })
  },
  onLoad: function (t) {

    //定义第一次进入
    this.data.fir_in = 1;

    if (t.order_id) this.data.order_id = t.order_id;
    if (t.order_sn) this.data.order_sn = t.order_sn;

    if (t.is_fwk) {
      this.setData({ is_fwk: 1 });
    }

    wx.setNavigationBarTitle({ title: "订单详情", })
    var th = this;
    getApp().getConfig2(function (e) {
      th.setData({
        bconfig: e
      });
    }, 1);
    this.setData({ is_b_now: t.is_bnow == undefined ? 0 : t.is_bnow, });
    th.data.param = t;
    //清理一下，确保最新的系统配置
    getApp().globalData.config2 = null;
    //清空is_pick_up
    getApp().request.put("/api/weshop/useraddress/updatePickUp", {
      data: { user_id: getApp().globalData.user_id, is_pickup: 0 },
      success: function (s) {
      }
    });
    if (!getApp().globalData.userInfo) {
      getApp().goto("/packageE/pages/togoin/togoin");
    }

    getApp().getConfig2(function (e) {
      th.setData({
        bconfig: e
      });
    }, 1);

    //判断是不是佣金抵扣
    getApp().is_distribut(this);

  },
  onUnload: function () {
    this.setData({ isclose: 1 })
  },
  onHide: function () {
    this.setData({
      isget_by_quan: {},
      is_no_by: {},
      is_by: {}
    })
    this.data.fir_in = 0;
  },

  //----------子页返回父页触发----------
  onShow: function () {

    this.data.paying = 0;
    console.log('onshow-2222');


    this.updateOrderCoupon();

    var th = this;
    //判断是不是第一次进入
    if (this.data.fir_in) {
      this.data.fir_in = 0;
    } else {

      console.log('onshow-3333');
      let o_list = "/pages/user/order_list/order_list";
      if (this.data.is_fwk) {
        o_list = '/pages/user/order_list/order_list?index=2&tabindex=1';
      }
      //-- 富友支付的 --
      var fy = ut.fy_back(o_list, 1);
      if (fy) return false;
      util_pay.set_fir();
      t_pay.set_fir();

      //-- 通联的第三方支付的返回优化 --
      ut.is_pay_ok(th.data.ok_order_sn, "back", "back", function () {

        console.log('onshow-444');
        console.log(th.data.ok_order_sn);

        if (!th.data.ok_order_sn) return false;

        let ord_url = '';
        let ord_req = {};
        //-- 如果是服务卡项的时候 --
        if (th.data.is_fwk) {
          ord_url = "/api/weshop/recharge/user/page";
          ord_req = { store_id: os.stoid, order_sn: th.data.ok_order_sn, user_id: getApp().globalData.user_id };
        } else {
          ord_url = "/api/weshop/order/page";
          ord_req = { store_id: os.stoid, parent_sn: th.data.ok_order_sn };
        }

        getApp().request.promiseGet(ord_url,
          { data: ord_req }).then(res => {
            if (ut.ajax_ok(res)) {

              console.log('onshow-444');
              console.log(res);

              var item = res.data.data.pageData[0];
              if (item.pay_status == 1) {
                //支付支付，返回首页
                ut.m_toast('支付成功');
                setTimeout(() => {
                  wx.navigateBack();
                }, 1000)

              } else {
                //支付支付，返回首页
                ut.m_toast('支付失败');
                setTimeout(() => {
                  wx.navigateBack();
                }, 1000)
              }
            }
          })
      });

    }



    th.setData({ show_submit: 0 }); //让提交先掩藏
    th.data.g_cart_q_time = null;
    if (th.data.isclose == 0) {
      wx.navigateTo({
        url: "/pages/index/index/index"
      })
    } else {
      this.getuser_addr(function (ie) {
        //地址切换要把包邮券清空
        if (!th.data.user_addr || !ie || th.data.user_addr.address_id != ie.address_id) {
          var using_quan = th.data.using_quan;
          for (var i in using_quan) {
            var item = using_quan[i];
            if (item.isby == 1) {
              var ob = {}, txt = "using_quan[" + i + "]";
              ob[txt] = {};
              th.setData(ob);
            }
          }
          th.data.isget_by_quan = {};
        }


        th.data.prom_goods_map = {};
        th.data.is_summit_ing = 0;
        //更换地址回来要重新调用计算价钱的接口
        if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) {
          th.setData({ user_addr: ie });
          th.setData({ add_back: 1, same_ok: 1 });
          th.calculatePrice2();
        } else {
          th.setData({ user_addr: ie });
        }
        var going = 0;
      });

      var is_card_back = getApp().globalData.is_card_back;
      //--更新默认地址--,看一下是不是跳到地址页面,同时也不是购买等级卡返回的，这里很重要，否则会重新更新收货物流公司
      if (!getApp().globalData.is_cart_old && !is_card_back && !getApp().globalData.plus_buy_back) {
        this.update_code();
      } else {
        getApp().globalData.is_cart_old = 0;
        getApp().globalData.plus_buy_back = 0;
      }
    }

    //先获取是否有关闭使用优惠券
    getApp().getConfig2(function (ee) {
      var json_d = JSON.parse(ee.switch_list);
      th.data.json_d = json_d;
      th.data.ispt_goods = json_d.ispt_goods;  //是不是平摊到单品的控制参数赋值
      var is_default_logistics = json_d.is_default_logistics;
      var is_same_city = json_d.is_same_city;

      th.setData({
        is_close_quan: json_d.is_close_quan,
        sales_rules: ee.sales_rules,
        rank_switch: json_d.rank_switch,
        is_default_logistics: is_default_logistics,
        is_same_city: is_same_city,
        sys_switch: json_d,
      });

      var rank_switch = json_d.rank_switch;
      var max_price = -1;
      var show_card = null;
      var name = "";
      //如果有开等级卡的时候,
      //因为都是调接口，要返回在计算
      if (rank_switch == 2) {
        //-- 获取所有的等级卡, --
        getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?storeId=" + os.stoid,
          {}).then(res => {
            if (res.data.code == 0) {
              var plusCard = res.data.data;
              //-- 循环判断，拿到最贵的那张卡 --
              for (var ih in plusCard) {
                if (plusCard[ih].IsStopBuy == true) {
                  continue;
                }
                if (max_price < 0) {
                  max_price = plusCard[ih].CardFee;
                  name = 'card' + plusCard[ih]['CorrPrice'];
                  show_card = plusCard[ih];
                } else {
                  if (max_price < plusCard[ih].CardFee) {
                    max_price = plusCard[ih].CardFee;
                    name = 'card' + plusCard[ih]['CorrPrice'];
                    show_card = plusCard[ih];
                  }
                }
              }

              if (show_card) {
                name = name.toLowerCase();
                th.setData({ card_name: name, show_card: show_card })
              }
            }
            //-----先获取物流，再获取用户信息，再展示页面-----
            th.get_wuliu(th.get_info(th.show_page));
          })
      } else {
        //-----先获取物流，再获取用户信息，再展示页面-----
        th.get_wuliu(th.get_info(th.show_page));
      }

    }, 1);

    //值在这里换
    getApp().globalData.plus_buy_back = 0;
  },

  //-------------------获取物流---------------
  get_wuliu(func) {
    var th = this;
    to.getwuliu(function (e) {
      //系统是是否开启了默认的物流
      if (th.data.is_default_logistics) {
        //如果第一个不是开启默认，说明要让用户自己选
        if (!e[0].is_default) {
          th.setData({ is_default_logistics: 0 });
        }
      }
      th.setData({ wu_arr: e })
      typeof func == "function" && func();
    })
  },
  //------获取会员信息-----先获取用户信息，在进行下一步---
  get_info: function (func) {
    var user_id = t.globalData.user_id;
    to.auth.get_u(func);
  },

  //------获取会员收货地址-----
  getuser_addr: function (func) {
    var th = this;
    a.get("/api/weshop/useraddress/page", {
      data: { user_id: to.globalData.user_id, store_id: oo.stoid, pageSize: 600, t: Math.random() },
      success: function (su) {

        var item = null;
        if (su.data.code == 0 && su.data.data && su.data.data.pageData) {
          var user_addr = su.data.data.pageData;
          var def_item = null;
          for (var i = 0; i < user_addr.length; i++) {
            if (user_addr[i]['is_default'] == 1) {
              def_item = user_addr[i];
            }
            if (user_addr[i]['is_pickup'] == 1) {
              item = user_addr[i];
            }
          }

          if (item == null) item = def_item;
          if (item == null) item = user_addr[0];
        }

        if (item == undefined) item = null;
        if (!item) th.setData({ user_addr: null });  //地址为空的时候，要清空，因为返回的时候，有缓存

        func(item);
      }
    });
  },

  //----------------展示页面,是再获取用户信息之后--------------
  show_page: function () {
    var th = this,
      to = getApp();
    th.setData({
      userinfo: to.globalData.userInfo,
    });
    //选获取地址
    th.getuser_addr(function (addr) {

      if (addr == null || addr == undefined || addr.length == 0) {
        th.setData({
          enterAddressPage: 1,
        });

      } else {
        th.setData({
          user_addr: addr, enterAddressPage: 0,
        });
      }
      //获取立即购买的商品信息
      th.get_buy_goods(th.data.order_id, th.data.order_sn);
    });
    //获取提现金额
    getApp().request.get("/api/weshop/withdrawals/summoney", {
      data: {
        user_id: to.globalData.user_id,
        store_id: oo.stoid,
        status: 0
      },
      success: function (su) {
        console.log("withdrawals");
        if (su.data.code == 0) {
          var yuer = parseFloat(th.data.userinfo.user_money -
            th.data.userinfo.frozen_money - su.data.data.summoney).toFixed(2);
          th.setData({
            txmon: su.data.data.summoney,
            yuer: yuer
          });
        }
      }
    });
  },

  //-----获取商品------
  async get_buy_goods(ord, o_sn) {

    console.log('is_fwk');
    console.log(this.data.is_fwk);

    if (this.data.is_fwk) {
      this.get_buy_card(o_sn, ord);
      return false;
    }

    var order = null,
      order_goods = null,
      goods = null,
      pickup = null,
      distr_type = 0,
      exp_type = 0,
      presell = null,  //订单从表
      pre_arr = null,  //订单内容
      act = null,  //订单内容
      th = this;

    if (o_sn) {
      //获取order信息根据订单编号order_sn
      await getApp().request.promiseGet("/api/weshop/order/page", {
        data: { store_id: os.stoid, order_sn: o_sn, }
      }).then(res => {
        order = res.data.data.pageData[0];
      })


      ord = order.order_id;
    } else {
      //---获取订单---
      await getApp().request.promiseGet("/api/weshop/order/get/" + oo.stoid + "/" + ord, {}).then(res => {
        order = res.data.data;
      });
    }


    //---获取订单从表---
    await getApp().request.promiseGet("/api/weshop/ordergoods/page", {
      data: {
        store_id: oo.stoid,
        order_id: ord
      }
    }).then(res => {
      order_goods = res.data.data.pageData[0];
    });

    await getApp().request.promiseGet("/api/weshop/order/orderPresell/get/" + oo.stoid + "/" + order.order_id, {}).then(res => {
      presell = res.data.data;
    });

    //等待定金
    if (order.order_status < 2 && presell.deposit_pay_time <= 0) {
      th.setData({ wait_dj: 1 })
    }
    //等待尾款
    if (order.order_status < 2 && presell.deposit_pay_time > 0 && presell.tail_pay_state == 0 && presell.presell_type != 1) {
      th.setData({ wait_wk: 1 })
      wx.setNavigationBarTitle({ title: "支付尾款", })
    }
    //等待发货
    if (order.pay_status == 1 && order.shipping_status == 0) {
      th.setData({ wait_fh: 1 })
    }

    if (order.pay_status == 1 && order.shipping_status == 1 && order.order_status < 2) {
      th.setData({ wait_sh: 1 })
    }
    //------获取预售主表----------
    await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellForm/get/" + os.stoid + "/" + presell.prom_id, {}).then(res => {
      if (res.data.code == 0 && res.data.data) {
        act = res.data.data;

        th.setData({
          act: res.data.data,
        });
      }
    })

    //-- 判断一下会员的身份 --
    if (order.pay_status == 0) {
      var pre_data = { store_id: os.stoid, presell_id: presell.prom_id, timetype: 12, goods_id: order_goods.goods_id };
      pre_data.user_id = order.user_id;
      var isok = 1;
      await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellList/page", {
        data: pre_data,
      }).then(e => {
        if (e.data.code == 0 && e.data.data.pageData && e.data.data.pageData.length > 0) {
          pre_arr = e.data.data.pageData[0];
        } else {
          isok = 0;
        }
      })

      if (!isok) {
        getApp().confirmBox("会员身份不符合");
        return false;
      }

      if (th.data.wait_dj) {
        if (act.is_end) {
          getApp().confirmBox("活动已经结束");
          return false;
        }
        if (!act.isuse) {
          getApp().confirmBox("活动未启用");
          return false;
        }
        if (th.data.act.end_time < ut.gettimestamp()) {
          getApp().confirmBox("活动的定金时间已经结束", function () {
            ut.wx_back();
          });
          return false;
        }

      }
      if (th.data.wait_wk) {
        if (th.data.act.pay_enddate < ut.gettimestamp()) {
          getApp().confirmBox("活动的尾款时间已经结束", function () {
            ut.wx_back();
          });
          return false;
        }
      }
    }
    else {
      await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellList/list", {
        data: { store_id: os.stoid, goods_id: order_goods.goods_id, presell_id: order_goods.prom_id }
      }).then(re => {
        if (re.data.code == 0 && re.data.data && re.data.data.length > 0) {
          pre_arr = re.data.data[0];
        }
      })

      if (!pre_arr) {
        getApp().confirmBox("未找到商品");
        return false;
      }
    }

    //---获取商品---
    await getApp().request.promiseGet("/api/weshop/goods/get/" + oo.stoid + "/" + order_goods.goods_id, {}).then(res => {
      goods = res.data.data;
      order.market_price = goods.market_price;
      order.show_img = oo.imghost + goods.original_img;
    });

    //-- 如果商品有同城配送的参数的时候,一件代发商品不能显示同城配送按钮 --
    if (goods.is_same_city && th.data.is_same_city && goods.whsle_id <= 0) {

      await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + order.pickup_id, {}).then(res => {
        if (res.data.code == 0) {
          var pk = res.data.data;
          if (pk && pk.is_same_city) {
            th.setData({ show_same_city: 1 })
          }
        }

      })

    }

    //如果有开启佣金抵扣，同时会员是分销商的时候
    if (getApp().globalData.userInfo.is_distribut
      && th.data.dis_config && th.data.dis_config.is_yongjin_dk) {
      var fir_num = 0;
      var sec_num = 0;
      var thi_num = 0;
      if (th.data.dis_config.pattern == 1) {
        fir_num = (goods.fir_rate || 0) * order_goods.goods_num;
        sec_num = (goods.sec_rate || 0) * order_goods.goods_num;
        thi_num = (goods.thi_rate || 0) * order_goods.goods_num;
      } else {
        fir_num = parseFloat((goods.commission || 0) * order_goods.goods_num * (th.data.dis_config.firstRate || 0) / 100).toFixed(2);
        sec_num = parseFloat((goods.commission || 0) * order_goods.goods_num * (th.data.dis_config.secondRate || 0) / 100).toFixed(2);
        thi_num = parseFloat((goods.commission || 0) * order_goods.goods_num * (th.data.dis_config.thirdRate || 0) / 100).toFixed(2);
      }
      var c_num = getApp().get_commission(fir_num, sec_num, thi_num, th);
      goods.use_commission = c_num;
    }


    var g_url = "/packageC/pages/presell/goodsInfo/goodsInfo?goods_id=" + order_goods.goods_id + "&pre_id=" + pre_arr.id;
    if (act.is_end || th.data.act.end_time < ut.gettimestamp()) {

      if (goods.prom_type == 8 && goods.prom_id == act.id) {
        g_url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + order_goods.goods_id;
        getApp().request.put("/api/weshop/goods/update",
          {
            data: { goods_id: order_goods.goods_id, store_id: os.stoid, prom_id: 0, prom_type: 0 },
            success: function (e) { }
          });
      } else {
        g_url = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + order_goods.goods_id;
        if (goods.prom_type == 8) {
          g_url = "/packageC/pages/presell/goodsInfo/goodsInfo?goods_id=" + order_goods.goods_id + "&prom_id=" + goods.prom_id;
        }

      }

    }


    //判断使用优惠券的接口需要
    th.data.check_quan_ware_list = goods.erpwareid;
    //---获取门店---
    await getApp().request.promiseGet("/api/weshop/pickup/get/" + oo.stoid + "/" + order.pickup_id, {}).then(res => {
      pickup = res.data.data;
    });

    order['is_all_return'] = 0;
    //------------对比一下有没有退款记录------------
    await getApp().request.promiseGet("/api/weshop/order/returngoods/page", {
      data: {
        order_id: order.order_id, store_id: oo.stoid,
        user_id: order.user_id, pageSize: 200
      }
    }).then(rss => {
      var ttd = rss;
      //----没有相关的退款记录----
      if (ttd.data.data.total == 0) {
        order['is_all_return'] = 0;
      } else {
        var eea = ttd.data.data.pageData[0];
        //1.退款正在进行中，
        //2.退款被拒绝就要显示可以退款
        //3.退款已经完成
        order['is_all_return'] = 1;
        order['is_all_return_status'] = ttd.data.data.pageData[0].status;

        if (order['order_status'] == 1 && order['pay_status'] == 1) {
          switch (eea.status) {
            case 0:
            case 1:
              order.order_status_detail = "退款中";
              order['return_btn'] = 2; break;
            case 2:
              order.order_status_detail = "退款完成";
              order['return_btn'] = 4; break;
            case 3:
              order['return_btn'] = 3; break;
            default:
              order['return_btn'] = 0;
          }
        }
      }
    })

    var price = presell.presell_price;
    if (!goods) return false;

    if (goods.is_minishop == 1 && getApp().is_sp_hao()) {

      if (goods.distr_type == 1 || pickup.distr_type == 1) {
        wx.showToast({
          title: "视频号仅支持物流",
          icon: 'none',
          duration: 2000
        })

        setTimeout(function () {
          wx.navigateBack({ delta: 1 })
        }, 1000)

        return false
      }

      goods.distr_type = 2;
      th.setData({ show_same_city: 0 })

    }

    //--判断物流--
    if (goods.distr_type)
      distr_type = goods.distr_type;
    else
      distr_type = pickup.distr_type;

    switch (distr_type) {
      case 0:
        exp_type = 1;
        //-- 系统后台有设置要默认的 --
        if (th.data.sys_switch.pickupway && th.data.sys_switch.pickupway == 1) exp_type = 0;
        break; //自选
      case 1:
        exp_type = 1;

        break //自提
      case 2:
        exp_type = 0;
        break; //物流
    }


    if (th.data.show_same_city == 1 && th.data.sys_switch.pickupway && th.data.sys_switch.pickupway == 2) {
      exp_type = 2;
    }

    if (th.data.exp_type) {
      exp_type = th.data.exp_type
    }


    //等待发货的时候
    if (th.data.wait_fh) {
      var send_time = th.data.act.delivery_date;
      if (th.data.act.delivery_type == 2) {
        send_time = ut.gettimestamp() + th.data.act.delivery_daynum * 3600 * 24;
      }
    }

    order.order_goods = order_goods;
    var tail_pay = pre_arr.presell_price * order_goods.goods_num - presell.presell_deposit;
    this.setData({
      order: order,
      distr_type: distr_type,
      pickup: pickup,
      exp_type: exp_type,
      goods: goods,
      presell: presell,
      pre_arr: pre_arr,
      userInfo: getApp().globalData.userInfo,
      tail_pay: tail_pay,
      order_goods: order_goods,
      all_price: pre_arr.presell_price * order_goods.goods_num,
      pickup_id: pickup.pickup_id,
      send_time: send_time,
      g_url: g_url
    });
    th.get_diff();
    //如果可以
    if (th.data.act.is_usecoupon) {
      await th.get_buy_now_quan();
    }
    //统一进行计算金额
    th.calculatePrice2();

  },


  //-- 服务卡项购买的时候 --
  async get_buy_card(o_sn, ord) {

    let order = null,
      order_goods = null,
      goods = null,
      pickup = null,
      distr_type = 0,
      exp_type = 0,
      presell = null,  //订单从表
      pre_arr = null,  //订单内容
      act = null,  //订单内容
      th = this;

    let url = '/api/weshop/recharge/user/page'
    let data = {
      store_id: os.stoid,
      user_id: getApp().globalData.user_id,
      order_sn: o_sn,
    };

    if (!o_sn) {
      delete data.order_sn;
      data.order_id = ord;
    }



    // 请求数据
    let res = await app.promiseGet(url, {
      data: data,
    });

    if (!ut.ajax_ok(res)) {
      getApp().confirmBox("未找到订单");
      return false;
    }

    order = res.data.data.pageData[0];
    //---获取订单从表---
    await getApp().request.promiseGet("/api/weshop/rechargeServicelist/page", {
      data: {
        store_id: os.stoid,
        order_id: order.order_id
      }
    }).then(res => {
      order_goods = res.data.data.pageData[0];
    });

    order_goods.goods_num = order_goods.qty;

    await getApp().request.promiseGet("/api/weshop/recharge/rechargePresell/get/" + oo.stoid + "/" + order.order_id, {}).then(res => {
      presell = res.data.data;
    });

    //等待定金
    if (order.order_status < 2 && presell.deposit_pay_time <= 0) {
      th.setData({ wait_dj: 1 })
    }
    //等待尾款
    if (order.order_status < 2 && presell.deposit_pay_time > 0 && presell.tail_pay_state == 0 && presell.presell_type != 1) {
      th.setData({ wait_wk: 1 })
      wx.setNavigationBarTitle({ title: "支付尾款", })
    }
    //等待发货
    if (order.pay_status == 1 && order.shipping_status == 0) {
      th.setData({ wait_fh: 1 })
    }

    if (order.pay_status == 1 && order.shipping_status == 1 && order.order_status < 2) {
      th.setData({ wait_sh: 1 })
    }
    //------获取预售主表----------
    await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellForm/get/" + os.stoid + "/" + presell.prom_id, {}).then(res => {
      if (res.data.code == 0 && res.data.data) {
        act = res.data.data;
        th.setData({
          act: res.data.data,
        });
      }
    })

    //-- 判断一下会员的身份 --
    if (order.pay_status == 0) {
      var pre_data = { store_id: os.stoid, presell_id: presell.prom_id, timetype: 12, goods_id: order_goods.card_id };
      pre_data.user_id = order.user_id;
      var isok = 1;
      await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellList/page", {
        data: pre_data,
      }).then(e => {
        if (e.data.code == 0 && e.data.data.pageData && e.data.data.pageData.length > 0) {
          pre_arr = e.data.data.pageData[0];
        } else {
          isok = 0;
        }
      })

      if (!isok) {
        getApp().confirmBox("会员身份不符合");
        return false;
      }

      if (th.data.wait_dj) {
        if (act.is_end) {
          getApp().confirmBox("活动已经结束");
          return false;
        }
        if (!act.isuse) {
          getApp().confirmBox("活动未启用");
          return false;
        }
        if (th.data.act.end_time < ut.gettimestamp()) {
          getApp().confirmBox("活动的定金时间已经结束", function () {
            ut.wx_back();
          });
          return false;
        }

      }
      if (th.data.wait_wk) {
        if (th.data.act.pay_enddate < ut.gettimestamp()) {
          getApp().confirmBox("活动的尾款时间已经结束", function () {
            ut.wx_back();
          });
          return false;
        }
      }
    }
    else {
      await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellList/list", {
        data: { store_id: os.stoid, goods_id: order_goods.card_id, presell_id: order_goods.prom_id }
      }).then(re => {
        if (re.data.code == 0 && re.data.data && re.data.data.length > 0) {
          pre_arr = re.data.data[0];
        }
      })

      if (!pre_arr) {
        getApp().confirmBox("未找到商品");
        return false;
      }
    }

    //---获取商品---
    await getApp().request.promiseGet("/api/weshop/serviceCard/get/" + oo.stoid + "/" + order_goods.card_id, {}).then(res => {
      goods = res.data.data;
      order.market_price = goods.show_price;
      order.show_img = oo.imghost + goods.imgUrl;
      goods.original_img = goods.imgUrl;
      goods.goods_name = goods.serviceName;
    });

    var g_url = "/packageC/pages/presell/cardInfo/goodsInfo?goods_id=" + order_goods.card_id + "&pre_id=" + pre_arr.id;
    if (act.is_end || th.data.act.end_time < ut.gettimestamp()) {
      g_url = "/packageA/pages/goods/goodsInfo/goodsInfo?goods_id=" + order_goods.card_id;
    }

    //---获取门店---
    await getApp().request.promiseGet("/api/weshop/pickup/get/" + oo.stoid + "/" + order_goods.pickup_id, {}).then(res => {
      pickup = res.data.data;
    });

    order['is_all_return'] = 0;
    var price = presell.presell_price;
    if (!goods) return false;


    //等待发货的时候
    if (th.data.wait_fh) {
      var send_time = th.data.act.delivery_date;
      if (th.data.act.delivery_type == 2) {
        send_time = ut.gettimestamp() + th.data.act.delivery_daynum * 3600 * 24;
      }
    }

    order.order_goods = order_goods;
    var tail_pay = pre_arr.presell_price * order_goods.goods_num - presell.presell_deposit;
    this.setData({
      order: order,
      pickup: pickup,
      goods: goods,
      presell: presell,
      pre_arr: pre_arr,
      userInfo: getApp().globalData.userInfo,
      tail_pay: tail_pay,
      order_goods: order_goods,
      all_price: pre_arr.presell_price * order_goods.goods_num,
      pickup_id: pickup.pickup_id,
      send_time: send_time,
      g_url: g_url
    });
    th.get_diff();
    //统一进行计算金额
    th.calculatePrice2();
  },

  async calculatePrice2() {
    var th = this;
    if (!this.data.pre_arr) return false;
    th.setData({ show_submit: 0, disabled_btn: 0 })
    
    //--计算物流--
    if (this.data.exp_type == 0) {
      await this.calculate_wuliu();
    } else if (this.data.exp_type == 2) {
      await this.calculate_same_city();
    } else {
      var allpice = this.data.pre_arr.presell_price * this.data.order_goods.goods_num;
      allpice = allpice.toFixed(2);
      //--看一下有没有订单优惠--
      var o_condition = parseFloat(allpice);
      //---如果有选择优惠券的情况下---
      var quan_price = 0, bn_pick = th.data.pickup.pickup_id;
      var quan_no = null;
      if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined)
        quan_no = th.data.using_quan[bn_pick].coupon_no;
      //-- 如果使用的券不是包邮券的时候 --
      if (quan_no && th.data.using_quan[bn_pick].isby != 1) {
        //---获取优惠券优惠---
        await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
          data: {
            storeId: oo.stoid,
            CashRepNo: quan_no,
            WaresSum: th.data.ckeck_quan_price,
            WareIds: th.data.check_quan_ware_list,
          }
        }).then(res => {
          if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
            quan_price = res.data.data[0].WareCashSum;
          }
        })
      } else {
        th.setData({ quan_price: 0 });
        if (th.data.using_quan && th.data.using_quan[bn_pick] && th.data.using_quan[bn_pick].isby == 1) {
          var txt = "using_quan[" + bn_pick + "]";
          th.setData({ [txt]: {} });
        }

      }

      if (quan_price > 0) {
        if (quan_price < th.data.tail_pay) th.setData({ quan_price: quan_price })
        else {
          th.setData({ quan_price: th.data.tail_pay })
        }
        o_condition = o_condition - quan_price;

      } else {
        th.setData({ quan_price: 0 })
      }
      if (o_condition < 0) o_condition = 0;

      //如果同意参与订单优惠
      if (o_condition > 0 && this.data.pre_arr.is_useorderyh) {
        th.check_is_order_prom(o_condition, function (ord_price) {
          var bn_pick = th.data.pickup.pickup_id
          var order_prom_amount = 0;
          var order_prom_id = 0;
          var o_condition1 = 0;
          if (th.data.order_prom[bn_pick]) {
            var ord_prom = th.data.order_prom[bn_pick];
            if (!ord_prom.is_xz_yh || quan_price <= 0) {
              order_prom_id = ord_prom['id'];
              switch (ord_prom['type']) {
                case 0:
                  var all_1 = o_condition;
                  o_condition1 = Math.round(ord_price * ord_prom['expression']) / 100;//满额打折
                  order_prom_amount = (all_1 - o_condition1).toFixed(2);
                  break;
                case 1:

                  var bs = 1;
                  if (ord_prom.is_bz) {
                    bs = Math.floor(o_condition / ord_prom.money);
                  }

                  o_condition1 = ord_price - bs * ord_prom['expression'];//满额优惠金额
                  order_prom_amount = bs * ord_prom['expression'];
                  break;
              }
            }
          }
          //--订单优惠的显示--
          var order_prom_txt1 = "order_prom_id";
          var order_prom_txt2 = "order_prom_amount";
          if (order_prom_id > 0) {
            th.setData({ [order_prom_txt1]: order_prom_id, [order_prom_txt2]: order_prom_amount })
          } else {
            o_condition1 = ord_price;
            th.setData({ [order_prom_txt1]: 0, [order_prom_txt2]: 0 })
          }

          o_condition1 = parseFloat(o_condition1) - parseFloat(th.data.presell.presell_deposit);

          if (o_condition1 < 0) o_condition1 = 0;
          else if (o_condition1 > th.data.goods.use_commission && th.data.bn_use_commission) {
            o_condition1 -= th.data.goods.use_commission;
          }

          th.setData({ exp_price: 0, order_m: o_condition1, show_submit: 1, })
        })
      } else {
        o_condition = parseFloat(o_condition) - parseFloat(th.data.presell.presell_deposit);
        if (o_condition < 0) o_condition = 0;
        //if (o_condition1 < 0) o_condition1 = 0;
        else if (o_condition > th.data.goods.use_commission && th.data.bn_use_commission) {
          o_condition -= th.data.goods.use_commission;
        }

        th.setData({ exp_price: 0, order_m: o_condition, show_submit: 1, })
      }
      //调用默认优惠券方法
      th.def_coupon_fn()
    }

  },

  //---------------检查是否有收货地址-------------------
  checkAddressList: function () {
    var t = this;
    return !(!this.data.order || null == this.data.order.userAddress) || (wx.showModal({
      title: "请先填写或选择收货地址~",
      success: function (a) {
        a.confirm ? t.enterAddressPage() : wx.navigateBack();
      },
      fail: function () {
        wx.navigateBack();
      }
    }), !1);
  },
  showInvoice: function () {
    this.setData({
      invoiceToggle: !this.data.invoiceToggle
    });
  },
  keyUpChangePay1: function (t) {
    this.setData({
      payWithUserMoney: !(t.detail.value.length > 0)
    });
  },
  keyUpChangePay2: function (t) {
    this.setData({
      payWithPoints: !(t.detail.value.length > 0)
    });
  },
  keyUpChangeNum: function (t) {
    this.setData({
      maxWord: t.detail.value.length,
      user_note: t.detail.value
    });
  },

  set_can_num: function () {
    var th = this;
    //-- 这个地方，循环计算几张优惠券可用--
    for (var iter in th.data.cartlist) {
      var num = 0;
      var c_item = th.data.cartlist[iter];
      var pkid = c_item.pickup_id;
      //-- 普通券 --
      if (c_item.quan_list) {
        for (var iter1 in c_item.quan_list) {
          //判断是不是其他订单有选用
          var is_other_is_use = th.check_other_use(c_item.quan_list[iter1], pkid);
          if (!is_other_is_use) num++;
        }
      }
      //-- 包邮券 --
      var by_quan = th.data.get_by_quan_list_cart[pkid];
      if (by_quan) {
        for (var iter2 in by_quan) {
          //判断是不是其他订单有选用
          var is_other_is_use = th.check_other_use_by(by_quan[iter2], pkid);
          if (!is_other_is_use) num++;
        }
      }
      var set_txt = "cartlist[" + iter + "].can_num";
      th.setData({ [set_txt]: num });
    }
  },
  useCoupon: function () {
    if (this.data.order.couponNum <= 0) {
      getApp().my_warnning("无可用优惠券", 0, this);
      return;
    }

    var a = {
      lid: this.data.coupon ? this.data.coupon.id : "0"
    };
    wx.navigateTo({
      url: "/pages/user/checkcoupon/checkcoupon?" + s.Obj2Str(a)
    });
  },
  enterAddressPage: function () {
    if (!this.data.wait_wk) return false;

    getApp().globalData.is_cart_old = 1;
    this.data.isget_by_quan = {};
    this.data.enterAddressPage = !0, wx.navigateTo({
      url: "/packageF/pages/user/address_list/address_list"
    });
  },

  //--------立即购买时，选择自提和物流----------
  setexptype: function (t) {
    var th = this;
    var ty = t.currentTarget.dataset.t, def_exp_code = getApp().globalData.userInfo.def_exp_code;
    th.setData({ bn_exp_type: ty });
    if (ty == 0) {
      th.setData({ is_all_zt: 0 });
    }

    //当物流为空的时候。
    if (ty == 0 && th.data.wu_arr == null) {
      th.data.isget_by_quan = {};
      return th.get_wuliu(th.calculatePrice2());
    }

    //--自提就要把包邮券清理掉--
    if (ty == 1) {
      th.data.isget_by_quan = {};
      if (th.data.using_quan[bn_pick] && th.data.using_quan[bn_pick].isby == 1) {
        th.setData({ using_quan: {} });
      }
    }

    //判断有没有默认的物流地址值
    if (def_exp_code != "" && def_exp_code != null && def_exp_code != undefined && !th.data.is_default_logistics) {
      var wu_arr = this.data.wu_arr;
      if (wu_arr != null && wu_arr != "") {
        for (var i = 0; i < wu_arr.length; i++) {
          if (wu_arr[i].shipping_code == def_exp_code) {
            th.setData({ index: i });
          }
        }
      }
    }
    th.calculatePrice2()

  },

  //--------立即购买时，使用余额--------
  set_bn_useyuer: function () {
    var th = this;
    th.setData({ bn_use_money: !th.data.bn_use_money });
    th.calculatePrice2();
  },
  //-----------------计算物流-------------
  calculatewuliu: function (code, o_shipping_price, goods_weight, out_of_weight,
    goods_piece, user_addr, freight_free, o_price, rs, pickid) {
    var price = 0, th = this;
    price += parseFloat(o_shipping_price);
    //如果是包邮
    if (freight_free > 0 && o_price >= freight_free && out_of_weight >= 0) {
      return 0;
    }
    if (user_addr == null) {
      return 0;
    }
    //计算物流的config  item;
    var item = null;
    //先根据 镇 县 区找计算的config
    item = th.get_wuliu_config(user_addr.district, code, rs);
    if (item == null) item = th.get_wuliu_config(user_addr.city, code, rs);
    if (item == null) item = th.get_wuliu_config(user_addr.province, code, rs);
    if (item == null) item = th.get_wuliu_default(code, rs);
    if (item == null) return o_shipping_price;
    var fw_price = 0, fp_price = 0;
    item = item.config;
    if (item == null) return o_shipping_price;
    //------按重量----------
    if (goods_weight >= 0 && item['money']) {
      fw_price = parseFloat(item['money']);
      if (goods_weight > item['first_weight']) {
        var fw = goods_weight - item['first_weight'];
        var n = Math.ceil(fw / item['second_weight'])
        fw_price = fw_price + n * parseFloat(item['add_money']);
      }
    }
    //------超出重量----------
    if (out_of_weight < 0 && o_price >= freight_free && !th.data.is_no_by[pickid]) {
      fw_price = parseFloat(item['money']);
      var out_of_weight = Math.abs(out_of_weight);
      if (out_of_weight > item['first_weight']) {
        var fw = out_of_weight - item['first_weight'];
        var n = Math.ceil(fw / item['second_weight'])
        fw_price = fw_price + n * parseFloat(item['add_money']);
      }
    }
    //------按件数----------
    if (goods_piece > 0 && item['piecemoney']) {
      fp_price = parseFloat(item['piecemoney']);
      if (goods_piece > item['first_piece']) {
        var fp = goods_piece - item['first_piece'];
        var m = Math.ceil(fp / item['second_piece'])
        fp_price = fp_price + m * parseFloat(item['add_piecemoney']);
      }
    }
    var rspice = parseFloat(price + fw_price + fp_price);
    return rspice;
  },

  //------------循环获取config-----------
  get_wuliu_config: function (region_id, code, rs) {
    var item = null, rslist = rs.pageData;
    for (var i = 0; i < rslist.length; i++) {
      if (rslist[i].code == code && rslist[i].region_id == region_id) {
        item = rslist[i];
      }
    }
    return item;
  },
  //-------循环获取config,code default-------
  get_wuliu_default: function (code, rs) {
    var item = null, rslist = rs.pageData;
    for (var i = 0; i < rslist.length; i++) {
      if (rslist[i].shipping_code == code && rslist[i].is_default == 1) {
        item = rslist[i];
      }
    }
    return item;
  },

  //----------立即购买，选择物流-------------
  bindPickerChange: function (e) {
    var ind = e.detail.value
    this.setData({ index: ind });
    this.calculatePrice2();
  },
  /*----券的所有操作----*/
  open_coupon_list: function (e) {
    var th = this;
    var pickid = e.currentTarget.dataset.pickid;
    var bn = e.currentTarget.dataset.bn;
    var cindx = e.currentTarget.dataset.cind;
    var get_by_quan_list_cart = th.data.get_by_quan_list_cart[pickid];


    if (bn == 1) {
      th.setData({ open_quan: 1, selected_quan_pick: pickid, disabled: 1 });
    } else {
      //---多单打开券的时候，就要判断券在其他门店是否有使用---
      var quanlist = th.data.cartlist[cindx].quan_list;
      var exp_type = th.data.cartlist[cindx].exp_type;


      //对于在其他门店已经选择了的券 要判断是否显示到界面
      var t_user = th.data.using_quan[pickid];

      for (var i in quanlist) {
        quanlist[i].is_using = th.check_in_sele(quanlist[i].CashRepNo, pickid);
        if (t_user && quanlist[i].CashRepNo == t_user.coupon_no)
          quanlist[i].show_red = 1;
        else
          quanlist[i].show_red = 0;
      }

      if (get_by_quan_list_cart) {
        for (var i in get_by_quan_list_cart) {
          get_by_quan_list_cart[i].is_using = th.check_in_sele(get_by_quan_list_cart[i].no, pickid);
          if (t_user && get_by_quan_list_cart[i].no == t_user.coupon_no)
            get_by_quan_list_cart[i].show_red = 1;
          else
            get_by_quan_list_cart[i].show_red = 0;
        }
        th.setData({ by_quan_list_cart: get_by_quan_list_cart });
      } else {
        th.setData({ by_quan_list_cart: null });
      }

      th.setData({
        sele_cart_ind: cindx,
        sele_exp_type: exp_type,
        open_quan: 1,
        selected_quan_pick: pickid,
        selected_quan_list: quanlist,
        disabled: 1
      });
    }
  },
  close_coupon: function (e) {
    var th = this;
    th.setData({ open_quan: 0, disabled: 0 });
  },

  //---判断券时候在已经选择的列表中---
  check_in_sele: function (no, pick_id) {
    var th = this;
    if (th.data.using_quan.length <= 0) return false;
    for (var i in th.data.using_quan) {
      //--如果键值等于本身就要跳出--
      if (parseInt(i) == parseInt(pick_id)) continue;
      var item = th.data.using_quan[i];
      if (item.coupon_no == no) {
        return true;
      }
    }
    return false;
  },

  /*--点击选择券--*/
  sele_quan_item_befor: function (e) {
    var th = this;
    var ind = 0;
    var quan_item = this.data.selected_quan_list[ind];
    var pickid = this.data.pickup.pickup_id;  //现在选择的是哪一个门店

    var quanlist = this.data.selected_quan_list;
    //---所有的券的显示红色选择都清理一遍---
    for (var i in quanlist) {
      quanlist[i].show_red = 0;
    }
    this.setData({ selected_quan_list: quanlist });
    var by_quanlist = this.data.get_by_quan_list;
    if (by_quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var inb in by_quanlist) {
        by_quanlist[inb].show_red = 0;
      }
      this.setData({ get_by_quan_list: by_quanlist });
    }

    var by_cart_list = this.data.by_quan_list_cart;
    if (by_cart_list) {
      //---所有的券的显示红色选择都清理一遍---
      for (var inc in by_cart_list) {
        by_cart_list[inc].show_red = 0;
      }
      this.setData({ by_quan_list_cart: by_cart_list });
    }

    var using_quan = this.data.using_quan;

    //---如果是不使用优惠券---
    // if (no_use == 1) {
    //     if (using_quan[pickid]) {
    //         using_quan[pickid].is_nouse_red = 1;
    //     }
    //     else {
    //         using_quan[pickid] = { is_nouse_red: 1 };
    //     }
    //     this.setData({ using_quan: using_quan, is_coupon: 2222 });
    //     return;
    // }


    var txt = "selected_quan_list[" + ind + "].show_red";
    var obj = {};
    obj[txt] = 1;
    if (quan_item.show_red) {
      obj[txt] = 0;
    }
    this.setData(obj);
    console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt);
    if (using_quan[pickid]) {
      using_quan[pickid].is_nouse_red = 0;
    }
    else {
      using_quan[pickid] = { is_nouse_red: 0 };
    }
    this.setData({ using_quan: using_quan });
    return true
  },
  /*--点击选择券--*/
  sele_quan_item: function (e) {
    var th = this;
    var ind = e.currentTarget.dataset.ind;
    var quan_item = this.data.selected_quan_list[ind];
    var pickid = this.data.pickup.pickup_id;  //现在选择的是哪一个门店

    var no_use = e.currentTarget.dataset.no, quanlist = this.data.selected_quan_list;
    //---所有的券的显示红色选择都清理一遍---
    for (var i in quanlist) {
      quanlist[i].show_red = 0;
    }
    this.setData({ selected_quan_list: quanlist });
    var by_quanlist = this.data.get_by_quan_list;
    if (by_quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var inb in by_quanlist) {
        by_quanlist[inb].show_red = 0;
      }
      this.setData({ get_by_quan_list: by_quanlist });
    }

    var by_cart_list = this.data.by_quan_list_cart;
    if (by_cart_list) {
      //---所有的券的显示红色选择都清理一遍---
      for (var inc in by_cart_list) {
        by_cart_list[inc].show_red = 0;
      }
      this.setData({ by_quan_list_cart: by_cart_list });
    }

    var using_quan = this.data.using_quan;

    //---如果是不使用优惠券---
    if (no_use == 1) {
      if (using_quan[pickid]) {
        using_quan[pickid].is_nouse_red = 1;
      }
      else {
        using_quan[pickid] = { is_nouse_red: 1 };
      }
      this.setData({ using_quan: using_quan, is_coupon: 2222 });
      return;
    }


    var txt = "selected_quan_list[" + ind + "].show_red";
    var obj = {};
    obj[txt] = 1;
    if (quan_item.show_red) {
      obj[txt] = 0;
    }
    this.setData(obj);
    console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt);
    if (using_quan[pickid]) {
      using_quan[pickid].is_nouse_red = 0;
    }
    else {
      using_quan[pickid] = { is_nouse_red: 0 };
    }
    this.setData({ using_quan: using_quan });

  },
  /*----- 点击选择包邮券 -----*/
  sele_quan_item_by_befor: function (e) {
    // var no_use = e.currentTarget.dataset.no;
    //立即购买的包邮券
    var by_quanlist = this.data.get_by_quan_list;
    if (by_quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in by_quanlist) {
        by_quanlist[ind].show_red = 0;
      }
      this.setData({ get_by_quan_list: by_quanlist });
    }

    //--购物车过来的包邮券--
    var by_cart_list = this.data.by_quan_list_cart;
    if (by_cart_list) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in by_cart_list) {
        by_cart_list[ind].show_red = 0;
      }
      this.setData({ by_quan_list_cart: by_cart_list });
    }
    //普通券
    var quanlist = this.data.selected_quan_list;
    if (quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in quanlist) {
        quanlist[ind].show_red = 0;
      }
      this.setData({ selected_quan_list: quanlist });
    }

    var th = this;
    var using_quan = this.data.using_quan;
    //---如果是不使用优惠券---
    // if (no_use == 1) {
    //     if (using_quan[th.data.selected_quan_pick]) {
    //         using_quan[th.data.selected_quan_pick].is_nouse_red = 1;
    //     }
    //     else {
    //         using_quan[th.data.selected_quan_pick] = { is_nouse_red: 1 };
    //     }
    //     this.setData({ using_quan: using_quan, is_coupon: 2222 });
    //     return;
    // }

    var pickid = th.data.selected_quan_pick;  //现在选择的是哪一个门店
    var ind = 0;
    //--如果是立即购买的部分--
    var txt = "";
    var txt1 = "";
    var quan_item = null;

    quan_item = this.data.get_by_quan_list[ind];
    txt = "get_by_quan_list[" + ind + "].show_red";
    var obj = {};
    obj[txt] = 1;
    this.setData(obj);


    if (using_quan[th.data.selected_quan_pick]) {
      using_quan[th.data.selected_quan_pick].is_nouse_red = 0;
    }
    else {
      using_quan[th.data.selected_quan_pick] = { is_nouse_red: 0 };
    }
    this.setData({ using_quan: using_quan });
  },
  /*----- 点击选择包邮券 -----*/
  sele_quan_item_by: function (e) {
    var no_use = e.currentTarget.dataset.no;
    //立即购买的包邮券
    var by_quanlist = this.data.get_by_quan_list;
    if (by_quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in by_quanlist) {
        by_quanlist[ind].show_red = 0;
      }
      this.setData({ get_by_quan_list: by_quanlist });
    }

    //--购物车过来的包邮券--
    var by_cart_list = this.data.by_quan_list_cart;
    if (by_cart_list) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in by_cart_list) {
        by_cart_list[ind].show_red = 0;
      }
      this.setData({ by_quan_list_cart: by_cart_list });
    }
    //普通券
    var quanlist = this.data.selected_quan_list;
    if (quanlist) {
      //---所有的券的显示红色选择都清理一遍---
      for (var ind in quanlist) {
        quanlist[ind].show_red = 0;
      }
      this.setData({ selected_quan_list: quanlist });
    }

    var th = this;
    var using_quan = this.data.using_quan;
    //---如果是不使用优惠券---
    if (no_use == 1) {
      if (using_quan[th.data.selected_quan_pick]) {
        using_quan[th.data.selected_quan_pick].is_nouse_red = 1;
      }
      else {
        using_quan[th.data.selected_quan_pick] = { is_nouse_red: 1 };
      }
      this.setData({ using_quan: using_quan, is_coupon: 2222 });
      return;
    }

    var pickid = th.data.selected_quan_pick;  //现在选择的是哪一个门店
    var ind = e.currentTarget.dataset.ind;
    //--如果是立即购买的部分--
    var txt = "";
    var txt1 = "";
    var quan_item = null;

    quan_item = this.data.get_by_quan_list[ind];
    txt = "get_by_quan_list[" + ind + "].show_red";
    var obj = {};
    obj[txt] = 1;
    this.setData(obj);


    if (using_quan[th.data.selected_quan_pick]) {
      using_quan[th.data.selected_quan_pick].is_nouse_red = 0;
    }
    else {
      using_quan[th.data.selected_quan_pick] = { is_nouse_red: 0 };
    }
    this.setData({ using_quan: using_quan });
  },
  //--确认使用券---
  confirm_quan: function () {
    var using_quan = this.data.using_quan;     //正在使用中的券列表
    var pickid = this.data.pickup.pickup_id; //选中的门店ID
    var th = this;
    var selected_quan_list = this.data.selected_quan_list;  //选择了那个门店的券列表
    var get_by_quan_list = this.data.get_by_quan_list;      //立即购买的包邮券列表
    var by_quan_list_cart = this.data.by_quan_list_cart;    //购物车购买的包邮券列表

    //循环普通的券
    for (var i in selected_quan_list) {
      var item = selected_quan_list[i];
      if (item.show_red) {
        th.insert_into_using_quan(item, using_quan, pickid);
        return;
      }
    }
    //循环包邮的券，立即购买的
    for (var i in get_by_quan_list) {
      var item = get_by_quan_list[i];
      if (item.show_red) {
        if (th.data.is_no_by[pickid] == 1) {
          getApp().my_warnning("已全场不能包邮，不能选择包邮券", 0, th);
          return false;
        }
        if (th.data.is_by[pickid] == 1) {
          getApp().my_warnning("已全场包邮，不能选择包邮券", 0, th);
          return false;
        }

        th.insert_into_using_quan(item, using_quan, pickid, 1);
        return;
      }
    }

    //循环包邮的券
    for (var i in by_quan_list_cart) {
      var item = by_quan_list_cart[i];
      if (item.show_red) {
        if (th.data.is_no_by[pickid] == 1) {
          getApp().my_warnning("已全场不能包邮，不能选择包邮券", 0, th);
          return false;
        }
        if (th.data.is_by[pickid] == 1) {
          getApp().my_warnning("已全场包邮，不能选择包邮券", 0, th);
          return false;
        }
        th.insert_into_using_quan(item, using_quan, pickid, 1);
        return;
      }
    }

    //选择了的券，看是不是点击了不使用券,点击了不使用优惠券
    if (using_quan[pickid]) {
      if (using_quan[pickid].is_nouse_red == 1) {
        using_quan[pickid] = { is_nouse_red: 1 };
        th.calculatePrice2();
        th.setData({ open_quan: 0 });
        th.setData({ using_quan: using_quan });
      }
    }



  },
  //--确认使用券---
  confirm_quan_befor: async function () {
    var using_quan = this.data.using_quan;     //正在使用中的券列表
    var pickid = this.data.pickup.pickup_id; //选中的门店ID
    var th = this;
    var selected_quan_list = this.data.selected_quan_list;  //选择了那个门店的券列表
    var get_by_quan_list = this.data.get_by_quan_list;      //立即购买的包邮券列表
    var by_quan_list_cart = this.data.by_quan_list_cart;    //购物车购买的包邮券列表

    //循环普通的券
    for (var i in selected_quan_list) {
      var item = selected_quan_list[i];
      if (item.show_red) {
        th.insert_into_using_quan(item, using_quan, pickid, 0, false);
        return;
      }
    }
    //循环包邮的券，立即购买的
    for (var i in get_by_quan_list) {
      var item = get_by_quan_list[i];
      if (item.show_red) {
        if (th.data.is_no_by[pickid] == 1) {
          // getApp().my_warnning("已全场不能包邮，不能选择包邮券", 0, th);
          return false;
        }
        if (th.data.is_by[pickid] == 1) {
          // getApp().my_warnning("已全场包邮，不能选择包邮券", 0, th);
          return false;
        }

        th.insert_into_using_quan(item, using_quan, pickid, 1, false);
        return;
      }
    }

    //循环包邮的券
    for (var i in by_quan_list_cart) {
      var item = by_quan_list_cart[i];
      if (item.show_red) {
        if (th.data.is_no_by[pickid] == 1) {
          // getApp().my_warnning("已全场不能包邮，不能选择包邮券", 0, th);
          return false;
        }
        if (th.data.is_by[pickid] == 1) {
          // getApp().my_warnning("已全场包邮，不能选择包邮券", 0, th);
          return false;
        }
        th.insert_into_using_quan(item, using_quan, pickid, 1, false);
        return;
      }
    }

    //选择了的券，看是不是点击了不使用券,点击了不使用优惠券
    if (using_quan[pickid]) {
      if (using_quan[pickid].is_nouse_red == 1) {
        using_quan[pickid] = { is_nouse_red: 1 };
        th.calculatePrice2();
        th.setData({ open_quan: 0 });
        th.setData({ using_quan: using_quan });
      }
    }



  },
  //默认选择优惠券
  def_coupon_fn() {
    // setTimeout(() => {
    //   this.def_coupon_fn_aft()
    // }, 100);
    wx.showLoading({
      title: '加载中',
      mask:true
    })
    try {
      setTimeout(() => {
        wx.hideLoading()
        this.def_coupon_fn_aft()
      }, 1000);
    } catch (error) {}

  },
  //默认选择优惠券
  def_coupon_fn_aft() {
    console.error('进入默认优惠券选择');
    let th = this;
    let first_entry = th.data.first_entry;
    console.error(first_entry);
    if (first_entry > 0) {
      return
    }
    first_entry += 1;
    th.setData({
      first_entry
    })
    let length1 = th.data.def_coupon1 ? th.data.def_coupon1.length : 0
    let length2 = th.data.def_coupon2 ? th.data.def_coupon2.length : 0
    let length3 = th.data.def_coupon3 ? th.data.def_coupon3.length : 0
    let length4 = th.data.def_coupon4 ? th.data.def_coupon4.length : 0
    // let length = length1 + length2 + length3 + length4
    let length = length1 + length2 
    if (th.data.exp_type==0) {
      length+= length3 + length4
    }
    console.error(length);
    if (length != 1) {
      return
    }
    if (length1 == 1) {
      console.error('优惠券1');
      let first_entry = th.data.first_entry;
      let quan_list = th.data.def_coupon1
      if (quan_list && quan_list.length == 1 && first_entry == 1) {
        // first_entry += 1;
        th.setData({
          sele_cart_ind: 0,
          sele_exp_type: th.data.cartlist[0].exp_type,
          selected_quan_pick: th.data.cartlist[0].pickup_id,
          selected_quan_list: th.data.cartlist[0].quan_list,
          // first_entry
        })
        let quan_off = th.sele_quan_item_befor();
        if (quan_off) {
          th.confirm_quan_befor()
        }
      }
      return
    }
    if (length2 == 1) {
      console.error('优惠券2');
      let first_entry = th.data.first_entry;
      let quanlist = th.data.def_coupon2 
      if (quanlist && quanlist.length == 1 && first_entry == 1) {
        // first_entry += 1;
        th.setData({
          selected_quan_pick: th.data.bn_pick,
          // first_entry
        })
          let quan_off = th.sele_quan_item_befor();
          if (quan_off) {
            th.confirm_quan_befor()
          }
        
      }
      return
    }
    if (length3 == 1  && th.data.exp_type==0) {
      console.error('优惠券3');
      let first_entry = th.data.first_entry;
      let quanlist =  th.data.def_coupon3
      if (quanlist && quanlist.length == 1 && first_entry == 1) {
        // first_entry += 1;
        th.setData({
          selected_quan_pick: th.data.bn_pick,
          // first_entry
        })
 
          th.sele_quan_item_by_befor();
          th.confirm_quan_befor()

      }
      return
    }

  },
  //----把券插入之后的操作，同时还要重新计算价格----
  insert_into_using_quan: function (item, using_quan, pickid, isby, showToast = true) {
    var th = this;
    if (isby == 1) {
      using_quan[pickid] = {
        coupon_no: item.no,
        money: 0,
        is_nouse_red: 0,
        region_list: item.region_list,
        goods_list: item.goods_list
      };
      using_quan[pickid].isby = 1;
    } else {
      using_quan[pickid] = { coupon_no: item.CashRepNo, money: item.Sum, is_nouse_red: 0 };
      using_quan[pickid].isby = 0;
    }
    this.setData({ using_quan: using_quan });
    th.calculatePrice2();
    th.setData({ open_quan: 0 });
  },

  cart_set_err: function (e) {
    var txt = e.currentTarget.dataset.err;
    var ob = {};
    ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif";
    this.setData(ob);
  },
  //--验证是否已经冻结--
  check_is_frozenQuan: function (quanlist, frozenQuan, isby) {
    console.log("券列表", quanlist);
    if (!quanlist) return null;
    if (!frozenQuan) return quanlist;
    var arr = [];
    for (var i = 0; i < quanlist.length; i++) {
      var item = quanlist[i];
      var is_find = 0;
      var Q_no = quanlist[i].CashRepNo;
      if (isby) Q_no = quanlist[i].no;
      for (var j = 0; j < frozenQuan.length; j++) {
        var q_no = frozenQuan[j].cashRepNo;
        if (Q_no == q_no) {
          is_find = 1;
          break;
        }
      }
      if (!is_find) arr.push(item);
    }
    return arr;
  },

  //// 开启物流的弹窗
  show_wu_arr: function (e) {
    var wu_arr_txt = e.currentTarget.dataset.txt;
    var w_sele_index = e.currentTarget.dataset.w_sele_index;
    var is_express = null;
    var ob = { open_express: 1, wu_arr_txt: wu_arr_txt, disabled: 1 };

    //--如果是多个门店的时候--
    if (w_sele_index != undefined) {
      is_express = this.data.cartlist[w_sele_index].wind;
      ob['is_express'] = is_express;
    }
    this.setData(ob);
  },
  // 关闭物流的弹窗
  close_express: function () {
    this.setData({ open_express: 0, disabled: 0 });
  },
  // 选择物流
  click_express_name: function (e) {
    var express_name = e.currentTarget.dataset.name, shippingcode = e.currentTarget.dataset.shippingcode;
    var index = e.currentTarget.dataset.idxe;
    var ob = { is_express: index, is_shipping_code: shippingcode, disabled: 0 };
    ob[this.data.wu_arr_txt] = index;
    this.setData(ob);
  },

  //点击确定物流
  determine_expres: function (e) {
    this.setData({ open_express: 0 });
    this.calculatePrice2();
  },

  //点击打开优惠券使用说明
  clik_coupons: function (e) {
    var ind = e.currentTarget.dataset.idx;
    var is_open = this.data.selected_quan_list[ind].is_open;

    if (is_open == 1) is_open = 0;
    else is_open = 1;

    var txt = "selected_quan_list[" + ind + "].is_open"
    var obj = {};
    obj[txt] = is_open;

    this.setData(obj);
    this.setData({ disabled: 1 })
  },

  clik_coupons2: function (e) {
    var ind = e.currentTarget.dataset.idx;
    var is_open = this.data.get_by_quan_list[ind].is_open;

    if (is_open == 1) is_open = 0;
    else is_open = 1;

    var txt = "get_by_quan_list[" + ind + "].is_open"
    var obj = {};
    obj[txt] = is_open;

    this.setData(obj);
    this.setData({ disabled: 1 })
  },


  //设置默认物流
  select_default_logistics: function () {
    var th = this;
    var is_shipping_code = this.data.is_shipping_code
    getApp().request.put("/api/weshop/users/update", {
      data: { user_id: getApp().globalData.user_id, store_id: oo.stoid, def_exp_code: is_shipping_code },
      success: function (rse) {
        if (rse.data.code == 0) {
          getApp().globalData.userInfo.def_exp_code = is_shipping_code;
          th.setData({ open_express: 0 });
          //----计算此时购物车的价格----
          th.calculatePrice2();

        }
      }
    })
  },

  //更新下默认，在onshow里面
  update_code() {
    var th = this, m_wind = 0, def_exp_code = getApp().globalData.userInfo.def_exp_code;

    //--定时器，判断wu_arr不未空--
    var uii = setInterval(function () {
      if (th.data.wu_arr) {
        clearInterval(uii);
        if (th.data.is_default_logistics) return false;
        for (var k = 0; k < th.data.wu_arr.length; k++) {
          var item = th.data.wu_arr[k];
          if (def_exp_code == item.code) {
            m_wind = k;
          }
        }
        //--如果是立即购买--
        if (th.data.is_b_now == 1) {
          th.setData({ index: m_wind, is_express: m_wind });
        } else {
          var ui = setInterval(function () {
            if (th.data.cartlist) {
              var c_arr = th.data.cartlist;
              for (var i in c_arr) {
                c_arr[i].wind = m_wind;
              }
              th.setData({ cartlist: c_arr, is_express: m_wind })
              clearInterval(ui);
            }
          }, 500)
        }
      }
    }, 500);
  },
  //-----获取购物车进来的劵-------
  get_cart_quan: async function (order_prom_list_cart) {
    var th = this;
    var is_xz_yh = 1;
    //等待值的出现
    //getApp().waitfor2(this,"g_cart_q_time","order_prom_list_cart",async function () {
    //var arr=th.data.order_prom_list_cart;
    var arr = order_prom_list_cart;
    if (!arr) arr = [];
    //如果系统有限制使用优惠券
    if (th.data.is_close_quan) return false;

    //------------开始计算使用优惠券相关------------
    for (var ind in arr) {
      var ep = arr[ind];
      var goodlist = ep.goods;
      var pickup_id = ep.pickup_id;
      //--更优惠券抵用有关，立即购买的，如果是购物车，如果有等级价还有考虑等级价的东西
      //就要把相应的值，写入cartlist数组中--
      var ckeck_quan_price = 0,
        check_quan_price_list = '',
        check_quan_ware_list = '';

      let check_quan_price_scj=0;

      for (var i in goodlist) {
        var gd = goodlist[i];
        //--如果是秒杀就跳出,如果是赠品，如果是组合购，如果是限制使用优惠券--
        if (gd.prom_type == 1 || gd.is_gift || gd.prom_type == 7) {
          continue;
        }
        //如果有限制使用优惠券，就要返回
        if (gd.prom_type == 3) {
          if (th.data.prom_goods_map[pickup_id][gd.prom_id].is_xz_yh) continue;
          th.data.prom_goods_map[pickup_id][gd.prom_id].coupon_sele = 1;
        }
        is_xz_yh = 0;
        var item_price = gd.goods_price * gd.goods_num;
        //-- 如果有平摊下去，有实收价格的时候，就要用account来计算价格 --
        if (gd.account_fir != null && gd.account_fir != undefined) {
          item_price = gd.account_fir * gd.goods_num;
        }
        ckeck_quan_price += item_price;
        check_quan_price_scj += gd.market_price * gd.goods_num;

        //--组装价格list--
        if (check_quan_price_list) {
          check_quan_price_list += "," + item_price;
        } else {
          check_quan_price_list = item_price;
        }
        //--组装商品的线下erpwareid--
        if (check_quan_ware_list) {
          check_quan_ware_list += "," + encodeURIComponent(gd['erpwareid']);
        } else {
          check_quan_ware_list = encodeURIComponent(gd['erpwareid']);
        }
      }
      //优惠券优惠的金额要控制到优惠券的选择条件
      var cut_price = 0;
      for (var i in th.data.prom_goods_map[pickup_id]) {
        var obj = th.data.prom_goods_map[pickup_id][i];
        if (obj.coupon_sele) {
          cut_price += obj.price - obj.prom_price;
        }
      }

      arr[ind].ckeck_quan_price = ckeck_quan_price - cut_price;
      arr[ind].check_quan_ware_list = check_quan_ware_list;
      arr[ind].check_quan_price_list = check_quan_price_list;
      arr[ind].check_quan_price_scj = check_quan_price_scj;

      //是否关闭使用优惠券
      if (th.data.is_close_quan != 1 && !is_xz_yh) {
        //--调用接口，获取优惠券的列表，3秒钟内控制接口请求--
        var url = "/api/weshop/couponList/getUseCouponList";
        await app.request.promiseGet(url, {
          data: {
            storeId: oo.stoid,
            userId: app.globalData.user_id,
            BuySum: ckeck_quan_price,
            WareIds: check_quan_ware_list,
            pageSize: 100,
            scj: check_quan_price_scj,
          }
        }).then(res => {
          console.error('优惠券1---------------------');
          if (res.data.code == 0) {
            var quan_list = res.data.data.pageData;
            arr[ind].quan_list = th.check_is_frozenQuan(quan_list, th.data.frozenQuan);
            th.setData({
              def_coupon1: quan_list
            })
          }
        })
      }
    }

    //如果是搭配购的立即购买的时候
    if (th.data.is_b_now) {
      if (arr && arr.length > 0) {
        var quanlist = arr[0].quan_list;
        th.setData({ selected_quan_list: quanlist, cartlist: arr })
      }
    } else {
      th.setData({ cartlist: arr })
      th.set_can_num();
    }
  },

  //------ 获取立即购买的购物车的劵 --------
  get_buy_now_quan: async function () {
    var quanlist = null, th = this, frozenQuan = null;
    var allprice = this.data.pre_arr.presell_price * this.data.order_goods.goods_num;
    th.data.ckeck_quan_price = allprice;
    th.data.check_quan_price_scj = this.data.goods.market_price* this.data.order_goods.goods_num;

    //--如果商家后台没有限制使用优惠券，同时商品的优惠活动没有限制使用优惠券--
    if (th.data.is_close_quan != 1) {
      var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id;
      var url = "/api/weshop/couponList/getUseCouponList";
      await app.request.promiseGet(url0, { 1: 1 }).then(res => {
        if (res.data.code == 0) {
          frozenQuan = res.data.data;
          th.data.frozenQuan = frozenQuan;
        }

        let quan_rq={
          storeId: oo.stoid,
          userId: app.globalData.user_id,
          BuySum: th.data.ckeck_quan_price,
          WareIds: encodeURIComponent(th.data.check_quan_ware_list),
          pageSize: 100
        };

        if(th.data.ckeck_quan_price>=th.data.check_quan_price_scj){
          quan_rq.BuyPosSum=th.data.ckeck_quan_price;
          quan_rq.PosWareIds=encodeURIComponent(th.data.check_quan_ware_list);
        }

        app.request.time_limit_get(6, url, {
          data: quan_rq,
          success: function (res) {
            console.error('优惠券2-------------------');
            if (res.data.code == 0) {
              quanlist = res.data.data.pageData;
              if (quanlist) {
                quanlist = th.check_is_frozenQuan(quanlist, frozenQuan);
                th.setData({ selected_quan_list: quanlist, def_coupon2: quanlist })
              }
            }
          }
        })
      })
    }
  },

  //检查区域是不是包邮
  check_area: function (arr) {
    var user_addr = this.data.user_addr;
    if (!user_addr) return 0;
    for (var i in arr) {
      var item = arr[i];
      if (user_addr.twon == item || user_addr.district == item
        || user_addr.city == item || user_addr.province == item) {
        return 0;
      }
    }
    return 1;
  },

  //检查立即购买的商品是不是不包邮
  check_good: function (arr, goods_id) {
    if (!goods_id) goods_id = this.data.goods.goods_id;
    for (var i in arr) {
      var item = arr[i];
      if (goods_id == item) return 0;
    }
    return 1;
  },
  check_by_area: function (region_list) {
    var arr = region_list.split(",");
    var check = this.check_area(arr);
    return !check;
  },
  check_by_goods: function (goods_list, goods_id) {
    var arr = goods_list.split(",");
    var check = this.check_good(arr, goods_id);
    return !check;
  },


  //--检查订单优惠--
  check_is_order_prom: function (condition, func, pick) {
    var th = this;
    pick = this.data.pickup.pickup_id;
    //---获取订单优惠---
    getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
      data: { store_id: os.stoid, orderAmount: condition }
    }).then(res => {
      if (res.data.code == 0) {
        var data = res.data.data;

        //如果订单促销的取价不是实收，清空订单促销
        if (data && data.discount_field > 0) data = null;

        th.data.order_prom[pick] = data;
      } else {
        th.data.order_prom[pick] = null;
      }
      func(condition);
    })
  },

  //--- 加入优惠活动的映射中，同时要有一个good列表 ---
  add_prom_goods_map: async function (item) {
    var th = this;
    var pickid = item.pick_id;
    var map = th.data.prom_goods_map;
    var obj = map[pickid];

    if (map[pickid]) {
      if (map[pickid][item.prom_id]) {
        var ob = map[pickid][item.prom_id];
        ob.price += item.goods_price * item.goods_num;
        ob.goods_num += item.goods_num;
        ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num });

      } else {
        var prom = null;
        await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + item.prom_id, {}).then(res => {
          if (res.data.code == 0) {
            prom = res.data.data;
          }
        })
        var ob = {};
        ob.prom_id = item.prom_id;
        ob.price = item.goods_price * item.goods_num;
        ob.goods_num = item.goods_num;
        ob.is_bz = prom.is_bz;
        ob.is_xz_yh = prom.is_xz_yh;
        ob.goods = new Array();
        ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num });
        map[pickid][item.prom_id] = ob;
      }
    } else {
      var ob = {};
      var prom = null;
      await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + item.prom_id, {}).then(res => {
        if (res.data.code == 0) {
          prom = res.data.data;
        }
      })
      ob.prom_id = item.prom_id;
      ob.price = item.goods_price * item.goods_num;
      ob.goods_num = item.goods_num;
      ob.is_bz = prom.is_bz;
      ob.is_xz_yh = prom.is_xz_yh;
      ob.goods = new Array();
      ob.goods.push({ goods_id: item.goods_id, goods_price: item.goods_price, goods_num: item.goods_num });

      var obj = {};
      obj[item.prom_id] = ob;
      map[pickid] = obj;

    }
  },

  //计算立即购买赠品的物流费用
  get_now_gift_goods_wuliu: function (code, o_shipping_price, user_addr, gift_freight_free, allpice, rs, shipping_price, no_by_data, goods_weight1, goods_piece1) {
    var good = this.data.buy_now_gift_goods;
    var goods_weight = -1, goods_piece = -1;
    var gift_shipping_price = 0;
    var th = this;
    switch (good['exp_sum_type']) {
      case 1:
        //统一运费
        gift_shipping_price += good['uniform_exp_sum'];
        gift_shipping_price += o_shipping_price;
        break;
      case 2:
        if (goods_weight < 0) goods_weight = 0;
        //累积商品重量 每种商品的重量 * 数量
        goods_weight += good['weight'] * good['buynum'];
        if (goods_weight1 > 0) {
          goods_weight += goods_weight1;
        }
        break;
      case 3:
        if (goods_piece < 0) goods_piece = 0;
        //累积商品数量
        goods_piece += good['buynum'];
        if (goods_piece1) {
          goods_piece += goods_piece1;
        }
        break;
    }


    //如果有设置不包邮区域的时候
    if (no_by_data && no_by_data.region_list) {
      if (th.check_by_area(no_by_data.region_list)) {
        gift_freight_free = 0;
        // out_of_weight = 0;
        th.data.is_no_by[bn_pick] = 1;
      }
    }
    //如果有设置不包邮商品
    if (no_by_data && no_by_data.goods_list && gift_freight_free) {
      if (th.check_by_goods(no_by_data.goods_list, good.goods_id)) {
        gift_freight_free = 0;
        // out_of_weight = 0;
        th.data.is_no_by[bn_pick] = 1;
      }
    }

    var t_shipping_price =
      this.calculatewuliu(code, gift_shipping_price, goods_weight, out_of_weight,
        goods_piece, user_addr, gift_freight_free, allpice, rs, th.data.bn_pick);
    return t_shipping_price;

  },

  //从优惠的映射中拿出商品从表的item
  item_map_get_goods: function (goods_id, map) {
    for (var i in map.goods) {
      if (map.goods[i].goods_id == goods_id) return map.goods[i];
    }
  },
  //从优惠的映射中拿出商品从表的item
  arr_get_goods: function (goods_id, arr) {
    for (var i in arr) {
      if (arr[i].goods_id == goods_id) return arr[i];
    }
  },

  //检查是不是有其他门店的订单在选择了券
  check_other_use: function (iter, pkid) {
    var using = this.data.using_quan;
    var is_use = 0;
    if (using) {
      for (var i in using) {
        if (i == pkid) continue;
        if (iter.CashRepNo == using[i].coupon_no) {
          is_use = 1;
          break;
        }
      }
    }
    return is_use;
  },
  //检查是不是有其他门店的订单在选择了包邮券
  check_other_use_by: function (iter, pkid) {
    var using = this.data.using_quan;
    var is_use = 0;
    if (using) {
      for (var i in using) {
        if (i == pkid) continue;
        if (iter.no == using[i].coupon_no) {
          is_use = 1;
          break;
        }
      }
    }
    return is_use;
  },



  //----计算物流的钱----
  async calculate_wuliu() {
    var to = getApp(), th = this;
    //to.getwuliuprice(async function (rs) {
    var o_shipping_price = 0,
      goods_weight = -1,
      goods_piece = -1,
      good = th.data.goods,
      quan_price = 0,
      exp_price = 0;

    var quan_no = null;
    var bn_pick = th.data.pickup.pickup_id;
    var allpice = th.data.all_price;
    var out_of_weight = null; //超出多少重量

    good.buynum = th.data.order.order_goods.goods_num;

    if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined)
      quan_no = th.data.using_quan[bn_pick].coupon_no;

    if (quan_no) {
      if (th.data.using_quan[bn_pick].isby != 1) {
        //---获取优惠券优惠---
        await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
          data: {
            storeId: oo.stoid,
            CashRepNo: quan_no,
            WaresSum: th.data.ckeck_quan_price,
            WareIds: th.data.check_quan_ware_list
          }
        }).then(res => {
          if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
            quan_price = res.data.data[0].WareCashSum;
          }
        })

        if (quan_price > 0) {
          if (quan_price < th.data.tail_pay) th.setData({ quan_price: quan_price })
          else {
            th.setData({ quan_price: th.data.tail_pay })
            quan_price = th.data.tail_pay;
          }
        } else {
          th.setData({ quan_price: 0 })
        }
      } else {
        th.setData({ quan_price: 0 })
      }
    } else {
      th.setData({ quan_price: 0 })
    }


    //---获取订单优惠---
    var condition = allpice - quan_price; //判断的条件
    var prom_ord = null
    if (condition > 0 && this.data.pre_arr.is_useorderyh) {
      await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
        data: { store_id: os.stoid, orderAmount: condition }
      }).then(res => {
        if (res.data.code == 0) {
          prom_ord = res.data.data;

          //如果订单促销的取价不是实收，清空订单促销
          if (prom_ord && prom_ord.discount_field > 0) prom_ord = null;
        }

      })
    }

    //-----------当地址不为空，且是物流时，计算物流费用----------
    if (th.data.user_addr != null && th.data.exp_type == 0 && good.is_free_shipping == 0) {
      //看是不是有调用过包邮券,如果活动可以使用优化券的情况下
      if (!th.data.isget_by_quan[bn_pick] && th.data.act.is_usecoupon) {

        //--判断要不要显示包邮券,链式调用接口，调取包邮券，已经是减了优惠的金额，见到优惠券的钱---
        getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea", {
          data: {
            store_id: os.stoid,
            isuse: 0,
            condition: condition,
            user_id: getApp().globalData.user_id,
            pageSize: 2000
          }
        }).then(res => {
          if (res.data.code == 0 && res.data.data.total > 0) {
            //此时要循环判断包邮的地区，不包邮商品是不是符合
            var arr = [], quanlist = res.data.data.pageData;
            quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan, 1);
            for (var i in quanlist) {
              var item = quanlist[i];
              if (item.region_list && th.check_by_area(item.region_list)) continue;  //如果是不包邮区域
              if (item.goods_list && th.check_by_goods(item.goods_list)) continue;    //如果是不包邮商品
              arr.push(item);
            }
            if (arr) {
              th.setData({ get_by_quan_list: arr, def_coupon3: arr });
            }
            th.data.isget_by_quan[bn_pick] = 1;
          }
        })
      }
      if (quan_no && th.data.using_quan[bn_pick].isby == 1) {
        exp_price = 0;
      } else {
        var user_addr = th.data.user_addr;
        var req_d = {
          province: user_addr.province, city: user_addr.city, district: user_addr.district,
          wuliu: parseFloat(condition).toFixed(2), store_id: os.stoid
        }
        var back_data = null;

        //-- 判断是不是包邮 --
        if (this.data.act.is_post_temp && (!prom_ord || prom_ord.is_post_temp)) {

          await getApp().request.promisePost("/api/weshop/order/areaFreight", {
            is_json: 1, data: req_d
          }).then(rs => {
            if (rs.data.code == 0) back_data = rs.data.data;
          });
        }

        var gd_arr_list = [];
        gd_arr_list.push(good);

        var cut_good_weight = 0;
        for (let i in gd_arr_list) {
          let item = gd_arr_list[i];

          if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) {

            if(back_data.weight_free* 1000<item['weight'] * item['buynum']) {
              if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) {
                if (goods_weight < 0) goods_weight = 0;
                goods_weight += item['weight'] * item['buynum'];
                cut_good_weight += item['weight'] * item['buynum'];
              }
              if (back_data.weight_free > 0) {
                out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
              }
            }
            continue;
          }

          switch (item['exp_sum_type']) {
            case 1:
              //统一运费
              o_shipping_price += item['uniform_exp_sum'];
              break;
            case 2:
              if (goods_weight < 0) goods_weight = 0;
              //累积商品重量 每种商品的重量 * 数量
              goods_weight += item['weight'] * item['buynum'];

              if (back_data && back_data.is_by_all && !back_data.no_free_goods) {
                cut_good_weight += item['weight'] * item['buynum'];
                if (back_data.weight_free > 0) {
                  out_of_weight = (back_data.weight_free * 1000) - cut_good_weight;
                }
              }
              break;
            case 3:
              if (goods_piece < 0) goods_piece = 0;
              //累积商品数量
              goods_piece += item['buynum'];
              break;
          }
        }

        //如果是正值的时候
        if (out_of_weight >= 0) out_of_weight = -cut_good_weight;
        else out_of_weight = -back_data.weight_free * 1000;


        if (!th.data.wu_arr) {
          wx.hideLoading();
          wx.showToast({
            title: "物流配置未启用物流公司", icon: 'none', duration: 2000
          })
          //th.setData({ show_submit:0, });
          th.setData({ show_submit: 1, submit: 0, same_ok: 0 })
          return false;
        }

        var code = th.data.wu_arr[th.data.index].code;
        th.data.is_no_by[th.data.bn_pick] = 0;

        //--------------开始计算物流------------------
        var shipping_price = 0;

        //ut.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight,
        //goods_piece, th.data.user_addr, back_data, rs);
        var w_data = {
          store_id: os.stoid, code: code,
          o_shipping_price: o_shipping_price,
          goods_weight: goods_weight,
          out_of_weight: out_of_weight, goods_piece: goods_piece,
          user_addr_province: th.data.user_addr.province,
          user_addr_city: th.data.user_addr.city,
          user_addr_district: th.data.user_addr.district,
          is_by_all: back_data && back_data.is_by_all ? 1 : 0,
          no_free_goods: back_data && back_data.no_free_goods && back_data.no_free_goods.length > 0 ? 1 : 0,
        }

        var is_ok = 0;
        await getApp().request.promisePost('/api/weshop/order/getOrderWuLiPrice', { data: w_data, is_json: 1 }).then(res => {
          if (res.data.code == 0) {
            shipping_price = res.data.data; is_ok = 1;
          }
        })
        if (!is_ok) {
          wx.hideLoading();
          wx.showToast({
            title: "计算物流错误", icon: 'none', duration: 2000
          })
          //th.setData({ show_submit:0 });
          th.setData({ show_submit: 1, submit: 0, same_ok: 0 })
          return false;
        }

        exp_price = parseFloat(shipping_price).toFixed(2);
      }
      th.wuliu_next(allpice, quan_price, exp_price, prom_ord, 1);
    } else {
      th.wuliu_next(allpice, quan_price, exp_price, prom_ord, 1);
    }
    //调用默认优惠券方法
    // th.def_coupon_fn()
    //});
  },

  async calculate_same_city() {
    var th = this,
      good = th.data.goods,
      quan_price = 0,
      exp_price = 0;

    var quan_no = null;
    var bn_pick = th.data.pickup.pickup_id;
    var allpice = th.data.all_price;

    good.buynum = th.data.order.order_goods.goods_num;

    if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined)
      quan_no = th.data.using_quan[bn_pick].coupon_no;

    if (quan_no) {
      if (th.data.using_quan[bn_pick].isby != 1) {
        //---获取优惠券优惠---
        await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", {
          data: {
            storeId: oo.stoid,
            CashRepNo: quan_no,
            WaresSum: th.data.ckeck_quan_price,
            WareIds: th.data.check_quan_ware_list
          }
        }).then(res => {
          if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
            quan_price = res.data.data[0].WareCashSum;
          }
        })

        if (quan_price > 0) {
          if (quan_price < th.data.tail_pay) th.setData({ quan_price: quan_price })
          else {
            th.setData({ quan_price: th.data.tail_pay })
            quan_price = th.data.tail_pay;
          }
        } else {
          th.setData({ quan_price: 0 })
        }
      } else {
        th.setData({ quan_price: 0 })
      }
    } else {
      th.setData({ quan_price: 0 })
    }

    //-----------当地址不为空，且是物流时，计算物流费用----------
    if (th.data.user_addr != null) {
      th.wuliu_next(allpice, quan_price, 0);
    } else {
      wx.showToast({
        title: '请先选择收货地址', icon: 'none', duration: 2000
      })
      th.setData({ show_submit: 1, })
      return false;
    }
    //});
  },




  //相同的东西统一在一起，is_get表示订单优惠有没有被读取一遍
  async wuliu_next(allpice, quan_price, exp_price, ord_prom, is_get) {
    var th = this;
    var o_condition = parseFloat(allpice) - parseFloat(quan_price);
    if (o_condition < 0) o_condition = 0;

    if (!ord_prom && !is_get) {
      if (o_condition > 0 && this.data.pre_arr.is_useorderyh) {
        await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", {
          data: { store_id: os.stoid, orderAmount: o_condition }
        }).then(res => {
          if (res.data.code == 0) {
            ord_prom = res.data.data;

            //如果订单促销的取价不是实收，清空订单促销
            if (ord_prom && ord_prom.discount_field > 0) ord_prom = null;
          }
        })
      }
    }


    var bn_pick = th.data.pickup.pickup_id
    //如果同意参与订单优惠
    if (ord_prom) {
      //th.check_is_order_prom(o_condition,async function (ord_price) {
      var ord_price = o_condition;
      var order_prom_amount = 0;
      var order_prom_id = 0;
      var order_m = 0;
      //if (th.data.order_prom[bn_pick]) {
      //var ord_prom = th.data.order_prom[bn_pick];
      //么有使用券，或者活动没有限制使用优惠券
      if (quan_price <= 0 || !ord_prom.is_xz_yh) {
        order_prom_id = ord_prom['id'];
        switch (ord_prom['type']) {
          case 0:
            order_m = Math.round(ord_price * ord_prom['expression']) / 100;//满额打折
            order_prom_amount = (ord_price - order_m).toFixed(2);
            break;
          case 1:
            order_m = ord_price - ord_prom['expression'];//满额优惠金额
            order_prom_amount = ord_prom['expression'];
            break;
        }
        ord_price = order_m;
      }
      //}

      //--订单优惠的显示--
      if (order_prom_id > 0) {
        var order_prom_txt1 = "order_prom_id";
        var order_prom_txt2 = "order_prom_amount";
        th.setData({ [order_prom_txt1]: order_prom_id, [order_prom_txt2]: order_prom_amount })
      } else {
        var order_prom_txt1 = "order_prom_id";
        var order_prom_txt2 = "order_prom_amount";
        th.setData({ [order_prom_txt1]: 0, [order_prom_txt2]: 0 })
      }

      if (th.data.exp_type == 2) {
        var good = th.data.goods;
        //--------------开始计算物流------------------
        var shipping_price = 0;
        var lon = 0;
        var lat = 0;
        //-- 获取距离  --
        await getApp().request.promisePost("/api/weshop/order/sameCityExp/getGeocoder", {
          is_json: 1, data: { address: th.data.user_addr.more_address + th.data.user_addr.address, store_id: os.stoid }
        }).then(res => {
          if (res.data.code == 0) {
            var data = JSON.parse(res.data.data);
            if (data.status == 0) {
              lon = data.result.location.lng;
              lat = data.result.location.lat;
            }
          }
        })
        var gd_w = good['weight'] * good['buynum'];
        //-- 获取距离  --
        var req_data = {
          store_id: os.stoid,
          order_amount: parseFloat(ord_price),
          lon: lon, lat: lat,
          pickup_id: bn_pick,
          goods_weight: gd_w
        }

        var is_next = 1;
        //获取同城配送参数
        await getApp().request.promisePost("/api/weshop/order/sameCityExp/getMoney", {
          is_json: 1,
          data: req_data
        }).then(res => {
          if (res.data.code == 0) {
            shipping_price = res.data.data;
            th.setData({
              sameCityExp_off: 0,
              sameCityExp_info: ''
            })
          } else {
            if (res.data.code == -2) {  //未达到起送价
              th.setData({
                sameCityExp_off: 2,
                sameCityExp_info: res.data.msg
              })
            } else {
              th.setData({
                sameCityExp_off: 1,
                sameCityExp_info: res.data.msg
              })
            }
            // is_next = 0;
            wx.showToast({
              title: res.data.msg, icon: 'none', duration: 2000
            })
          }
        })
        if (!is_next) {
          th.setData({ show_submit: 1, disabled_btn: 1 })
          return false
        }
        exp_price = parseFloat(shipping_price).toFixed(2);
        th.data.lon = lon;
        th.data.lat = lat;
        th.data.bn_gd_w = gd_w;
        th.data.bn_samecity_order_amount = req_data.order_amount;
      }

      ord_price = parseFloat(ord_price) - parseFloat(th.data.presell.presell_deposit);
      if (ord_price < 0) ord_price = 0;

      var the_price = ord_price + parseFloat(exp_price);

      if (the_price < th.data.goods.use_commission) {

        if (th.data.bn_use_commission) {
          wx.showToast({
            title: '应付金额小于本单佣金，不可使用！',
            icon: 'none',
            duration: 2000
          })
        }

        th.setData({
          bn_use_commission: 0
        });

      }

      if (th.data.bn_use_commission) {
        the_price -= th.data.goods.use_commission;
      }
      th.setData({ exp_price: exp_price, order_m: the_price, show_submit: 1, })

      //})
    } else {

      var o_condition1 = parseFloat(o_condition) - parseFloat(th.data.presell.presell_deposit);
      if (o_condition1 < 0) o_condition1 = 0;

      if (th.data.exp_type == 2) {
        var good = th.data.goods;
        //--------------开始计算物流------------------
        var shipping_price = 0;
        var lon = 0;
        var lat = 0;
        //-- 获取距离  --
        await getApp().request.promisePost("/api/weshop/order/sameCityExp/getGeocoder", {
          is_json: 1, data: { address: th.data.user_addr.more_address + th.data.user_addr.address, store_id: os.stoid }
        }).then(res => {
          if (res.data.code == 0) {
            var data = JSON.parse(res.data.data);
            if (data.status == 0) {
              lon = data.result.location.lng;
              lat = data.result.location.lat;
            }
          }
        })
        var gd_w = good['weight'] * good['buynum'];
        //这个不是取尾款而是取总金额
        let order_amount = parseFloat(o_condition);
        // var o_condition1 = parseFloat(o_condition);
        if (order_amount < 0) order_amount = 0;
        //-- 获取距离  --
        var req_data = {
          store_id: os.stoid,
          order_amount: parseFloat(order_amount),
          lon: lon, lat: lat,
          pickup_id: bn_pick,
          goods_weight: gd_w,
        }

        var is_next = 1;
        //获取同城配送参数
        await getApp().request.promisePost("/api/weshop/order/sameCityExp/getMoney", {
          is_json: 1,
          data: req_data
        }).then(res => {
          if (res.data.code == 0) {
            shipping_price = res.data.data;
            th.setData({
              sameCityExp_off: 0,
              sameCityExp_info: ''
            })
          } else {
            if (res.data.code == -2) {  //未达到起送价
              th.setData({
                sameCityExp_off: 2,
                sameCityExp_info: res.data.msg
              })
            } else {
              th.setData({
                sameCityExp_off: 1,
                sameCityExp_info: res.data.msg
              })
            }
            // is_next = 0;
            wx.showToast({
              title: res.data.msg, icon: 'none', duration: 2000
            })
          }
        })
        if (!is_next) {

          th.setData({ show_submit: 1, disabled_btn: 1, same_ok: 0 })
          return false
        }
        exp_price = parseFloat(shipping_price).toFixed(2);
        th.data.lon = lon;
        th.data.lat = lat;
        th.data.bn_gd_w = gd_w;
        th.data.bn_samecity_order_amount = req_data.order_amount;
      }


      var the_price = parseFloat(o_condition1) + parseFloat(exp_price);

      if (the_price < th.data.goods.use_commission) {

        if (th.data.bn_use_commission) {
          wx.showToast({
            title: '应付金额小于本单佣金，不可使用！',
            icon: 'none',
            duration: 2000
          })
        }

        th.setData({
          bn_use_commission: 0
        })
      }

      if (th.data.bn_use_commission) {
        the_price -= th.data.goods.use_commission;
      }

      th.setData({ exp_price: exp_price, order_m: the_price.toFixed(2), show_submit: 1, })
    }
    //调用默认优惠券方法
    th.def_coupon_fn()
  },

  //-- 获取时间差 --
  get_diff() {

    switch (this.data.act.presell_type) {
      //部分定金
      case 0:
        if (this.data.act.pay_begindate > ut.gettimestamp()) {
          this.setData({ no_start: 1 })
        } else if (this.data.act.pay_enddate < ut.gettimestamp()) {
          this.setData({ is_end: 1 })
        } else {
          var end_time = this.data.act.pay_enddate;
          var e_str = ut.formatTime(end_time);
          var new_date = new Date(); //新建一个日期对象，默认现在的时间
          var old_date = new Date(e_str.replace(/-/g, '/')); //设置过去的一个时间点，"yyyy-MM-dd HH:mm:ss"格式化日期
          var difftime = Math.abs((new_date - old_date) / 1000); //计算时间差,并把毫秒转换成秒
          var days = parseInt(difftime / 86400); // 天  24*60*60*1000
          var hours = parseInt(difftime / 3600) - 24 * days;    // 小时 60*60 总小时数-过去的小时数=现在的小时数
          var minutes = parseInt(difftime % 3600 / 60); // 分钟 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
          var seconds = parseInt(difftime % 60);  // 以60秒为一整份 取余 剩下秒数
          this.setData({ days: days, hours: hours, minutes: minutes, seconds: seconds })
        }
        break;
      //全额付款
      case 1:
        if (this.data.act.start_time > ut.gettimestamp()) {
          this.setData({ no_start: 1 })
        } else if (this.data.act.end_time < ut.gettimestamp()) {
          this.setData({ is_end: 1 })
        } else {
          var end_time = this.data.act.end_time;
          var e_str = ut.formatTime(end_time);
          var new_date = new Date(); //新建一个日期对象，默认现在的时间
          var old_date = new Date(e_str.replace(/-/g, '/')); //设置过去的一个时间点，"yyyy-MM-dd HH:mm:ss"格式化日期
          var difftime = Math.abs((new_date - old_date) / 1000); //计算时间差,并把毫秒转换成秒
          var days = parseInt(difftime / 86400); // 天  24*60*60*1000
          var hours = parseInt(difftime / 3600) - 24 * days;    // 小时 60*60 总小时数-过去的小时数=现在的小时数
          var minutes = parseInt(difftime % 3600 / 60); // 分钟 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
          var seconds = parseInt(difftime % 60);  // 以60秒为一整份 取余 剩下秒数
          this.setData({ days: days, hours: hours, minutes: minutes, seconds: seconds })
        }
        break;

    }
  },


  //显示支付选择
  show_pay: function () {

    //-- 服务卡项没有余额支付 --
    if (this.data.is_fwk) {
      this.to_pay_type(0);
      return false;
    }

    //不用钱直接支付
    if (this.data.order_m <= 0) {
      this.to_pay_type(1);
    } else {
      this.setData({ show_pay_type: 1 });
    }

  },
  //关闭支付
  close_show_pay: function () {
    this.setData({ show_pay_type: 0 });
  },
  //--弹起支付框--
  to_pay() {
    //--物流支付时要有地址--
    if (this.data.exp_type == 0 && this.data.user_addr == null) {
      return getApp().my_warnning("请选择收货地址", 0, this);
    }

    this.setData({ show_pay_type: 1 });
  },
  //选择支付方式
  set_pay_type: function (e) {
    if (this.data.paying) return false;
    this.data.paying = 1;
    var type = e.currentTarget.dataset.type;
    this.to_pay_type(type);
  },

  //--立即支付--
  to_pay_type: function (ind) {
    var th = this;
    //--物流支付时要有地址--
    //if (th.data.exp_type == 0 && th.data.user_addr == null) {
    if (getApp().is_no_addr(th, th.data.exp_type)) {
      this.data.paying = 0;
      return getApp().my_warnning("请选择收货地址", 0, th);
    }
    th.data.exp_type = parseInt(th.data.exp_type + '');
    //---支付参数--
    var dd = {
      order_sn: th.data.order.order_sn,
      order_id: th.data.order.order_id,
      store_id: oo.stoid,
      exp_type: th.data.exp_type,
      user_id: getApp().globalData.userInfo.user_id,
      prom_id: th.data.pre_arr.presell_id,
      tail_pay_type: ind,//0微信支付 1余额支付
    };


    //尾款支付的网址
    var wk_url = oo.url + '/api/weshop/order/pay/payPresellWk';
    if (!th.data.is_fwk) {
      if (th.data.exp_type == 0 || th.data.exp_type == 2) {
        var index = th.data.index;
        dd.shipping_code = th.data.wu_arr[index].code;
        dd.shipping_name = th.data.wu_arr[index].name;
        dd.shipping_price = parseFloat(th.data.exp_price);
        dd.addressid = th.data.user_addr.address_id;
      }
    } else {
      delete dd.exp_type;
      wk_url = oo.url + '/api/weshop/order/pay/payPresellWkCard';
    }

    if (dd.exp_type == 2) {
      dd.lon = th.data.lon ? th.data.lon : 0;
      dd.lat = th.data.lat ? th.data.lat : 0;
      dd.goods_weight = th.data.bn_gd_w;
      dd.samecity_order_amount = th.data.bn_samecity_order_amount;
    }

    if (th.data.order_prom_amount > 0) {
      var e = {
        order_prom_id: th.data.order_prom_id,
        order_prom_amount: th.data.order_prom_amount,
      }
      dd.order_prom_list = e;
    }

    if (th.data.bn_use_commission) {
      dd.use_commission = th.data.goods.use_commission;
    }


    var bn_pick = th.data.pickup_id;
    var quan_no = '';
    if (th.data.using_quan[bn_pick] != null && th.data.using_quan[bn_pick] != undefined)
      quan_no = th.data.using_quan[bn_pick].coupon_no;
    if (quan_no) {
      dd.coupon_no = quan_no;
      if (th.data.quan_price) dd.coupon_price = th.data.quan_price;
    }
    if (th.data.user_note) {
      dd.user_note = th.data.user_note;
    }
    dd.order_amount = parseFloat(th.data.order_m).toFixed(2);

    if (getApp().globalData.scene)
      dd.scene = getApp().globalData.scene;

    console.log(JSON.stringify(dd));

    getApp().request.promisePost(wk_url, {
      data: dd,is_json:1,is_normal:1
    }).then(t => {

        th.close_show_pay();

        //---用微信支付---
        if (dd.tail_pay_type == 0) {

          if (t.data.code != 0) {
            getApp().my_warnning(t.data.msg, 1, th);
            th.data.paying = 0;
            return false;
          }

          //-- 订单OK --
          th.data.ok_order_sn = th.data.order.order_sn;

          util_pay.pay_data(t, function () {
            //---用余额支付---
            getApp().my_warnning("支付成功", 1, th);
            var send_time = th.data.pre_arr.delivery_date;
            if (th.data.pre_arr.delivery_type == 2) {
              send_time = ut.gettimestamp() + th.data.pre_arr.delivery_daynum * 3600 * 24;
            }
            th.setData({ isclose: 0, 'order.order_status': 1, 'order.pay_status': 1, 'wait_wk': 0, 'presell.tail_pay_state': 1, 'wait_fh': 1, send_time: send_time });
            th.data.paying = 0;

          }, function (e) {
            th.data.paying = 0;
            wx.showToast({
              title: e,
              icon: 'none',
              duration: 2500
            })


            th.updateOrderCoupon(); //取消支付的时候

          })
          // var n = t.data.data;
          // th.weixinPay(n,
          //     function () {
          //         //---用余额支付---
          //         getApp().my_warnning("支付成功", 1, th);
          //         var send_time = th.data.pre_arr.delivery_date;
          //         if (th.data.pre_arr.delivery_type == 2) {
          //             send_time = th.data.pre_arr.delivery_daynum * 3600;
          //         }
          //         th.setData({ isclose: 0, 'order.order_status': 1, 'order.pay_status': 1, 'wait_wk': 0, 'presell.tail_pay_state': 1, 'wait_fh': 1, send_time: send_time });
          //         th.data.paying=0;
          //
          //     }, function () {
          //         this.data.paying=0;
          //         getApp().my_warnning("支付失败", 0, th);
          //     })
        } else {
          if (t.data.code == 0) {
            var send_time = th.data.pre_arr.delivery_date;
            if (th.data.pre_arr.delivery_type == 2) {
              send_time = ut.gettimestamp() + th.data.pre_arr.delivery_daynum * 3600 * 24;
            }
            //---用余额支付---
            getApp().my_warnning("支付成功", 1, th);
            th.setData({ isclose: 0, 'order.order_status': 1, 'order.pay_status': 1, 'wait_wk': 0, 'presell.tail_pay_state': 1, 'wait_fh': 1, send_time: send_time });

          } else {
            getApp().my_warnning(t.data.msg, 1, th);
          }
          th.data.paying = 0;
        }
    }).catch(function(err) {
      th.data.paying = 0;
      wx.hideLoading();
      th.updateOrderCoupon()
    })
  },

  //------调起支付框--------
  weixinPay: function (n, success, fail) {
    if (!n) return false;
    var th = this;

    getApp().globalData.no_clear = 1;

    wx.requestPayment({
      timeStamp: String(n.timeStamp),
      nonceStr: n.nonceStr,
      package: n.packageValue,
      signType: n.signType,
      paySign: n.paySign,
      success: function (n) {
        console.log(n), getApp().showSuccess("支付成功！");
        "function" == typeof success && success();
      },
      fail: function (n) {
        console.log(n), "requestPayment:fail" == n.errMsg ? getApp().my_warnning("支付失败", 0, th) : "requestPayment:fail cancel" == n.errMsg ? getApp().my_warnning("您已取消支付", 0, th) : getApp().my_warnning("支付失败：" + n.errMsg.substr("requestPayment:fail ".length), 0, th),
          "function" == typeof fail && fail();
      }
    });
  },


  show_liuyan: function () {
    this.setData({ sh_liuyan: true })
  },
  close_liuyan() {
    this.setData({ sh_liuyan: false })
  },

  //--------点击选择----------
  set_wuliu: function (e) {
    var type = e.currentTarget.dataset.type;
    this.setData({
      exp_type: type,
      same_ok: 1,
      sameCityExp_off: 0,
      sameCityExp_info: '',
      first_entry: 0
    });
    this.calculatePrice2();
  },

  //--------立即支付----------
  async jumpToCart4(e) {
    var th = this;
    if (this.data.optionIsGoup)
      wx.navigateTo({
        url: "/pages/team/team_confirm/team_confirm?orderSn=" + this.data.order.order_sn + "&orderPay=true"
      })
    var order = this.data.order;
    var order_goods = this.data.order_goods;
    var user_id = getApp().globalData.userInfo.user_id;

    var wlist = "";

    var good = order_goods;
    //线下取价功能已经关闭或者过期
    if (!th.data.is_open_offline && good.offline_cut > 0) {
      wx.showModal({
        title: '提示',
        content: '线下取价功能已经关闭或者过期！'
      });
      return false;
    }
    //如果不是小程序有的功能，直接提示要去3.0处理
    if (good.prom_type == 2) {
      wx.showModal({
        title: '提示',
        content: '小程序还未有该活动，请到3.0公众号支付'
      });
      return false;
    }

    //要每件每件的商品进行检查，看有么有超出库存，超出限购
    var goodsbuynum = 0, promgoodsbuynum = 0, gg = null;
    //获取单品的现在的活动状态
    await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + good.goods_id, {
    }).then(res => {
      gg = res.data.data;
    })
    var limit = gg.viplimited;
    var store_count = gg.store_count;
    good.erpwareid = gg.erpwareid;

    //---要获得商品，该用户买了多少件,同步应用---
    await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
      data: {
        store_id: os.stoid,
        user_id: getApp().globalData.user_id,
        goods_id: good.goods_id,
        prom_type: good.prom_type,
        prom_id: good.prom_id,
        isnew: 1,
        timetype:gg.viplimited_timetype
      },
    }).then(res => {
      var buy_num_data = res.data.data;
      if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum;
      goodsbuynum = buy_num_data.goodsbuynum;
    })

    var buyed_mum2 = goodsbuynum + good.goods_num;
    if (buyed_mum2 > limit && limit > 0) {

      var content = gg.goods_name + '购买数量超出商品限购,请取消订单';
      th.toast(content);
      return false;
    }



    //如果是预售的时候，
    if (good.prom_type == 8) {
      await getApp().request.promiseGet("/api/weshop/order/orderPresell/countBuyGoodsSum", {
        data: { store_id: os.stoid, user_id: user_id, goods_id: good.goods_id, prom_id: good.prom_id },
      }).then(e => {
        if (e.data.code == 0) {
          promgoodsbuynum = e.data.data.sumgoodsnum;
        }
      })

      var presell_id = good.prom_id;
      var presellList = null;
      var url = "/api/weshop/marketing/marketingPresellList/list"
      var rd = {
        store_id: os.stoid,
        presell_id: presell_id,
        goods_id: good.goods_id
      }
      //------获取预售从表----------
      await getApp().request.promiseGet(url, {
        data: rd
      }).then(res => {
        if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
          var arr = res.data.data[0];
          presellList = arr
        }
      })

      if (!presellList) {
        var content = good.goods_name + '未找到预售活动,请取消订单';
        th.toast(content);
        th.setData({ paying: 0 });
        return false;
      }


      if (presellList) {

        if (good.goods_num > presellList.presell_sumqty - presellList.buy_goodnum) {
          var content = gg.goods_name + '购买数量超出商品库存,请取消订单';
          th.toast(content);
          return false;
        }
        var buyed_mum3 = promgoodsbuynum + good.goods_num;
        if (buyed_mum3 > presellList.vip_butyqty && presellList.vip_butyqty > 0) {
          var content = gg.goods_name + '购买数量超出商品限购,请取消订单';
          th.toast(content);
          return false;
        }

        var fres = await getApp().request.promiseGet("/api/weshop/marketing/marketingPresellForm/get/" + os.stoid + "/" + presell_id, {});
        //接口调用成功的时候
        if (fres && fres.data.code == 0 && fres.data.data) {
          //如果有指定门店的时候
          if (fres.data.data.pick_up_lists) {
            var idx0 = fres.data.data.pick_up_lists.findIndex(function (e) {
              return e.pickup_id == order.pickup_id;
            })
            if (idx0 < 0) {
              getApp().confirmBox(good.goods_name + "预售活动的门店不可售");
              th.setData({ paying: 0 });
              return false;
            }
          }

        } else {
          var content = good.goods_name + '未找到预售活动,请取消订单';
          th.toast(content);
          th.setData({ paying: 0 });
          return false;
        }


      }
    }


    //如果优惠促销和搭配购的时候
    if ((good.prom_type == 3 || good.prom_type == 5) && good.is_collocation != 1 && good.is_gift != 1) {
      var p_ok = 1;
      await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + good.goods_id + "/0" + "/" + getApp().globalData.user_id, {}).then(res => {
        if (res.data.code == 0) {
          var r_data = res.data.data;
          if (!r_data.collocationPromList && good.prom_type == 5) {

            var content = good.goods_name + '未找到活动,请取消订单重新购买';
            th.toast(content);
            p_ok = 0;
          }
          if (!r_data.promGoodsLists && good.prom_type == 3) {

            var content = good.goods_name + '未找到活动,请取消订单重新购买';
            th.toast(content);
            p_ok = 0;
          }
        } else {

          var content = good.goods_name + '未找到活动,请取消订单重新购买';
          th.toast(content);
          p_ok = 0;
        }
      })
      if (!p_ok) return false;
    }

    //商品的普通购买 ，不要进行判断
    if ((good.prom_type == 1 || good.prom_type == 2 || good.prom_type == 4 || good.prom_type == 6 || good.prom_type == 8 || good.prom_type == 9) && !good.is_gift && !good.is_collocation && !good.is_integral_normal && !good.is_pd_normal) {

    } else {
      if ((gg.prom_type == 1 || gg.prom_type == 3 || gg.prom_type == 5 || gg.prom_type == 6 || gg.prom_type == 4)
        && !good.is_collocation && !good.is_gift && !good.is_integral_normal && !good.is_pd_normal) {
        var prom = null;
        //---如果是活动的时候---
        var prom = null, th = this;
        if (gg.prom_type == 1) {
          await getApp().request.promiseGet("/api/ms/flash_sale/get/" + os.stoid + "/" + gg.prom_id, {
          }).then(res => {
            if (res.data.code == 0) {
              prom = res.data.data;
            }
          })
        }
        if (gg.prom_type == 6) {
          await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + gg.prom_id, {
          }).then(res => {
            if (res.data.code == 0) {
              prom = res.data.data;
            }
          })
        }

        if (gg.prom_type == 4) {
          await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1", {
            data: { store_id: os.stoid, goods_id: gg.goods_id, user_id: getApp().globalData.user_id, }
          }).then(res => {
            if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length) {
              prom = res.data.data.pageData[0];
            }
          })
        }

        if (prom) {
          var t_now = ut.gettimestamp();
          if (prom.is_end == 0 && prom.start_time < t_now && prom.end_time > t_now) {

            var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买';
            th.toast(content);
            return false;
          }
        }
      }
      else {
        //不是赠品的时候
        if (!good.is_gift && good.prom_type != 3) {
          var t_ok = 1;
          await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + good.goods_id + "/0" + "/" + getApp().globalData.user_id, {}).then(res => {
            if (res.data.code == 0) {
              var r_data = res.data.data;
              //-- 参加了全局的优惠活动 --
              if (r_data.promGoodsLists) {

                var content = gg.goods_name + '商品的活动发生了变化,请取消订单重新购买';
                th.toast(content);
                t_ok = 0;
              }
            }
          })
          if (!t_ok) return false;
        }

        //-- 如果有参加线下取价 --
        if (good.offline_cut > 0) wlist += encodeURIComponent(gg.erpwareid) + ",";
      }
      //赠品和搭配购不判断商品金额
      var isok = 1;
      var card_field = th.data.card_field;
      //如果会员是等级会员,商品有等级价,且不是活动商品
      if (!good.is_gift && !good.is_collocation && good.prom_type != 8) {
        if (card_field && gg[card_field] > 0) {
          if (good.goods_price != gg[card_field] && good.offline_cut <= 0) isok = 0;
          if (good.goods_price > gg[card_field] && good.offline_cut > 0) isok = 0;  //如果线下价格比较贵，则不通过

        } else {
          if (good.goods_price != gg.shop_price && good.offline_cut <= 0) isok = 0;
          if (good.goods_price > gg.shop_price && good.offline_cut > 0) isok = 0; //如果线下价格比较贵，则不通过
        }
        var is_h = 0;
        if (!isok) {

          var content = gg.goods_name + '商品的价格发生了变化,请取消订单重新购买';
          th.toast(content);
          return false;
        }
      }


      if (good.goods_num > store_count) {

        var content = gg.goods_name + '商品的库存不足,请取消订单';
        th.toast(content);
        return false;
      }


    }

    console.log("------------------------------------");
    //---如果是活动的时候---
    var prom = null, goodsinfo = good, th = this;
    if (goodsinfo.prom_type == 1) {
      await getApp().request.promiseGet("/api/ms/flash_sale/get/" + os.stoid + "/" + goodsinfo.prom_id, {
      }).then(res => {
        if (res.data.code == 0) {
          prom = res.data.data;
        }
      })
    }
    if (goodsinfo.prom_type == 6 && !good.is_pd_normal) {
      await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + goodsinfo.prom_id, {
      }).then(res => {
        if (res.data.code == 0) {
          prom = res.data.data;
        }
      })
    }

    if (goodsinfo.prom_type == 4 && !good.is_integral_normal) {
      await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList?stype=1&stypeup=1", {
        data: { store_id: os.stoid, goods_id: goodsinfo.goods_id, user_id: getApp().globalData.user_id, }
      }).then(res => {
        if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length) {
          prom = res.data.data.pageData[0];
        }
      })
    }

    //----------如果有活动，并且在进行中，就不计算线下库存---------------
    if (prom) {
      var now = ut.gettimestamp();
      if (prom.is_end == 1 && prom.end_time < now) {

        var content = goodsinfo.goods_name + '商品的活动已经结束,请取消订单重新购买';
        th.toast(content);
        return false;
      }

      buyed_mum2 = promgoodsbuynum + good.goods_num;
      if (buyed_mum2 > prom.buy_limit && prom.buy_limit > 0) {

        var content = goodsinfo.goods_name + '购买数量超出商品活动限购,请取消订单重新购买';
        th.toast(content);
        return false;
      }

      if (goodsinfo.prom_type == 4) {
        if (good.goods_num > prom.limitqty - prom.buy_num) {

          var content = goodsinfo.goods_name + '购买数量超出商品活动库存,请取消订单';
          th.toast(content);
          return false;
        }
      } else {
        var redis_num = 0;
        //------判断活动是否抢光-----
        await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
          os.stoid + "/" + goodsinfo.prom_type + "/" + goodsinfo.prom_id, {
        }).then(res => {
          redis_num = res.data.data;
        });

        if (good.goods_num > redis_num) {

          var content = gg.goods_name + '超出商品活动库存,请取消订单';
          th.toast(content);
          return false;
        }
      }

    }



    //-- 要判断一下线下取价价格是不是发生改变 --
    if (wlist != "" && th.data.is_open_offline && th.data.is_open_offline > 0) {
      wlist = ut.sub_last(wlist);
      var keyid = order.pickup_id;
      var user_info = getApp().globalData.userInfo;
      if (!keyid) return false;
      var offarr = null;
      await getApp().request.promiseGet("/api/weshop/goods/listWarePrice", {
        data: {
          VIPId: encodeURIComponent(user_info.erpvipid),
          store_id: os.stoid,
          PickupId: keyid,
          WareIds: wlist
        },
      },
      ).then(res => {
        if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
          offarr = res.data.data;
        }
      })
      if (!offarr && offarr.length <= 0) {
        wx.showModal({ title: '获取线下取价失败', });
      }
      var newarr = ut.convert_arr_key(offarr, 'WareId');
      //-- 循环判断线下的价格 --
      for (var k in order_goods) {
        var good = order_goods[k];
        //判断线下取价是不是一样
        if (newarr[good.erpwareid] &&
          parseFloat(newarr[good.erpwareid].WarePrice) != parseFloat(good.goods_price)) {

          var content = good.goods_name + '商品的价格发生了变化,请取消订单重新购买';
          th.toast(content);
          return false;
        }
      }

    }

    if (this.data.paying) return false;
    this.data.paying = 1;

    /*---
     o.jumpToCart4({
     order_sn: this.data.order.order_sn,
     order_amount: this.data.order.order_amount,
     type: 1 //正常单
     }, 1);--*/


    th.data.ok_order_sn = this.data.order.order_sn;
    util_pay.pay(this.data.order.order_sn, function () {
      wx.showToast({ title: '支付成功' })
      wx.navigateBack();
    }, null, os.stoid, 1);


  },

  //--------取消订单---------
  cancelOrder: function (e) {
    var t = this, th = t, ord_id = this.data.order.order_id, order = this.data.order;

    wx.showModal({
      title: "是否取消订单？",
      success: function (e) {
        if (!e.confirm) return false;
        //如果是秒杀和拼单的商品，取消订单要返回redis,并取消订单
        //if(is_skill==1 || is_zsorder>=2){
        getApp().request.post("/api/weshop/order/cancelOrder/" + os.stoid + "/" + ord_id + "/" + getApp().globalData.user_id, {
          data: {},
          success: function (t) {
            if (t.data.code == 0) {
              th.setData({ 'order.order_status': 3 });
              wx.setStorageSync("order:order_list:update", !0);
            }

          },
        })

      }
    });
  },


  //-----删除订单-----
  deleteOrderData: function (t) {
    var th = this;
    var order_id = this.data.order.order_id;
    var up_data = {
      order_id: order_id, isdel: 1
    };
    if (th.data.order.order_status != 6) {
      up_data.order_status = 5;
    }
    wx.showModal({
      title: "是否删除订单？",
      success: function (tt) {
        tt.confirm && getApp().request.put("/api/weshop/order/updatebyId", {
          data: up_data,
          success: function (t) {
            getApp().my_warnning("删除成功", 1, th);
            setTimeout(function () {
              getApp().goto("/pages/user/order_list/order_list");
            }, 1000);
          }
        })
      }
    });
  },

  go_goods: function (e) {
    var url = e.currentTarget.dataset.url;
    getApp().goto(url);
  },
  toast(msg) {
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 3000
    })
  },
  //--------确认收货---------
  confirmOrder: function (e) {
    var th = this;
    var o = this.data.order.order_id, order = this.data.order;
    wx.showModal({
      title: "是否确认收货?",
      success: function (t) {
        t.confirm && getApp().request.post("/api/weshop/order/confirmOrder/" + os.stoid + "/" + o + "/" + getApp().globalData.user_id, {
          success: function (e) {
            if (e.data.code == 0) {
              th.setData({})
            }
          }
        })
      }
    });
  },


  //---------联系客服------------
  contactService: function () {
    getApp().con_Service();
  },

  //---------联系微信客服------------
  con_weixin: function () {
    getApp().con_wx(this);
  },

  //使用
  set_bn_commission: function () {
    var th = this;
    th.setData({ bn_use_commission: !th.data.bn_use_commission });
    th.calculatePrice2();
  },

  //-- 查看物流 --
  go_wuliu: function (e) {
    getApp().go_wuliu(e);
  },
  //去凑单
  qcd() {
    getApp().goto("/pages/index/index/index");
  },

  //优惠券锁定后解锁方法
  async updateOrderCoupon(){
    try{
      let req_data={
        store_id:oo.stoid,
        user_id:(getApp().globalData.userInfo.user_id || 0),
        order_id:this.data.order_id,
      }
      await getApp().request.promisePost("/api/weshop/order/updateOrderCoupon",{
        is_json:1,
        data:req_data
      }).then(res=>{
        console.log(111)
      })
    }catch(error){
      console.log(error)
    }
  }





});
