import { Tag } from '@arco-design/web-vue'
import { h } from 'vue'
import { passwordRule, passwordWithBlankRule } from '@/rules/user-rules'
import { phoneRule } from '@/rules/login-rules'
import { useUserStore } from '@/store/user'
import { TableOption } from '@/types'

const userStore = useUserStore()
const option: TableOption = {
  api: {
    base: '/sys/tenant',
    page: '/page/res',
    add: '/add'
  },
  permissionPrefix: 'sys_tenant_',
  permissions: userStore.permissions,
  viewBtn: { display: false },
  delBtn: { display: false },
  columns: [
    {
      name: '租户名称',
      prop: 'name',
      editDisabled: true,
      rules: [
        { required: true, message: '名称不能为空' },
        { minLength: 3, message: '名称不少于3个字符' },
        { maxLength: 50, message: '不能超过50个字符' }
      ]
    },
    {
      name: 'Logo',
      prop: 'logo',
      type: 'upload',
      listType: 'picture-card',
      limit: 1,
      // 上传图片专用接口，
      // size=128表示宽高最大不能超过此值(会按比例缩放)，
      // scale=0.5表示缩小50%，
      // quality=0.8表示，
      // rotate=90表示旋转90度
      // base64=1表示返回的是base64
      action: '/sys/file/upload/image?size=80&quality=0.8',
      urlOnly: true
    },
    {
      name: '超管姓名',
      prop: 'fullName',
      editDisabled: true,
      rules: [
        { required: true, message: '不能为空' },
        { minLength: 2, message: '不少于2个字符' },
        { maxLength: 20, message: '不能超过20个字符' }
      ]
    },
    {
      name: '超管手机号',
      prop: 'phone',
      editDisabled: true,
      addRules: phoneRule
    },
    {
      name: '超管密码',
      prop: 'password',
      display: false,
      addDisplay: true,
      editDisplay: true,
      editTooltip: '当密码不为空时，将会修改该租户超管密码',
      rules: passwordRule,
      editRules: passwordWithBlankRule
    },
    {
      name: '活跃用户数限制',
      prop: 'activeUserNumberLimit',
      type: 'number',
      min: 0,
      max: 100000000,
      value: 0,
      tooltip: '为0表示不限制租户活跃用户数',
      rules: [{ required: true, message: '不能为空' }]
    },
    {
      name: '套餐',
      prop: 'packageIds',
      type: 'select',
      placeholder: '请选择套餐',
      dicUrl: '/sys/package/list',
      allowClear: true,
      allowSearch: true,
      props: {
        value: 'id',
        label: 'name'
      },
      multiple: true,
      searchMultiple: false,
      rules: [{ required: true, message: '套餐不能为空' }]
    },
    {
      name: '锁定',
      prop: 'isLock',
      width: 150,
      value: false,
      type: 'switch',
      addDisplay: false,
      editDisplay: true,
      formatValue: (record: any) => {
        return h(
          Tag,
          { color: record.isLock ? 'orangered' : '' },
          { default: () => [h('span', record.isLock ? '是' : '否')] }
        )
      }
    },
    {
      name: '过期时间',
      prop: 'expirationDate',
      type: 'date',
      tooltip: '为空表示默认为2999-12-31'
    }
  ]
}
export default option
