<template>
  <div class="detail-container">
    <el-page-header @back="goBack" content="详情"></el-page-header>

    <div class="main-title">
      <div class="title">基本信息</div>
    </div>

    <div class="diy-table-1">
      <el-row>
        <el-col :span="8" class="item">
          <div class="label">直接调拨单号</div>
          <div class="value">{{ detailData.id }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">申请日期</div>
          <div class="value">{{ detailData.orderTime }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">单据状态</div>
          <div class="value">{{ detailData.examineStatus | statusFilter }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">经销商编号</div>
          <div class="value">{{ detailData.customerNumber }}</div>
        </el-col>
        <el-col :span="16" class="item">
          <div class="label">经销商名称</div>
          <div class="value">{{ detailData.customerName }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">销售订单号</div>
          <div class="value">
            {{
              detailData.orderType === 'TRADE' ||
              detailData.orderType === 'HOME' ||
              detailData.orderType === 'REQUISITION_TRADE' ||
              detailData.orderType === 'REQUISITION_HOME'
                ? detailData.enginOrderNo
                : detailData.mainOrderId
            }}
          </div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">销售单类型</div>
          <div class="value">{{ detailData.orderType | orderTypeFilter }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">调拨类型</div>
          <div class="value">{{ detailData.type | typeFilter }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">调出库存组织</div>
          <div class="value">{{ detailData.requsitionOut }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">调入库存组织</div>
          <div class="value">{{ detailData.requsitionIn }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">调拨方向</div>
          <div class="value">{{ detailData.direction }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">备注</div>
          <div class="value">{{ detailData.remark }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">制单人</div>
          <div class="value">{{ detailData.createBy }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">制单日期</div>
          <div class="value">{{ detailData.createTime }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">审核人</div>
          <div class="value">{{ detailData.approvalName }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">审核日期</div>
          <div class="value">{{ detailData.approvalTime }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">最后更新人</div>
          <div class="value">{{ detailData.updateBy }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">最后更新日期</div>
          <div class="value">{{ detailData.updateTime }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">关闭人</div>
          <div class="value">{{ detailData.closeName }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">关闭日期</div>
          <div class="value">{{ detailData.closeTime }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">审批说明</div>
          <div class="value">{{ detailData.approvalRemark }}</div>
        </el-col>
      </el-row>
    </div>

    <div class="main-title">
      <div class="title">货品信息</div>
    </div>

    <div class="table" style="margin-top: 20px">
      <el-table
        :data="detailData.results"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
        stripe
        max-height="400"
      >
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column
          align="center"
          label="销售类型"
          prop="saleTypeName"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          label="产品编码"
          prop="materialCode"
          min-width="120"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          label="产品名称"
          prop="materialName"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          label="规格型号"
          prop="specification"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          label="单位"
          prop="unit"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          label="调拨数量"
          prop="qty"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>

        <el-table-column
          align="center"
          label="总成本"
          prop="totalAmount"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column align="center" label="调出仓库" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.correspondName }}</template>
        </el-table-column>
        <el-table-column align="center" label="调出仓位" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.stockName }}</template>
        </el-table-column>
        <el-table-column align="center" label="调入仓库" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.inCorrespondName }}</template>
        </el-table-column>
        <el-table-column align="center" label="调入仓位" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.inStockName }}</template>
        </el-table-column>
        <el-table-column align="center" label="调出库存状态" min-width="110" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.stockStatusType }}</template>
        </el-table-column>
        <el-table-column align="center" label="调入库存状态" min-width="110" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.inStockStatusType }}</template>
        </el-table-column>
        <el-table-column align="center" label="调出库主" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.requsitionOut }}</template>
        </el-table-column>
        <el-table-column align="center" label="调入库主" min-width="100" show-overflow-tooltip>
          <template slot-scope="">{{ detailData.requsitionIn }}</template>
        </el-table-column>

        <el-table-column
          align="center"
          label="备注"
          prop="remark"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
    </div>

    <div v-if="isExamine">
      <div class="main-title">
        <div class="title">审批记录</div>
      </div>
      <div class="diy-table-1">
        <el-row :gutter="0">
          <el-col :span="12" class="item">
            <div class="label">审批人</div>
            <div class="value">{{ detailData.approvalName }}</div>
          </el-col>
          <el-col :span="12" class="item">
            <div class="label">审批结果</div>
            <div class="value">{{ detailData.examineStatus | statusFilter }}</div>
          </el-col>
          <el-col :span="24" class="item">
            <div class="label">审批说明</div>
            <div class="value">{{ detailData.approvalRemark }}</div>
          </el-col>
        </el-row>
      </div>
    </div>

    <div class="page-footer">
      <div class="footer" :class="classObj">
        <el-button @click="goBack">关 闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getDetail } from '@/api/supply/direct'

export default {
  name: 'DirectDetail',
  componentName: 'DirectDetail',
  props: ['listItem'],
  filters: {
    statusFilter(val) {
      const MAP = [
        { label: '已保存', value: 'SAVE' },
        { label: '待审核', value: 'WAIT' },
        { label: '审核通过', value: 'OK' },
        // { label: '审核驳回', value: 'FAIL' },,
        { label: '已关闭', value: 'CLOSE' }
      ]
      let obj = MAP.find(o => o.value == val)
      return obj ? obj.label : ''
    },
    orderTypeFilter(val) {
      const MAP = [
        { label: '商用工程订单', value: 'TRADE' },
        { label: '家用工程订单', value: 'HOME' },
        { label: '零售单', value: 'RETAIL' },
        { label: '销售政策单', value: 'RETAIL_POLICY' }
      ]
      let obj = MAP.find(o => o.value == val)
      return obj ? obj.label : ''
    },
    typeFilter(val) {
      const MAP = {
        1: '组织内调拨'
      }
      return MAP[val]
    }
  },
  data() {
    return {
      detailData: {}
    }
  },

  computed: {
    sidebar() {
      return this.$store.state.app.sidebar
    },
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened
      }
    },
    isExamine() {
      return this.detailData.examineStatus === 'OK' || this.detailData.examineStatus === 'FAIL'
    }
  },

  created() {
    this.getDetail()
  },

  methods: {
    // 返回列表
    goBack() {
      this.$emit('backListFormDetail')
    },

    // 获取详情
    getDetail() {
      getDetail({ id: this.listItem.id }).then(res => {
        this.detailData = res.data
      })
    }
  }
}
</script>

<style scoped lang="scss">
.detail-container {
  width: 100%;
  height: 100%;
}
.main-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  height: 60px;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 20px;
  .title {
    font-size: 16px;
    font-weight: 600;
    padding-left: 10px;
  }
}
</style>
