import pCascaderZone from '@/blocks/components/cascaderZone'
import departmenTree from '@/blocks/components/formConfig/departmenTree.multiple.js'
function divider(self, value) {
  return {
    label: '',
    span: 24,
    itemHeight: '60px',
    labelCol: { span: 0 },
    wrapperCol: { span: 24 },
    type: () => {
      return self._c('a-divider', { attrs: { orientation: 'left' } }, [self._v(value)])
    },
  }
}

/**0=不显示,1=查看,2=新建,3=修改,4=复制 */
// addressData: {
//   address: '越秀财富中心',
//   longitude: 114.250019,
//   latitude: 30.568682,
// },
export const setFormItems = (self, expData = []) => {
  let selectedRowKeys = []
  let inputType = (self) => (self.st === 1 ? 'txt' : 'input')
  let e = []
  if (expData.length > 0) {
    expData.forEach((item) => {
      let type = item.type;
      Object.defineProperty(item, 'type', {
        get() {
          return self.st === 1 ? 'txt' : type
        }
      })
    })
    e = [divider(self, '扩展信息'), ...expData]
  }
  return [
    divider(self, '基本信息'),
    { name: 'cargoOwnerId', label: 'id', hidden: true, value: '' },
    {
      label: '货主编码',
      name: 'cargoOwnerCode',
      get type() {
        return inputType(self)
      },
      required: true,
      get readOnly() {
        return self.st === 3 ? true : false
      },
    },
    {
      label: '货主名称',
      name: 'cargoOwnerName',
      readOnly: self.st === 3 ? true : false,
      required: true,
      get readOnly() {
        return self.st === 3 ? true : false
      },
      get type() {
        return inputType(self)
      },
    },
    {
      label: '货主简称',
      get type() {
        return inputType(self)
      },
      name: 'cargoOwnerShortName',
    },
    { label: '状态名称', hidden: true, name: 'statusName' },

    // {
    //   label: '状态',
    //   name: 'status',
    //   type: 'select',
    //   mode:'txt',
    //   value: 1,
    //   get options() {
    //     return self.options.MAINDATA_STATUS
    //   },
    // },
    ...departmenTree(self),

    {
      name: 'contact',
      label: '联系人',
      get type() {
        return inputType(self)
      },
    },
    {
      name: 'phoneNumber',
      label: '手机号',
      get type() {
        return inputType(self)
      },
      trigger: 'blur' ,

      rules: [
        {
          type: 'phone',
        },
      ],
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'landlineNumber',
      label: '座机号',
      trigger: 'blur' ,
      rules: [
        {
          type: 'tel',
        },
      ],
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'mail',
      label: '邮箱',
      trigger: 'blur' ,
      rules: [
        {
          type: 'email',
        },
      ],
    },

    {
      name: 'provinceCityDistrict',
      value: '',
      on: {
        change(value, arrValue, form) {
          if (arrValue && arrValue.length) {
            form.setFieldsValue({
              provinceName: arrValue[0] ? arrValue[0].zname : '',
              province: arrValue[0] ? arrValue[0].zoneid : '',
              cityName: arrValue[1] ? arrValue[1].zname : '',
              city: arrValue[1] ? arrValue[1].zoneid : '',
              districtName: arrValue[2] ? arrValue[2].zname : '',
              district: arrValue[2] ? arrValue[2].zoneid : '',
            })
          }
        },
        popupVisibleChange(open, value) {},
      },
      label: '省市区',
      level: 3,
      get type() {
        return self.st === 1 ? 'txt' : pCascaderZone
      },
    },
    {
      name: 'province',
      label: '省编码',
      value: '',
      hidden: true,
    },
    {
      name: 'provinceName',
      label: '省名称',
      value: '',
      hidden: true,
    },
    {
      name: 'city',
      label: '市编码',

      value: '',
      hidden: true,
    },
    {
      name: 'cityName',
      label: '市名称',

      value: '',
      hidden: true,
    },
    {
      name: 'district',
      label: '区/县编码',

      value: '',
      hidden: true,
    },
    {
      name: 'districtName',
      label: '区/县名称',

      value: '',
      hidden: true,
    },
    {
      type: 'row',
      label: '详细地址',
      span: 12,
      wrapperCol: { span: 21 },
      labelCol: { span: 3 },
      list: [
        {
          name: 'address',
          get type() {
            return inputType(self)
          },
          value: '',
          span: 20,
          style: 'padding-right: 5px',
        },
        {
          get type() {
            return self.st === 1 ? '' : 'button'
          },
          value: '地址解析',
          btnType: 'primary',
          span: 4,
          on: {
            click(event, form) {
              if (typeof self.onShowMap == 'function') {
                return self.onShowMap(form)
              }
              self.$emit('showMap', form)
            },
          },
        },
      ],
    },

    {
      name: 'longitude',
      label: '经度',
      readOnly: true,
      get type() {
        return inputType(self)
      },
      value: '',
    },
    {
      name: 'latitude',
      label: '纬度',
      readOnly: true,
      get type() {
        return inputType(self)
      },
      value: '',
    },
    {
      name: 'memo',
      label: '备注',
      get type() {
        return inputType(self)
      },
      value: '',
    },
    divider(self, '开户信息'),
    {
      get type() {
        return inputType(self)
      },
      name: 'legalman',
      label: '法人代表',
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'invoice',
      label: '发票抬头',
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'invoiceTaxNumber',
      label: '税号',
    },
    {
      get type() {
        return self.st === 1 ? 'txt' : 'money'
      },

      name: 'registeredCapital',
      label: '注册资金',
    },
    {
      type: 'select',
      name: 'bank',
      label: '开户行',
      get mode() {
        return self.st === 1 ? 'txt' : ''
      },
      get options() {
        return self.options.BANK
      },
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'bankAccount',
      label: '银行帐号',
    },
    {
      get type() {
        return self.st === 1 ? 'txt' : 'date'
      },

      name: 'established',
      label: '成立时间',
      format: 'YYYY-MM-DD',
    },
    {
      get type() {
        return inputType(self)
      },
      name: 'registeredAddress',
      label: '注册地址',
    },
    ...e,
  ]
}
