<template>
  <div class="app-container">
    <!-- 订单信息 -->
    <div class="info">
      <div class="info-title">订单信息</div>
      <div class="info-item">
        <div class="info-item-content">
          <div class="info-item-content-one">
            <div class="title">订单编号：</div>
            <div class="txt">{{ info.orderId }}</div>
          </div>
          <div class="info-item-content-one">
            <div class="title">订单类型：</div>
            <div class="txt">用户提货订单</div>
          </div>
        </div>
        <div class="info-item-content">
          <div class="info-item-content-one">
            <div class="title">下单时间：</div>
            <div class="txt">{{ parseTime(info.createdTime) }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 买家信息 -->
    <div class="info">
      <div class="info-title">买家信息</div>
      <div class="info-item">
        <div class="info-item-content">
          <div class="info-item-content-one">
            <div class="title">用户昵称：</div>
            <div class="txt">{{ info.nickName || "--" }}</div>
          </div>
          <div class="info-item-content-one">
            <div class="title">收货人：</div>
            <div class="txt">{{ info.receiver || "--" }}</div>
          </div>
          <div class="info-item-content-one">
            <div class="title">联系电话：</div>
            <div class="txt">{{ info.tel || "--" }}</div>
          </div>
        </div>
        <div class="info-item-content">
          <div class="info-item-content-one">
            <div class="title">收货地址：</div>
            <div class="">
              {{
                `${info.province || "--"}${info.city || "--"}${
                  info.area || "--"
                }${info.address || "--"}`
              }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 订单状态 -->
    <div class="info">
      <div class="info-title">订单状态</div>
      <div class="info-item">
        <div class="info-item-content">
          <div class="info-item-content-one">
            <div class="title">订单状态：</div>
            <div class="txt">{{ status.desc || "--" }}</div>
          </div>
        </div>
        <div class="info-item-content">
          <el-button
            v-if="status.value === 1"
            v-hasPermi="['business:ticket:on']"
            type="primary"
            @click="toGoods()"
            >发货</el-button
          >
        </div>
      </div>
    </div>
    <!-- 物流信息 -->
    <div class="info" v-if="status.value === 2">
      <div class="info-title">物流信息</div>
      <div class="info-item">
        <div
          class="info-item-logistics"
          v-for="(item, index) in deliverList"
          :key="index"
        >
          <div class="title">快递{{ index + 1 }}</div>
          <div class="info">
            <div class="info-one">
              <div class="tit">快递公司：</div>
              <div class="txt">{{ item.companyName || "--" }}</div>
            </div>
            <div class="info-one">
              <div class="tit">快递单号：</div>
              <div class="txt">{{ item.deliveryFlowId || "--" }}</div>
            </div>
            <div class="info-one">
              <div class="tit">发货时间：</div>
              <div class="txt">{{ parseTime(item.deliveryTime) || "--" }}</div>
            </div>
          </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>
      </div>
    </div>
    <!-- 商品信息 -->
    <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.deliveryFlowId ? "已发货" : "未发货" }}</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.orderAmt) }}元
        </div>
      </div>
    </div>

    <!-- 发货 -->
    <send-goods :send-show="goodsShow" :goods-info="info" @close="close" />
  </div>
</template>
<script>
import { deliverDetail } from "@/api/business/order";
import { publicFileGetUrl } from "@/api/common";
import SendGoods from "./components/SendGoods";
export default {
  name: "UserDetail",
  components: {
    SendGoods,
  },
  data() {
    return {
      // 订单ID
      orderId: "",
      // 订单详情
      info: {},
      // 订单状态
      status: {},
      // 商品信息列表
      list: [],
      // 物流信息性别
      deliverList: [],
      // 发货显示
      goodsShow: false,
    };
  },
  created() {
    this.orderId = this.$route.query.id;
    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.getDetail();
    },
  },
};
</script>
<style lang="scss" scoped>
.info {
  margin-bottom: 30px;
  &-title {
    font-size: 14px;
    margin-bottom: 20px;
    font-weight: bold;
  }
  &-item {
    padding-left: 50px;
    &-content {
      display: flex;

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

        .title {
          width: 100px;
        }

        .txt {
          width: 200px;
        }
      }
    }

    &-logistics {
      margin-bottom: 20px;
      .title {
        font-weight: bold;
        margin-bottom: 20px;
      }
      .info {
        display: flex;
        margin-bottom: 20px;
        &-one {
          display: flex;
        }
        .tit {
          width: 100px;
        }
        .txt {
          width: 200px;
        }
      }
      .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: 20px;
    &-price {
      span {
        display: inline-block;
        width: 80px;
        margin-bottom: 20px;
      }
    }
  }
}
.flex {
  display: flex;
  align-items: center;
  .txt {
    margin-left: 20px;
  }
}
</style>