/*
 *    Copyright (c) 2018-2025, cyweb All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 */

import {ROLE_CODE} from "../../../../config/global";
import {getDetailsByName,getDetailsByCode} from "@/api/asset/assetdept/assetdept";
var validaterName = (rule, value, callback) => {
  getDetailsByName(value).then(response => {
    if (window.boxType === 'edit') callback()
    let result = response.data.data;
    if (result != null && result != undefined) {
      callback(new Error('部门名称已经存在'))
    } else {
      callback()
    }
  });
};

var validaterCode = (rule, value, callback) => {
  getDetailsByCode(value).then(response => {
    if (window.boxType === 'edit') callback()
    let result = response.data.data;
    if (result != null && result != undefined) {
      callback(new Error('部门编号已经存在'))
    } else {
      callback()
    }
  });
};

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  align: 'center',
  editBtn: false,
  delBtn: false,
  addBtn: false,
  dic: [],
  column: [
    // {
    //   label: '',
    //   prop: 'id'
    // },
    // {
    //   label: '创建人',
    //   prop: 'createBy'
    // },
    // {
    //   label: '创建时间',
    //   prop: 'createTime'
    // },
    // {
    //   label: '更新人',
    //   prop: 'updateBy'
    // },
    // {
    //   label: '更新时间',
    //   prop: 'updateTime'
    // },
    // {
    //   label: '开始年份',
    //   prop: 'startYear'
    // },

    // {
    //   label: '删除标志位',
    //   prop: 'delFlag'
    // },
    // {
    //   label: '租户id',
    //   prop: 'tenantId'
    // },
    {
      label: '部门编码',
      prop: 'deptCode',
      search:true,
      type: 'input',  // 控件类型
      maxlength: 5,   //长度限制  0/n
      span: 24,
      addDisplay:true, //添加是否显示
      editDisplay:true, //修改是否显示
      rules: [{          //自定义规则
        required: true,
        trigger: 'blur',
        message:"请填写部门编码"
      },
        {validator: validaterCode, trigger: 'blur'}]
    },
    {
      label: '部门名称',
      prop: 'deptName',
      search:true,
      type: 'input',  // 控件类型
      maxlength: 10,   //长度限制  0/n
      span: 24,
      addDisplay:true, //添加是否显示
      editDisplay:true, //修改是否显示
      rules: [{          //自定义规则
        required: true,
        trigger: 'blur',
        message:"请填写部门名称"
      },
        {validator: validaterName, trigger: 'blur'}
      ]
    },
    {
      span: 24,
      label: '部门成员',
      prop: 'deptMember',
      slot: true,
      overHidden: true,
      type: 'select',
      multiple:true,
      remote: true,
      props: {
        label: 'realName',
        value: 'realName'
      },
      dicUrl: '/professional/teacherbase/queryTeacherBaseByNo/{{key}}',
      rules: [{
        required: true,
        message: '请设置部门成员',
        trigger: 'blur'
      }],
    },
    {
      label: '备注',
      prop: 'remarks',
      type: 'textarea',
      span: 24,
      minRows: 2,
      maxlength: 250,   //长度限制  0/n
      addDisplay:true, //添加是否显示
      editDisplay:true, //修改是否显示
    }

  ]
}
