<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      width="1100px"
      height="500px"
      @close="close"
      @keyup.enter.native="getContact"
      :visible.sync="visible">
      <div style="height: calc(100% - 80px);">
<!--        <el-form size="small" :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>-->
<!--          &lt;!&ndash; 搜索框&ndash;&gt;-->
<!--          <el-form-item label="联系人姓名" prop="name">-->
<!--            <el-input size="small" v-model="searchForm.name" placeholder="请输入联系人姓名" clearable></el-input>-->
<!--          </el-form-item>-->

<!--          <el-form-item>-->
<!--            <el-button type="primary" @click="list()" size="small" icon="el-icon-search">查询</el-button>-->
<!--            <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>-->
<!--          </el-form-item>-->
<!--        </el-form>-->

        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="400px"
          :loading="loading"
          size="small"
          ref="contactTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          :print-config="{}"
          @sort-change=""
          :sort-config="{remote:true}"
          :data="dataList"
          :checkbox-config="{}">
          <vxe-column type="seq" width="40"></vxe-column>
          <vxe-column type="checkbox" width="40px"></vxe-column>

          <vxe-column width="" title="联系人姓名" field="name"></vxe-column>
          <vxe-column width="" title="联系方式1" field="linkPhone"></vxe-column>
          <vxe-column width="" title="联系方式2" field="linkMobile"></vxe-column>

        </vxe-table>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="getContact()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import InputNumber from '@/views/modules/sys/workContract/InputNumber.vue'
  import WorkClientService from '@/api/sys/WorkClientService'
  import SelectUserTree from '@/views/modules/utils/treeUserSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        dataList: [],
        searchForm: {
          ids: [],
          id: '',
          name: '',
          deputy: ''
        },
        rowId: ''
      }
    },
    workClientService: null,
    created () {
      this.workClientService = new WorkClientService()
    },
    components: {
      SelectUserTree,
      InputNumber
    },
    methods: {
      init (ids, deputy) {
        // if (!this.commonJS.isEmpty(id)) {
        //   this.$refs.workContractTable.setCurrentRow(id)
        // }
        this.searchForm.ids = ids
        this.searchForm.deputy = deputy
        this.visible = true
        this.list()
      },
      // 表单提交
      getContact () {
        let rows = this.$refs.contactTable.getCheckboxRecords()
        if (this.commonJS.isEmpty(rows)) {
          this.$message.error('请是至少选择一条数据')
          return
        }
        let list = []
        if (!this.commonJS.isEmpty(rows)) {
          rows.forEach(item => {
            let p = {
              id: item.id,
              contacts: item.name,
              linkMobilePhoneFirst: item.linkPhone,
              linkMobilePhoneSecoed: item.linkMobile,
              job: '',
              remarks: ''
            }
            list.push(p)
          })
        }
        this.close()
        this.$emit('getContact', list, this.searchForm.deputy)
      },
      list () {
        this.dataList = []
        this.searchForm.ids.forEach((item) => {
          this.workClientService.findById(item).then((data) => {
            console.log(data.data.workClientLinkman)
            data.data.workClientLinkman.forEach(i => {
              this.dataList.push(i)
            })
          })
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.list()
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.list()
      },
      close () {
        this.visible = false
      }
    }
  }
</script>
