<!--
 * @Description: 结果执行管理-选择采购项目
 * @Author:hdk
 * @Date: 2020-11-11 09:59:05
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="dialogData.checkProjectVisible"
      :before-close="handleClose"
      :title="addprocItemTxt[dialogData.planType]"
      append-to-body
      custom-class="el-dialog__body-p8 el-dialog_table"
      width="1000px"
    >
      <section class="clearfix">
        <div class="fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            label-width="98px"
            label-position="left"
            inline
            @submit.native.prevent
          >
            <el-form-item ref="tenderNo" label="采购单编号" prop="tenderNo">
              <el-input v-model.trim="searchForm.tenderNo" @keyup.enter.native="onSearch" />
            </el-form-item>
            <el-form-item ref="purchaseName" label="物资名称" prop="purchaseName">
              <el-input v-model.trim="searchForm.purchaseName" @keyup.enter.native="onSearch" />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <section>
        <el-table
          ref="singleTable"
          v-loading="loading"
          class="pointer"
          :data="tableData"
          highlight-current-row
          @row-click="singleElection"
          @current-change="currentChange"
        >
          <!-- 选择-->
          <el-table-column label="选择" align="center" width="60">
            <template slot-scope="scope">
              <el-radio v-model="materialRowId" :label="scope.$index">
                {{ '' }}
              </el-radio>
            </template>
          </el-table-column>
          <el-table-column
            type="index"
            width="60px"
            align="center"
            label="序号"
          />
          <el-table-column
            prop="tenderNo"
            label="采购单编号"
            header-align="center"
            align="left"
            min-width="230"
          />
          <el-table-column
            prop="tenderMethod"
            label="采购方式"
            min-width="180"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              {{ filterDictText(tenderMethodList, scope.row.tenderMethod) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseNo"
            label="行项目编号"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseCode"
            label="物资编码"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseName"
            label="物资名称"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="suppliersName"
            label="供货厂商"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseBrand"
            label="品牌"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseClassificationParent"
            width="150"
            label="一级专业分类"
            header-align="center"
          />
          <el-table-column
            prop="purchaseClassification"
            label="二级专业分类"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseSpecification"
            label="物资描述"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="resultAffirmNo"
            label="结果执行编号"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="collectionType"
            label="是否集采"
            min-width="180"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              {{ filterDictText(collectionTypeList, scope.row.collectionType) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseNum"
            label="数量"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseUnit"
            label="计量单位"
            min-width="180"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              {{ filterDictText(purchaseUnitList, scope.row.purchaseUnit) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="purchaseBudget"
            label="预算净单价（元）"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            label="税率（%）"
            min-width="150"
            header-align="center"
            align="left"
          >
            <template slot-scope="scope">
              {{ filterDictText(taxRateList,scope.row.purchaseTaxRate) }}
            </template>
          </el-table-column>
          <el-table-column sortable="custom" 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
            prop="deliveryAddress"
            label="交货地点"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseDepartName"
            label="采购单位"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseUserRealName"
            label="上报人"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="remark"
            label="备注"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchaseBuyer"
            label="采购员"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="purchasePlanNo"
            label="采购计划编号"
            min-width="180"
            header-align="center"
            align="left"
          />
          <el-table-column
            sortable="custom"
            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="110"
            label="批准日期"
            align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.approvalTime && $Moment(scope.row.approvalTime).format(momentDate) }}
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="purchaseName"
            label="附件"
            min-width="180"
            header-align="center"
            align="left"
          /> -->
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ensure">
          {{ language.Determine }}
        </el-button>
        <el-button @click="handleClose">
          {{ language.cancel }}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
/* 接口*/
import { getPurchasePlanOpenBidPackList, selectProtPlanPurchaseDetailsPack } from '@/api/procurement/purchasplan.js' // 获取角色信息
/* 公共组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
/* 公共混入*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { rstMgmtMixins } from '../mixins/rstMgmtMixins'
/* 公共方法*/
import { filterObj, restoreInitialValue, filterDictText } from '@/assets/js/utils'
import { mapGetters } from 'vuex'
export default {
  name: 'SelectPurItemDialog',
  components: {
    pagination // 分页组件
  },
  mixins: [ListMixin, rstMgmtMixins],
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return {
          checkProjectVisible: false,
          executeId: '', // 执行单ID
          planType: '00' // 区分新增招标和框架的新增结果执行 00 招标采购项目 01框架采购项目
        }
      }
    },
    callBack: {
      type: Function,
      default: function() {
      }
    }
  },
  data() {
    return {
      loading: false,
      materialRowId: '', // 单选选择的物料id
      roleData: {}, // 选择信息
      tableData: [], // 表格数据
      searchForm: {}, // 搜索参数
      addprocItemTxt: {
        '00': '选择采购项目',
        '01': '选择框架项目'
      }
    }
  },
  computed: {
    ...mapGetters(['language', 'info'])
  },
  watch: {
    'dialogData.checkProjectVisible'(val) {
      if (val) {
        this.loadData()
      }
    }
  },
  created() {
  },
  methods: {
    // 数据字典查询
    filterDictText,
    // 数据请求方法
    loadData() {
      this.loading = true
      this.materialRowId = ''
      // 查询条件
      const params = this.getQueryParams()
      // 获取采购项目列表
      getPurchasePlanOpenBidPackList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 关闭弹窗
    handleClose() {
      this.dialogData.checkProjectVisible = false
    },
    // 指定一个key标识这一行的数据
    getRowKey(row) {
      return row.id
    },
    // 查询条件
    getQueryParams() {
      this.searchForm.pageNo = this.paginationData.pageNo
      this.searchForm.pageSize = this.paginationData.pageSize
      this.searchForm.planType = this.dialogData.planType
      return filterObj(this.searchForm)
    },
    // 点击行设置单选按钮选中
    singleElection(row) {
      this.materialRowId = this.tableData.indexOf(row)
    },
    // 当前选择的信息
    currentChange(val) {
      this.roleData = val
    },
    // 确定
    ensure() {
      if (!this.dialogData.executeId || !this.roleData.tenderId) {
        this.$message.warning('请选择采购项目')
        return false
      }
      const params = {
        executeId: this.dialogData.executeId, // 执行单ID
        tenderId: this.roleData.tenderId // 采购单ID
      }
      // 录入结果执行，确定选择采购单
      selectProtPlanPurchaseDetailsPack(params).then(response => {
        this.callBack() // 查询项目信息
        this.$emit('callBack', this.roleData)
        this.handleClose()
      }).catch(() => {
      })
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 查询数据
      this.loadData()
    },
    // 重置
    resetForm() {
      // 清除数据
      restoreInitialValue(this.searchForm)
      // 查询数据
      this.onSearch()
    }
  }
}
</script>

<style scoped>

</style>
