<!--
  @description: 委托代理合同-选择委托人弹框
  @Modifier：肖文龙
  @routerPath:
  @date：  2019-11-28 14:31:27
-->
<template>
  <el-dialog
    :visible.sync="dialogData.dialog"
    :close-on-click-modal="false"
    :lock-scroll="false"
    title="选择招标人"
    width="840px"
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <!--搜索-->
    <section class="clearfix">
      <el-form ref="agencyForm" :model="agencyForm" inline>
        <el-form-item label="招标人编号" prop="orgCode">
          <el-input v-model="agencyForm.orgCode" placeholder="招标人编号" style="width: 228px" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item label="招标人名称" prop="departName">
          <el-input v-model="agencyForm.departName" placeholder="招标人名称" style="width: 228px" @keyup.enter.native="search" />
        </el-form-item>
        <el-form-item class="fr">
          <el-button type="primary" @click="search('agencyForm')">
            搜索
          </el-button>
          <el-button plain type="info" @click="resetForm('agencyForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </section>
    <!--查询列表-->
    <section>
      <el-table
        ref="singleTable"
        :data="agencyData"
        class="pointer"
        highlight-current-row
        @current-change="handleParameterCurrentChange"
      >
        <el-table-column type="index" label="序号" align="center" width="50" />
        <el-table-column prop="orgCode" label="招标人编号" align="center" width="160" />
        <el-table-column prop="departName" label="招标人名称" align="left" min-width="300" header-align="center" />
        <el-table-column prop="linkerName" label="联系人" align="center" />
        <el-table-column prop="mobilePhone" label="手机号" align="center" />
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="showBuyersDialog" />
    </section>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialogData.dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getDepartListByDepartRoleName } from '@/api/common/user.js'

import pagination from '@comp/common/pagination/pagination'
import { filterObj } from '@/assets/js/utils'
import { ListMixin } from '@/mixins/ListMixin'
export default {
  name: 'AgencyDialog',
  components: {
    pagination
  },
  mixins: [ListMixin],
  props: {
    dialogData: {
      type: Object,
      default: function() {
        return
      }
    }
  },
  data() {
    return {
      // 查询参数
      agencyForm: {
        orgCode: '',
        departName: '',
        pageSize: 10,
        pageNo: 1
      },
      agencyCurrentRow: '',
      agencyData: [] // 渲染代理机构弹框表格
    }
  },
  watch: {
    'dialogData.dialog'(val) {
      if (val) {
        this.agencyForm.orgCode = ''
        this.agencyForm.departName = ''
        this.showBuyersDialog()
      }
    }
  },
  methods: {
    // 点击选择委托人
    handleParameterCurrentChange(val) {
      this.agencyCurrentRow = val
    },
    // 选择采购人列表弹框获取数据
    showBuyersDialog() {
      this.dialogData.dialog = true
      this.loadData()
    },
    // 加载数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      params.departRoleName = '10'
      getDepartListByDepartRoleName(params).then(response => {
        this.agencyData = response.data.results
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.agencyForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 选择委托人重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.loadData()
    },
    // 选择采购人 搜索
    search() {
      this.paginationData.page = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 委托人信息确定按钮
    ensure() {
      if (this.agencyCurrentRow) {
        this.$emit('buyersInfo', this.agencyCurrentRow, '10')
        this.dialogData.dialog = false
      } else {
        this.$message({
          message: '请选择委托人',
          type: 'warning'
        })
      }
    }
  }
}
</script>

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