import { goodsTableUrl } from './api.js'
import { driverAttr, carAttr } from '@/blocks/components/searchModalConfig/index'

export const setUpdateForm = (self, title) => {
  return [
    { name: 'ids', label: 'ids', hidden: true },
    {
      name: 'selfWithdrawalDate',
      label: '自提时间',
      type: 'date',
      format: 'YYYY-MM-DD HH:mm',
      required: true,
      showTime: true,
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      value: self.moment().format('YYYY-MM-DD HH:mm'),
    },
    {
      name: 'handoverPerson',
      label: '交接人',
      type: 'input',
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'selfWithdrawalPerson',
      label: '自提人',
      type: 'input',
      required: true,
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'contactTel',
      label: '联系方式',
      type: 'input',
      rules: [
        {
          type: 'phone',
          required: true,
        },
      ],
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'vehiclePlateNumber',
      label: '车牌号',
      type: 'input',
      value: '',
      rules: [
        {
          type:'plateNumber'
        }
      ],
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'idCrad',
      label: '身份证',
      type: 'input',
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'memo',
      span: 24,
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
      value: '',
      label: '备注',
      type: 'textarea',
    },
    {
      name: 'picUrl',
      itemHeight: 'auto',
      label: '添加图片',
      span: 24,
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
      scopedSlots: { customRender: 'photo' },
      value: '',
    },
  ]
}

// 自提车辆等记
export const setVehicleRegisterForm = (self, title) => {
  let sdriverAttr = { ...driverAttr }
  sdriverAttr.targetClick = false

  let scarAttr = { ...carAttr }
  scarAttr.targetClick = false
  return [
    { name: 'ids', label: 'ids', hidden: true },
    { name: 'selfWithdrawalPersonIds', label: 'selfWithdrawalPersonIds', hidden: true },
    {
      name: 'selfWithdrawalPerson',
      label: '自提人',
      required: true,
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      type: 'searchModal',
      targetClick: false,
      ...sdriverAttr,
      on: {
        ok(...args) {
          let idList = []
          let phoneList = []
          args[2].forEach(item => {
            idList.push(item.id)
            phoneList.push(item.phoneNumber)
          })
          args[3].setFieldsValue({
            selfWithdrawalPersonIds: idList.join(','),
            contactTel: phoneList.join(','),
            vehiclePlateNumber: ''
          })
        },
        input(...args) {
          args[3].setFieldsValue({
            vehiclePlateNumber: ''
          })
        },
      }
    },
    {
      name: 'contactTel',
      label: '联系方式',
      type: 'input',
      rules: [
        {
          type: 'phone',
          required: true,
        },
      ],
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'vehiclePlateNumber',
      label: '车牌号',
      required: false,
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      type: 'searchModal',
      targetClick: false,
      ...scarAttr,
      remoteBefore: (vNode, remoteUrl, form) => {
        let { selfWithdrawalPersonIds } = form.getFieldsValue()
        remoteUrl.data = { driverIds: selfWithdrawalPersonIds.split(','), ...remoteUrl.data }
      },
    },
    {
      name: 'idCrad',
      label: '身份证',
      type: 'input',
      value: '',
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
    {
      name: 'memo',
      span: 24,
      labelCol: { span: 4 },
      wrapperCol: { span: 20 },
      value: '',
      label: '备注',
      type: 'textarea',
    },
    // {
    //   //name: 'itemVOList',
    //   itemHeight: 'auto',
    //   label: '申请数量',
    //   span: 24,
    //   labelCol: { span: 4 },
    //   wrapperCol: { span: 20 },
    //   customRender: (value, form, props) => {
    //     return self._c('p-table-edit-pro', {
    //       attrs: {
    //         remoteUrl: {
    //           url: goodsTableUrl,
    //           method: 'post',
    //         },
    //         dataSource:self.itemVOList,
    //         pagination: false,
    //         hasRowCount: false,
    //         rowSelectType: false,
    //         filterDropdownColumn: false,
    //         rowKey: 'itemId',
    //         remoteBefore(vNode, params) {
    //           let { ids } = self.currentData
    //           params.data = { shipbillId: ids, pageNum: 0, pageSize: 0 }
    //         },
    //         columns: [
    //           { dataIndex: 'itemId', title: '商品ID', type: 'txt', hidden: true },
    //           {
    //             dataIndex: 'itemName',
    //             title: '商品名称',
    //             type: 'txt',
    //           },
    //           {
    //             dataIndex: 'pcs',
    //             title: '数量',
    //             align: 'center',
    //             customRender(text) {
    //               return ~~text
    //             },
    //           },
    //           {
    //             dataIndex: 'inventoryPcs',
    //             title: '库存数量',
    //             align: 'center',
    //             customRender(text) {
    //               return ~~text
    //             },
    //           },
    //           {
    //             dataIndex: 'applyPcs',
    //             title: '申请数量',
    //             type: 'number',
    //             align: 'center',
    //             customColumnProps({ name, value, record, index, props }) {
    //               let max= ~~record.pcs>=~~record.inventoryPcs?~~record.inventoryPcs:~~record.pcs
    //               if (!record.pcs || !record.inventoryPcs) {
    //                props.disabled = true
    //               } else {
    //                 props.max=max
    //               }
    //             },
    //             defaultValue: 0
    //           },
    //         ],
    //       },
    //       on: {
    //         'update:dataSource': (arr) => {
    //           self.itemVOList=arr

    //         }
    //       },
    //     })
    //   },
    // },
  ]
}
