<!--
 * @Description: 项目经理（集团外用户）-行项目信息组件
 * @Author:lxl
 * @Date: 2020-08-3 13:58:30
-->
<template>
  <div>
    <el-table ref="smallTable" :data="lineProjectData">
      <el-table-column
        type="index"
        label="序号"
        width="60"
        align="center"
        fixed
      />
      <el-table-column
        header-align="center"
        min-width="180"
        align="left"
        prop="purchaseNo"
        label="行项目编号"
        fixed
      />
      <el-table-column
        header-align="center"
        min-width="160"
        align="left"
        prop="purchaseCode"
        label="物资编码"
        fixed
      />
      <el-table-column
        header-align="center"
        align="left"
        prop="purchaseName"
        min-width="230"
        label="物资名称"
      />
      <el-table-column
        header-align="center"
        min-width="220"
        prop="purchaseDepartName"
        label="采购单位"
      />
      <!-- <el-table-column
        header-align="center"
        align="left"
        prop="purchaseType"
        min-width="150"
        label="类型"
      /> -->
      <el-table-column
        header-align="center"
        align="left"
        prop="purchaseClassificationParent"
        min-width="230"
        label="一级专业分类"
      />
      <el-table-column
        header-align="center"
        align="left"
        prop="purchaseClassification"
        min-width="230"
        label="二级专业分类"
      />
      <el-table-column
        header-align="center"
        align="left"
        prop="purchaseSpecification"
        min-width="160"
        label="物资规格"
      />
      <el-table-column
        header-align="center"
        align="right"
        width="110"
        prop="purchaseNum"
        label="数量"
      />
      <el-table-column
        header-align="center"
        align="left"
        width="120"
        label="计量单位"
      >
        <template slot-scope="scope">
          <p>
            {{ filterDictText(purchaseUnitList,scope.row.purchaseUnit ) }}
          </p>
        </template>
      </el-table-column>
      <el-table-column header-align="center" label="税率（%）" align="left" min-width="150">
        <template slot-scope="scope">
          {{ filterDictText(taxRateList,scope.row.purchaseTaxRate) }}
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="right"
        min-width="120"
        label="预算净单价(元)"
      >
        <template slot-scope="scope">
          <p>{{ scope.row.purchaseBudget && numFilter(scope.row.purchaseBudget) }}</p>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="right"
        min-width="140"
        label="预算净总价(元)"
      >
        <template slot-scope="scope">
          <p>{{ scope.row.purchaseTotalBudget && numFilter(scope.row.purchaseTotalBudget) }}</p>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        min-width="180"
        prop="deliveryTime"
        label="交货时间"
      />

      <el-table-column
        header-align="center"
        align="left"
        min-width="230"
        label="交货地点"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.deliveryAreaName">{{ scope.row.deliveryAreaName.replace(/,/g,'') }}</span><span>{{ scope.row.deliveryAddress }}</span>
        </template>
      </el-table-column>
      <!-- 采购单位-暂时隐藏 -->
      <!-- <el-table-column
        header-align="center"
        align="left"
        min-width="180"
        prop="purchaseDepartName"
        label="采购单位"
      /> -->
      <el-table-column
        header-align="center"
        align="left"
        min-width="220"
        label="备注"
      >
        <template slot-scope="scope">
          <span>
            {{ scope.row.remark }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        min-width="80"
        align="center"
        label="附件"
      >
        <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
        v-if="detailIder!=='00'"
        fixed="right"
        header-align="center"
        label="操作"
        align="center"
        min-width="180"
      >
        <template slot-scope="scope">
          <el-link
            :underline="false"
            size="mini"
            plain
            type="primary"
            @click="editRow(scope.row)"
          >
            [编辑]
          </el-link>
          <el-link
            :underline="false"
            size="mini"
            plain
            type="primary"
            @click="deleteRow(scope.row)"
          >
            [移除]
          </el-link>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
/* api接口*/
// import { deletePurchasePlanDetail } from '@/api/procurement/purchasplan'
/* 公共方法*/
import { numFilter, filterDictText } from '@/assets/js/utils' // 金额转换千分位
export default {
  name: 'AddlineItemTable',
  props: {
    lineProjectData: {
      type: Array,
      default: function() {
        return []
      }
    },
    detailIder: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      /* -----------数据字典start-------------*/
      purchaseUnitList: [], // 计量单位
      taxRateList: [], // 税率
      dictionaryType: ['purchaseUnit', 'taxRate'],
      /* -----------数据字典end-------------*/
      // 查看行项目物资附件弹框-展示/隐藏状态 true 展示/false 隐藏
      attachmentDialog: {
        consignContractVisible: false
      },
      purchaserType: this.$route.params.purchaserType // 项目组织形式 00 自采 01 代理采购
    }
  },
  created() {
    this.getGroupType()// 字典请求初始化
  },
  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]
          }
        }
      })
    },
    // 编辑行项目信息
    editRow(row) {
      const data = {
        planDetailId: row.planDetailId, // 计划id
        planAdd: '01' // 00 编辑 01 回显
      }
      this.$emit('planDetail', data)
    },
    // 附件查看
    checkAccessory(row) {
      this.$emit('checkFile', row, true)
    },
    // 移除行项目信息
    deleteRow(row) {
      this.$emit('deleteItem', row)
      // this.$confirm('此操作将删除该行项目信息, 是否继续?', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   confirmButtonClass: 'confirmBtn',
      //   cancelButtonClass: 'cancelBtn',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     if (row.planDetailId) {
      //       const params = {
      //         planDetailId: row.planDetailId
      //       }
      //       deletePurchasePlanDetail(params).then(res => {
      //         this.$emit('watchData', true)
      //         this.$message.success(res.header.msg)
      //       }).catch((error) => {
      //         this.$message.warning(error)
      //       })
      //     }
      //   })
      //   .catch(() => {})
    }
  }
}
</script>

<style lang='less' scoped>
</style>
