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

    <div id="printData">
      <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.deliverDate }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">单据状态</div>
            <div class="value">已受理</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">订单号</div>
            <div class="value">{{ detailData.orderNo }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">订单类型</div>
            <div class="value">{{ detailData.orderType | typeFilter }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">工程编号</div>
            <div class="value">{{ detailData.projectNo }}</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.serviceName }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">币种</div>
            <div class="value">{{ detailData.amountType }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">仓库</div>
            <div class="value">{{ detailData.correspondName }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">仓位</div>
            <div class="value">{{ detailData.stockName }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">台账备注</div>
            <div class="value">{{ detailData.aaa }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">项目名称</div>
            <div class="value">{{ detailData.projectName }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">厂工程编码</div>
            <div class="value">{{ detailData.factoryNo }}</div>
          </el-col>
          <el-col :span="16" class="item">
            <div class="label">备注</div>
            <div class="value">{{ detailData.remark }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">文件编号</div>
            <div class="value">{{ detailData.fileNo }}</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.items"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
          max-height="400"
          show-summary
          :summary-method="$getSummaries"
        >
          <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
          <el-table-column
            align="center"
            label="物料编码"
            prop="materialNumber"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="产品编码"
            prop="materialOldNumber"
            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="right"
            label="申请数量"
            prop="directTransferQty"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column align="right" label="含税单价" prop="price" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.price | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="right" label="无税单价" prop="afterTaxPrice" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.afterTaxPrice | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="right" label="价税合计" prop="mustTotalAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.mustTotalAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="right"
            label="税率"
            prop="taxRate"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column align="right" label="折扣额" prop="discAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.discAmount | numToFixed }}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="page-footer">
      <div class="footer">
        <el-button type="primary" icon="el-icon-printer" v-print="printObj">打 印</el-button>
        <el-popconfirm title="确定关闭吗？" @onConfirm="goBack" style="margin-left: 10px">
          <el-button slot="reference">关 闭</el-button>
        </el-popconfirm>
      </div>
    </div>
  </div>
</template>

<script>
import print from 'vue-print-nb'
import { getDetail } from '@/api/supply/adjust'

export default {
  name: 'AdjustDetail',
  componentName: 'AdjustDetail',
  props: ['listItem'],
  directives: {
    print
  },
  filters: {
    typeFilter(val) {
      const typeList = [
        { label: '商用工程订单', value: 'TRADE' },
        { label: '家用工程订单', value: 'HOME' },
        { label: '零售订单', value: 'RETAIL' },
        { label: '销售政策订单', value: 'RETAIL_POLICY' }
      ]
      let obj = typeList.find(o => o.value == val)
      return obj ? obj.label : ''
    }
  },
  data() {
    return {
      printObj: {
        id: 'printData'
      },
      detailData: {}
    }
  },

  created() {
    this.getDetail()
  },

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

    // 获取详情
    getDetail() {
      getDetail({ id: this.listItem.deliverNo }).then(res => {
        if (res.data.items) {
          res.data.items.forEach(item => {
            item.sums1 = ['directTransferQty']
            item.sums2 = ['afterTaxPrice', 'price', 'mustTotalAmount', 'discAmount']
          })
        }
        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: 30px;
  height: 60px;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 20px;
  .title {
    font-size: 16px;
    font-weight: 600;
    padding-left: 10px;
  }
}
</style>
