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

    <div id="printMe">
      <div class="main-title">
        <div class="title">退货单信息</div>
      </div>
      <div class="diy-table-1">
        <el-row :gutter="0">
          <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.createBy }}</div>
          </el-col>
          <el-col :span="8" class="item">
            <div class="label">单据日期</div>
            <div class="value">{{ detailData.retreatTime }}</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="24" class="item">
            <div class="label">备注</div>
            <div class="value">{{ detailData.remark }}</div>
          </el-col>
        </el-row>
      </div>

      <div class="table" style="margin-top: 20px">
        <el-table
          :data="detailData.retreatDocumentOrder"
          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="mainOrderId"
            min-width="200"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="发货单号"
            prop="invoiceId"
            min-width="180"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="仓库名称"
            prop="correspondName"
            min-width="120"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="产品编号"
            prop="materialCode"
            min-width="160"
            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="num"
            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="payAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.payAmount | 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="noTotalAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.noTotalAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="right" label="价税合计" prop="payAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.payAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="right"
            label="税率"
            prop="tax"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="right"
            label="使用返利金额"
            prop="payRebateAmount"
            min-width="120"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ scope.row.payRebateAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column align="right" label="折扣金额" prop="totalDiscAmount" min-width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.totalDiscAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="退补标记"
            prop="status"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="厂产品代码"
            prop="materialOldNumber"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="业务员"
            prop="serviceName"
            min-width="100"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="center"
            label="备注"
            prop="remark"
            min-width="160"
            show-overflow-tooltip
          ></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-button @click="goBack">关 闭</el-button>
      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'ReturnDetail',
  componentName: 'ReturnDetail',
  props: ['listItem'],
  directives: {
    print
  },
  data() {
    return {
      printObj: {
        id: 'printMe'
      },
      detailData: {}
    }
  },

  created() {
    this.getDetail()
  },

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

    // 获取详情
    getDetail() {
      getDetail({ id: this.listItem.id }).then(res => {
        if (res.data.retreatDocumentOrder) {
          res.data.retreatDocumentOrder.forEach(item => {
            item.sums1 = ['num']
            item.sums2 = ['payAmount', 'price', 'payRebateAmount', 'totalDiscAmount', 'afterTaxPrice', 'noTotalAmount']
          })
        }
        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>
