// packageE/others/cloudwarehouse/cloudOrderList/cloudOrderList.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    page: 1,
    language: "",
    regional: "请选择快递公司",
    dateshow_1: false,
    columns: [],
    checkList: [],
    orderPayId: "",
    options: [],
    //确认发货
    dialogVisible: false,
    expressName: "",
    numberName: "",
    addresseeInfo: {},
    showQrcode: false,
    qrcode_url: "",
    // 上拉菜单弹出层
    sendGoogsFail: {
      show: false,
      msg: "",
    },
    jurisdiction_set: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  onClick(e) {
    let ind = e.detail.index;
    this.setData({
      active: ind,
      page: 1,
    });
    this.getData();
  },
  tapDetail(e) {
    console.log(e);
    let kid = e.currentTarget.dataset.id;
    wx.navigateTo({
      url:
        "/packageE/others/cloudwarehouse/cloudOrderDetail/cloudOrderDetail?id=" +
        kid,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.current_page >= this.data.last_page) {
      return;
    } else {
      let pages = this.data.page + 1;
      this.setData({
        page: pages,
      });
      this.getMore();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  getMore() {
    let that = this;
    let url;
    if (this.data.active == 0) {
      url = "plugin.cloud-warehouse.frontend.order-list.index";
    } else if (this.data.active == 1) {
      url = "plugin.cloud-warehouse.frontend.order-list.waitSend";
    } else if (this.data.active == 2) {
      url = "plugin.cloud-warehouse.frontend.order-list.waitReceive";
    } else if (this.data.active == 3) {
      url = "plugin.cloud-warehouse.frontend.order-list.completed";
    }
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            info: that.data.info.concat(res.data.data),
            current_page: res.data.current_page,
            last_page: res.data.last_page,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  getData() {
    let that = this;
    let url;
    if (this.data.active == 0) {
      url = "plugin.cloud-warehouse.frontend.order-list.index";
    } else if (this.data.active == 1) {
      url = "plugin.cloud-warehouse.frontend.order-list.waitSend";
    } else if (this.data.active == 2) {
      url = "plugin.cloud-warehouse.frontend.order-list.waitReceive";
    } else if (this.data.active == 3) {
      url = "plugin.cloud-warehouse.frontend.order-list.completed";
    }
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      data: {
        page: that.data.page,
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            info: res.data.data,
            current_page: res.data.current_page,
            last_page: res.data.last_page,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //根据按钮值判断用途
  operation(e) {
    let btn = e.currentTarget.dataset.item;
    let order = e.currentTarget.dataset.order;
    let orderidx = e.currentTarget.dataset.orderidx;
    console.log(orderidx);
    if (!btn.api) {
      if (btn.value == "expediting_delivery") {
        wx.showToast({
          icon: "none",
          title: "已提醒过商家",
          duration: 1000,
        });
      } else {
        //接口没有返回按钮点击请求的地址
        wx.showToast({
          icon: "none",
          title: "error:错误4008820",
          duration: 1000,
        });
      }
      return;
    }

    console.log(btn);
    if (btn.value == 8) {
      //查看物流
      this._checklogistics(order, btn);
    } else if (btn.value == 12) {
      //删除订单
      this._deleteOrder(order, btn, orderidx);
    } else if (btn.value == 10) {
      //评价订单
      this._comment(order, btn);
    } else if (btn.value == 1) {
      //订单支付
      this._toPay(order, btn);
    } else if (btn.value == 13) {
      //退款
      let that = this;
      that.getTemplate(order, btn);
    } else if (btn.value == 9) {
      //取消订单
      this._cancleOrder(order, btn, orderidx);
    } else if (btn.value == 5) {
      //确认订单
      this._confirmOrder(order, btn);
    } else if (btn.value == 18) {
      //退款中
      this._toRefundDetail(order, btn);
    } else if (btn.value == "cashierPay") {
      //订单已付款
      this._cashPayOrder(order, btn);
    } else if (btn.value == "verification_code") {
      this._verification(order, btn);
    } else if (btn.value == 20) {
      this._verificationCash(order, btn);
    } else if (btn.value == 21) {
      //跳到OrderRecord
      wx.navigateTo({
        url:
          "/packageD/member/myOrder/order_record/order_record?order_id=" +
          item.id,
      });
    } else if (btn.value == 22) {
      this.setData({
        orderPayId: order.id,
      });
      // 确认支付
      this._payMoney(order, btn);
    } else if (btn.value == "coupon") {
      console.log(order.id);
      wx.navigateTo({
        url: "/packageD/coupon_share/coupon_share?orderid=" + order.id,
      });
    } else if (btn.value == 23 || btn.value == 60) {
      // 确认发货
      this.setData({
        orderPayId: order.id,
      });
      if (order.dispatch_type_id == 3) {
        this.sendGoogs();
      } else {
        this._getCompany();
        this.setData({
          dialogVisible: true,
        });
      }

      this.triggerEvent("stoprefresh", true);
      this.setData({
        expressName: "",
        numberName: "",
      });
    } else if (btn.value == 24 || btn.value == 61) {
      //取消发货
      this.setData({
        orderPayId: order.id,
      });
      this._deliverGoodsCancel(order, btn);
    } else if (btn.value == 25) {
      //确认收货
      this.setData({
        orderPayId: order.id,
      });
      this._collectGoods(order, btn);
    } else if (btn.value == 26) {
      //关闭订单
      this.setData({
        orderPayId: order.id,
      });
      this._closeOrderPay(order, btn);
    } else if (btn.value == 27) {
      this.setData({
        orderPayId: order.id,
      });
      this._evaluate(order, btn);
    } else if (btn.value == 28) {
      //卡密
      this._truckList(btn, order);
    } else if (btn.value == 41) {
      //398售后
    } else if (btn.value == 50) {
      //查看发票
      this._checkInvoice(btn, order);
    } else if (btn.value == 11) {
      //酒店确认下单
      this.confirmHotelOrder(btn.api, order.id);
    } else if (
      btn.value == "lease_toy_refund" ||
      btn.value == "package_deliver_clerk"
    ) {
      console.log("申请归还");
      this.getRuruen(btn, order); //进行归还请求
    } else if (btn.value == "lease_toy_apply_adopt") {
      console.log("填写归还");
      wx.navigateTo({
        url: "/packageB/member/OrderReturn/OrderReturn?id=" + order.id,
      });
    } else if (btn.value == "lease_toy_return_info") {
      console.log("归还详情");
      wx.navigateTo({
        url:
          "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + order.id,
      });
    } else if (btn.value == "package_deliver") {
      console.log("自提点核销");
      console.log(btn.api);
      this.getQrImg(btn, order);
    } else if (btn.value == "expediting_delivery") {
      this.setData({
        orderPayId: order.id,
      });
      this.publicMessage(btn, order, "提醒商家发货");
    }
  },
  // 自提点确认核销
  getQrImg(btn, order) {
    let urlStr = app.getNetAddresss(btn.api);
    if (btn.value == "package_deliver") {
      urlStr += "&order_id=" + order.id;
    } else {
      urlStr += "&order_pay_id=" + order.id;
    }
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            showQrcode: true,
            qrcode_url: res.data.qr_code_url,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  // onClose() {
  //   this.setData({
  //     showQrcode: false,
  //   });
  // },
  publicMessage(btn, order, text) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: `确定${text}?`,
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          urlStr += app.getNetAddresss(btn.api);
          urlStr += "&order_id=" + that.data.orderPayId;
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              resdata = resdata.data;
              if (resdata.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", "pay");
                wx.showToast({
                  icon: "success",
                  title: `${text}成功`,
                  duration: 1000,
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: resdata.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (resdata) {
              console.log(resdata);
            },
          });
        }
      },
    });
  },
  onClose() {
    this.setData({
      showQrcode: false,
    });
  },
  //查看物流
  _checklogistics(item, btn) {
    //logistics
    console.log(item, btn);
    wx.navigateTo({
      url:
        "/packageA/member/order/logistics/logistics?id=" +
        item.id +
        "&api=" +
        btn.api,
    });
  },
  // 申请归还
  getRuruen(btn, order) {
    let urlStr = app.getNetAddresss(btn.api);
    urlStr += "&order_id=" + order.id;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
          this.triggerEvent("ConfrimOrderNotification");
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //删除订单
  _deleteOrder(item, btn, orderidx) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定删除此订单?",
      success(res) {
        if (res.confirm) {
          //删除当前选中的地址
          let datasource = that.data.info;
          datasource.splice(orderidx, 1);
          that.setData({
            info: datasource,
          });
          that._sentRequest(btn.api, "&order_id=" + item.id, false);
        }
      },
    });
  },
  _sentRequest(action, params, isIndicator) {
    let urlStr = app.getNetAddresss(action);
    urlStr += params;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.navigateBack({
                  delta: 1,
                });
              }, 1500); //延迟时间
            },
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //评价订单
  _comment(item, btn) {
    wx.navigateTo({
      url:
        "/packageB/comment/comment?order=" + JSON.stringify(item ? item : {}),
    });
    // 跳到评价订单
    //comment
  },
  _toPay(item, btn) {
    //status-2合并支付 type-1订单支付
    wx.navigateTo({
      url: "/packageD/buy/orderPay/orderPay?order_id=" + item.id + "&status=1",
    });
  },
  //退款中
  _toRefundDetail(item, btn) {
    //aftersales
    wx.navigateTo({
      url:
        "/packageD/member/myOrder/Aftersales/Aftersales?refund_id=" +
        item.refund_id,
    });
  },
  //退款
  _toRefund(item, btn) {
    //refund
    wx.navigateTo({
      url:
        "/packageD/member/myOrder/refund/refund?order_id=" +
        item.id +
        "&type=1",
    });
  },
  //取消订单
  _cancleOrder(item, btn, orderidx) {
    var that = this;
    wx.showModal({
      title: "提示",
      content: "确定取消此订单?",
      success(res) {
        if (res.confirm) {
          //取消当前选中的地址
          let datasource = that.data.info;
          datasource.splice(orderidx, 1);
          that.setData({
            info: datasource,
          });
          that._sentRequest(btn.api, "&order_id=" + item.id, false);
        }
      },
    });
  },
  //确认收货
  _confirmOrder(item, btn) {
    let that = this;
    let urlStr = app.getNetAddresss(btn.api);
    urlStr += "&order_id=" + item.id;
    wx.showModal({
      title: "提示",
      content: "您确定收到货物?",
      success(resqu) {
        if (resqu.confirm) {
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              var res = resdata.data;
              if (res.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", item.id);
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
        }
      },
    });
  },
  _cashPayOrder(item, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定此订单已付款?",
      success(res) {
        if (res.confirm) {
          that._sentRequest(
            btn.api,
            "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id,
            false
          );
        }
      },
    });
  },
  _verification(item, btn) {
    //订单核销
    //orderVerification
    wx.navigateTo({
      url:
        "/packageD/member/myOrder/orderVerification/orderVerification?order_id=" +
        item.id +
        "&api=" +
        btn.api,
    });
  },
  _verificationCash(item, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定此订单已付款?",
      success(res) {
        if (res.confirm) {
          that._sentRequest(
            btn.api,
            "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id,
            false
          );
        }
      },
    });
  },
  //确认支付
  _payMoney(item, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确认支付该订单?",
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          if (
            that.data.orderType == "supplier" ||
            that.data.orderType == "subsidiary"
          ) {
            urlStr += app.getNetAddresss(btn.api);
            urlStr += "&order_id=" + that.data.orderPayId;
          } else {
            urlStr += app.getNetAddresss(
              "plugin.store-cashier.frontend.store.center.order-operation.pay"
            );
            urlStr += "&order_id=" + that.data.orderPayId;
          }
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              var res = resdata.data;
              if (res.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", "pay");
                wx.showToast({
                  icon: "success",
                  title: "支付成功",
                  duration: 1000,
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
        }
      },
    });
  },
  //获取快递公司
  _getCompany() {
    let that = this;
    let urlStr = "";
    if (that.data.orderType == "supplier") {
      urlStr += app.getNetAddresss(
        "plugin.supplier.frontend.order.express-company"
      );
    } else if (that.data.orderType == "subsidiary") {
      urlStr += app.getNetAddresss(
        "plugin.subsidiary.frontend.order.express-company"
      );
    } else {
      urlStr += app.getNetAddresss(
        "plugin.store-cashier.frontend.store.center.sendOrder"
      );
    }
    urlStr += "&order_id=" + that.data.orderPayId;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            options: res.data.express_companies,
          });
          var arrayOfSquares = that.data.options.map(function (item) {
            return item.name;
          });
          if (!app._isTextEmpty(res.data.jurisdiction_set)) {
            that.setData({
              jurisdiction_set: res.data.jurisdiction_set,
            });
          }
          that.setData({
            columns: arrayOfSquares,
            addresseeInfo: res.data.address,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //取消发货
  _deliverGoodsCancel(order, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定取消发货?",
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          if (
            that.data.orderType == "supplier" ||
            that.data.orderType == "subsidiary"
          ) {
            urlStr += app.getNetAddresss(btn.api);
            urlStr += "&order_id=" + that.data.orderPayId;
          } else if (that.data.orderType == "auction") {
            urlStr += app.getNetAddresss(
              "plugin.auction.api.order-operation.cancel-send"
            );
            urlStr += "&order_id=" + that.data.orderPayId;
          } else {
            urlStr += app.getNetAddresss(
              "plugin.store-cashier.frontend.store.center.order-operation.cancel-send"
            );
            urlStr += "&order_id=" + that.data.orderPayId;
          }
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              var res = resdata.data;
              if (res.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", "pay");
                wx.showToast({
                  icon: "success",
                  title: "取消发货成功",
                  duration: 1000,
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
        }
      },
    });
  },
  //确认收货
  _collectGoods(order, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确认收货?",
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          if (
            that.data.orderType == "supplier" ||
            that.data.orderType == "subsidiary"
          ) {
            urlStr += app.getNetAddresss(btn.api);
            urlStr += "&order_id=" + that.data.orderPayId;
          } else {
            urlStr += app.getNetAddresss(
              "plugin.store-cashier.frontend.store.center.order-operation.receive"
            );
            urlStr += "&order_id=" + that.data.orderPayId;
          }
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              var res = resdata.data;
              if (res.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", "pay");
                wx.showToast({
                  icon: "success",
                  title: "收货成功",
                  duration: 1000,
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
        }
      },
    });
  },
  //关闭订单
  _closeOrderPay(order, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定关闭订单?",
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          if (
            that.data.orderType == "supplier" ||
            that.data.orderType == "subsidiary"
          ) {
            urlStr += app.getNetAddresss(btn.api);
            urlStr += "&order_id=" + that.data.orderPayId;
          } else {
            urlStr += app.getNetAddresss(
              "plugin.store-cashier.frontend.store.center.order-operation.close"
            );
            urlStr += "&order_id=" + that.data.orderPayId;
            urlStr += "&shop_id=" + null;
          }
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              resdata = resdata.data;
              if (resdata.result == 1) {
                that.triggerEvent("ConfrimOrderNotification", "pay");
                wx.showToast({
                  icon: "success",
                  title: "关闭订单成功",
                  duration: 1000,
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: resdata.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (resdata) {
              console.log(resdata);
            },
          });
        }
      },
    });
  },
  // 评价
  _evaluate(order, btn) {
    //抢单评价
    //DeliveryEvaluate
    wx.navigateTo({
      url:
        "/packageD/member/myOrder/DeliveryEvaluate/DeliveryEvaluate?order_id=" +
        order.order_id +
        "&api=" +
        btn.api +
        "&name=distributor",
    });
  },
  //卡密
  _truckList(btn, order) {
    //TruckList
    wx.navigateTo({
      url: "/packageD/member/myOrder/truckList/truckList?order_id=" + order.id,
    });
  },
  //查看发票
  _checkInvoice(btn, order) {
    //Invoice
    wx.navigateTo({
      url: "/packageD/member/myOrder/invoice/invoice?order_id=" + order.id,
    });
  },
  //快递单号输入值绑定
  numberNamebtn(e) {
    let val = e.detail.value;
    this.setData({
      numberName: val,
    });
  },
  //确认发货
  sendGoogs(event) {
    if (!event || event.detail === "confirm") {
      let that = this;
      // 发货失败上拉弹出菜单函数
      const sendGoogsFail = (msg) => {
        this.setData({
          sendGoogsFail: {
            show: true,
            msg,
          },
          dialogVisible: false,
        });
      };
      if (this.data.orderType == "supplier") {
        let urlStr = "";
        urlStr += app.getNetAddresss("plugin.supplier.frontend.order.send");
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            console.log("msg=", res);
            if (res.result == 1) {
              that.setData({
                dialogVisible: false,
              });
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            } else {
              sendGoogsFail(res.msg);
            }
          },
          fail: function (res) {},
        });
      } else if (this.data.orderType == "subsidiary") {
        let urlStr = "";
        urlStr += app.getNetAddresss("plugin.subsidiary.frontend.order.send");
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.setData({
                dialogVisible: false,
              });
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            } else {
              sendGoogsFail(res.msg);
            }
          },
          fail: function (res) {},
        });
      } else if (this.data.orderType == "auction") {
        let urlStr = "";
        urlStr += app.getNetAddresss("plugin.auction.api.order-operation.send");
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.setData({
                dialogVisible: false,
              });
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            } else {
              sendGoogsFail(res.msg);
            }
          },
          fail: function (res) {},
        });
      } else {
        let urlStr = "";
        urlStr += app.getNetAddresss(
          "plugin.store-cashier.frontend.store.center.order-operation.send"
        );
        urlStr += "&order_id=" + that.data.orderPayId;
        urlStr += "&express_code=" + that.data.expressName.value;
        urlStr += "&express_company_name=" + that.data.expressName.name;
        urlStr += "&express_sn=" + that.data.numberName;
        app._getNetWork({
          url: urlStr,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              console.log("result=", res.result);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
              that.setData({
                dialogVisible: false,
              });
            } else {
              sendGoogsFail(res.msg);
            }
          },
          fail: function (res) {},
        });
      }
    } else {
      this.setData({
        dialogVisible: false,
      });
      this.triggerEvent("stoprefresh", false);
    }
  },
  // 关闭上拉弹出
  colseSendGoogsFailPopup() {
    this.setData({
      "sendGoogsFail.show": false,
    });
  },
  //快递选择
  seleRegional: function () {
    this.setData({
      dateshow_1: true,
    });
  },
  onCancelbtn: function () {
    this.setData({
      dateshow_1: false,
    });
  },
  onConfirmbtn: function (e) {
    let index = e.detail.index;
    let val = e.detail.value;
    let array = this.data.options;
    this.setData({
      dateshow_1: false,
      regional: val,
      expressName: array[index],
    });
  },
  // for prevent touchmove
  noop: function noop() {},
  //value 11 酒店确认下单
  confirmHotelOrder(api, id) {
    let urlStr = "";
    urlStr += app.getNetAddresss(api);
    urlStr += "&order_id=" + id;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  copyorderbtn(e) {
    let copydata = e.currentTarget.dataset.copydata;
    wx.setClipboardData({
      data: copydata ? copydata : "",
      success(res) {
        wx.showToast({
          icon: "none",
          title: "复制成功",
          duration: 1000,
        });
      },
    });
  },
});
