import request from '@/utils/request';
import moment from 'moment';
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,SERVICES_FILE_MANAGEMENT } from '@/config/serviceSettings.js'
const serviceName = UPCLOUD_RDC_TMS_MAINDATA_SERVICE

//获取证件ID
export const getPaperId = (_this, data, st) => {
  return request({
    url: serviceName + '/paper/getPaperId',
    method: 'post',
    data
  });
};

function startDisabledTime(startValue, form) {
  let endValue = form.getFieldValue('endDate');
  if (!startValue || !endValue) {
    return false;
  }
  return startValue.valueOf() > new Date(endValue).valueOf();
}
function endDisabledTime(endValue, form) {
  let startValue = form.getFieldValue('startDate');
  if (!startValue || !endValue) {
    return false;
  }
  return new Date(startValue).valueOf() >= endValue.valueOf();
}
export const setFormItems = (self, view) => {
  return [
    { name: 'id', label: 'id', type: 'txt', hidden: true },
    { name: 'status', label: ' status', type: 'number', hidden: true, value: 1 },
    {
      type: view > 1 ? 'txt' : 'input',
      name: 'code',
      label: '证件号码',
      value: '',
      // rules: [
      //   {
      //     type: 'idCard',
      //     required: true
      //   }
      // ],
      required: true
    },
    {
      name: 'type',
      label: '证件类型',
      required: true,
      type: 'select',
      allowClear: false,
      mode: view > 1 ? 'txt' : undefined,
      value: 1,
      get options() {
        return self.options&&self.options.PAPER_TYPE;
      }
      // options: [
      //   { value: 1, label: '身份证' },
      //   { value: 3, label: '驾驶证' }
      // ]
    },
    {
      name: 'startDate',
      label: ' 有效期始',
      disabledDate: startDisabledTime,
      format: 'YYYY-MM-DD',
      required: true,
      type: view === 3 ? 'txt' : 'date'
    },
    {
      name: 'endDate',
      label: ' 有效期止',
      disabledDate: endDisabledTime,
      format: 'YYYY-MM-DD',
      required: true,
      type: view === 3 ? 'txt' : 'date'
    },
    { name: 'issuingAuthority', label: '发证机关', type: view === 3 ? 'txt' : 'input', value: '' },
    { name: 'issuingDate', label: '发证日期', format: 'YYYY-MM-DD', type: view === 3 ? 'txt' : 'date', value: '' },
    {
      name: 'memo',
      label: ' 备注',
      type: view === 3 ? 'txt' : 'textarea',
      span: 24,
      labelCol: { span: 3 },
      wrapperCol: { span: 20 },
      value: ''
    },
    {
      name: 'picture',
      itemHeight: 'auto',
      label: '照片',
      span: 24,
      labelCol: { span: 3 },
      wrapperCol: { span: 20 },
      scopedSlots: { customRender: 'photo' },
      value: ''
    }
  ];
};
function responseThen(response) {
  if (response.success) {
    this.$message.success(response.message);
  } else {
    this.$exception(response);
  }
  setTimeout(() => {
    this.confirmLoading = false;
  }, 1000);
  return response;
}

export const updateImg = (_this, data, st) => {

  return request({
    processData: false,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    url:SERVICES_FILE_MANAGEMENT +'/file/upload-file/v2',
    method: 'post',
    data
  })
};
