<template>
  <ele-pro-table
    ref="table"
    :needPage="false"
    :columns="competAnalysisListcolumns"
    :toolkit="[]"
    :datasource="productList"
    row-key="id"
  >
    <template v-slot:toolbar>
      <div class="headbox">
        <span class="amount" v-if="isSinglePrice"
          >总计：{{ form.totalPrice || form.totalAmount }}元</span
        >
<!--  v-if="isDiscountTotalPrice"       -->
        <span class="amount"
          style="margin-left: 12px">优惠总金额：{{ form.discountTotalPrice || form.payAmount }}元</span>
      </div>
    </template>

    <template v-slot:technicalDrawings="{ row }">
      <div v-if="row.technicalDrawings && row.technicalDrawings?.length">
        <el-link
          v-for="link in row.technicalDrawings"
          :key="link.id"
          type="primary"
          :underline="false"
          @click="downloadFile(link)"
        >
          {{ link.name }}</el-link
        >
      </div>
    </template>
    <template v-slot:industryArtFiles="{ row }">
      <div v-if="row.industryArtFiles && row.industryArtFiles?.length">
        <el-link
          v-for="link in row.industryArtFiles"
          :key="link.id"
          type="primary"
          :underline="false"
          @click="downloadFile(link)"
        >
          {{ link.name }}</el-link
        >
      </div>
    </template>
    <template v-slot:otherFiles="{ row }">
      <div v-if="row.otherFiles && row.otherFiles?.length">
        <el-link
          v-for="link in row.otherFiles"
          :key="link.id"
          type="primary"
          :underline="false"
          @click="downloadFile(link)"
        >
          {{ link.name }}</el-link
        >
      </div>
    </template>
    <template v-slot:customerReqFiles="{ row }">
      <div v-if="row.customerReqFiles && row.customerReqFiles?.length">
        <el-link
          v-for="link in row.customerReqFiles"
          :key="link.id"
          type="primary"
          :underline="false"
          @click="downloadFile(link)"
        >
          {{ link.name }}</el-link
        >
      </div>
    </template>
    <template v-slot:sendTotalCount="{ row }">
      <el-link type="primary" @click="toSendTab">{{row.sendTotalCount}}</el-link>
    </template>
  </ele-pro-table>
</template>
<script>
  import {getFile} from "@/api/system/file";

  export default {
    props: {
      contractStartDate: {},
      isDiscountTotalPrice: {
        default: false,
        type: Boolean
      },
      isDeliveryDeadline: {
        default: true,
        type: Boolean
      },
      isGuaranteePeriod: {
        default: true,
        type: Boolean
      },
      isCustomerMark: {
        default: true,
        type: Boolean
      },
      isSinglePrice: {
        default: true,
        type: Boolean
      },
      contractBookType: {
        default: 1
      }
    },
    data() {
      return {
        competAnalysisListcolumns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            width: 200,
            prop: 'productName',
            label: '名称',
            slot: 'productName',
            align: 'center'
          },
          {
            width: 120,
            prop: 'productCode',
            label: '编码',
            slot: 'productCode',
            align: 'center'
          },
          {
            width: 200,
            prop: 'productCategoryName',
            label: '类型',
            slot: 'productCategoryName',
            align: 'center'
          },
          {
            width: 160,
            prop: 'productBrand',
            label: '牌号',
            slot: 'productBrand',
            align: 'center'
          },
          {
            width: 120,
            prop: 'modelType',
            label: '型号',
            slot: 'modelType',
            align: 'center'
          },
          {
            width: 120,
            prop: 'specification',
            label: '规格',
            slot: 'specification',
            align: 'center'
          },
          {
            width: 160,
            prop: 'customerMark',
            label: '客户代号',
            slot: 'customerMark',
            show: this.isCustomerMark,
            align: 'center'
          },
          {
            width: 120,
            prop: 'totalCount',
            label: '数量',
            slot: 'totalCount',
            align: 'center'
          },
          {
            width: 120,
            prop: 'sendTotalCount',
            label: '已发货数量',
            slot: 'sendTotalCount',
            align: "center"
          },
          {
            width: 120,
            prop: 'notSendTotalCount',
            label: '未发货数量',
            slot: 'notSendTotalCount',
            align: "center"
          },
          {
            width: 120,
            prop: 'measuringUnit',
            label: '计量单位',
            slot: 'measuringUnit',
            align: 'center'
          },
          {
            width: 120,
            prop: 'singleWeight',
            label: '单重',
            slot: 'singleWeight',
            align: 'center'
          },
          {
            width: 120,
            prop: 'totalWeight',
            label: '总重',
            slot: 'totalWeight',
            align: 'center'
          },
          {
            width: 120,
            prop: 'weightUnit',
            label: '重量单位',
            slot: 'weightUnit',
            align: 'center'
          },

          {
            width: 160,
            prop: 'singlePrice',
            label: '单价',
            slot: 'singlePrice',
            show:this.isSinglePrice,
            align: 'center'
          },
          {
            width: 160,
            prop: 'discountSinglePrice',
            label: '折让单价',
            show:this.isSinglePrice,
            align: 'center',
            formatter: (_row, _column, cellValue) => {
              return _row.discountSinglePrice
                ? Number(_row.discountSinglePrice).toFixed(2)
                : '';
            }
          },

          {
            width: 120,
            prop: 'totalPrice',
            label: '合计',
            slot: 'totalPrice',
            formatter: (_row, _column, cellValue) => {
              return _row.totalPrice?_row.totalPrice + '元':'';
            },
            align: 'center'
          },
          {
            width: 120,
            prop: 'discountTotalPrice',
            label: '折让合计',
            slot: 'discountTotalPrice',
            formatter: (_row, _column, cellValue) => {
              return _row.discountTotalPrice?_row.discountTotalPrice + '元':'';
            },
            align: 'center'
          },



          // {
          //   width: 120,
          //   prop: 'deliveryDays',
          //   label: '交期(天)',
          //   slot: 'deliveryDays'
          // },
          // {
          //   width: 160,
          //   prop: 'deliveryDeadline',
          //   label: '交期截止日期',
          //   slot: 'deliveryDeadline',
          //   show: this.isDeliveryDeadline
          // },
          {
            width: 160,
            prop: 'customerExpectDeliveryDeadline',
            label: this.contractBookType == 1 ? '客户期望交期' : '交付日期',
            slot: 'customerExpectDeliveryDeadline',
            align: 'center'
          },
          {
            width: 160,
            prop: 'produceDeliveryDeadline',
            label: '生产交付交期',
            slot: 'produceDeliveryDeadline',
            show: this.contractBookType == 1 ? true : false,
            align: 'center'

          },
          {
            width: 200,
            prop: 'guaranteePeriod',
            label: '质保期',
            slot: 'guaranteePeriod',
            formatter: (_row, _column, cellValue) => {
              return (_row.guaranteePeriod||'') + _row.guaranteePeriodUnitName;
            },
            align: 'center'
          },
          {
            width: 200,
            prop: 'guaranteePeriodDeadline',
            label: '质保期截止日期',
            slot: 'guaranteePeriodDeadline',
            show: this.isGuaranteePeriod,
            align: 'center'
          },
          // {
          //   width: 120,
          //   prop: 'guaranteePeriodUnitCode',
          //   label: '',
          //   slot: 'guaranteePeriodUnitCode'
          // },
          {
            width: 220,
            prop: 'customerReqFiles',
            label: '客户需求',
            slot: 'customerReqFiles',
            align: 'center'
          },
          {
            width: 120,
            prop: 'technicalAnswerName',
            label: '技术答疑人',
            slot: 'technicalAnswerName',
            align: 'center'
          },
          {
            width: 220,
            prop: 'technicalParams',
            label: '技术参数',
            slot: 'technicalParams',
            align: 'center'
          },
          {
            width: 240,
            prop: 'technicalDrawings',
            label: '技术图纸',
            slot: 'technicalDrawings',
            align: 'center'
          },
          {
            width: 240,
            prop: 'technologyRouteName',
            label: '工艺路线',
            slot: 'technologyRouteName',
            show: this.contractBookType == 1 ? true : false

          },
          {
            width: 240,
            prop: 'industryArtFiles',
            label: '工艺附件',
            slot: 'industryArtFiles',
            align: 'center'
          },
          {
            width: 240,
            prop: 'otherFiles',
            label: '其他附件',
            slot: 'otherFiles',
            align: 'center'
          },
          {
            width: 220,
            prop: 'remark',
            label: '备注',
            slot: 'remark',
            align: 'center'
          }
        ],
        form: {},
        productList: []
      };
    },
    computed: {},

    methods: {
      toSendTab(){
        this.$emit('toSendTab','invoice')
      },
      //修改回显
      putTableValue(data) {
        let productList =
          (data && (data.redressProductList||data.quoteProductList || data.productList)) || [];
        if (data) {
          this.form = data;
          this.productList = productList;
        }
      },
      downloadFile(file) {
        getFile({ objectName: file.storePath }, file.name);
      },
    }
  };
</script>
<style lang="scss" scoped></style>
