<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1100px"
      height="500px"
      @close="close"
      @keyup.enter.native="getContact"
      v-model="visible">
      <div style="height: calc(100% - 80px);">

        <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-config="{remote:true}"
          :data="dataList"
		  :key="clientTableKey"
          :checkbox-config="{}">
          <vxe-column type="seq" width="40"></vxe-column>
          <vxe-column type="checkbox" width="50px"></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>
		<template #footer>
			<span slot="footer" class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button type="primary" v-if="method != 'view'" @click="getContact()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>

    </el-dialog>
  </div>
</template>

<script>
  import WorkClientService from '@/api/sys/WorkClientService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
		  clientTableKey: '',
        dataList: [],
        searchForm: {
          ids: [],
          id: '',
          name: '',
          deputy: ''
        },
        rowId: ''
      }
    },
    workClientService: null,
    created () {
      this.workClientService = new WorkClientService()
    },
    components: {
    },
    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)
            data.workClientLinkman.forEach(i => {
              this.dataList.push(i)
            })
			  this.clientTableKey = Math.random()
          })
        })
      },
      // 当前页
      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>
