<template>
  <div>
    <el-row>
      <el-col :span="18">
        <div v-loading="isLoading">
          <div class="empty-data" v-if="list && list.length < 1">
            <img src="../../../static/image/empty-data.png" />
          </div>
          <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>
                <div class="sign_time" v-if="item.waimaiOrderId && item.takeType==1">{{item.exceptTime}}前送达</div>
                <div class="sign_txt" v-if="item.waimaiOrderId && item.takeType==0">立即送达</div>
                <!-- <div class="sign_d">预约 09/10 17:30自动发起配送</div> -->
              </div>
              <!-- 订单查询 -->
              <div class="order_item_header_r" v-if="tabNum === -1">
                <span class="header_r">{{showDeliveryStatus(item)}}</span>
                <el-button size='small' class="btn" @click.stop="orderPrinter(item.waimaiOrderId)">补打发票</el-button>
              </div>
              <!-- 新订单 -->
              <div class="order_item_header_r" v-if="tabNum === 0">
                <!-- <span class="header_r">已发单1分钟</span> -->
                <el-button size='small' class="btn" @click.stop="deleteItem(item)">发起配送</el-button>
              </div>
              <!-- 预约单 -->
              <div class="order_item_header_r" v-if="tabNum === 1">
                <!-- <span class="header_r">已发单1分钟</span> -->
                <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 size='small' class="btn" @click.stop="settingTime(item)">定时发单</el-button>
                <el-button size='small' class="btn" @click.stop="deleteItem(item)">发起配送</el-button>
              </div>
              <!-- 待接单 -->
              <div class="order_item_header_r" v-if="tabNum === 2">
                <span class="header_r">已发单{{item.takeTimeTxt}}</span>
                <el-button size='small' @click.stop="cancelOrder(item.id)">取消订单</el-button>
                <el-button size='small' @click.stop="orderPrinter(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="tabNum === 3">
                <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)">补打发票</el-button>
              </div>
              <!-- 配送中 -->
              <div class="order_item_header_r" v-if="tabNum === 4">
                <span class="header_r" v-if="item.exceptTime">预计{{item.exceptTime}}送达</span>
                <el-button size='small' class="btn" @click.stop="orderPrinter(item.waimaiOrderId)">补打发票</el-button>
              </div>
              <!-- 异常单 -->
              <div class="order_item_header_r" v-if="tabNum === 5">
                <span class="header_r">{{showCancelType(item.cancelType)}}</span>
                <el-button size='small' class="btn" @click.stop="orderBack(item.id)">撤回订单</el-button>
              </div>
              <!-- 取消单 -->
              <div class="order_item_header_r" v-if="tabNum === 6">
                <span class="header_r">{{showCancelType(item.cancelType)}}</span>
                <!-- <el-button size='small' class="btn" @click.stop="orderBack(item.id)">撤回订单</el-button> -->
              </div>
            </div>
            <div class="order_item_cont">
              <div class="content">{{item.receiptContactName}}<span>{{item.receiptPhone}}</span></div>
              <div class="address">
                {{item.receiptProvinceName}}
                {{item.receiptCityName}}
                {{item.receiptDistrictName}}
                {{item.receiptAddress}}
                <span v-if="item.orderDistance" @click.stop="checkMap(item)">
                  <i class="el-icon-location"></i>
                  <span v-if="item.orderDistance < 1000">
                    {{item.orderDistance}}m
                  </span>
                  <span v-else>
                    {{item.orderDistance / 1000}}km
                  </span>
                </span>
              </div>
              <div v-if="item.caution" class="itme_r">备注：{{item.caution}}</div>
            </div>
          </div>
          <div v-if="item.caution" class="itme_r">备注：{{item.caution}}</div>
        </div>
      </el-col>
      <!-- 订单追踪、订单详情 -->
      <el-col :span="6">
        <div class="order_detail">
          <div class="detail_title">
            <div v-show="needTrack" 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" :tabNum="tabNum" :trackOrder="trackOrder" v-if="!orderDetailStutus && needTrack"></order-track>
          <order-detail v-show="showDetail" :tabNum="tabNum" :orderDetail="orderDetail" v-else></order-detail>
          <!-- 订单跟踪、订单详情底部按钮 -->
          <div v-show="showDetail || showTrack">
            <!-- 新订单 -->
            <div class="btns" v-if="tabNum === 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)" class="btn_bots">补打发票</el-button>
              <el-button size='small' @click.native="deleteItem(list[curIdx])" class="btn_bots btn">发起配送</el-button>
            </div>
            <!-- 预约单 -->
            <div class="btns" v-if="tabNum === 1">
              <div class="btn_bot">
                <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 size='small' @click.native="settingTime(list[curIdx])" class="btn_bots btn">定时发单</el-button>
              <el-button size='small' @click.native="deleteItem(list[curIdx])" class="btn_bots btn">发起配送</el-button>
            </div>
            <!-- 订单查询 -->
            <div class="btns" v-if="tabNum === -1">
              <el-button size='small' @click.native="orderPrinter(list[curIdx].waimaiOrderId)" class="btn_bots btn">补打发票</el-button>
            </div>
            <!-- 待接单 -->
            <div class="btns" v-if="tabNum === 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)" 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="tabNum === 3">
              <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)" class="btn_bots btn">补打发票</el-button>
            </div>
            <!-- 配送中 -->
            <div class="btns" v-if="tabNum === 4">
              <el-button size='small' @click.native="orderPrinter(list[curIdx].waimaiOrderId)" class="btn_bots btn">补打发票</el-button>
            </div>
            <!-- 异常单 -->
            <div class="btns" v-if="tabNum === 5">
              <el-button size='small' @click.native="orderPrinter(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="tabNum === 6">
              <!-- <el-button size='small' @click.native="orderPrinter(list[curIdx].waimaiOrderId)" class="btn_bots btn">再来一单</el-button> -->
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <!-- 发起配送 -->
    <send-order-popup 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" :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="忽略订单" destroy-on-close :visible.sync="ignoreStatus">
      <div class="ignore-modal">
        <div class="title">请选择忽略该笔订单的原因</div>
        <div class="check-item">
          <img src="../../../static/image/check-radio.png" @click.stop="changeRadio(1)" v-if="radio != 1" class="radio" />
          <img src="../../../static/image/check-radio-active.png" v-if="radio == 1" class="radio" />
          <span>通过其他配送方式完成</span>
        </div>
        <div class="check-item">
          <img src="../../../static/image/check-radio.png" @click.stop="changeRadio(2)" v-if="radio != 2" class="radio" />
          <img src="../../../static/image/check-radio-active.png" v-if="radio == 2" class="radio" />
          <span>取消该笔订单（由于用户取消或其他原因）</span>
        </div>
      </div>
      <div style="text-align: center;margin-top: 20px;">
        <el-button @click.stop="ignoreStatus = false">取消</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="commitIGnore(orderId)">确定</el-button>
      </div>
    </el-dialog>
    <!-- 设置预约发单时间弹出层 -->
    <el-dialog width="580px" center title="设置预约时间" 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;">提示：设置后系统将根据您设置的提前时间自动发单。</p>
      <div style="text-align: center;margin-top: 20px;">
        <el-button @click.stop="settingTimeStatus = false">取消</el-button>
        <el-button type="primary" class="submit-btn" @click.stop="commitTimeValue(orderId)">确定</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,
  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: "", // 小费金额
      addTipTimer: null, // 加小费刷新支付计时器
      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: 0,
      isLoading: false,
      dialogTableVisible: false,
      ignoreStatus: false, // 忽略订单弹出层
      remark: "",
      orderId: "",
      item: {},
      radio: "",
      needTrack: false,
      curIdx: 0,
      trackOrder: {},
      orderDetail: {},
      showDetail: false,
      showTrack: false,
      showCode: false,
      link: "",
    };
  },
  props: {
    tabNum: Number,
    list: Array,
  },
  components: {
    sendOrderPopup,
    orderMap,
    OrderDetail,
    orderTrack,
    qrCode,
  },
  watch: {
    tabNum(newVal, oldVal) {
      if (newVal === 0 || newVal === 1) {
        this.needTrack = false;
        this.orderDetailStutus = 0;
      } else {
        this.needTrack = true;
        this.orderDetailStutus = 0;
      }
      this.curIdx = 0;
    },
    list(newVal, oldVal) {
      this.getDetailOrder();
      this.getTrackOrder();
    },
    addTipStatus(val) {
      if (!val) {
        clearTimeout(this.addTipTimer);
        this.addTipTimer = null;
      }
    },
  },
  destroyed() {
    clearTimeout(this.addTipTimer);
    this.addTipTimer = null;
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  methods: {
    paySuccess() {
      this.showCode = false;
      this.addTipStatus = false;
      bus.$emit("refreshData");
    },
    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");
            this.addTipStatus = false;
            this.tipAmount = "";
            clearTimeout(this.addTipTimer);
            this.addTipTimer = null;
          } 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.addTipStatus = true;
    },
    changeReason(item) {
      this.reasonIndex = item.id;
      this.chooseReason = item.name;
    },
    // 取消订单
    commitCancelReason() {
      if (!this.reasonIndex) {
        return this.$message({
          message: "请选择取消原因",
          type: "error",
        });
      }
      if (this.reasonIndex == 8 && !this.cancelReason.trim()) {
        return this.$message({
          message: "请填写其他取消原因",
          type: "error",
        });
      }
      cancelOrder({
        orderId: this.orderId,
        cancelReason:
          this.reasonIndex != 8 ? this.chooseReason : this.cancelReason,
      }).then((res) => {
        this.cancelStatus = false;
        if (res.code == 200) {
          this.$message({
            message: "取消订单成功",
            type: "success",
          });
          this.orderId = "";
          this.cancelReason = "";
          this.chooseReason = "";
          this.reasonIndex = null;
          bus.$emit("refreshData");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    cancalSettingTime() {
      cancelTimingPublish({ orderId: this.item.orderId }).then((res) => {
        this.settingTimeStatus = false;
        if (res.code == 200) {
          this.$message({
            message: "取消定时发单成功",
            type: "success",
          });
          this.item = {};
          bus.$emit("refreshData");
        } 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"); //当前时间的前1小时时间
      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");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 定时发单
    settingTime(item) {
      this.item = item;
      this.settingTimeStatus = true;
      this.timeValue = item.delayTime ? item.delayTime : 1;
    },
    // 取消订单
    cancelOrder(orderId) {
      this.orderId = orderId;
      this.cancelStatus = true;
    },
    chooseOrder(v, index) {
      this.curIdx = index;
      this.getDetailOrder();
      this.getTrackOrder();
    },
    changeRadio(i) {
      this.radio = i;
    },
    // 忽略订单
    iGnoreOrder(orderId) {
      this.orderId = orderId;
      this.ignoreStatus = true;
    },
    commitIGnore(orderId) {
      if (!this.radio) {
        return this.$message({
          message: "请选择忽略原因",
          type: "error",
        });
      }
      let params = {
        orderId,
        ignoreReason: this.radio == 1 ? 0 : 1,
      };
      ignoreOrder(params).then((res) => {
        this.ignoreStatus = false;
        if (res.code == 200) {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          bus.$emit("refreshData");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    itemAddRemark(orderId, item) {
      this.dialogTableVisible = true;
      this.orderId = orderId;
      this.item = item;
      this.remark = item.takeRemark || "";
    },
    // 一键发单备注
    commitRemark(orderId, item) {
      let params = {
        orderId,
        remark: this.remark.trim(),
      };
      addRemark(params).then((res) => {
        this.dialogTableVisible = false;
        if (res.code == 200) {
          this.$message({
            message: "添加备注成功",
            type: "success",
          });
          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) {
      getMapData({ orderId: item.id }).then((res) => {
        if (res.code === 200) {
          console.log(res.data);
          this.$refs.orderMap.setDialogStatus(item, res.data);
        } else {
          this.$message({
            type: "error",
            message: res.msg,
          });
        }
      });
    },
    deleteItem(item) {
      this.getValuation(item);
    },
    // 撤回订单
    orderBack(orderId) {
      rollOrder({ orderId }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "操作成功",
            type: "success",
          });
          bus.$emit("refreshData");
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    // 补打发票
    orderPrinter(waimaiId) {
      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.takeType,
        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() {
      this.showTrack = false;
      if (this.list.length) {
        this.orderId = this.list[this.curIdx].id;
      } else {
        return;
      }
      if (this.tabNum < 2) 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",
          });
        }
      });
    },
    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:
          break;
      }
      return name;
    },
    showDeliveryStatus(item) {
      let name = "";
      if (item.wmstatus === 4) {
        name = "其他平台完成";
      }
      if (item.deliveryStatus === 4) {
        name = "已完成";
      }
      if (item.deliveryStatus === -1) {
        name = "已取消";
      }
      return name;
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped="scoped">
.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;
}
.empty-data {
  font-size: 0;
  text-align: center;
  background-color: #fff;
  padding: 100px 0;

  img {
    width: 349px;
    height: 222px;
  }
}
.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 #009cff;
      background: #f2faff;
      border-radius: 2px;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      font-weight: 600;
      color: #009cff;
      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;
    }

    .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;
    }

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

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

.itme_r {
  font-size: 14px;
  font-weight: 400;
  color: #b1b1b1;
}
.order_detail {
  width: 100%;
  border-left: 10px solid #f1f2f5;
  background: #fff;
  box-sizing: border-box;
  border-left: 10px solid #f1f2f5;

  .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;
    }

    .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>
