import { SERVICE_PLATFORM_POWER_BASE } from '@/config/serviceSettings.js'

/**
 * 角色
 * */
 export const roleAttr = {
  placeholder: '请选择角色',
  targetClick: true,
  targetValueKey: 'name',
  remoteUrl: { url: SERVICE_PLATFORM_POWER_BASE + '/userpower/getRole', method: 'get' },
  rowKey: 'id',
  toolBar: {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
    items: [
      { type: 'input', name: 'name', label: '角色名称' },
      { type: 'input', name: 'num', label: '角色编码' },
    ],
   },
   modalConfig: {
    title: '角色'
  },
   tableConfig: {
    pagination: 9999,
    rowSelectType: 2,
    scroll: { x: true,y:300},
    columns: [
      { dataIndex: 'name', title: '角色名称' },
      { dataIndex: 'num', title: '角色编码' },
    ],
  },
 }


/**
 * 用户
 * */
export const userAttr = {
  placeholder: '请选择用户',
  targetClick: true,
  targetValueKey: 'nickname',
  remoteUrl: { url: SERVICE_PLATFORM_POWER_BASE + '/userpower/getEnterpriseUsers', method: 'get' },
  rowKey: 'id',
  modalConfig: {
    title: '用户'
  },
  toolBar: {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
    items: [
      { type: 'input', name: 'name', label: '查询条件', placeholder: '请输入用户编码/名称', value: '' }
    ]
  },

  tableConfig: {
    rowSelectType: 2,
    scroll: { x: true,y:300},
    pagination:9999,
    columns: [
      { dataIndex: 'nickname', title: '用户名称' },
      { dataIndex: 'username', title: '用户账号' }
    ]
  }
}

export const matchTable = (self) => {
  return [
    {
      dataIndex: 'noticeToId',
      type: 'txt',
      title: 'noticeToId',
      hidden: true
    },
    {
      dataIndex: 'noticeToName',
      type: 'searchModal',
      title: '角色/用户',
      disabled: true,
      targetClick: true,
      on: {
        change({ record, value, modalRowData, index }) {
          record.noticeToId=modalRowData.map(record => {
            return record.id
          })
          record.noticeToId=record.noticeToId.join(',')
        }
      },
      customColumnProps({ name, value, record, index, props }) {
        if (record.type) {
          props.disabled = false
          if (record.type == 'U') {
            props = { ...userAttr, ...props }
          } else if (record.type == 'R') {
            props = { ...roleAttr, ...props }
          }
          props.tableConfig.done=() => {
            props.tableConfig.selectedRowKeys = record.noticeToId.split(',')
          }
          return props
        } else {
          props.disabled = true
        }
      }
    },
    {
      dataIndex: 'type',
      title: '通知类型',
      width: 140,
      align: 'center',
      customRender(value, record, index) {

        return self._c('a-radio-group', {
          attrs: {
            //replaceFields:{ true: 1, false: 0 },
            name:'type',
            checked: value,
             value,
            options: [
              {value:'U',label:'用户'},
              {value:'R',label:'角色'},
            ]
          },
          on: {
            change(v) {
              record.type = v.target.value
              record.noticeToId=''
              record.noticeToName=''
            }
          }
        })

      },
    },
    {
      key:'delRow',
      type: 'delRow',
      width: 40,
      align: 'center'
    }

  ];
};

export const viewTable = (self) => {
  return [
    {
      dataIndex: 'noticeToName',
      type: 'searchModal',
      title: '角色/用户',
    },
    {
      dataIndex: 'type',
      title: '通知类型',
      width: 140,
      align: 'center',
      customRender(txt) {
        let o = {
          'U':'用户',
          'R':'角色'
        }
        return self._c('span',[self._v(o[txt])])

      }

    }

  ];
};



