import { cargo_ownerUrl } from '../../api'
import pCascaderZone from '@/blocks/components/cascaderZone'
import departmenTree from '@/blocks/components/formConfig/departmenTree.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)])
    },
  }
}
let inputType = (self) => (self.st === 1 ? 'txt' : 'input')

export const mainGetFormList = {
  main: {
    formItems: (self,expData=[]) => {
      let selectedRowKeys = []
      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: 'id', label: 'id', hidden: true, value: '' },
        {
          name: 'code',
          target: 'blur',
          label: '供应商编码',
          value: '',
          get readOnly() {
            return self.st === 3 ? true : false
          },

          required: true,
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'name',
          label: '供应商名称',
          value: '',
          get readOnly() {
            return self.st === 3 ? true : false
          },
          required: true,
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'shortName',
          label: '供应商简称',
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'cargoOwnerName',
          value: '',
          label: '所属货主',
          required: true,
          targetClick: true,
          get readOnly() {
            return self.st === 2 ? true : false
          },

          /**0=不显示,1=查看,2=新建,3=修改,4=复制 */
          // /**0=不显示, 1=新建，2=修改 ，3=查看 ，4=复制  */

          //  type: self.st == 3 ? 'txt' : 'searchModal',
          get type() {
            return self.st === 1 ? 'txt' : 'searchModal'
          },
          toolBar: {
            labelCol: { span: 8 },
            wrapperCol: { span: 16 },
            items: [
              {
                type: 'input',
                name: 'cargoOwnerCode',
                label: '货主编码',
                value: '',
              },
              {
                type: 'input',
                name: 'cargoOwnerName',
                label: '货主名称',
                value: '',
              },
            ],
          },
          remoteUrl: {
            url: cargo_ownerUrl,
            method: 'post',
          },
          rowKey: 'cargoOwnerId',
          targetValueKey: 'cargoOwnerName',
          on: {
            change(event, value, dataArr, form) {
              let data = dataArr[0],
                obj = { cargoOwnerId: '', cargoOwnerCode: '' }
              if (!value) {
                return form.setFieldsValue(obj)
              }
              obj = { cargoOwnerId: data.cargoOwnerId, cargoOwnerCode: data.cargoOwnerCode }
              form.setFieldsValue(obj)
            },
            'update:selectedRowKeys'(value) {},
          },
          tableConfig: {
            columns: [
              { dataIndex: 'cargoOwnerId', title: 'ID', hidden: true },
              { dataIndex: 'cargoOwnerName', title: '货主名称' },
              { dataIndex: 'cargoOwnerCode', title: '货主编码' },
            ],
          },
        },
        ...departmenTree(self),
        {
          name: 'cargoOwnerId',
          label: '所属货主ID',
          hidden: true,
        },
        {
          name: 'cargoOwnerCode',
          label: '所属货主code',
          hidden: true,
        },
        {
          name: 'contractNature',
          label: '合作性质',
          allowClear: false,
          required: true, //CONTRACT_NATURE

          get mode() {
            return self.st === 1 ? 'txt' : ''
          },
          type: 'select',
          value: 1,
          get options() {
            return self.options.CONTRACT_NATURE
          },
        },
        {
          name: 'taxRegisterNumber',
          label: '税务登记号',
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'businessLicenseNumber',
          label: '营业执照号',
          get type() {
            return inputType(self)
          },
          span: 6,
        },
        {
          name: 'memo',
          label: '备注',
          get type() {
            return inputType(self)
          },
          span: 12,
          labelCol: { span: 3 },
          wrapperCol: { span: 20 },
        },
        divider(self, '联系信息'),
        {
          name: 'contact',
          label: '联系人',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'phoneNumber',
          label: '手机号',
          allowClear: false,
          get type() {
            return inputType(self)
          },
          value: '',
          trigger: 'blur',
          rules: [
            {
              type: 'phone',
              //required: true
            },
          ],
        },
        {
          name: 'landlineNumber',
          label: '座机号',
          trigger: 'blur',
          allowClear: false,
          get type() {
            return inputType(self)
          },
          value: '',
          rules: [
            {
              type: 'tel',
            },
          ],
        },
        {
          name: 'email',
          label: '邮箱',
          trigger: 'blur',
          allowClear: false,
          rules: [
            {
              type: 'email',
              //required: true
            },
          ],
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'postCode',
          label: '邮编',
          trigger: 'blur',
          allowClear: false,
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          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,
          type: self.st == 1 ? 'txt' : pCascaderZone,
        },
        { name: 'province', label: '省编码', type: 'input', value: '', hidden: true },
        { name: 'provinceName', label: '省名称', type: 'input', value: '', hidden: true },
        { name: 'city', label: '市编码', type: 'input', value: '', hidden: true },
        { name: 'cityName', label: '市名称', type: 'input', value: '', hidden: true },
        { name: 'district', label: '区/县编码', type: 'input', value: '', hidden: true },
        { name: 'districtName', label: '区/县名称', type: 'input', 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',
            },
            {
              type: 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: '',
        },
        divider(self, '开户信息'),
        {
          name: 'legalman',
          label: '法人代表',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'invoice',
          label: '发票抬头',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'invoiceTaxNumber',
          label: '税号',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'established',
          label: '成立时间',
          get type() {
           return  self.st == 1 ? 'txt' : 'date'
         },
          format: 'YYYY-MM-DD',
        },
        {
          name: 'registeredCapital',
          label: '注册资金',
         get type(){return self.st == 1 ? 'txt' : 'money'},
          value: 0,
          // prefix: '￥',
          // suffix: 'RMB'
        },
        {
          name: 'bank',
          label: '开户行',
          get type() {return self.st == 1 ? 'txt' : 'select' },
          value: undefined,
          placeholder: '请选择开户行',
          get options() {
            return self.options.BANK
          },
        },
        {
          name: 'bankAccount',
          label: '银行账号',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'registeredAddress',
          label: '注册地址',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        divider(self, '业务属性'),
        {
          name: 'pickUpSign',
          offset: 1,
          type: 'check',
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '提货签到',
          value: 0,
        },
        {
          name: 'autoPickUpSign',
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          type: 'check',
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '自动签到',
          value: 0,
        },
        {
          label: '可签到时间点',
          type: 'row',
          span: 10,
          labelCol: { span: 5 },
          wrapperCol: { span: 18},
          list: [
        // deliverySignTime:'',
        // deliverySignTimeDura:'',
        // deliverySignTimeUnit:''
            {
               get disabled() {
                return self.st === 1
              },
              name:'pickUpSignTime',
              type: 'select',
              style: 'padding-right:6px',
              get options() {
                return self.options&&self.options.PICK_UP_SIGN_TIME
              }
            },
            {
              get disabled() {
                return self.st === 1
              },
              type:'number',

              name: 'pickUpSignTimeDura',
              style: 'padding-right:6px',

            },
            {
              get disabled() {
                return self.st === 1
              },
              name:'pickUpSignTimeUnit',
              type: 'select',
              get options() {
                return self.options&&self.options.SIGN_TIME_UNIT
              },
              unit:'区间'
            }
          ]
          },

        {
          name: 'pickUpPicture',
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          type: 'check',
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '提货图片',
          value: 0,
        },
        {
          name: 'defaultPickUpRail',
          labelCol: { span: 6 },
          wrapperCol: { span: 10},
          label: '默认提货围栏',
          span:6,
          unit:'千米',
          min: 0,
          get type() {
           return self.st == 1 ? 'txt' : 'number'
          },
          value: 0,
        },
        {
          name: 'deliverySign',
          offset: 1,
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          type: 'check',
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '送达签到',
          value: 0,
        },
        {
          name: 'autoDeliverySign',
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          type: 'check',
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '自动签到',
          value: 0,
        },
         {

          label: '可签到时间点',
          type: 'row',
          span: 10,
          labelCol: { span: 5 },
          wrapperCol: { span: 18},
          list: [
            {
              get disabled() {
                return self.st === 1
              },
              name:'deliverySignTime',
              type: 'select',
              style: 'padding-right:6px',
              get options() {
                return self.options&&self.options.PICK_UP_SIGN_TIME
              }
            },
            {
              get disabled() {
                return self.st === 1
              },
              type:'number',
              name: 'deliverySignTimeDura',
              style: 'padding-right:6px',
            },
            {
              name:'deliverySignTimeUnit',
              type: 'select',
              get disabled() {
                return self.st === 1
              },
              get options() {
                return self.options&&self.options.SIGN_TIME_UNIT
              },
              unit:'区间'
            }
           ]
          },
        {
          name: 'deliveryPicture',
          get readOnly() {
            return self.st == 1
          },
          replaceFields: {
            true: 1,
            false: 0,
          },
          type: 'check',
          span: 2,
          wrapperCol: { span: 24 },
          checkedText: '送货图片',
          value: 0,
        },
        {
          name: 'defaultDeliveryRail',
          labelCol: { span: 6 },
          wrapperCol: { span: 10},
          span:6,
          label: '默认送货围栏',
          unit:'千米',
          min: 0,
          get type() {
           return self.st == 1 ? 'txt' : 'number'
          },
          value: 0,
        },
        ...e
      ]
    },
  },

  children: {
    formItems: (self) => {
      return [
        { name: 'id', label: 'id', hidden: true, value: '' },
        { name: 'providerId', label: 'providerId', hidden: true, type: 'txt', value: self.mainId },
        {
          name: 'code',
          label: '发货方编码',
          value: '',
          get readOnly() {
            return self.st === 3 ? true : false
          },
          required: true,
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'name',
          label: '发货方名称',
          value: '',
          get readOnly() {
            return self.st === 3 ? true : false
          },
          required: true,
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'shortName',
          label: '发货方简称',
          get type() {
            return inputType(self)
          },
        },
        {
          name: 'contact',
          label: '联系人',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'phoneNumber',
          label: '手机号',
          get type() {
            return inputType(self)
          },
          value: '',
          trigger: 'blur',
          allowClear: false,
          rules: [
            {
              type: 'phone',
              //required: true
            },
          ],
        },
        {
          name: 'landlineNumber',
          label: '座机号',
          trigger: 'blur',
          allowClear: false,
          get type() {
            return inputType(self)
          },
          value: '',
          rules: [
            {
              type: 'tel',
            },
          ],
        },
        {
          name: 'email',
          label: '邮箱',
          trigger: 'blur',
          allowClear: false,
          rules: [
            {
              type: 'email',
              //required: true
            },
          ],
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          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: '省编码', type: 'input', value: '', hidden: true },
        { name: 'provinceName', label: '省名称', type: 'input', value: '', hidden: true },
        { name: 'city', label: '市编码', type: 'input', value: '', hidden: true },
        { name: 'cityName', label: '市名称', type: 'input', value: '', hidden: true },
        { name: 'district', label: '区/县编码', type: 'input', value: '', hidden: true },
        { name: 'districtName', label: '区/县名称', type: 'input', 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',
            },
            {
              type: self.st == 1 ? '' : 'button',
              value: '地址解析',
              btnType: 'primary',
              span: 4,
              on: {
                click(event, form) {
                  self.$emit('showMap', form)
                },
              },
            },
          ],
        },

        {
          name: 'longitude',
          label: '经度',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'latitude',
          label: '纬度',
          get type() {
            return inputType(self)
          },
          value: '',
        },
        {
          name: 'memo',
          label: '备注',
          get type() {
            return inputType(self)
          },
          span: 12,
          labelCol: { span: 3 },
          wrapperCol: { span: 20 },
        },
      ]
    },
  },
}
