<!--
 * @Description: 项目经理（集团外用户）-录入采购计划代理机构弹窗
 * @Author:lxl
 * @Date: 2020-08-3 14:04:30
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.consignContractVisible"
    append-to-body
    :close-on-click-modal="false"
    title="选择执行机构"
    width="700px"
  >
    <section class="p0-16">
      <!--查询条件-->
      <div class="clearfix">
        <el-form ref="searchForm" :model="searchForm" inline @submit.native.prevent>
          <!--执行机构名称-->
          <el-form-item
            label="执行机构名称"
            prop="purchasePlanName"
          >
            <gx-input
              v-model.trim="searchForm.departname"
            />
          </el-form-item>
          <el-form-item class="fr">
            <el-button
              type="primary"
              @click="onSearch('searchForm')"
            >
              搜索
            </el-button>
            <el-button
              plain
              type="info"
              @click="resetForm('searchForm')"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-table
          :data="list"
          :row-class-name="tableRowClassName"
          :row-style="selectedHighlight"
          width="100%"
          highlight-current-row
          @row-click="rowClick"
        >
          <el-table-column
            type="index"
            label="序号"
            width="50"
          />
          <el-table-column
            header-align="center"
            align="left"
            prop="departname"
            label="执行机构名称"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="orgCode"
            label="统一社会信用代码"
          />
        </el-table>
        <pagination :pagination-data="paginationData" @change="loadData" />
      </div>
    </section>
    <!--底部操作按钮-->
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogData.consignContractVisible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
/* 接口*/
import { getDepartList } from '@/api/procurement/commonUser'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
// import { mapGetters } from 'vuex'
export default {
  name: 'OrganizationDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {

      }
    }
  },
  data() {
    return {
      searchForm: {
        departname: '', // 机构名称
        departRoleName: '11'// 主体类型 10-招标人||11-招标代理机构||12-投标人
      },
      title: '执行机构',
      list: [], // 列表数据
      currentData: []// 当前选择的信息
    }
  },
  computed: {
    // ...mapGetters(['language'])
  },
  watch: {
    // 监听-弹框展示状态
    'dialogData.consignContractVisible'(val) {
      if (val) {
        // 清楚数据
        this.searchForm.departname = ''
        // 加载数据
        this.loadData()
      }
    }
  },
  methods: {
    // 点击一行获取下标
    rowClick(row) {
      this.getIndex = row.index
    },
    // 获取表格内每一行下标
    selectedHighlight({ row, rowIndex }) {
      row.index = rowIndex
    },
    // 给选中的一行添加样式
    tableRowClassName({ row, rowIndex }) {
      if (this.getIndex === rowIndex) {
        return 'procurement_pith_on'
      }
    },
    // 选择机构-确定
    ensure() {
      if (typeof this.getIndex === 'number') {
        let data = {}
        data = {
          departname: this.list[this.getIndex].departname,
          id: this.list[this.getIndex].id
        }
        this.$emit('consignContractInfo', data)
        this.dialogData.consignContractVisible = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      getDepartList(params).then(response => {
        this.list = response.data.results
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    onReset() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 搜索
    onSearch() {
      this.onReset()
    },
    // 重置
    resetForm() {
      this.searchForm.departname = ''
      this.onReset()
    }
  }
}
</script>

<style scoped lang="less">

</style>
