<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.tel }}</div>
        </el-col>
        <el-col :span="8" :xs="{span: 24, offset: 0}">
          <div class="title">门店名称：{{ info.channelName }}</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.totalQuantity }}</div>
        </el-col>
        <el-col :span="7" :xs="{span: 24, offset: 0}">
          <div class="title">已核销：{{ info.totalVerifyQty }}</div>
        </el-col>
        <el-col :span="8" :xs="{span: 24, offset: 0}">
          <div class="title">剩余库存：{{ info.totalRemainQty }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">结算库存：{{ info.totalSettleQty }}</div>
        </el-col>
        <el-col :span="7" :xs="{span: 24, offset: 0}">
          <div class="title">采购成本：￥{{ $numberFormat(info.items && info.items[0].purchaseCost) }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">门店应付金额：￥{{ $numberFormat(info.totalPurchaseCost) }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}">
          <div class="title">实际结算金额：￥{{ $numberFormat(info.settleAmt) }}</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.desc }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}" v-if="status && status.value == 2">
          <div class="title">支付金额：￥{{ $numberFormat(info.payAmount) }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}" v-if="(status && status.value == 2) || (status && status.value == 3)">
          <div class="title">发起结算时间：{{ parseTime(info.pushTime) }}</div>
        </el-col>
        <el-col :span="8" :offset="1" :xs="{span: 24, offset: 0}" v-if="status && status.value == 2">
          <div class="title">结算时间：{{ parseTime(info.settleTime) || '--' }}</div>
        </el-col>
        <el-button
        v-if="status && status.value == 1"
          v-hasPermi="['business:ticket:on']"
          type="primary"
          @click="toInventory()"
        >去结算</el-button
        >
      </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="purchaseCost" min-width="80">
            <template slot-scope="{ row }">
              <div>￥{{ $numberFormat(row.purchaseCost) }}</div>
            </template>
          </el-table-column>
            <el-table-column label="库存" prop="quantity" min-width="80"/>
            <el-table-column label="已核销" prop="verifyQty" min-width="80"/>
            <el-table-column label="剩余库存" prop="remainQty" min-width="80"/>
        </el-table>
      </div>
    </div>
      </el-col>
    </el-row>
    <!-- 结算 -->
    <inventory-goods :inventory-show="inventoryShow" :inventory-info="info" @close="close" v-if="inventoryShow"/>
  </div>
</template>
<script>
import { getInventoryDetail } from "@/api/business/inventory";
import { publicFileGetUrl } from "@/api/common";
import InventoryGoods from "./components/InventoryGoods";
export default {
  name: "InventoryDetail",
  components: {
    InventoryGoods,
  },
  data() {
    return {
      // 订单ID
      orderId: "",
      // 订单详情
      info: {},
      // 订单状态
      status: {},
      // 商品信息列表
      list: [],
      // 结算显示
      inventoryShow: false,
    };
  },
  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() {
      getInventoryDetail(this.orderId).then((res) => {
        if (res.code == 0) {
          this.info = res.data;
          this.status = JSON.parse(res.data.status);
          res.data.items &&
            res.data.items.forEach((item) => {
              let picUrlArr = item.picUrl.split(",");
              item.picUrl = publicFileGetUrl + picUrlArr[0];
            });
          this.list = res.data.items;
        }
      });
    },

    // 点击发货
    toInventory() {
      this.inventoryShow = true;
    },

    // 发货关闭
    close() {
      this.inventoryShow = false;
      this.getDetail();
    },
  },
};
</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>
