/*
 * @Company: 沈阳信诚科技
 * @Email: html_venustar@163.com
 * @Author: Liuqiming
 * @Description: 岗位配置
 * @LastEditors: Liuqiming
 * @LastEditTime: 2024-03-06 14:09:46
 * @Date: 2024-02-04 16:56:20
 */

const handleUpdateFn = ref(null)
const handleDeleteFn = ref(null)
const handleUserNumFn = ref(null)
const deptListVal = ref([])


export const init = (proxy, { handleUpdate, handleDelete, deptList, handleUserNum }) => {
  handleUpdateFn.value = handleUpdate
  handleDeleteFn.value = handleDelete
  handleUserNumFn.value = handleUserNum
  deptListVal.value = deptList


  
  const { sys_normal_disable } = proxy.useDict("sys_normal_disable"); 
  const { sys_user_sex } = proxy.useDict("sys_user_sex"); 
  // 表格筛选条件
  const searchList = ref([
    // {
    //   label: '岗位编码',
    //   field: 'postCode',
    //   clearable: true,
    //   placeholder: '请输入岗位编码',
    // },
    {
      label: '岗位名称',
      field: 'postName',
      placeholder: '请输入岗位名称'
    },
    {
      label: '部门',
      field: 'deptId',
      // type: 'cascader',
      type: 'treeSelect',
      props: { value: 'deptId', label: 'deptName', children: 'children' },
      clearable: true,
      placeholder: '请选择部门',
      options: deptListVal.value
    }
  ])
  // 表格配置按钮
  const btnList = ref([
    { label: '新增岗位', type: 'primary', plain: false, icon: 'Plus', met: 'handleAdd', hasPermi:'system:post:add' },
  ])
  // 表格配置项
  const tableOption = ref({
    checkbox: false, // 是否展示多选框
    index: true, // 是否展示序号
    fixed: "", // 是否将多选框及序号列固定在最左侧
    stripe: true, // 是否斑马纹表格
    border: false, // 是否表格边框
    pageHidden: false // 是否隐藏分页
  })
  // 表格列
  const columns = ref([
    // {
    //   label: "岗位编码",
    //   prop: "postCode",
    //   minWidth: 100
    // },
    {
      label: "岗位名称",
      prop: "postName",
      minWidth: 100,
    },
    // {
    //   label: "岗位排序",
    //   prop: "postSort",
    //   minWidth: 100,
    // },
    {
      label: "部门名称",
      prop: "deptName",
      minWidth: 100,
    },
    {
      label: "使用人数",
      prop: "relateUserNum",
      minWidth: 100,
      slots: (row) => {
        return <el-button type="primary" link onClick={()=>{handleUserNumFn.value(row)}}>{row.relateUserNum}</el-button>
      }
    },
    // {
    //   label: "状态",
    //   prop: "status",
    //   minWidth: 100,
    //   slots: (row) => {
    //     return <dict-tag options={sys_normal_disable.value} value={row.status} />
    //   }
    // },
    {
      label: "创建时间",
      prop: "createTime",
      sort: true,
      minWidth: 100,
      slots: (row) => {
        return <span>{ proxy.parseTime(row.createTime) }</span>
      }
    },
    {
      label: "操作",
      minWidth: 100,
      slots: (row) => {
        if (row.relateUserNum == 0) {
          return (<>
            <el-button type="primary" link onClick={()=>{handleUpdateFn.value(row)}} v-hasPermi={['system:post:edit']}>修改</el-button>
            <el-button type="danger" link onClick={()=>{handleDeleteFn.value(row)}} v-hasPermi={['system:post:remove']}>删除</el-button>
          </>)
        } else {
          return <el-button type="primary" link onClick={()=>{handleUpdateFn.value(row)}} v-hasPermi={['system:post:edit']}>修改</el-button>
        }
      }
    },
  ])
  // 分页配置
  const pageSet = ref({
    pageNum: 1,
    pageSize: 10,
    total:0
  })
  // 表单元素
  const fieldList = ref([
    {
      label: '岗位名称',
      field: 'postName',
      width: '400px',
      rules: [{ required: true, message: "岗位名称不能为空", trigger: "blur" }],
      placeholder: '请输入岗位名称'
    },
    // {
    //   label: '岗位编码',
    //   field: 'postCode',
    //   width: '270px',
    //   rules: [{ required: true, message: "岗位编码不能为空", trigger: "blur" }],
    //   placeholder: '请输入岗位编码'
    // },
    {
      label: '岗位顺序',
      field: 'postSort',
      type: 'number',
      hidden: true,
      width: '320px',
      rules: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }],
      placeholder: ''
    },
    {
      label: '所属部门',
      field: 'deptId',
      // type: 'cascader',
      type: 'treeSelect',
      width: '400px',
      props: { value: 'deptId', label: 'deptName', children: 'children' },
      clearable: true,
      rules: [{ required: true, message: "所属部门不能为空", trigger: "change" }],
      placeholder: '请选择所属部门',
      options: deptList
    },
    {
      label: '备注',
      field: 'remark',
      type: 'textarea',
      max: 100,
      width: '400px',
      placeholder: '请输入备注内容'
    },
    // {
    //   label: '岗位状态',
    //   field: 'status',
    //   type: 'radio',
    //   radioButton: false,
    //   options: sys_normal_disable
    // },
  ])
  // 表单配置项
  const formOption = ref({
    inline: false,
    labelWidth: '80px',
    scrollToError: true,
    btnCenter: true,
    labelPosition: 'right',
    btn: ['submit', 'cancel']
  })
  // 使用人数弹窗表格配置
  const userTableOption = ref({
    fixed: "", // 是否将多选框及序号列固定在最左侧
    stripe: true, // 是否斑马纹表格
    pageHidden: false // 是否隐藏分页
  })
  // 分页配置
  const userPageSet = ref({
    pageNum: 1,
    pageSize: 10,
    total:0
  })
  const userColumns = ref([
    {
      label: "员工编号",
      prop: "userName",
      minWidth: 100
    },
    {
      label: "姓名",
      prop: "nickName",
      minWidth: 100,
    },
    {
      label: "性别",
      prop: "sex",
      minWidth: 100,
      slots: (row) => {
        return <span>{ row.sex ? sys_user_sex.value.find(item => item.value === row.sex).label : '' }</span>
      }
    },
    {
      label: "手机号码",
      prop: "phonenumber",
      minWidth: 100,
    },
  ])
  return {
    searchList,
    btnList,
    columns,
    pageSet,
    tableOption,
    fieldList,
    formOption,
    userTableOption,
    userPageSet,
    userColumns
  }
}

