<!--
 * @Author: 曹捷
 * @Date: 2021-03-25 11:32:15
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-03-25 15:21:59
 * @Description: fileContent
-->
<template>
  <a-modal class="obit-modal-default" v-if="showModal" :maskClosable="false" title="选择用户" v-model:visible="showModal"
    @cancel="closeDialog" @ok="saveInfo" cancelText="取消" okText="确认" width="60%">
    <obitUniversalTable name="" :pagination="pagination" v-if="$fmt(['sys_normal_disable'])">
      <template #search>
        <obit-search-form :params="params" :paramList="paramList" @search="pageQuery(true)">
        </obit-search-form>
      </template>
      <a-table :loading="pageLoading" rowKey="userId" :columns="tableColumns" :dataSource="pageDataList"
        :scroll="{ x: '100%' }" :row-selection="rowSelection" :pagination="false" class="obit-atable"
        highlight-current-row style="width: 100%">
      </a-table>
    </obitUniversalTable>
  </a-modal>
</template>
<script>
import { getCurrentInstance, inject, reactive, toRefs, watch } from 'vue'
import { util } from '../../../entery'
import { useRoute, useRouter } from 'vue-router'
import page from './../../../hook/page.js'

export default {
  props: {
    open: {
      type: Boolean
    },
  },
  setup (props, context) {
    let route = useRoute()
    let pageIns = page({
      url: 'system/role/authUser/unallocatedList',
      key: 'userId',
      getQueryParam () {
        return route.query;
      }
    })
    let http = inject('http')
    let { proxy } = getCurrentInstance()
    let _data = reactive({
      showModal: props.open,
      pageSelectionList: [],
      rowSelection: {
        onChange: (selectedRowKeys, selectedRows) => {
          _data.pageSelectionList = selectedRowKeys
        }
      },
      tableColumns: [
        { dataIndex: 'userName', title: '用户名称', width: 120 },
        { dataIndex: 'nickName', title: '用户昵称', width: 120 },
        { dataIndex: 'email', title: '邮箱', width: 200 },
        { dataIndex: 'phonenumber', title: '手机', width: 150 },
        { dataIndex: 'status', customRender: ({ text, record, index }) => proxy.$fmt('sys_normal_disable', text), title: '状态', width: 100 },
        { dataIndex: 'createTime', title: '创建时间', width: 180 },
      ],
      paramList: [
        { name: '用户名称', key: 'userName' },
        { name: '手机号码', key: 'phonenumber' },
      ],
    })
    let _methods = {
      closeDialog () {
        context.emit('reload')
        context.emit('update:open', false)
      },
      saveInfo () {
        let param = {
          userIds: util.util.cloneObj(_data.pageSelectionList),
          roleId: route.query.roleId
        }
        http.saveSystemRoleSelectAll(param).then((res) => {
          proxy.$message.success('授权成功')
          _methods.closeDialog()
        })
      },
    }
    watch(() => props.open, (value) => {
      pageIns._method.pageQuery()
    })
    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
      ..._methods,
    }
  },
}
</script>
<style lang="less">
.ant-checkbox-group {
  width: 100%;
}
.bind-modal {
  .ant-modal-body {
    padding: 0;
    padding-top: 20px;
    .fromTitle {
      padding: 0;
    }
    .role-tree {
      padding: 10px 20px;
    }
    .ant-layout {
      padding: 0;
      background: #fff;
    }
  }
}
</style>