<template>
  <div>
    <el-row class="track-detail">
      <!-- 订单追踪、订单详情 -->
      <el-col :span="7" v-loading="!orderDetailStutus && !showTrack" element-loading-text="拼命加载中">
        <div class="order_detail">
          <div class="detail_title">
            <div v-show="buttonStatus !== 0 && buttonStatus !== 10" class="detail_txt" @click="orderDetailStutus = 0" :class="{ detail_txt_ac: !orderDetailStutus }">
              订单跟踪
            </div>
            <div class="detail_txt" @click="orderDetailStutus = 1" :class="{ detail_txt_ac: !!orderDetailStutus }">
              订单详情
            </div>
          </div>
          <order-track v-show="showTrack" :riderArriveTime="riderArriveTime" :buttonStatus="buttonStatus" :trackOrder="trackOrder" v-if="!orderDetailStutus && needTrack"></order-track>
          <order-detail v-show="showDetail" :buttonStatus="buttonStatus" :orderDetail="orderDetail" v-else></order-detail>
          <!-- 订单跟踪、订单详情底部按钮 -->
          <div class="bottom-btns" v-show="showDetail || showTrack">
            <!-- 新订单 -->
            <div class="btns" v-if="buttonStatus === 0">
              <el-button size="small" @click.native="itemAddRemark(list[curIdx].id, list[curIdx])" class="btn_bots">添加备注</el-button>
              <el-button size="small" @click.native="iGnoreOrder(list[curIdx].id)" class="btn_bots">忽略订单</el-button>
              <el-button size="small" @click.native="orderPrinter(list[curIdx].waimaiOrderId,list[curIdx])" class="btn_bots">补打发票</el-button>
              <el-button size="small" @click.native="sendNow(list[curIdx])" class="btn_bots btn">发起配送</el-button>
            </div>
            <!-- 预约单 -->
            <div class="btns" v-if="buttonStatus === 10">
              <div class="btn_bot" v-if="list[curIdx].waimaiOrderId">
                <el-dropdown>
                  <span class="el-dropdown-link">更多</span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="orderPrinter(list[curIdx].waimaiOrderId)"><span style="color: #fc7200">补打发票</span></el-dropdown-item>
                    <el-dropdown-item @click.native="iGnoreOrder(list[curIdx].id)">忽略订单</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
              <el-button size="small" @click.native="itemAddRemark(list[curIdx].id, list[curIdx])" class="btn_bots">添加备注</el-button>
              <el-button v-if="list[curIdx].waimaiOrderId" size="small" @click.native="settingTime(list[curIdx])" class="btn_bots btn">{{
                  list[curIdx].delayTime ? "修改定时" : "定时发单"
                }}</el-button>
              <el-button v-else size="small" @click.native="cancelOrder(list[curIdx].id)" class="btn_bots">取消订单</el-button>

              <el-button size="small" @click.native="sendNow(list[curIdx])" class="btn_bots btn">发起配送</el-button>
              <!-- <el-dropdown-item @click.native="orderPrinter(list[curIdx].waimaiOrderId,list[curIdx])"><span style="color: #fc7200">补打发票</span></el-dropdown-item> -->

            </div>
            <!-- 待接单 -->
            <div class="btns" v-if="buttonStatus === 1">
              <el-button size="small" @click.native="cancelOrder(list[curIdx].id)" class="btn_bots">取消订单</el-button>
              <el-button size="small" @click.native="orderPrinter(list[curIdx].waimaiOrderId)" v-if="list[curIdx].waimaiOrderId" class="btn_bots">补打发票</el-button>
              <el-button size="small" @click.native="addTip(list[curIdx].id)" class="btn_bots btn">加小费</el-button>
            </div>
            <!-- 取货中 -->
            <div class="btns" v-if="buttonStatus === 2">
              <el-button size="small" @click.native="cancelOrder(list[curIdx].id)" class="btn_bots">取消订单</el-button>
              <el-button size="small" @click.native="orderPrinter(list[curIdx].waimaiOrderId)" v-if="list[curIdx].waimaiOrderId" class="btn_bots btn">补打发票</el-button>
            </div>
            <!-- 配送中 -->
            <div class="btns" v-if="buttonStatus === 3">
              <el-button size="small" @click.native="orderPrinter(list[curIdx].waimaiOrderId)" v-if="list[curIdx].waimaiOrderId" class="btn_bots btn">补打发票</el-button>
            </div>
            <!-- 异常单 -->
            <div class="btns" v-if="buttonStatus === -2">
              <el-button size="small" @click.native="orderPrinter(list[curIdx].waimaiOrderId)" v-if="list[curIdx].waimaiOrderId" class="btn_bots">补打发票</el-button>
              <el-button size="small" @click.native="orderBack(list[curIdx].id)" class="btn_bots btn">撤回订单</el-button>
            </div>
            <!-- 已取消 -->
            <div class="btns" v-if="buttonStatus === -1">
              <!-- <el-button size='small' @click.native="orderPrinter(list[curIdx].waimaiOrderId)" class="btn_bots btn">再来一单</el-button> -->
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row class="list-info">
      <el-col :span="17">
        <div v-loading="isLoading" element-loading-text="正在计算中...">
          <div :class="
              curIdx === i ? 'order_item active-order-item' : 'order_item'
            " @click="chooseOrder(item, i)" v-for="(item, i) in list" :key="i">
            <div class="order_item_header">
              <div class="order_item_header_l">
                <div v-if="item.daySeq" class="Serial_number">
                  #{{ item.daySeq }}
                </div>
                <img :src="item.logo || item.waimaiLogo" class="logo" />
                <span class="name">{{ item.shopName }}</span>
                <!-- <span class="name">{{item.sendAddress}}</span> -->
                <div class="sign_time" v-if="item.waimaiOrderId && [1,2].includes(item.takeType)">
                  {{ item.exceptTime.slice(5,16) }}前送达
                </div>
                <div class="sign_txt" v-if="item.buttonStatus === 0 && item.waimaiOrderId && item.takeType == 0">
                  立即送达，{{item.orderTime.slice(-8,-3)}}下单
                </div>
                <div class="sign_d" v-if="item.buttonStatus === 10 && item.timeTxt">{{item.timeTxt}}自动发起配送</div>

                <div v-if="item.buttonStatus === 10 && !item.waimaiOrderId" class="sign_d">{{item.deliveryTime.slice(5)}}自动发起配送</div>
                <!-- 近三日订单 -->
                <!-- <div class="sign_f" v-if="[-1,7].includes(tabNum) &&item.finishTime">{{item.finishTime && item.finishTime.slice(5)}}已完成</div> -->
              </div>
              <!-- 新订单 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 0">
                <!-- <span class="header_r">已发单1分钟</span> -->
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">新订单</el-tag>
                <el-button size="small" class="btn" @click.stop="sendNow(item)">发起配送</el-button>
              </div>
              <!-- 预约单 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 10">
                <!-- <span class="header_r">已发单1分钟</span> -->
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">预约单</el-tag>
                <!-- <el-button size='small' @click.stop="iGnoreOrder(item.id)">忽略订单</el-button> -->
                <!-- <el-button size='small' @click.stop="itemAddRemark(item.id, item)">添加备注</el-button> -->
                <el-button v-if="item.waimaiOrderId" size="small" class="btn" @click.stop="settingTime(item)">{{
                  item.delayTime ? "修改定时" : "定时发单"
                }}</el-button>

                <el-button v-else size="small" class="btn" @click.stop="sendNow(item)">立即配送</el-button>
              </div>
              <!-- 待接单 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 1">
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">待接单</el-tag>
                <span class="header_r">已发单{{ item.takeTimeTxt }}</span>
                <!-- <el-button size='small' @click.stop="cancelOrder(item.id)">取消订单</el-button> -->
                <el-button size="small" class="btn" @click.stop="orderPrinter(item.waimaiOrderId)" v-if="item.waimaiOrderId">补打发票</el-button>
                <!-- <el-button size='small' class="btn" @click.stop="addTip(item.id)">加&nbsp;小&nbsp;费</el-button> -->
              </div>
              <!-- 取货中 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 2">
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">取货中</el-tag>
                <!-- <span v-show="Number(item.riderArriveMinute)" class="header_r">预计{{Number(item.riderArriveMinute)}}分钟取件</span> -->
                <!-- <el-button size='small' @click.stop="cancelOrder(item.id)">取消订单</el-button> -->
                <el-button size="small" class="btn" @click.stop="orderPrinter(item.waimaiOrderId)" v-if="item.waimaiOrderId">补打发票</el-button>
              </div>
              <!-- 配送中 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 3">
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">配送中</el-tag>
                <!-- <span class="header_r" v-if="item.exceptTime">预计{{ item.exceptTime }}送达,{{item.surPlusMinute >= 0 ? '剩余'+item.surPlusMinute + '分钟' : '超时' +item.surPlusMinute +"分钟" }}</span> -->
                <el-button size="small" class="btn" @click.stop="orderPrinter(item.waimaiOrderId)" v-if="item.waimaiOrderId">补打发票</el-button>
              </div>
              <!-- 异常单 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === -2">
                <el-tag class="header_r">{{
                  showCancelType(item.cancelType)
                }}</el-tag>
                <el-button size="small" class="btn" @click.stop="orderBack(item.id)">撤回订单</el-button>
              </div>
              <!-- 取消单 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === -1">
                <el-tag class="header_r">{{
                  showCancelType(item.cancelType)
                }}</el-tag>
                <!-- <el-button size='small' class="btn" @click.stop="orderBack(item.id)">撤回订单</el-button> -->
              </div>
              <!-- 猎豹平台已完成 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 97">
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">已完成</el-tag>
              </div>
              <!-- 其他平台已完成 -->
              <div class="order_item_header_r" v-if="item.buttonStatus === 98">
                <el-tag v-if="[-1,7].includes(tabNum)" class="header_r">其他平台已完成</el-tag>
              </div>
            </div>
            <div class="order_item_cont">
              <div class="content">
                {{ item.receiptContactName
                }}<span>{{ item.receiptPhone }}{{item.receiptExtension ? "_" + item.receiptExtension : ""}}</span>
              </div>
              <div class="address">
                <!-- {{ item.receiptProvinceName }}
                {{ item.receiptCityName }} -->
                <!-- {{ item.receiptDistrictName }} -->
                {{ item.receiptAddress }}
                <span class="distance" @click.stop="checkMap(item)">
                  <i class="el-icon-location"></i>
                  <span>查看地图</span>
                </span>
              </div>
              <div v-if="item.caution" class="itme_r">
                备注：{{ item.caution }}
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <!-- 发起配送 -->
    <send-order-popup :tabNum="tabNum" ref="sendOrderPopup"></send-order-popup>
    <!-- 骑手、商家、发件人地图 -->
    <order-map ref="orderMap"></order-map>
    <!-- 备注弹出层 -->
    <el-dialog width="580px" center title="新增备注" destroy-on-close :visible.sync="dialogTableVisible">
      <div>
        <el-input placeholder="请添加备注信息，最多输入20个字！" v-model="remark" clearable :maxlength="20" />
      </div>
      <div style="text-align: center; margin-top: 20px">
        <el-button @click.stop="dialogTableVisible = false">取消</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="commitRemark(orderId, item)">确定</el-button>
      </div>
    </el-dialog>
    <!-- 设置预约发单时间弹出层 -->
    <el-dialog width="580px" center :title="exceptTime" destroy-on-close :visible.sync="settingTimeStatus">
      <div>
        <span>提前多长时间发起配送：</span>
        <el-select size="small" style="width: 80px" v-model="timeValue" placeholder="请选择">
          <el-option v-for="(item, index) in timeList" :key="index" :label="item" :value="item"></el-option>
        </el-select>
        <span>小时</span>
      </div>
      <p style="color: #f74141">
        提示：设置后系统将根据您设置的提前时间自动发单。{{delayTime ? '' : '如需骑手立即取件请点击立即配送!'}}
      </p>
      <div style="text-align: center; margin-top: 20px">
        <el-button v-if="delayTime" @click.stop="cancalSettingTime">取消预约发单</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="commitTimeValue(orderId)">{{delayTime ? '确定修改' : '保存'}}</el-button>
      </div>
    </el-dialog>
    <!-- 取消订单弹出层 -->
    <el-dialog width="680px" center title="取消原因" destroy-on-close :visible.sync="cancelStatus">
      <div class="cancel-list">
        <div class="item" @click.stop="changeReason(item)" :class="[
            (index + 1) % 3 == 0 ? 'no-margin' : '',
            item.id == reasonIndex ? 'active' : '',
          ]" v-for="(item, index) in cancelList" :key="index">
          {{ item.name }}
        </div>
      </div>
      <div class="text-area">
        <el-input show-word-limit :rows="4" type="textarea" resize="none" :maxlength="50" placeholder="请输入其他原因" v-model="cancelReason"></el-input>
      </div>
      <div style="text-align: center; margin-top: 20px">
        <el-button @click.stop="cancelStatus = false">取消</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="commitCancelReason(orderId)">确定</el-button>
      </div>
    </el-dialog>
    <!-- 加小费弹出层 -->
    <el-dialog width="580px" center title="加小费" destroy-on-close :visible.sync="addTipStatus">
      <div>
        <div class="tip-title">小费金额</div>
        <div class="tip-list">
          <div class="tip-item" @click.stop="tipActive = index" :class="tipActive == index ? 'tip-active' : ''" v-for="(item, index) in tipList" :key="index">
            {{ item }}元
          </div>
          <div class="tip-item" @click.stop="tipActive = -1" :class="tipActive == -1 ? 'tip-active' : ''">
            <el-input placeholder="其他金额" v-model="tipAmount" />
          </div>
        </div>
        <!-- 支付方式 -->
        <div class="choose-self" style="border: none">
          <div class="self-top">
            <span>支付方式</span>
          </div>
          <div class="pay-list">
            <div class="pay-item" @click.stop="paymentType = item.id" :class="paymentType == item.id ? 'pay-active' : ''" v-for="(item, index) in payList" :key="index">
              <img :src="item.icon" class="pay-icon" />
              <span>{{ item.name }}</span>
            </div>
          </div>
        </div>
      </div>
      <div style="text-align: center; margin-top: 20px">
        <el-button @click.stop="addTipStatus = false">取消</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="richMoney(orderId)">确定</el-button>
      </div>
    </el-dialog>
    <!-- 支付二维码弹出层 -->
    <qr-code v-if="showCode" @paySuccess="paySuccess" @refreshCode="recharge" @closeCode="showCode = false" ref="code" :payAmount="payAmount" :link="link" :paymentType="paymentType" :orderSn="orderSn"></qr-code>
    
  </div>
</template>

<script>
import moment from "moment";
import bus from "../../common/bus.js";
import orderMap from "./orderAMap.vue";
import OrderDetail from "./orderDetail.vue";
import orderTrack from "./orderTrack.vue";
import { mapState } from "vuex";
import sendOrderPopup from "./sendOrderPopup.vue";
import qrCode from "../../common/qrCode.vue";
import {
  sendValuation,
  waimaiprinter,
  addRemark,
  ignoreOrder,
  rollOrder,
  setDeliveryTime,
  cancelTimingPublish,
  cancelOrder,
  trackOrder,
  detailOrder,
  tips,
  getRiderArriveTime,
  getPayResult,
  getMapData,
} from "../../api/order.js";
export default {
  name: "OrderList",
  data() {
    return {
      payAmount: 0,
      paymentType: 1, // 1 支付宝 0 微信
      payList: [
        {
          id: 1,
          name: "支付宝支付",
          icon: "../../../static/image/alipay.png",
        },
        {
          id: 2,
          name: "微信支付",
          icon: "../../../static/image/we-chat.png",
        },
        {
          id: 4,
          name: "余额/三方支付",
          icon: "../../../static/image/yu-e.png",
        },
      ],
      tipActive: 0,
      tipList: [1, 2, 5, 10, 15, 20, 30, 50],
      tipAmount: "", // 小费金额
      addTipStatus: false, // 加小费弹出层
      reasonIndex: null, // 取消原因索引
      chooseReason: "", // 选择取消原因
      cancelReason: "", // 输入取消原因
      cancelList: [
        { id: 1, name: "无骑手接单" },
        { id: 2, name: "骑手接单后不取货" },
        { id: 3, name: "骑手电车装不下" },
        { id: 4, name: "计划有变，无需配送" },
        { id: 5, name: "骑手服务态度恶劣" },
        { id: 6, name: "骑手要求取消订单" },
        { id: 7, name: "信息填写错误" },
        { id: 8, name: "其他原因" },
      ],
      timeList: [1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12],
      timeValue: 1, // 定时发单，默认1小时
      cancelStatus: false, // 取消订单弹出层
      settingTimeStatus: false, // 定时发单弹出层
      needTrack: false,
      orderDetailStutus: 1,
      isLoading: false,
      dialogTableVisible: false,
      remark: "",
      orderId: "",
      item: {},
      radio: "",
      needTrack: false,
      curIdx: 0,
      trackOrder: {},
      orderDetail: {},
      showDetail: false,
      showTrack: false,
      showCode: false,
      link: "",
      buttonStatus: 0,
      exceptTime: "",
      delayTime: "", // 预约延迟时间
      riderArriveTime: {}, //骑手预计取货送达时间
    };
  },
  props: {
    tabNum: Number,
    list: Array,
  },
  components: {
    sendOrderPopup,
    orderMap,
    OrderDetail,
    orderTrack,
    qrCode,
  },
  watch: {
    tabNum(newVal, oldVal) {
      this.curIdx = 0;
    },
    list: {
      handler(newVal, oldVal) {
        this.buttonStatus = newVal.length ? newVal[0].buttonStatus : 0;
        if (this.buttonStatus === 0 || this.buttonStatus === 10) {
          this.needTrack = false;
          this.orderDetailStutus = 1;
        } else {
          this.needTrack = true;
          this.orderDetailStutus = 0;
        }
        this.getDetailOrder();
        this.getTrackOrder();
        this.getRiderArriveTime();
      },
      immediate: true,
    },
  },
  destroyed() {},
  computed: {
    ...mapState(["userInfo"]),
  },
  methods: {
    paySuccess() {
      this.showCode = false;
      this.addTipStatus = false;
      bus.$emit("refreshData");
      bus.$emit("refreshData2");
    },
    richMoney() {
      let reg = /(^[1-9]\d*$)/g;
      if (this.tipActive == -1) {
        if (!reg.test(this.tipAmount * 1)) {
          return this.$message({
            message: "请选择或输入正确的整数金额",
            type: "error",
          });
        }
      }
      let params = {
        orderId: this.orderId,
        tipAmount:
          this.tipActive == -1 ? this.tipAmount : this.tipList[this.tipActive],
        paymentType: this.paymentType,
        createType: 1,
      };
      tips(params).then((res) => {
        if (res.code == 200) {
          if (this.paymentType == 4) {
            // 余额支付
            this.$message({
              message: "小费添加成功",
              type: "success",
            });
            bus.$emit("refreshData");
            bus.$emit("refreshData2");
            this.addTipStatus = false;
            this.tipAmount = "";
          } else if (this.paymentType == 1 || this.paymentType == 2) {
            // 支付宝、微信支付
            this.payAmount = res.data.amount || 0;
            this.orderSn = res.data.orderSn;
            this.link = res.data.data;
            this.showCode = true;
          }
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    addTip(orderId) {
      this.orderId = orderId;
      this.paymentType = 4;
      this.addTipStatus = true;
    },
    changeReason(item) {
      this.reasonIndex = item.id;
      this.chooseReason = item.name;
    },
    doCancelOrder() {
      cancelOrder({
        orderId: this.orderId,
        cancelReason:
          this.reasonIndex != 8 ? this.chooseReason : this.cancelReason,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "取消订单成功",
            type: "success",
          });
          this.orderId = "";
          this.cancelReason = "";
          this.chooseReason = "";
          this.reasonIndex = null;
          bus.$emit("refreshData");
          bus.$emit("refreshData2");
          this.cancelStatus = false;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 取消订单
    commitCancelReason() {
      if (!this.reasonIndex) {
        return this.$message({
          message: "请选择取消原因",
          type: "error",
        });
      }
      if (this.reasonIndex == 8 && !this.cancelReason.trim()) {
        return this.$message({
          message: "请填写其他取消原因",
          type: "error",
        });
      }
      if (this.buttonStatus !== 2) {
        this.doCancelOrder();
        return;
      }
      this.$confirm("取消订单可能会存在违约金, 是否继续?", "提示", {
        confirmButtonText: "取消",
        cancelButtonText: "确定",
        showClose: false,
        closeOnClickModal: false,
        center: true,
        type: "warning",
      })
        .then(() => {
          this.cancelStatus = false;
        })
        .catch(() => {
          this.doCancelOrder();
        });
    },
    // 取消定时发单
    cancalSettingTime() {
      cancelTimingPublish({ orderId: this.item.id }).then((res) => {
        this.settingTimeStatus = false;
        if (res.code == 200) {
          this.$message({
            message: "取消定时发单成功",
            type: "success",
          });
          this.item = {};
          bus.$emit("refreshData");
          bus.$emit("refreshData2");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    commitTimeValue() {
      let timestamp = new Date().valueOf();
      let exT = moment(this.item.exceptTime).valueOf();
      let nowTime = moment(exT)
        .subtract(this.timeValue, "hours")
        .format("YYYY-MM-DD HH:mm:ss"); //当前时间的前n小时时间
      let t1 = moment(nowTime).valueOf(); // 时间戳
      console.log(nowTime, this.item, "-------------");
      if (t1 - timestamp < 0) {
        return this.$message({
          message: `设置发单时间超出当前时间`,
          type: "error",
        });
      }
      setDeliveryTime({
        orderId: this.item.id,
        delayTime: this.timeValue,
      }).then((res) => {
        this.settingTimeStatus = false;
        if (res.code == 200) {
          this.$message({
            message: "设置定时发单成功",
            type: "success",
          });
          this.item = {};
          bus.$emit("refreshData");
          bus.$emit("refreshData2");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 定时发单
    settingTime(item) {
      this.item = item;
      this.settingTimeStatus = true;
      this.delayTime = item.delayTime;
      this.timeValue = item.delayTime ? item.delayTime : 1;
      this.exceptTime = `预约期望${item.exceptTime.slice(5)}送达`;
    },
    // 取消订单
    cancelOrder(orderId) {
      this.orderId = orderId;
      this.cancelStatus = true;
    },
    chooseOrder(v, index) {
      this.buttonStatus = this.list[index].buttonStatus;
      if (this.buttonStatus === 0 || this.buttonStatus === 10) {
        this.needTrack = false;
        this.orderDetailStutus = 1;
      } else {
        this.needTrack = true;
        this.orderDetailStutus = 0;
      }
      this.curIdx = index;
      this.getDetailOrder();
      this.getTrackOrder();
      this.getRiderArriveTime();
    },
    // 忽略订单
    iGnoreOrder(orderId) {
      this.orderId = orderId;
      this.$confirm("确定要忽略此单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        showClose: false,
        closeOnClickModal: false,
        type: "warning",
      })
        .then(() => {
          ignoreOrder({ orderId }).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "已忽略!",
              });
              bus.$emit("refreshData");
              bus.$emit("refreshData2");
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    itemAddRemark(orderId, item) {
      this.dialogTableVisible = true;
      this.orderId = orderId;
      this.item = item;
      this.remark = item.takeRemark || "";
    },
    // 一键发单备注
    commitRemark(orderId, item) {
      // if(!this.remark.trim()){
      //   return this.$message({
      //       message: '请输入发单备注再确认！',
      //       type: "error",
      //     });
      // }
      let params = {
        orderId,
        remark: this.remark.trim(),
      };
      addRemark(params).then((res) => {
        this.dialogTableVisible = false;
        if (res.code == 200) {
          this.$message({
            message: "添加备注成功",
            type: "success",
          });
          bus.$emit("refreshData");
          bus.$emit("refreshData2");
          // this.$set(
          //   this.list.find((v) => {
          //     return item.id == v.id;
          //   }),
          //   "takeRemark",
          //   this.remark
          // );
          // this.$forceUpdate();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 查看地图
    checkMap(item) {
      this.$refs.orderMap.setDialogStatus(item);
    },
    sendNow(item) {
      this.getValuation(item);
    },
    // 撤回订单
    orderBack(orderId) {
      rollOrder({ orderId }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          bus.$emit("refreshData");
          bus.$emit("refreshData2");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 补打发票
    orderPrinter(waimaiId, item) {
      if (!waimaiId) return;
      waimaiprinter({ waimaiId }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "操作成功",
            type: "success",
          });
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 计价
    getValuation(order) {
      let requestData = {
        productId: order.productId,
        transport: 0,
        productAmount: 50,
        sendAddress: {
          id: order.sendAddressId,
          provinceName: order.sendProvinceName,
          cityName: order.sendCityName,
          districtName: order.sendDistrictName,
          street: order.sendStreet,
          lat: order.sendLat,
          lng: order.sendLng,
          phone: order.sendPhone,
          extension: order.sendExtension,
          contact: order.sendContactName,
          address: order.sendAddress,
          cityCode: order.sendCityCode,
        },
        receiptAddress: {
          id: order.receiptAddressId,
          provinceName: order.receiptProvince,
          cityName: order.receiptCityName,
          districtName: order.receiptDistrictName,
          lat: order.receiptLat,
          lng: order.receiptLng,
          phone: order.receiptPhone,
          extension: order.receiptExtension,
          contact: order.receiptContactName,
          street: order.receiptStreet || "",
          address: order.receiptAddress,
          cityCode: order.receiptCityCode,
        },
        takeTime: order.takeTime,
        weight: order.weight,
        takeType: order.waimaiOrderId ? order.takeType : 0,
        type: this.userInfo.memberType == 1 ? 1 : 2,
        isWaimai: order.waimaiId ? true : false,
        waimaiOrderId: order.waimaiOrderId,
        takeRemark: order.takeRemark || "",
        orderId: order.id,
      };
      this.isLoading = true;
      sendValuation(requestData).then((res) => {
        console.log(res, "发起配送计算");
        this.isLoading = false;
        if (res.code == 200) {
          res.data.optionals.forEach((item) => {
            item.optionals = item.optionals ? item.optionals : [];
            item.lowOptionals = item.lowOptionals ? item.lowOptionals : [];
            item.supports = item.supports ? item.supports : [];
          });
          this.$refs.sendOrderPopup.init(res.data, {
            ...requestData,
            orderId: order.id,
            orderSn: order.orderSn,
          });
        }
      });
    },
    // 订单详情
    getDetailOrder() {
      this.showDetail = false;
      if (this.list.length) {
        this.orderId = this.list[this.curIdx].id;
      } else {
        return;
      }
      detailOrder({ orderId: this.orderId }).then((res) => {
        if (res.code === 200) {
          this.orderDetail = res.data;
          this.showDetail = true;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 订单跟踪
    getTrackOrder() {
      if (this.buttonStatus === 0 || this.buttonStatus === 10) return;
      this.showTrack = false;
      if (this.list.length) {
        this.orderId = this.list[this.curIdx].id;
      } else {
        return;
      }
      trackOrder({ orderId: this.orderId }).then((res) => {
        if (res.code === 200) {
          this.trackOrder = res.data;
          this.showTrack = true;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 获取骑手预计到达时间
    getRiderArriveTime() {
      // 只有取货中和配送中调用该接口
      if (![2, 3].includes(this.buttonStatus)) return;
      if (this.list.length) {
        this.orderId = this.list[this.curIdx].id;
      } else {
        return;
      }
      getRiderArriveTime({ orderId: this.orderId }).then((res) => {
        if (res.code === 200) {
          this.riderArriveTime = res.data;
        }
      });
    },
    showCancelType(type) {
      let name = "";
      switch (type) {
        case 1:
          name = "商家取消";
          break;
        case 2:
          name = "骑手取消";
          break;
        case 3:
          name = "系统取消";
          break;
        case 4:
          name = "用户取消";
          break;
        case 5:
          name = "平台取消";
          break;
        default:
          name = "已取消";
          break;
      }
      return name;
    },
    showDeliveryStatus(item) {
      let name = "";
      if (item.wmstatus === 4) {
        return (name = "其他平台完成");
      }
      if (item.deliveryStatus === 4) {
        return (name = "已完成");
      }
      if (item.deliveryStatus === -1) {
        return (name = "已取消");
      }
      // if (item.deliveryStatus === -2) {
      //   return this.showCancelType(item.cancelType);
      // }
    },
  },
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped="scoped">
.el-row {
  position: absolute !important;
  width: 100%;
  left: 0;
  top: 0;
}
.track-detail {
  display: flex;
  justify-content: flex-end;
  height: calc(100vh - 210px);
  /deep/ .el-col {
    // margin-right: 15px;
    height: 100%;
    z-index: 2;
  }
  .order-detail {
    height: calc(100vh - 250px);
    overflow: auto;
  }
  .detail_cont {
    height: calc(100vh - 250px);
    overflow: auto;
  }
}
.list-info {
  height: calc(100vh - 210px);
  overflow-y: auto;
}
.choose-self {
  padding-top: 25px;
  border-bottom: 1px solid #eee;

  .self-top {
    display: flex;
    align-items: center;
    margin-bottom: 11px;

    .choose-self-icon {
      width: 4px;
      height: 15px;
      margin-right: 10px;
    }

    span {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #92959b;
    }
  }
  .pay-list {
    display: flex;
    align-items: center;
    padding-top: 10px;

    .pay-item {
      flex: 1;
      display: flex;
      justify-content: center;
      text-align: center;
      align-items: center;
      height: 51px;
      border: 1px solid #eee;
      border-radius: 8px;
      cursor: pointer;

      &.pay-active {
        border-color: #fc7200;
      }

      &:nth-child(2) {
        margin: 0 13px;
      }

      span {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #222222;
      }

      .pay-icon {
        margin-right: 6px;
      }

      .pay-icon:nth-child(1) {
        width: 25px;
        height: 24px;
      }
    }
  }
}
.tip-title {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #92959b;
  padding-bottom: 13px;
}
.tip-list {
  display: flex;
  flex-wrap: wrap;
  .tip-item {
    margin-right: 10px;
    margin-bottom: 10px;
    width: 93px;
    height: 38px;
    line-height: 38px;
    text-align: center;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #222222;
    box-sizing: border-box;
    background: #f4f4f4;
    cursor: pointer;
    border-radius: 2px;
    border: 1px solid transparent;
    /deep/ .el-input__inner {
      border: none;
      height: 32px !important;
      background-color: #f4f4f4;
      font-size: 13px;
      padding: 0 15px !important;
    }
  }
  .tip-active {
    border-color: #fc7200;
    color: #fc7200;
  }
}
.text-area {
  /deep/ .el-textarea__inner {
    background-color: #f2f2f2;
    border: none;
  }
}
.cancel-list {
  display: flex;
  flex-wrap: wrap;
  .item {
    color: #222;
    width: 193px;
    height: 50px;
    line-height: 50px;
    box-sizing: border-box;
    text-align: center;
    font-size: 16px;
    border: 2px solid #d7d7d7;
    border-radius: 6px;
    margin-right: 20px;
    margin-bottom: 20px;
    cursor: pointer;
    &:last-child {
      color: #d7d7d7;
    }
    &.active {
      color: #fc7101;
      border-color: #fc7101;
    }
  }
  .no-margin {
    margin-right: 0 !important;
  }
}
.ignore-modal {
  .title {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #92959b;
  }
  .check-item {
    display: flex;
    align-items: center;
    margin-top: 20px;
    .radio {
      width: 14px;
      height: 14px;
      margin-right: 6px;
    }
    span {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #222222;
    }
  }
}
.submit-btn {
  border: none !important;
  background-color: #fc7200;
}
.active-order-item {
  border: 2px solid #fc7200;
  height: 136px !important;
  width: calc(100% - 4px) !important;
}
.order_item {
  width: 100%;
  height: 140px;
  background: #fff;
  margin-bottom: 10px;
  border-radius: 5px;

  .order_item_header {
    width: 100%;
    height: 49px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 10px;
    box-sizing: border-box;

    .order_item_header_l,
    .order_item_header_r {
      display: flex;
      align-items: center;
    }

    .Serial_number {
      width: 60px;
      height: 26px;
      background: #fc7200;
      border-radius: 0 30px 30px 0;
      font-size: 10px;
      font-weight: 500;
      color: #ffffff;
      text-align: center;
      line-height: 26px;
    }

    .logo {
      width: 21px;
      height: 21px;
      border-radius: 50%;
      margin-left: 23px;
    }

    .name {
      font-size: 14px;
      font-weight: 500;
      color: #333333;
      margin-left: 5px;
    }

    .sign_time {
      padding: 0 8px;
      height: 20px;
      border: 1px solid #fc7200;
      background: #fff;
      border-radius: 2px;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      font-weight: 600;
      color: #fc7200;
      margin-left: 15px;
    }

    .sign_txt {
      // width: 64px;
      height: 20px;
      border: 1px solid #009cff;
      background: #f2faff;
      border-radius: 2px;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      font-weight: 600;
      color: #009cff;
      margin-left: 10px;
      padding: 0 5px;
    }

    .sign_d {
      height: 20px;
      border: 1px solid #f74141;
      background: #fff5f5;
      border-radius: 2px;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      font-weight: 600;
      color: #f74141;
      margin-left: 10px;
      padding: 0 7px;
    }
    .sign_f {
      height: 20px;
      border: 1px solid #999;
      background: #fff;
      border-radius: 2px;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      font-weight: 600;
      color: #999;
      margin-left: 10px;
      padding: 0 7px;
    }

    .header_r {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      // margin-right: 22px;
    }

    .btn {
      background: #fc7200;
      border-color: #fc7200;
      color: #fff;
      margin-left: 20px;
      //  position: absolute;
      //  right: 10px;
    }
  }
  .order_item_cont {
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    padding: 5px 20px;
    height: 80px;
  }
  .address {
    .distance {
      margin-left: 10px;
      color: #409eff;
      cursor: pointer;
      font-size: 16px;
    }
  }
}

.itme_r {
  font-size: 14px;
  font-weight: 400;
  color: #b1b1b1;
  word-wrap: break-word;
}
.order_detail {
  position: relative;
  width: 100%;
  height: 100%;
  border-left: 10px solid #f1f2f5;
  background: #fff;
  box-sizing: border-box;
  border-left: 10px solid #f1f2f5;
  .bottom-btns {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    border-top: 2px dotted #f0f0f0;
    background: #fff;
  }
  .detail_title {
    width: 100%;
    height: 44px;
    background: #fafafa;
    padding-left: 16px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: flex-end;

    .detail_txt {
      color: #b1b1b1;
      padding-bottom: 13px;
      border-bottom: 2px solid #fafafa;
      margin-right: 28px;
      cursor: pointer;
      z-index: 2;
    }

    .detail_txt_ac {
      color: #00152a;
      border-color: #00152a;
    }
  }
  .btns {
    margin: 10px 15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .btn {
      background: #fc7200;
      border-color: #fc7200;
      color: #fff !important;
    }
    .btn_bots {
      margin: 0 !important;
      margin-bottom: 10px !important;
    }
    .btn_bot {
      width: 74px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #888888;
      margin-bottom: 10px !important;
      .el-dropdown-link {
        cursor: pointer;
      }
    }
  }
  .detail_cont {
    width: 100%;
    padding: 16px;
    box-sizing: border-box;

    .detail_title2 {
      width: 100%;
      font-size: 12px;
      font-weight: 600;
      color: #777777;
      margin-bottom: 15px;
    }

    .shop_detail {
      width: 100%;
      display: flex;
      margin-bottom: 10px;

      img {
        width: 47px;
        height: 47px;
        border-radius: 4px 4px 4px 4px;
        margin-right: 12px;
      }

      .info {
        flex-grow: 1;
        display: flex;
        justify-content: space-between;

        .shop_title {
          width: 70%;
          font-size: 14px;
          font-weight: 500;
          color: #333333;
          line-height: 18px;
        }

        .shop_num {
          color: #b1b1b1;
        }
      }
    }

    .detail_ine {
      width: 100%;
      height: 1px;
      border-top: 2px dotted #f0f0f0;
      margin: 16px 0;
    }

    .info2 {
      width: 100%;
      display: flex;

      .title {
        font-size: 14px;
        font-weight: 400;
        width: 80px;
        color: #b1b1b1;
      }

      .cont {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        line-height: 20px;
      }

      .cont2 {
        color: #fc7200;
      }
    }

    .info3 {
      margin-top: 10px;
    }

    .info4 {
      display: flex;
      justify-content: space-between;
    }

    .btns {
      margin-top: 30px;

      .btn {
        background: #fc7200;
        border-color: #fc7200;
        color: #fff;
      }
    }
  }
}
</style>
