<!--
  @description:月度计划信息列表弹窗
  @Modifier:zyy
  @routerPath:
  @date:2021/4/21-14:52
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="projectDialog"
    :close-on-click-modal="false"
    title="选择月度计划"
    width="840px"
    append-to-body
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <div class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="计划编号" prop="purchasePlanNo">
          <el-input
            v-model.trim="searchForm.purchasePlanNo"
            placeholder="计划编号"
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item label="计划名称" prop="purchasePlanName">
          <el-input
            v-model.trim="searchForm.purchasePlanName"
            placeholder="计划名称"
            style="width: 150px"
          />
        </el-form-item>
        <el-form-item class="fr">
          <el-button
            type="primary"
            @click="search('searchForm')"
          >
            搜索
          </el-button>
          <el-button
            plain
            type="info"
            @click="resetForm('searchForm')"
          >
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        ref="singleTable"
        v-loading="loading"
        :data="list"
        class="pointer"
        highlight-current-row
        size="mini"
        @current-change="currentChange"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          prop="purchasePlanNo"
          align="center"
          label="计划编号"
          width="160"
        />
        <el-table-column
          header-align="center"
          prop="purchasePlanName"
          label="计划名称"
          min-width="230"
        />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="projectDialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { getPurchasePlanMainDetailList } from '@/api/contractManagement/index' // 月度计划
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
import { filterDictText } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
// import { initGroupMixin } from '@/mixins/initGroupMixin'
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
export default {
  name: 'PurchasePlanDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, procurementGroupMixins],
  data() {
    return {
      loading: true,
      projectDialog: false, // 弹框打开状态
      // 搜索信息
      searchForm: {
        purchasePlanNo: '', // 项目编号
        purchasePlanName: '' // 项目名称
      },
      list: [], // 列表数据
      currentData: {}// 当前选择的信息
    }
  },
  created() {
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 打开弹框
    openProjectInfoDialog() {
      this.searchForm.purchasePlanNo = '' // 打开弹框清空
      this.searchForm.purchasePlanName = '' // 打开弹框清空
      this.loadData()
      this.projectDialog = true // 打开弹框
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getPurchasePlanMainDetailList(params).then(response => {
        this.loading = false
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.contractSource = '00'
      return filterObj(param)// 过滤空的key
    },
    // 选择信息-确定
    ensure() {
      if (this.currentData) {
        this.$emit('dialogDataInfo2', this.currentData)
        this.projectDialog = false
      } else {
        this.$message({
          message: `请选择计划`,
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
