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

    <div class="main-top">
      <div class="title">置换方式</div>
      <el-radio-group v-model="type">
        <!-- <el-radio :label="1">订单置换</el-radio> -->
        <el-radio :label="2">批量置换</el-radio>
      </el-radio-group>
    </div>

    <div class="order-info">
      <div>订单号：{{ detailData[0][0].orderId }}</div>
      <div>经销商：{{ detailData[0][0].customerName }}（{{ detailData[0][0].customerNumber }}）</div>
      <div>订单类型：{{ detailData[0][0].orderType | orderTypeFilter }}</div>
    </div>

    <div class="main-title">
      <div class="title">置换记录</div>
    </div>
    <div class="table" v-for="(item, index) in detailData" :key="index">
      <el-table :data="item" element-loading-text="Loading" border fit highlight-current-row stripe>
        <el-table-column
          align="left"
          label="置换日期"
          prop="createTime"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column align="left" label="" min-width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.isOld ? '旧机' : '新机' }}
          </template>
        </el-table-column>
        <el-table-column
          align="left"
          label="销售类型"
          prop="saleTypeName"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="left"
          label="物料编码"
          prop="materialNumber"
          min-width="120"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="left"
          label="产品名称"
          prop="materialName"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="left"
          label="规格型号"
          prop="specification"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="right"
          label="置换数量"
          prop="displaceQty"
          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="left"
          label="返利类型"
          prop="customerWalletName2"
          min-width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="right"
          label="使用返利金额"
          prop="singleRebateAmount"
          min-width="100"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ scope.row.singleRebateAmount | 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="left"
          label="现金钱包"
          prop="customerWalletName"
          min-width="100"
          show-overflow-tooltip
        ></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>
    </div>
  </div>
</template>

<script>
import { getDisplaceDetail } from '@/api/supply/displace'

export default {
  name: 'DisplaceDetail',
  componentName: 'DisplaceDetail',
  props: ['listItem'],
  filters: {
    orderTypeFilter(val) {
      const MAP = {
        HOME: '家用工程订单',
        TRADE: '商用工程订单',
        RETAIL: '其他零售订单',
        RETAIL_POLICY: '销售政策订单'
      }
      return MAP[val]
    }
  },
  data() {
    return {
      type: 2,
      detailData: {}
    }
  },

  created() {
    this.getDetail()
  },

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

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

<style scoped lang="scss">
.detail-container {
  width: 100%;
  height: 100%;
}
.main-top {
  display: flex;
  align-items: center;
  height: 60px;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 20px;
  margin-top: 20px;
  .title {
    font-size: 16px;
    padding-left: 10px;
    font-weight: 600;
  }
  .el-radio-group {
    margin-left: 30px;
  }
}
.order-info {
  display: flex;
  font-size: 14px;
  div {
    margin-right: 30px;
  }
}
</style>
