<!--
  @description: 采购计划-集采计划已打包列表表格数据
  @author: lxl
  @date： 2020-11-02 13:32
-->
<template>
  <el-table
    ref="smallTable"
    v-loading="loading"
    :data="tableData"
    @sort-change="sortChange"
  >
    <el-table-column
      key="2"
      type="index"
      label="序号"
      width="60px"
      align="center"
      fixed="left"
    />
    <el-table-column
      sortable="custom"
      prop="tenderNo"
      label="采购单编号"
      min-width="150"
      header-align="center"
      fixed="left"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseNo"
      min-width="150"
      label="行项目编号"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseCode"
      min-width="150"
      label="物资编码"
      align="center"
      fixed="left"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseName"
      min-width="150"
      label="物资名称"
      header-align="center"
      fixed="left"
    />
    <el-table-column
      header-align="center"
      sortable="custom"
      prop="tenderMethod"
      min-width="150"
      label="采购方式"
    >
      <template slot-scope="scope">
        {{ filterDictText(tenderMethodList, scope.row.tenderMethod) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="tenderType"
      min-width="120"
      label="公开/邀请"
    >
      <template slot-scope="scope">
        {{ filterDictText(tenderTypeList, scope.row.tenderType) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="supplierAttribute"
      min-width="150"
      label="供应商属性"
      header-align="center"
    >
      <template slot-scope="scope">
        {{ filterDictText(supplierAttributeList, scope.row.supplierAttribute) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="supplierCategory"
      min-width="150"
      label="供应商分类"
      header-align="center"
    >
      <template slot-scope="scope">
        {{ filterDictText(supplierCategoryList, scope.row.supplierCategory) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="reviewMethod"
      min-width="150"
      label="评审办法"
      header-align="center"
    >
      <template slot-scope="scope">
        {{ filterDictText(reviewMethodList, scope.row.reviewMethod) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="purchaseBrand"
      width="150"
      label="品牌"
      header-align="center"
    />
    <el-table-column
      prop="purchaseClassificationParent"
      width="150"
      label="一级专业分类"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseClassification"
      min-width="150"
      label="二级专业分类"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseSpecification"
      min-width="220"
      label="物资描述"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseNum"
      width="110"
      label="数量"
      header-align="center"
      align="right"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseUnit"
      min-width="100"
      align="center"
      label="计量单位"
    >
      <template slot-scope="scope">
        {{ filterDictText(purchaseUnitList, scope.row.purchaseUnit) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="purchaseBudget"
      min-width="130"
      label="预算净单价(元)"
      header-align="center"
      align="right"
    >
      <template slot-scope="scope">
        {{ scope.row.purchaseBudget && numFilter(scope.row.purchaseBudget) }}
      </template>
    </el-table-column>
    <el-table-column
      key="19"
      sortable="custom"
      prop="purchaseTotalBudget"
      min-width="130"
      label="预算净总价(元)"
      header-align="center"
      align="right"
    >
      <template slot-scope="scope">
        {{ scope.row.purchaseTotalBudget && numFilter(scope.row.purchaseTotalBudget) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="purchaseTaxRate"
      min-width="150"
      label="税率(%)"
      header-align="center"
    >
      <template slot-scope="scope">
        {{ filterDictText(taxRateList,scope.row.purchaseTaxRate) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="deliveryTime"
      min-width="110"
      label="交货日期"
      align="center"
    >
      <template slot-scope="scope">
        {{ scope.row.deliveryTime && $Moment(scope.row.deliveryTime).format(momentDate) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      prop="deliveryAddress"
      min-width="220"
      label="交货地点"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseDepartName"
      min-width="220"
      label="采购单位"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="purchaseUserRealName"
      min-width="150"
      label="上报人"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="remark"
      min-width="220"
      label="备注"
      header-align="center"
    />
    <el-table-column
      header-align="center"
      sortable="custom"
      prop="purchaseUserRealName"
      min-width="150"
      label="采购员"
    />
    <el-table-column
      sortable="custom"
      prop="purchasePlanNo"
      min-width="150"
      label="采购计划编号"
      align="center"
      header-align="center"
    />
    <!-- 计划编号 -->
    <el-table-column
      min-width="180"
      prop="ykPlanno"
      label="计划编号"
      header-align="center"
      align="center"
    />
    <!-- 计划名称 -->
    <el-table-column
      min-width="180"
      prop="ykPlannoT"
      label="计划名称"
      header-align="center"
    />
    <el-table-column
      sortable="custom"
      prop="createTime"
      min-width="110"
      label="创建日期"
      align="center"
    >
      <template slot-scope="scope">
        {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDate) }}
      </template>
    </el-table-column>
    <el-table-column
      sortable="custom"
      min-width="160"
      label="打包时间"
      align="center"
      prop="bizApplicationTime"
    />
    <el-table-column
      sortable="custom"
      prop="approvalTime"
      min-width="110"
      label="批准日期"
      align="center"
    >
      <template slot-scope="scope">
        {{ scope.row.approvalTime && $Moment(scope.row.approvalTime).format(momentDate) }}
      </template>
    </el-table-column>
    <el-table-column
      header-align="center"
      sortable="custom"
      min-width="120"
      label="操作人员"
      prop="bizApplication"
    />
    <el-table-column
      sortable="custom"
      min-width="180"
      prop="bizAuditStatus"
      label="审核状态"
      align="center"
    >
      <template slot-scope="scope">
        {{ filterDictText(auditStatusList, scope.row.bizAuditStatus) }}
      </template>
    </el-table-column>
    <el-table-column
      width="80"
      fixed="right"
      label="附件"
      align="center"
    >
      <template slot-scope="scope">
        <el-link v-if="scope.row.isContainAttachment==='1'" type="primary" @click.stop="checkAccessory(scope.row)">
          查看
        </el-link>
      </template>
    </el-table-column>
    <!-- 操作 -->
    <el-table-column
      fixed="right"
      width="180"
      label="操作"
      align="center"
    >
      <template slot-scope="scope">
        <el-link
          type="primary"
          @click.stop="handleCancel(scope.row)"
        >
          [查看采购方案]
        </el-link>
        <template v-if="scope.row.bizAuditStatus!=='03'">
          <el-link v-if="purchasplanPackAuditConfig" type="primary" @click.stop="handleFlow(scope.row)">
            [流程追踪]
          </el-link>
        </template>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import { filterDictText, numFilter } from '@/assets/js/utils' // 字典方法
import { purPlanBaleMixins } from './mixins/purPlanBaleMixins' // 工作流配置（是否启用工作流）
export default {
  name: 'AlreadyTable',
  mixins: [purPlanBaleMixins],
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      tenderMethodList: [], // 采购方式
      tenderTypeList: [], // 公开邀请
      supplierAttributeList: [], // 供应商属性
      supplierCategoryList: [], // 供应商分类
      reviewMethodList: [], // 评审办法
      // collectionTypeList: [], // 是否集采
      purchaseUnitList: [], // 计量单位
      taxRateList: [], // 税率
      auditStatusList: [], // 审核状态
      dictionaryType: ['tenderMethod', 'tenderType', 'supplierAttribute', 'supplierCategory', 'reviewMethod', 'purchaseUnit', 'taxRate', 'auditStatus']
    }
  },
  created() {
    this.getGroupType() // 字典请求初始化
    this.purchasplanPackAudit() // 获取是否工作流提交
  },
  methods: {
    filterDictText, // 字典
    numFilter, // 金额
    // 字典请求
    getGroupType() {
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 附件查看
    checkAccessory(row) {
      this.$emit('checkFile', row)
    },
    // 流程追宗
    handleFlow(row) {
      this.$emit('flowTrace', row)
    },
    // 编辑 - 暂时隐藏
    subBale(row) {
      this.$emit('subBaleFlow', row)
    },
    // 查看采购方案
    handleCancel(row) {
      this.$emit('viewPackInfo', row)
    },
    // 排序
    sortChange: function(column, prop, order) {
      let orderType = ''
      switch (column.order) {
        case 'ascending':
          orderType = 'ASC'
          break
        case 'descending':
          orderType = 'DESC'
          break
      }
      this.$emit('orderData', { column: column.prop, orderSort: orderType })
    }
  }
}
</script>
