<script>
import {queryQuoteGroupDetailByInquiry} from "../../../../api/quote/quoteGroupDetail";

export default {
  name: "inquiryQuoteDetail",
  props:{
    quotation: {
      type:Object,
      required:true
    },
    height:{
      type: [String,Number],
      default:"47vh",
    }
  },
  data(){
    return{
      queryLoading:false,
      dataList:[],
      columns: [
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2QuoteVersionNo',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'quoteVersionNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '报价单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2QuoteDate',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'quoteDate',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '报价日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2PartNo',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2PartDesc',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 240
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'qty',
          headerAlign: 'center',
          align: 'right',
          columnLabel: 'MOQ',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'unitPrice',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '未税单价',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'taxRate',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '税率',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'exchangeRate1',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '其他税率',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'taxUnitPrice',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '含税单价(CNY)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'currencyDesc2',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '币种',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'exchangeRate2',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '汇率',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Qty',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'currencyTotalCost2',
          headerAlign: 'center',
          align: 'right',
          columnLabel: '含税单价',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 102001,
          serialNumber: '102001Table2Remark',
          tableId: '102001Table2',
          tableName: '报价详情信息表',
          columnProp: 'remark',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
      ],
    };
  },
  methods:{
    handleQuery(){
      let params = {
        internalInquiryNo: this.quotation.quotationNo,
        site: this.quotation.site
      }
      this.queryLoading = true;
      queryQuoteGroupDetailByInquiry(params).then(({data})=>{
        if (data && data.code === 0){
          this.dataList = data.rows;
        }else {
          this.$message.warning(data.msg);
        }
        this.queryLoading = false;
      }).catch((error)=>{
        this.$message.error(error)
        this.queryLoading = false;
      })
    },
    handleClickDetail(row){
      if (this.$router.resolve('/quote-index').resolved.name === '404') {
        this.$alert('权限不足,访问失败', '警告', {confirmButtonText: '确定',})
      } else {
        this.$router.push({
          name: 'quote-index',
          params:{
            quoteVersionNo:row.quoteVersionNo,
            type:'project'
          }
        })
      }
    }
  },
  watch:{
    "quotation"(newVal,oldVal){
      if (newVal && newVal.site && newVal.quotationNo){
        this.handleQuery();
      }else {
        this.dataList = [];
      }
    }
  }
}
</script>

<template>
  <div>
    <el-table :height="height" :data="dataList" border v-loading="queryLoading" style="margin-top: 5px">
      <el-table-column label="操作" min-width="80px" fixed="left" align="center">
        <template slot-scope="scope">
          <a @click="handleClickDetail(scope.row)">详情</a>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columns" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed===''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope" >
          <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<style scoped>

</style>
