<template>
  <div class="app-container">
    <!-- 订单信息 -->
    <el-row :gutter="10">
      <el-col :span="22" :offset="1">
        <div class="info-title">订单信息</div>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">订单编号：{{ info.orderId }}</div>
        </el-col>
        <el-col :span="7" :xs="{span: 24, offset: 0}">
          <div class="title">订单类型：用户提货订单</div>
        </el-col>
        <el-col :span="8" :xs="{span: 24, offset: 0}">
          <div class="title">下单时间：{{ parseTime(info.createdTime) }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">付款方式：{{ info.payType == 1 || info.payType == 10 ? '支付宝支付': info.payType == 2 ? '微信支付': '--' }}</div>
        </el-col>
      </el-col>
    </el-row>

    <!-- 买家信息 -->
    <el-row :gutter="10" >
      <el-col :span="22" :offset="1">
        <div class="info-title">买家信息</div>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">用户昵称：{{ info.nickName || "--" }}</div>
        </el-col>
        <el-col :span="7" :xs="{span: 24, offset: 0}">
          <div class="title">收货人：{{ info.receiver || "--" }}</div>
        </el-col>
        <el-col :span="8" :xs="{span: 24, offset: 0}">
          <div class="title">联系电话：{{ info.tel || "--" }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">收货地址：{{
              `${info.province || "--"}${info.city || "--"}${
                info.area || "--"
              }${info.address || "--"}`
            }}</div>
        </el-col>
      </el-col>
    </el-row>

    <!-- 买家留言 -->
    <el-row :gutter="10">
      <el-col :span="22" :offset="1">
        <div class="info-title">备注信息</div>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">买家留言：{{ info.memo || "--" }}</div>
        </el-col>
      </el-col>
    </el-row>

    <!-- 订单状态 -->
    <el-row :gutter="10">
      <el-col :span="22" :offset="1">
        <div class="info-title">订单状态</div>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">订单状态：{{ status.value == 2 ? "已发货" : (status.desc || "--") }}</div>
        </el-col>
        <el-button
          v-if="status.value === 1 || status.value === 4"
          v-hasPermi="['business:ticket:on']"
          type="primary"
          @click="toGoods()"
        >发货</el-button
        >
      </el-col>
    </el-row>

    <!-- 物流信息 -->
    <el-row :gutter="10">
      <el-col :span="22" :offset="1">
        <div class="info" v-if="status.value === 2 || status.value === 3 || status.value === 4">
      <div class="info-title">物流信息</div>
      <el-col :span="24" :offset="1">
        <div
          class="info-item-logistics"
          v-for="(item, index) in deliverList"
          :key="index"
        >
          <div class="logistics-title">包裹{{ index + 1 }}</div>
          <div class="info">
            <el-col :span="5" :xs="{span: 24, offset: 0}">
              <div class="tit">配送方式：{{ item.companyName || item.deliveryFlowId ? "快递发货":"无需物流" }}</div>
            </el-col>
            <el-col :span="5" :xs="{span: 24, offset: 0}">
              <div class="tit" v-if="item.companyName">快递公司：{{ item.companyName || "--" }}</div>
              <div class="tit" v-else></div>
            </el-col>
            <el-col :span="5" :xs="{span: 24, offset: 0}">
              <div class="tit" v-if="item.deliveryFlowId">快递单号：{{ item.deliveryFlowId || "--" }}</div>
              <div class="tit" v-else></div>
            </el-col>
            <el-col :span="7" :xs="{span: 24, offset: 0}">
              <div class="tit">发货时间：{{ parseTime(item.deliveryTime) || "--" }}</div>
            </el-col>
            <el-col :span="2" :xs="{span: 24, offset: 0}">
              <div class="edit-express" @click="editExpress(item)" v-if="status.value === 2 || status.value === 4">修改</div>
            </el-col>
          </div>
          <div class="goods">
            <div class="goods-item" v-for="(ele, ins) in item.items" :key="ins">
              <img :src="ele.picUrl" alt="" />
              <div class="info">
                <div>{{ ele.title || "--" }}</div>
                <div>{{ ele.properties || "--" }}</div>
                <div>{{ ele.goodsNum }}件</div>
              </div>
            </div>
          </div>
        </div>
      </el-col>

      </div>
      </el-col>
    </el-row>

        <!-- 商品信息 -->
    <el-row :gutter="10">
      <el-col :span="22" :offset="1">
         <div class="info">
      <div class="info-title">商品信息</div>
      <div class="info-table">
        <el-table :data="list">
          <el-table-column label="商品信息" min-width="200">
            <div slot-scope="{ row }" class="flex">
              <el-image
                style="width: 100px; height: 100px"
                :src="row.picUrl"
                :preview-src-list="[row.picUrl]"
              />
              <div class="txt">{{ row.title }}</div>
            </div>
          </el-table-column>
          <el-table-column label="规格" min-width="100">
            <template slot-scope="{ row }">
              <div>{{ row.properties || "--" }}</div>
            </template>
          </el-table-column>
          <el-table-column label="数量" prop="orderNum">
            <template slot-scope="{ row }">
              <div>{{ row.goodsNum }}件</div>
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="{ row }">
              <div>{{ row.deliveryTime ? "已发货" : "未发货" }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 按钮 -->
      <div class="info-amt">
        <div class="info-amt-price">
          <span>运费：</span>{{ $numberFormat(info.freightAmt) }}元
        </div>
        <div class="info-amt-price">
          <span>共计金额：</span>{{ $numberFormat(info.payAmt) }}元
        </div>
      </div>
    </div>
      </el-col>
    </el-row>
    <!-- 发货 -->
    <send-goods :send-show="goodsShow" :goods-info="info" @close="close" />

    <!-- 修改快递信息 -->
    <express-edit
      v-if="editShow"
      :edit-show="editShow"
      :goods-info="expressInfo"
      :order-id="info.orderId"
      @close="close"
    />
  </div>
</template>
<script>
import { deliverDetail } from "@/api/business/order";
import { publicFileGetUrl } from "@/api/common";
import SendGoods from "./components/SendGoods";
import ExpressEdit from "./components/ExpressEdit";
export default {
  name: "DeliverDetail",
  components: {
    SendGoods,
    ExpressEdit,
  },
  data() {
    return {
      // 订单ID
      orderId: "",
      // 订单详情
      info: {},
      // 订单状态
      status: {},
      // 商品信息列表
      list: [],
      // 物流信息性别
      deliverList: [],
      // 发货显示
      goodsShow: false,
      // 修改快递信息弹框
      editShow: false,
      // 快递信息
      expressInfo: {}
    };
  },
  created() {
    this.orderId = this.$route.query.id;
    this.getDetail();
  },
  activated() {
    const orderId = this.$route.query.id;
    if (orderId != null && orderId != this.orderId) {
      this.orderId = orderId;
      this.getDetail();
    }
  },
  methods: {
    // 订单详情
    getDetail() {
      deliverDetail({ orderId: this.orderId }).then((res) => {
        if (res.code == 0) {
          this.info = res.data;
          this.status = JSON.parse(res.data.status);
          res.data.deliverList &&
            res.data.deliverList.forEach((item) => {
              item.items.forEach((ele) => {
                let picUrlArr = ele.picUrl.split(",");
                ele.picUrl = publicFileGetUrl + picUrlArr[0];
              });
            });
          this.deliverList = res.data.deliverList;
          res.data.items &&
            res.data.items.forEach((item) => {
              let picUrlArr = item.picUrl.split(",");
              item.picUrl = publicFileGetUrl + picUrlArr[0];
            });
          this.list = res.data.items;
        }
      });
    },

    // 点击发货
    toGoods() {
      this.goodsShow = true;
    },

    // 发货关闭
    close() {
      this.goodsShow = false;
      this.editShow = false;
      this.getDetail();
    },

    // 修改快递信息
    editExpress(item) {
      this.expressInfo = item
      this.editShow = true;
    },
  },
};
</script>
<style lang="scss" scoped>
.title {
  line-height: 30px;
  text-align: left;
}
.edit-express {
  color: #409eff;
  cursor: pointer;
}

.info {
  margin-bottom: 10px;
  &-title {
    font-size: 14px;
    margin-bottom: 20px;
    font-weight: bold;
  }
  &-item {
    padding-left: 50px;
    &-content {
      display: flex;

      &-one {
        display: flex;
        margin-bottom: 10px;

        .title {
          //width: 100px;
        }

        .txt {
          //width: 200px;
        }
      }
    }

    &-logistics {
      margin-bottom: 20px;
      .logistics-title {
        text-align: left;
        font-weight: bold;
        margin-bottom: 20px;
      }
      .info {
        display: flex;
        margin-bottom: 10px;
        &-one {
          display: flex;
        }
        .tit {
          line-height: 22px;
          //width: 100px;
        }
        .txt {
          line-height: 22px;
          //width: 200px;
        }
        .edit-express{
          color: #409eff;
          cursor: pointer;
        }
      }
      .goods {
        margin: 10px 0;
        &-item {
          display: flex;
          border-bottom: 1px solid #f3eeee;
          img {
            width: 100px;
            height: 100px;
          }
          .info {
            padding-left: 20px;
            display: flex;
            flex-direction: column;
            height: 100px;
            justify-content: space-between;
          }
        }
      }
    }
  }
  &-amt {
    margin-top: 10px;
    &-price {
      span {
        display: inline-block;
        width: 80px;
        margin-bottom: 20px;
      }
    }
  }
}
.flex {
  display: flex;
  align-items: center;
  .txt {
    margin-left: 20px;
  }
}
</style>
