<!--
 * @Author: 曹捷
 * @Date: 2021-03-15 14:54:07
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-06-04 17:26:11
 * @Description: 岗位管理
-->
<template>
  <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>
    <template #btn>
      <a-button  @click="exportData" class="m-r-15">
         下 载
      </a-button>
      <a-button type="primary" @click="addDialog">
        <i class="iconfont icon-add-bold p-r-5"></i> 新 增
      </a-button>
    </template>
    <a-table class="obit-atable" :columns="tableColumns" :data-source="pageDataList" :pagination="false" :row-selection="rowSelection"  rowKey="postSort">
      <template #dept="{record}">
        {{record.dept.deptName}}
      </template>
      <template #operation="{ record}" :key="record.userId">
        <a-button type="link" class="operation-btn" @click="editDialog(record)">编辑</a-button>
        <a-button type="link" class="operation-btn" @click="remove(record)"> 删除</a-button>
      </template>
    </a-table>
  </obitUniversalTable>
  <postAdd :addType="pageType" v-model:open="pageVisable" :detailsInfo="detailsInfo" @reload="pageQuery(true)">
  </postAdd>
</template>

<script>
import { getCurrentInstance, inject, onMounted, reactive, toRefs } from 'vue'
import page from './../../../hook/page.js'
import postAdd from './postAdd.vue'
export default {
  components: { postAdd, },
  setup (props, contenxt) {
    let { proxy } = getCurrentInstance()
    let http = inject('http')
    let pageIns = page({
      url: 'system/post/pageList',
      key: 'postId',
      removeUrl: 'system/post/remove',
    })
    let _data = reactive({
      roleVisable: false,
      userId: '',
      name: '',
      tableColumns: [
        { dataIndex: 'postId', title: '岗位编号' , width: '110px'},
        { dataIndex: 'postCode', title: '岗位编码' , width: '110px'},
        { dataIndex: 'postName', title: '岗位名称' , width: '110px'},
        { dataIndex: 'postSort', title: '岗位排序' , width: '110px'},
        { dataIndex: 'status', title: '状态', customRender: ({ text, record, index }) => proxy.$fmt('sys_normal_disable', text), width: '80px' },
        { dataIndex: 'createTime', title: '创建时间' , width: '180px'},
        { title: '操作', slots: { customRender: 'operation' } , width: '180px'},
      ],
      paramList: [
        { name: '岗位编码', key: 'postCode' },
        { name: '岗位名称', key: 'postName' },
        {
          type: 'ajax',
          key: 'status',
          name: '状态',
          valuename: 'dictValue',
          labelname: 'dictLabel',
          ajaxurl: 'system/dict/data/type/sys_normal_disable',
        },
      ],
    })
    let _methods = {
      exportData(){
        console.log('pageDataList', http)
        let params = {
          // pageNum: 1,
          // pageSize: 10
        }
        let config = {
        //   // fileName一般由后台传递 
        //   // 目前系统和后端约定 fileName 为response.headers['filename'].xlsx
          // fileName: '岗位数据表' + ".docx"
          fileName: '岗位数据表' + ".xlsx"
        //   // fileName: tableNames + ".zip"
        }
        http.downloadFile('system/post/export', params, config, 'post');

        // http.downloadFile('system/post/export', params, config, 'post').then(data => {
        //   console.log(data)
        // })
      }
    }
    onMounted(() => {
      pageIns._method.pageQuery()
    })
    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
      ..._methods,
    }
  },
}
</script>

<style>
</style>