import { customRenderOptions } from '../../api.js'
import { UPCLOUD_RDC_TMS_IMAGE_HOST } from '@/config/serviceSettings.js';

// approvalBusinessId:"[integer] 审批业务ID"
// approvalId:"[integer] 审批流程ID"
// approvalObjectName:"[string] 审批对象名称"
// approvalOpinion:"[string] 审批意见"
// cargoOwnerId:"[integer] 货主ID"
// nextApprovalOrder:"[integer] 审批流程下一节点顺序"
// nextApproverNodeId:"[integer] 下一审批节点ID"
// nextApproverRoleId:"[string] 下一审批角色ID"
// nextApproverRoleName:"[string] 下一审批角色名称"
// nextApproverUserId:"[string] 下一审批用户ID"
// nextApproverUserName:"[string] 下一审批用户名称"
// nodeApprovalType:"[integer] 审批方式 数据字典 NODE_APPROVAL_TYPE: 1 会签 2 或签"
// nodeApproverType:"[integer] 节点审批者类型 数据字典 NODE_APPROVER_TYPE 1 角色 2 用户"
// result:"[integer] 审批结果 数据字典 NODE_RESULT:1发起申请 2驳回发起人 3驳回上一级 4审批通过 5撤回 6 作废"

// 业务审批状态 数据字典 APPROVAL_BUSSINESS_STATUS: 1发起申请 2驳回 3撤回 4提交 5审核中 6作废 7审核完成
export const setBusColumns = (self, type) => {
  let t = {
    bus_detail: [
      { dataIndex: 'id', title: '审批业务明细ID', hidden: true },
      { dataIndex: 'approvalNodeOrder', title: '节点顺序' },
      { dataIndex: 'approverRoleName', title: '角色名称' },
      { dataIndex: 'approverUserName', title: '用户名称' },
      {
        dataIndex: 'statusName',
        title: '节点状态',
      },
      { dataIndex: 'approvalTime', title: '审批时间' },
    ],

    bus_log: [
      { dataIndex: 'id', title: '审批日志ID', hidden: true },
      { dataIndex: 'approverRoleName', title: '审核角色' },
      { dataIndex: 'approverPersonName', title: '审核人' },
      {
        dataIndex: 'resultName',
        title: '审核结果',
        //  customRender: customRenderOptions(self, 'APPROVAL_BUSSINESS_NODE_STATUS'),
      },
      { dataIndex: 'approvalTime', title: '审核时间' },
      { dataIndex: 'approvalOpinion', title: '审核意见' },
    ],
    approve: [
      {
        name: 'result',
        label: '审核结果',
        type: 'radio',
        required: true,
        itemHeight: '60px',
        message: '请选择审核结果',
        unit() {
          return self._c(
            'p-button',
            {
              attrs: { type: 'primary', size: 'large' },
              style: { width: '100px' },
              on: {
                // @审核提交
                clickSync: self.approvalSubmit,
              },
            },
            [self._v('审核')]
          )
        },
        options: [
          {
            label: '审核通过',
            value: 4,
          },
          {
            label: '驳回发起人',
            value: 2,
          },
          {
            label: '驳回上一级',
            value: 3,
          },
        ],
        //  result:"[integer] 审批结果 数据字典 NODE_RESULT:1发起申请 2驳回发起人 3驳回上一级 4审批通过 5撤回 6 作废"
      },
      { name: 'approvalOpinion', itemHeight: 'auto', label: '审核意见', type: 'textarea', rows: 8 },
    ],
  }
  return t[type]
}

export const setMainColumns = (self) => {
  return [
    { dataIndex: 'id', title: 'ID', hidden: true },
    { dataIndex: 'initiatedUserName', title: '申请人', width: 100 },
    { dataIndex: 'approvalFlowTypeName', title: '审批类型', width: 100 },
    {
      dataIndex: 'approvalObjectName',
      title: '审批详情',
      width: 200,
      customRender(txt, record) {
        return self._c(
          'a',
          {
            attrs: {
              href: 'javascript:void(0)',
            },
            on: {
              click: () => {
                return self.$emit('details', record)
              },
            },
          },
          [self._v(txt)]
        )
      },
    },
    { dataIndex: 'statusName', title: '状态名称', width: 200 },
    { dataIndex: 'initiatedTime', title: '发起时间', width: 200 },
    // {
    //   key: 'demo',
    //   title: '效果',
    //   width: 300,
    //   customRender(txt, record) {
    //     const { color, background } = record
    //     return self._c('div', { class: 'row-colorView',  }, [self._c("div", { class: 'content',style: { color, background,} }, [self._v('正文内容预览')])])
    //   }
    // },
  ]
}



/** 证件资料 certificate*/
export const certificateColumns = self => {
  return [
    { dataIndex: 'id', title: 'ID', hidden: true },
    // { dataIndex: 'plateNumber', title: '车牌号', hidden: false },
    {
      dataIndex: 'picture',
      title: '照片',
      width: 50,
      align: 'center',
      customRender(text, data) {
        let picture = text ? text.split(',') : ''


        if (Array.isArray(picture)) {
          return self._c('a-avatar', {
            attrs: {
              shape: 'square',
              src: picture.length > 0 ?UPCLOUD_RDC_TMS_IMAGE_HOST+'/'+picture[0] : '',
              size: 60
            },
            style: picture.length === 0 && 'border:1px solid #e8e8e8;backgroundColor: #fff',
            on: {
              click: () => {
                if (!picture) return
                self.$refs.updateFormModal.previewVisible = true
                self.$refs.updateFormModal.previewImage =UPCLOUD_RDC_TMS_IMAGE_HOST+'/'+picture[0];
              }
            },
            scopedSlots: {
              icon() {
                return picture.length === 0 ? self._c('a-icon', { attrs: { type: 'picture', theme: 'twoTone' } }) : undefined
              }
            }
          })
        }
        return ''
      }
    },
    {
      dataIndex: 'code',
      title: '证件号码'
    },
    {
      dataIndex: 'type',
      title: '证件类型',
      customRender: (text, data) => {
        return ['身份证', '行驶证', '驾驶证'][+text - 1]
      }
    },
    {
      dataIndex: 'status',
      title: '状态',
      align: 'center',
      customRender: (text, data) => {
        return self._c('a-badge', {
          attrs: {
            color: text > 0 ? 'cyan' : 'red',
            text: text > 0 ? '启用' : '停用'
          }
        })
      }
    },
    { dataIndex: 'issuingAuthority', title: '发证机关' },
    { dataIndex: 'issuingDate', title: '发证日期' },
    { dataIndex: 'startDate', title: '有效期始', width: 100 },
    { dataIndex: 'endDate', title: '有效期止', width: 100 },
    { dataIndex: 'memo', title: '备注' },
  ]
}
