<!--
 * @Description: 项目经理（集团外用户）-录入采购计划项目经理弹窗
 * @Author:lxl
 * @Date: 2020-08-3 14:01:30
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.consignContractVisible"
    append-to-body
    :close-on-click-modal="false"
    title="选择项目经理"
    width="700px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <div class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline @submit.native.prevent>
        <!--代理机构名称-->
        <el-form-item
          ref="realName"
          label="项目经理"
          prop="realName"
        >
          <gx-input
            v-model.trim="searchForm.realName"
          />
        </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>
    <section>
      <el-table
        :row-key="getRowKey"
        :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="realName"
          label="姓名"
        />
        <el-table-column
          header-align="center"
          align="center"
          prop="mobilePhone"
          label="联系电话"
        />
      </el-table>
      <pagination :pagination-data="paginationData" @change="loadData" />
    </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 { selectUserInfoListByRoleCodes } 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: 'ManagerDialog',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin],
  props: {
    // 弹框展示状态
    dialogData: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      searchForm: {
        departId: '', // 机构id
        realName: '', // 真实姓名
        roleCodes: '20' // 角色编码
      },
      title: '项目经理',
      list: [] // 列表数据
    }
  },
  // computed: {
  //   ...mapGetters(['language'])
  // },
  watch: {
    // 监听-弹框展示状态
    'dialogData.consignContractVisible'(val) {
      if (val) {
        // 清空历史数据
        this.searchForm.departId = ''
        this.searchForm.realName = ''
        // 加载数据
        this.loadData()
      }
    }
  },
  created() {
  },
  methods: {
    // 指定一个key标识这一行的数据
    getRowKey(row) {
      return row.id
    },
    // 点击一行获取下标
    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 = {
          realName: this.list[this.getIndex].realName,
          roleCode: this.list[this.getIndex].roleCode,
          userId: this.list[this.getIndex].userId,
          mobilePhone: this.list[this.getIndex].mobilePhone
        }
        this.$emit('consignMangContractInfo', data)
        this.dialogData.consignContractVisible = false
      } else {
        this.$message({
          message: `请选择${this.title}`,
          type: 'warning'
        })
      }
    },
    // 加载数据
    loadData() {
      const params = this.getParams()// 查询条件
      selectUserInfoListByRoleCodes(params).then(response => {
        this.list = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

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

<style scoped lang="less">

</style>
