<template>
  <div class="order" v-if="isorder">
    <div class="order-status">
      <div class="order-success">
        {{
          orderInfo.SALEBILL_STATE === 1010
            ? "待发货"
            : orderInfo.SALEBILL_STATE === 2010
              ? "待收货"
              : orderInfo.SALEBILL_STATE === 3000
                ? "已收货"
                : orderInfo.SALEBILL_STATE === 8000
                  ? "退款申请中"
                  : orderInfo.SALEBILL_STATE === 8010
                    ? "商品退货中"
                    : orderInfo.SALEBILL_STATE === 8020
                      ? "退款处理中"
                      : orderInfo.SALEBILL_STATE === 8900
                        ? "订单已退款"
                        : orderInfo.SALEBILL_STATE === 8999
                          ? "退款已关闭"
                          : orderInfo.SALEBILL_STATE === 9000
                            ? "订单已关闭"
                            : orderInfo.SALEBILL_STATE === 9999
                              ? "订单已撤销"
                              : ""
        }}
      </div>
      <div class="status-btn-box">
        <block v-if="orderInfo.SALEBILL_STATE === 1005">
          <div class="back-btn" @click="orderCancle">取消订单</div>
          <div class="continu-btn" @click="goPayment(orderInfo, orderInfo.TOTAL_PAY)">
            去付款 <span>{{ minutes }}</span>
          </div>
        </block>
        <block v-if="
          orderInfo.SALEBILL_STATE !== 1005 &&
          orderInfo.SALEBILL_STATE !== 2010 &&
          orderInfo.SALEBILL_STATE !== 3000 &&
          orderInfo.SALEBILL_STATE !== 8000 &&
          orderInfo.SALEBILL_STATE !== 8010 &&
          orderInfo.SALEBILL_STATE !== 8020 &&
          orderInfo.SALEBILL_STATE !== 8900 &&
          orderInfo.SALEBILL_STATE !== 8999 &&
          orderInfo.SALEBILL_STATE !== 9000 &&
          orderInfo.SALEBILL_STATE !== 9999 &&
          orderInfo.COMMENT_STATE === 0
        ">
          <!--  orderInfo.SALEBILL_STATE !== 1005 &&
            orderInfo.SALEBILL_STATE !== 1010 && -->
          <div class="continu-btn" @click="handleRefund" v-if="orderInfo.SALEBILL_STATE === 1010">
            发起退款
          </div>
          <!-- <div class="back-btn" @click="goShop" v-if="orderInfo.SALEBILL_STATE!=1010">再来一单</div> -->
          <div class="continu-btn" @click="goEvaluate" v-if="orderInfo.SALEBILL_STATE >= 3000">
            评价得积分
          </div>
        </block>
      </div>
    </div>
    <!-- <text @click="handleChangeOrderStatus">收货</text> -->

    <div class="hx-block"></div>

    <div class="pageDesc">*自提商品的提货地址：凌云大厦一楼彩云驿购</div>

    <div class="order-info">
      <p class="order-info-type order-info-h">
        <!-- :class="{ appoint: orderInfo.TAKE_TYPE === 2000 }" -->
        <span>订单信息</span>
        <span class="order-info-status">{{
          orderInfo.SALEBILL_STATE_TEXT
        }}</span>
      </p>
      <p class="order-info-type">
        <span class="order-info-t">收货方式</span><span>{{
          orderInfo.TAKE_TYPE === 1000
            ? "自提"
            : orderInfo.TAKE_TYPE === 2000
              ? "邮寄"
              : orderInfo.TAKE_TYPE === 3000
                ? "免发货"
                : ""
        }}</span>
      </p>
      <p class="order-info-type" v-if="orderInfo.TAKE_TYPE === 2000 && orderInfo.SALEBILL_STATE >= 2010">
        <span class="order-info-t">快递单号</span><span>{{ orderInfo.TABLE_NUMBER || "" }}</span>
      </p>

      <p class="order-info-type">
        <span class="order-info-t">订单编号</span><span>{{ orderInfo.SALEBILL_CODE }}</span>
      </p>

      <p class="order-info-type">
        <span class="order-info-t">下单时间</span><span>{{ orderInfo.ORDER_DATE }}</span>
      </p>
      <block v-if="orderInfo.TAKE_TYPE === 2000">
        <p class="order-info-type">
          <span class="order-info-t">下单人员</span><span>{{ orderInfo.ORDER_PERSON }}</span>
        </p>
        <p class="order-info-type" v-if="orderInfo.RESERVATION_DATE">
          <span class="order-info-t">预约时间</span><span>{{ orderInfo.RESERVATION_DATE }}</span>
        </p>
        <p class="order-info-type">
          <span class="order-info-t">预约电话</span><span>{{ orderInfo.ORDER_PERSONTEL }}</span>
        </p>
        <p class="order-info-type" v-if="orderInfo.BALANCE_PAYMENT">
          <span class="order-info-t">工会积分支付</span><span>￥{{ orderInfo.BALANCE_PAYMENT }}</span>
        </p>

        <p class="order-info-type" v-if="orderInfo.TOTAL_PAY">
          <span class="order-info-t">微信支付</span><span>￥{{ orderInfo.TOTAL_PAY }}</span>
        </p>
        <p class="order-info-type">
          <span class="order-info-t">订单备注</span><span>{{ orderInfo.SALEBILL_DESC }}</span>
        </p>
      </block>
    </div>

    <div class="order-box">
      <div class="order-top" @click="goShop">
        <div style="display: flex; align-items: center">
          <img src="https://eshangtech.com/ShopICO/shop_ico.png" style="
              width: 56rpx;
              height: 36rpx;
              vertical-align: middle;
              margin-right: 10rpx;
            " />
          <span class="order-addr">{{ ShopAddress }}</span>
        </div>
        <van-icon name="arrow" size="30rpx" v-if="pageMsg.type === 0" />
      </div>

      <div class="order-list" v-for="(item, i) in shopOrder" :key="i">
        <div style="display: flex;">
          <div class="order-name">
            {{
              item.COMMODITY_RULE
                ? item.COMMODITY_NAME + "(" + item.COMMODITY_RULE + ")"
                : item.COMMODITY_NAME
            }}
          </div>
          <div class="order-num">x{{ item.ORDER_COUNT }}</div>
          <div class="order-price">￥{{ item.AVERAGE_PRICE }}</div>
        </div>
        <div style="font-size: 24rpx;color: #a7a7a7;margin-top:8rpx">
          {{ item.SALEDETAIL_DESC || "" }}
        </div>
      </div>


      <hr />

      <div class="coupon" v-if="orderInfo.COUPON_AMOUNT">
        <div>
          <span>优惠券</span>
        </div>
        <div style="font-size: 28rpx; color: #000000; font-weight: bolder">
          -￥{{ orderInfo.COUPON_AMOUNT }}
        </div>
      </div>
      <div class="price-sum">
        <div class="link-store" @click="callPhone">
          <van-icon name="phone-circle-o" size="40rpx" color="#CAA97F" custom-style="margin-right:16rpx;"></van-icon>
          联系商家
        </div>
        <div class="">
          <span>合计</span>
          <span class="pay-price">￥{{ tatalMoney }}</span>
        </div>
      </div>
    </div>

    <uni-popup ref="payPopup" :safe-area="false">
      <div class="payShowBox">
        <div class="payBoxTitle">支付方式</div>

        <div class="payList">
          <radio-group :value="payType" class="radio-group">
            <div class="bottom-radio" color="#CAA97F" @click="handleChangePayType(1)">
              <div class="radioLeft">
                <div class="logoBox">
                  <image class="logoIcon" src="/static/images/home/alipayIcon.png" />
                </div>
                <text>支付宝支付</text>
              </div>
              <radio value="支付宝支付" color="#CAA97F" :checked="payType === 1" />
            </div>
            <div class="bottom-radio" color="#CAA97F" @click="handleChangePayType(2)">
              <div class="radioLeft">
                <div class="logoBox">
                  <image class="logoIcon" src="/static/images/home/wxPay.png" />
                </div>
                <text>微信支付</text>
              </div>
              <radio value="微信支付" color="#CAA97F" :checked="payType === 2" />
            </div>
          </radio-group>
        </div>

        <div class="goPayBox" @click="getOrderInfo">
          <div class="goPay">确认支付</div>
        </div>
      </div>
    </uni-popup>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      orderInfo: {},
      isorder: false,
      shopOrder: [],

      orderAmount: 0,
      orderNumber: "",
      status: "",
      statusName: "",
      orderInternal: "",
      payType: "余额支付",
      orderTime: "",
      RESERVATION_DATE: "",
      ORDER_PERSONTEL: "",
      TAKE_TYPE: 0,
      SERVERPARTSHOP_ID: "",
      couponAmount: "",
      ShopAddress: "",
      minutes: "",
      isMinute: false,
      timer: "",
      isShow: false,
      cardPay: {
        payType: "余额支付", // 用户支付方式
        reason: "",
        canCardPay: true, // 是否可以余额支付
        amount: "", // 实业饭卡余额
      },
      pageMsg: {
        type: 0,
      },
      sellchildid: "", // 子ID
      showNotice: false,
    };
  },
  computed: {
    ...mapGetters(["user"]),
    tatalMoney() {
      let total = this.orderAmount;
      total =
        Math.round((total - this.orderInfo.COUPON_AMOUNT || 0) * 100) / 100;

      return total;
    },
  },
  methods: {
    // 发起退款
    handleRefund() {
      let _this = this;
      uni.showModal({
        title: "提示",
        content: "仅支持整单退款，确认发起退款申请？",
        success: async function (res) {
          if (res.confirm) {
            console.log('_this.orderInfo_this.orderInfo_this.orderInfo_this.orderInfo', _this.orderInfo)
            uni.navigateTo({
              url: `/pages/order/orderdetail/reasonforRefund?salebillId=${_this.orderInfo.SALEBILL_ID}&&saleBillChildId=${_this.orderInfo.SALEBILL_CHILD_ID || ""}`,
            });
          }
        },
      });

      // 现在跳个页面 发起退款 所以下面的操作 就在其他页面完成
      return;
      // let _this = this;

      let openId = uni.getStorageSync("openId");
      console.log("openId", openId);
      console.log("_this.orderInfo", _this.orderInfo);
      uni.showModal({
        title: "提示",
        content: "仅支持整单退款，确认发起退款申请？",
        success: async function (res) {
          if (res.confirm) {
            let reqOrder = {
              action_type: "ScanOrder",
              salebillType: 3999,
              provinceCode: _this.user.PROVINCE_CODE || "530000",
              serverpartShopId: "5634",
              salebillDesc: "退款订单",
              wechatOpenId: openId || "",
              oriSalebillCode: _this.orderInfo.SALEBILL_CODE,
              wechatUnionId: _this.user.USER_UNIONID || "",
              takeType: _this.orderInfo.TAKE_TYPE,
              // addressId: this.addressInfo.MEMBERADDRESS_ID,
              // orderPersonTel: this.addressInfo.MOBILEPHONE,
              // couponCode: '',//优惠券
              t_saleorderdetail: JSON.stringify(_this.orderInfo.List),
              requestType: "application/x-www-form-urlencoded",
            };
            const orderData = await _this.$api.postCoop(reqOrder);
            if (orderData.ResultCode === "100") {
              const req = {
                action_type: "UpdateOrderState",
                action_data: _this.orderInfo.SALEBILL_ID,
                // saleBillChildId: _this.sellchildid,
                SALEBILL_STATE: 8000,
                // deliverDate: new Date()
              };
              const data = await _this.$api.getCoop(req);
              uni.showToast({
                title: data.msg,
                icon: "none",
              });
              if (data.error === 1) {
                _this.getOrderType();
              }
            } else {
              uni.showToast({
                title: orderData.ResultDesc,
                icon: "none",
              });
            }
          }
        },
      });
    },
    // 倒计时
    num(n) {
      return n < 10 ? "0" + n : "" + n;
    },
    showTime() {
      let _this = this;
      _this.timer = setInterval(function () {
        // debugger
        let oldTime = new Date(_this.orderTime).getTime() / 1000 + 15 * 60;
        let nowTime = new Date().getTime() / 1000;
        let timediff = parseInt(oldTime - nowTime);
        if (timediff > 0) {
          _this.minutes =
            "(" + parseInt(timediff / 60) + "分" + (timediff % 60) + "秒)";
          _this.isMinute = true;
        } else if (timediff <= 0) {
          _this.minutes = "";
          _this.isMinute = false;
          clearInterval(_this.timer);
          _this.getOrderType();
          // console.log(1)
        }
      }, 1000);
    },
    changePayType(data) {
      this.cardPay.payType = data.mp.detail;
    },
    isGoPay() {
      if (this.cardPay.payType === "余额支付") {
        // 如果该用户进行余额支付
        this.payByCard();
      } else {
        this.isShow = false;
        this.getOrderInfo();
      }
    },
    async goPayment(obj, payMoney) {
      console.log("tatalMoney", this.tatalMoney);
      // this.$refs.payPopup.open("bottom");
      // 判断用户是否可余额支付
      // if (
      //   this.user.MEMBERSHIP_TYPE === 3000 &&
      //   this.cardPay.payType === "余额支付"
      // ) {
      //   this.getCardAmount();
      //   this.isShow = true;
      // } else {
      //   this.getOrderInfo();
      // }
      let _this = this;
      // 拿到签名
      let mchid = "1672298991";
      let timeStamp = Math.ceil(new Date().getTime() / 1000);
      let nonceStr = Math.random().toString(36).substring(2, 8);
      let serial_no = "5BA7C0F427FC042DB5BF299E35B373D5EFCECD35";
      // let out_trade_no = this.generateOutTradeNo(32)
      let out_trade_no = obj.SALEBILL_CODE;
      console.log("obj", obj);
      console.log("payMoney", payMoney
        ? payMoney * 100
        : Number(_this.tatalMoney) * 100 || 1);
      let req = {
        appid: "wxee018fb96955552a", // 公众账号ID
        mchid: "1672298991", // 商户号
        description: "彩云驿出行", //商品描述
        out_trade_no: out_trade_no, // 商户订单号
        notify_url:
          "https://mp.eshangtech.com/Coop.Merchant/Handler/Handler_Trade.ashx", // 商户回调地址
        amount: {
          total: payMoney
            ? payMoney * 100
            : Number(_this.tatalMoney) * 100 || 1,
          currency: "CNY",
        }, // 订单金额
        payer: {
          openid: _this.user.WECHATAPP_OPENID,
        }, // 支付者信息
      };
      console.log("req", req);

      let reqSign = {
        parameters:
          "POST\n/v3/pay/transactions/jsapi\n" +
          timeStamp +
          "\n" +
          nonceStr +
          "\n" +
          JSON.stringify(req) +
          "\n",
      };
      console.log(
        "POST\n/v3/pay/transactions/jsapi\n" +
        timeStamp +
        "\n" +
        nonceStr +
        "\n" +
        JSON.stringify(req) +
        "\n"
      );

      const data = await this.$api.$get("/WeChat/GenerateSign", reqSign);
      console.log("data3213123", data.Result_Data);
      let Authorization = `mchid="${mchid}",nonce_str="${nonceStr}",signature="${data.Result_Data}",timestamp="${timeStamp}",serial_no="${serial_no}"`;
      let AuthorizationStr = `WECHATPAY2-SHA256-RSA2048 ${Authorization}`;
      console.log("AuthorizationStr", AuthorizationStr);

      uni.request({
        url: "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi", //仅为示例，并非真实接口地址。
        method: "POST",
        data: req,
        header: {
          Authorization: AuthorizationStr,
          Accept: "application/json", //自定义请求头信息
          "Content-Type": "application/json",
        },
        success: async (res) => {
          console.log(res.data.prepay_id);
          this.text = "request success";
          let paySign = "";
          let reqSign = {
            parameters:
              "wxee018fb96955552a\n" +
              timeStamp +
              "\n" +
              nonceStr +
              "\nprepay_id=" +
              res.data.prepay_id +
              "\n",
          };
          const data = await this.$api.$get("/WeChat/GenerateSign", reqSign);
          paySign = data.Result_Data;

          wx.requestPayment({
            timeStamp: timeStamp.toString(),
            nonceStr: nonceStr,
            package: `prepay_id=${res.data.prepay_id}`,
            signType: "RSA",
            paySign: paySign,
            total_fee: payMoney
              ? payMoney * 100
              : Number(_this.tatalMoney) * 100 || 1,
            success(res) {
              console.log("res", res);
            },
            fail(res) {
              console.log("fail", res);
            },
            complete(res) {
              uni.redirectTo({
                url: `/pages/order/orderdetail/index?orderInternal=${obj.SALEBILL_ID}`,
              });
            },
          });
        },
      });
    },
    // 获取订单状态
    getOrderType() {
      let _this = this;
      _this.$api
        .getCoop({
          action_type: "GetOrderDetail",
          salebillId: _this.orderInternal,
          saleBillChildId: _this.sellchildid ? _this.sellchildid : "",
        })
        .then((res) => {
          // console.log(res)
          if (res.ResultCode === "100") {
            let _data = res.Data;
            console.log("订单详情", _data);
            _this.orderInfo = _data;
            _this.getOrderAmount(_data.List);
            _this.status = _data.SALEBILL_STATE; // 订单状态
            _this.statusName = _data.SALEBILL_STATENAME; // 订单状态
            _this.SERVERPARTSHOP_ID = _data.SERVERPARTSHOP_ID;
            _this.ShopAddress = _data.SERVERPART_NAME + _data.SHOPNAME;
            _this.orderTime = _data.ORDER_DATE;
            _this.RESERVATION_DATE = _data.RESERVATION_DATE;
            _this.ORDER_PERSONTEL = _data.ORDER_PERSONTEL;
            _this.TAKE_TYPE = _data.TAKE_TYPE;
            _this.isorder = true;
            if (_this.status === 1005) {
              // 待付款时添加倒计时
              _this.showTime();
            }
          }
        });
    },
    getCardAmount() {
      // 获取用户余额
      let _this = this;
      _this.$api
        .getCoop({
          action_type: "GetIndustryMemberInfo",
          serverpartShopId: _this.SERVERPARTSHOP_ID,
        })
        .then((rs) => {
          if (rs.ResultCode === "100") {
            _this.cardPay.amount = rs.Data.INDUSTRY_ACCOUNT_BALANCE;

            if (_this.cardPay.amount < _this.orderAmount) {
              _this.cardPay.payType = "微信支付";
              _this.cardPay.canCardPay = false;
              _this.cardPay.reason = "余额不足";
            } else {
              _this.cardPay.payType = "余额支付";
              _this.cardPay.canCardPay = true;
              _this.cardPay.reason = "";
            }
          } else {
            _this.cardPay.amount = rs.Data.INDUSTRY_ACCOUNT_BALANCE;
            _this.cardPay.payType = "微信支付";
            _this.cardPay.canCardPay = false;
            _this.cardPay.reason = rs.ResultDesc;
          }
          _this.isShow = true;
          _this.$forceUpdate();
        });
    },
    payByCard() {
      // 实业饭卡支付
      let _this = this;
      _this.$api
        .postCoop({
          action_type: "ECodeConsume",
          saleBill: _this.orderInternal,
        })
        .then((rs) => {
          if (rs.ResultCode === "100") {
            // uni.showToast({
            //   title: '支付成功',
            //   icon: 'success',
            //   duration: 2000
            // })
            _this.isShow = false;
            // setTimeout(() => {
            _this.$store.commit("couponPrice", "");
            uni.redirectTo({
              url:
                "/pages/orders/orderdetail/main?orderNumber=" +
                _this.orderNumber +
                "&orderInternal=" +
                _this.orderInternal,
            });
            // }, 1000)
          } else {
            uni.showToast({
              title: rs.ResultDesc,
              icon: "none",
              duration: 2000,
            });
          }
        });
    },
    // 取消订单
    orderCancle() {
      let _this = this;
      // console.log(_this.orderInfo.SALEBILL_ID)
      uni.showModal({
        title: "温馨提示",
        content: "您是否确认取消订单。",
        async success(res) {
          if (res.confirm) {
            uni.showLoading({
              title: "取消中...",
              icon: "none",
            });
            const req = {
              action_type: "UpdateOrderState",
              action_data: _this.orderInfo.SALEBILL_ID,
              saleBillChildId: _this.sellchildid > 0 ? _this.sellchildid : "",
              SALEBILL_STATE: 9999,
              mixPay: 1,
              // deliverDate: new Date()
            };
            const data = await _this.$api.getCoop(req);
            console.log("data", data);
            uni.hideLoading();
            uni.showToast({
              title: data.msg,
              icon: "none",
            });

            if (data.error === 1) {
              if (_this.orderInfo.SALEBILL_TYPE === 3002) {
                // 反查品诺的订单号
                // 品诺的订单号详情
                const pingnuoOrderDetail = await _this.$api.$postNode(
                  "/pino/order/query-by-third",
                  { orderSn: _this.orderInfo.SALEBILL_CODE, orderSnType: 2 }
                );
                if (pingnuoOrderDetail.code === 200) {
                  let pingnuoOrderId =
                    pingnuoOrderDetail.data.data[0].parent_order_sn;

                  const pingnuoData = await _this.$api.$postNode(
                    "/pino/order/cancel-order",
                    { orderSn: pingnuoOrderId }
                  );
                  if (pingnuoData.code === 200) {
                    uni.showToast({
                      title: "取消订单成功",
                      icon: "none",
                      duration: 2000,
                      success: function () { },
                    });
                    uni.navigateBack({ delta: 1 });
                  } else {
                    uni.showModal({
                      title: "提示",
                      content: `${pingnuoData.data.description}`,
                      success: function (res) { },
                    });
                  }
                } else {
                  uni.showModal({
                    title: "提示",
                    content: `${pingnuoOrderDetail.data.description}`,
                    success: function (res) { },
                  });
                }
              } else {
                uni.showToast({
                  title: "取消订单成功",
                  icon: "none",
                  duration: 2000,
                  success: function () { },
                });
                uni.navigateBack({ delta: 1 });
              }

              // uni.redirectTo({
              //   url: "/pages/order/buyOrder/index",
              // });
            }
            // _this.$api
            //   .postCoop({
            //     action_type: "UpdateOrderState",
            //     action_data: _this.orderInfo.SALEBILL_ID,
            //     SALEBILL_STATE: 9000,
            //   })
            //   .then((res) => {
            //     if (res.error === 1) {
            //       uni.showToast({
            //         title: "取消订单成功",
            //         icon: "none",
            //         duration: 2000,
            //         success: function () { },
            //       });
            //       uni.navigateBack({ delta: 1 });
            //       // uni.redirectTo({url: '/pages/orders/order/main'})
            //     } else {
            //       uni.showToast({
            //         title: res.msg,
            //         icon: "none",
            //         duration: 2000,
            //       });
            //     }
            //   });
          } else if (res.cancel) {
          }
        },
      });
    },
    // 获取后台信息调取微信支付
    getOrderInfo() {
      let timeStamp = new Date() / 1000;
      let str = Math.random().toString(36).substr(2, 15);

      // uni.requestPayment({
      //   timeStamp: timeStamp,
      //   nonceStr: str,
      //   package: "prepay_id=***",
      //   paySign: "",
      //   success(res) {},
      //   fail(res) {},
      // });

      return;
      let _this = this;
      let req = {
        action_type: "JsApiPay",
        action_data: 1,
        action_record: _this.user.WECHATAPP_OPENID,
        // action_record: 'ortWV5OP2g9P81cxxJYIIhrAezS4',
        TOTAL_FEE: _this.orderAmount,
        OFFPRICE: 0,
        payType: 2,
        SALEBILL_ID: _this.orderInternal,
        // SALEBILL_CODE: _this.orderNumber,
        SALEBILL_CODE: this.orderInfo.SALEBILL_CODE,
        requestType: "application/x-www-form-urlencoded",
      };
      console.log("getOrderInfo", req);
      _this.$api.postCoop(req).then((res) => {
        console.log("getOrderInfo", res);
        if (res) {
          uni.requestPayment({
            appId: "wxee018fb96955552a", // 公众号名称，由商户传入
            timeStamp: res.timeStamp + "", // 时间戳，自1970年以来的秒数
            nonceStr: res.nonceStr, // 随机串
            package: res.package,
            signType: res.signType, // 微信签名方式
            paySign: res.paySign, // 微信签名
            success(res) {
              if (res.errMsg === "requestPayment:ok") {
                _this.$api
                  .postCoop({
                    action_type: "EndPay",
                    action_data: _this.orderNumber,
                    action_record: 1,
                  })
                  .then((res) => {
                    _this.$store.commit("couponPrice", "");

                    uni.redirectTo({
                      url:
                        "/pages/orders/orderdetail/main?orderNumber=" +
                        _this.orderNumber +
                        "&orderInternal=" +
                        _this.orderInternal,
                    });
                  });
              }
            },
            fail(res) {
              if (res.errMsg === "requestPayment:fail cancel") {
                // uni.showToast({
                //   title: '支付取消',
                //   icon: 'none',
                //   duration: 2000
                // })
              }
            },
            complete(res) { },
          });
        } else {
          uni.showToast({
            title: "网络异常，请稍后再试",
            icon: "none",
            duration: 2000,
          });
        }
      });
    },
    // 获取订单列表
    getOrderAmount(data) {
      let _this = this;
      let total = 0;
      _this.shopOrder = data;
      data.map((v) => {
        total += v.ORDER_AMOUNT;
      });

      _this.orderAmount = total;
    },
    goEvaluate() {
      console.log("this.orderInfo", this.orderInfo);
      if (this.orderInfo.List && this.orderInfo.List.length >= 2) {
        uni.navigateTo({
          url:
            "/pages/evaluateList/selectEvaluate?sellchildid=" +
            this.orderInfo.SALEBILL_CHILD_ID +
            "&orderInternal=" +
            this.orderInfo.SALEBILL_ID +
            "&orderStatus=" +
            this.orderInfo.SALEBILL_STATE +
            "&SUPPLIER_NAME=" +
            this.orderInfo.SUPPLIER_NAME,
        });
      } else {
        uni.navigateTo({
          url:
            "/pages/evaluateList/addEvaluate?sellchildid=" +
            this.orderInfo.SALEBILL_CHILD_ID +
            "&orderInternal=" +
            this.orderInfo.SALEBILL_ID +
            "&orderStatus=" +
            this.orderInfo.SALEBILL_STATE +
            "&SUPPLIER_NAME=" +
            this.orderInfo.SUPPLIER_NAME,
        });
        // uni.navigateTo({
        //   url: `/pages/evaluateList/addEvaluate?SALEBILL_ID=${obj.SALEBILL_ID}&SALEBILL_CHILD_ID=${obj.SALEBILL_CHILD_ID}`,
        // });
      }
      // uni.navigateTo({
      //   url:
      //     "/pages/evaluateList/addEvaluate?merchantsId=" +
      //     this.orderInfo.MERCHANTS_ID +
      //     "&orderInternal=" +
      //     this.orderInfo.SALEBILL_ID +
      //     "&sellchildid=" +
      //     this.orderInfo.SALEBILL_CHILD_ID,
      // });
    },
    goShop() {
      if (this.pageMsg.type === 0) {
        // let arr = {
        // id: this.orderInfo.SERVERPARTSHOP_ID
        // shopName: this.orderInfo.SHOPNAME,
        // serverpartId: this.orderInfo.SERVERPART_ID

        // }
        // this.$store.commit('nowStore', arr)
        this.$store.commit(
          "setprovinceCode",
          this.orderInfo.PROVINCE_CODE || "530000"
        );
        uni.navigateTo({
          url:
            "/pages/shopPages/shop/main?id=" +
            this.orderInfo.SERVERPARTSHOP_ID +
            "&mid=" +
            this.orderInfo.MERCHANTS_ID,
        });
      }
    },
    callPhone() {
      let _this = this;
      if (_this.orderInfo.SELLER_TELEPHONE) {
        uni.makePhoneCall({
          phoneNumber: _this.orderInfo.SELLER_TELEPHONE,
        });
      }
    },
    // 修改订单状态
    async handleChangeOrderStatus() {
      let _this = this;
      const req = {
        action_type: "UpdateOrderState",
        action_data: _this.orderInfo.SALEBILL_ID,
        saleBillChildId: _this.sellchildid > 0 ? _this.sellchildid : "",
        SALEBILL_STATE: 3000,
        // deliverDate: new Date()
      };
      console.log("req", req);
      const data = await _this.$api.getCoop(req);
    },
  },
  onUnload() {
    this.orderInfo = {};
    this.minutes = "";
    this.isMinute = false;
    clearInterval(this.timer);
    this.pageMsg.type = 0;
  },
  onShow() {
    this.getOrderType();
  },
  onLoad(option) {
    console.log("option", option);

    uni.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: "#2fa4ff",
      animation: {
        duration: 30,
        timingFunc: "linear",
      },
    });
    if (option.type) {
      this.pageMsg.type = 1;
    }
    if (option.sellchildid) {
      this.sellchildid = option.sellchildid;
    }
    this.couponAmount = this.$store.getters.couponPrice
      ? "-￥" + this.$store.getters.couponPrice
      : "";

    this.orderNumber = option.orderNumber;
    this.orderInternal = option.orderInternal;
    // this.getOrderType();
    this.$utils.addUserBehaviorNew();
  },
};
</script>
<style lang="less" scoped>
page {
  background-color: #f3f2f7;
}

// bodyColor = #f5ba56;

.disable {
  color: #999;
}

.order {
  background: #f3f2f7;
  padding-bottom: 30rpx;
  box-sizing: border-box;
  height: 100%;
}

.order-status {
  padding: 32rpx 32rpx 56rpx 32rpx;
  // background: linear-gradient(#c8b190, #a18153);
  // background: linear-gradient(270deg, #2fa4ff 0%, #197aff 100%);
  background: #2fa4ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.order-s-ico {
  width: 89rpx;
  height: 89rpx;
}

.order-success {
  color: #fff;
  font-size: 36rpx;
  // margin-bottom 32rpx
}

.status-btn-box {
  justify-content: flex-end;
  font-size: 24rpx;
  display: flex;
  align-items: center;
  margin-top: 12rpx;
}

.back-btn {
  color: #7e5314;
  border: 1rpx solid #7e5314;
  width: 120rpx;
  height: 48rpx;
  text-align: center;
  line-height: 48rpx;
  border-radius: 6rpx;
}

.continu-btn {
  color: #fff;
  border: 1rpx solid #fff;
  min-width: 160rpx;
  height: 48rpx;
  text-align: center;
  line-height: 48rpx;
  border-radius: 6rpx;
  margin-left: 36rpx;
  padding: 0 12rpx;
}

.refundBtn {
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 28rpx;
  color: #6c737a;
  line-height: 40rpx;
  text-align: left;
  padding: 12rpx 24rpx;
  border-radius: 8rpx;
  border: 2rpx solid #d9dbdd;
}

.hx-block {
  top: -26rpx;
  position: relative;
  width: 100%;
  height: 30rpx;
  border-radius: 30rpx 30rpx 0 0;
  background: #f3f2f7;
}

.order-box {
  background-color: #fff;
  padding: 0 24rpx;
  margin: 20rpx 24rpx;
  border-radius: 12rpx;
  box-sizing: border-box;
  // box-shadow 0 2rpx 16rpx 0.4rpx #e2e2e2
}

.pageDesc {
  width: 100%;
  text-align: left;
  font-size: 28rpx;
  color: red;
  box-sizing: border-box;
  padding-left: 32rpx;
  margin-bottom: 16rpx;
}

.order-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 30rpx;
  border-bottom: 1rpx solid #f5f5f5;
  height: 100rpx;
  box-sizing: border-box;
  margin-bottom: 24rpx;
}

.coupon {
  padding: 20rpx 0;
  box-sizing: border-box;
  background-color: #fff;
  display: flex;
  color: #000000;
}

.order-list {
  padding: 20rpx 0;
  box-sizing: border-box;
  background-color: #fff;
  // display: flex;
  color: #000000;
}

.order-name {
  font-size: 26rpx;
  flex: 0.7;
}

.payShowBox {
  width: 100%;
  height: 380px;
  background: #fff;
  box-sizing: border-box;
  padding: 12px;
  border-radius: 12px;

  .payBoxTitle {
    width: 100%;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
  }

  .payList {
    width: 100%;
    height: 250px;
    overflow-y: auto;

    .radio-group {
      .bottom-radio {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 24rpx;
        border-bottom: 1px solid #ededed;
        padding: 12px 0;

        .radioLeft {
          display: flex;
          align-items: center;

          .logoBox {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            overflow: hidden;
            margin-right: 8px;

            .logoIcon {
              width: 30px;
              height: 30px;
            }
          }
        }
      }
    }
  }

  .goPayBox {
    width: 100%;
    box-sizing: border-box;
    padding: 0 24px;

    .goPay {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
      border-radius: 20px;
      font-size: 18px;
      font-weight: bold;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #caa97f;
    }
  }
}

.order-num {
  font-size: 26rpx;
  color: #9a9a9a;
  flex: 0.1;
}

.order-price {
  font-size: 26rpx;
  flex: 0.2;
  color: #333;
  text-align: right;
  font-weight: bolder;
}

.coupon {
  justify-content: space-between;
  font-size: 26rpx;
  padding-top: 36rpx;
}

.coupon-h {
  display: inline-block;
  background: #ed4d3e;
  color: #ffffff;
  padding: 4rpx 6rpx;
  border-radius: 6rpx;
  margin-right: 10rpx;
}

.price-sum {
  border-top: 2rpx sold #f5f5f5;
  padding: 20rpx 0;
  box-sizing: border-box;
  background-color: #fff;
  text-align: right;
  font-size: 24rpx;
  display: flex;
  justify-content: space-between;
}

.pay-price {
  color: #000;
  font-size: 30rpx;
  margin-left: 10rpx;
}

.link-store {
  color: #c6a376;
  display: flex;
  align-items: center;
}

hr {
  background-color: #f5f5f5;
  height: 2rpx;
  margin-top: 24rpx;
}

// 订单信息
.order-info {
  background-color: #fff;
  padding: 0 20rpx;
  border-radius: 12rpx;
  margin: 0 24rpx;
}

.order-info-type {
  height: 96rpx;
  line-height: 96rpx;
  font-size: 26rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.order-info-type+.order-info-type {
  border-top: 1px solid #f5f5f5;
}

.order-info-t {
  color: #a7a7a7;
}

.appoint {
  display: flex;
  align-items: center;
}

.appoint:after {
  content: "预";
  padding: 0 4rpx;
  font-size: 20rpx;
  height: 24rpx;
  line-height: 24rpx;
  margin-left: 16rpx;
  font-weight: normal;
  color: #fff;
  border-radius: 4rpx;
  background: #f5ba4f;
}

.order-info-h {
  font-size: 28rpx;
  font-weight: bold;
  color: #000;
  display: flex;
  justify-content: space-between;
}

.order-info-status {
  font-weight: normal;
  font-size: 24rpx;
}

/* 支付方式选择 */
.bottom-box {
  height: 450rpx;
  width: 100%;
  box-sizing: content-box;
  background: #fff;
}

.bottom-pop-title {
  text-align: center;
  font-size: 32rpx;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f9f9f9;
}

.bottom-content {
  box-sizing: content-box;
  padding: 0 80rpx;
}

.bottom-radio {
  padding: 0 24rpx;
}

.bottom-btn {
  width: 600rpx;
  margin: 20rpx auto;
  border-radius: 8rpx;
  background: #444;
  color: #caa97f;
  font-size: 32rpx;
  text-align: center;
  height: 80rpx;
  line-height: 80rpx;
}

.initiateRefund {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
</style>
