import { genWarehouseAuthSearchModal,genCargoownerAuthSearchModal } from "../../../../kzyWMS/SearchModal";
import { upcloud_base_item, upcloud_base_common, upcloud_base_chain, SERVICE_DATA_API_BASE } from "@/config/serviceSettings";

let grid = {
  labelCol: { span: 5 }, span: 6,
};
let grid1 = {
  labelCol: { span: 8 }, span:11,
};
export function setFormItems(self) {
  let _this = self
  return [
    // {
    //   type: 'input',
    //   name: 'consignorId',
    //   label: '货主ID',
    //   value: '',
    //   hidden: true, 
    //   ...grid
    // },
    // {
    //   type: 'input',
    //   name: 'consignorCode',
    //   label: '货主编码',
    //   value: '',
    //   hidden: true, 
    //   ...grid
    // },
    
    ...genWarehouseAuthSearchModal(1, true, false, null, null, grid),
    ...genCargoownerAuthSearchModal(1, true, false, null, null, grid,{mapper: 
      { 
        cargoOwnerId: 'consignorId',
        consignorName: 'cargoOwnerName',
        consignorCode: 'cargoOwnerCode'
    
    }}),
    // {
    //   label: '货主名称',
    //   type: 'searchModal',
    //   targetClick: true,
    //   disabled: false,
    //   ...grid,
    //   name: 'consignorName',
    //   remoteUrl: { url: '/api/upcloud-base-chain/baseCargoOwnerMst/v1.0/pageList', method: 'post' },
    //   rowKey: 'cargoOwnerId',
    //   targetValueKey: 'cargoOwnerName',
    //   toolBar: {
    //     items: [
    //       {
    //         type: 'input',
    //         name: 'cargoOwnerCode',
    //         label: '货主编码',
    //         value: ''
    //       },
    //       {
    //         type: 'input',
    //         name: 'cargoOwnerName',
    //         label: '货主名称',
    //         value: ''
    //       }
    //     ]
    //   },
    //   tableConfig: {
    //     columns: [
    //       {
    //         dataIndex: 'cargoOwnerCode',
    //         title: '货主编码'
    //       },
    //       {
    //         dataIndex: 'cargoOwnerName',
    //         title: '货主名称'
    //       }
    //     ]
    //   },
    //   on: {
    //     ok(event, value, rowData, form) {
    //       console.log(form)
    //       if (form) {
    //         form.setFieldsValue({
    //           consignorName: rowData[0].cargoOwnerName,
    //           consignorCode: rowData[0].cargoOwnerCode,
    //           consignorId: rowData[0].cargoOwnerId
    //         })
    //       }
    //     },
    //     change(event, value, rowData, form) {
    //       if (!value) {
    //         form.setFieldsValue({
    //           cargoOwnerId: '',
    //           cargoOwnerCode: "",
    //         })
    //       }
    //     }
    //   }
    // },
    {
      type: 'input',
      name: 'tempid',
      label: '方案编号',
      value: '', 
      ...grid
    },
    {
      type: 'input',
      name: 'tempname',
      label: '方案名称',
      value: '', 
      ...grid
    },
    {
      type: 'select',
      name: 'temptype',
      label: '模板类型:',
      placeholder: '请选择模板类型',
      remoteUrl: { url: upcloud_base_common+'/dict/listbytype?dicttypeCodes=report_template', method: 'post' },
      replaceFields: {
        value: 'dictCode',
        label: 'dictName'
      },
      ...grid
    },
    {
      type: 'buttonGroup',
      style: { textAlign: 'left' },
      ...grid,
      options: [
        {
          value: '查询',
          icon: 'search',
          btnType: 'primary',
          // style: 'margin-left:10px',
          htmlType: 'submit'
        },
        {
          value: '重置',
          icon: 'redo',
          style: 'margin-left:10px',
          on: {
            click: () => {
              self.$refs.formTarget.form.resetFields()
            }
          }
        }
      ]
    }
  ]
}

export function detailFormItems(self) {
  let _this = self
  return [
    {
      type: 'input',
      hidden: true,
      name: 'tempid',
      label: 'tempid',
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      hidden: true,
      name: 'temppathid',
      label: 'temppathid',
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      name: 'consignorId',
      label: '货主ID',
      value: '',
      hidden: true, 
      ...grid1
    },
    {
      type: 'input',
      name: 'consignorCode',
      label: '货主编码',
      value: '',
      hidden: true, 
      ...grid1
    },
    {
      type: 'input',
      hidden: false,
      name: 'configname',
      disabled: true,
      // required: true,
      label: '方案名称',
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      hidden: false,
      name: 'configid',
      // required: true,
      disabled: true,
      label: '方案编号',
      value: '', 
      ...grid1
    },
    ...genWarehouseAuthSearchModal(1, true, false, null, null, grid1),
    {
      label: '货主名称',
      type: 'searchModal',
      targetClick: true,
      disabled: false, 
      ...grid1,
      name: 'consignorName',
      remoteUrl: { url: upcloud_base_chain+'/baseCargoOwnerMst/v1.0/pageList', method: 'post' },
      rowKey: 'cargoOwnerId',
      targetValueKey: 'cargoOwnerName',
      toolBar: {
        items: [
          {
            type: 'input',
            name: 'cargoOwnerCode',
            label: '货主编码',
            value: ''
          },
          {
            type: 'input',
            name: 'cargoOwnerName',
            label: '货主名称',
            value: ''
          }
        ]
      },
      tableConfig: {
        columns: [
          {
            dataIndex: 'cargoOwnerCode',
            title: '货主编码'
          },
          {
            dataIndex: 'cargoOwnerName',
            title: '货主名称'
          }
        ]
      },
      on: {
        ok(event, value, rowData, form) {
          console.log(form)
          if (form) {
            form.setFieldsValue({
              consignorName: rowData[0].cargoOwnerName,
              consignorCode: rowData[0].cargoOwnerCode,
              consignorId: rowData[0].cargoOwnerId
            })
          }
        },
        change(event, value, rowData, form) {
          if (!value) {
            form.setFieldsValue({
              cargoOwnerId: '',
              cargoOwnerCode: "",
            })
          }
        }
      }
    },

    {
      type: 'input',
      hidden: false,
      name: 'shipvendorname',
      // required:true,
      label: '物流商',
      value: '', 
      ...grid1
    },

    {
      type: 'input',
      hidden: false,
      name: 'printServiceUrl',
      required:true,
      label: '打印服务地址',
      value: '', 
      ...grid1
    },

    {
      type: 'select',
      name: 'temptype',
      label: '模板类型:',
      autoLoad: true,
      placeholder: '请选择模板类型',
      required:true,
      remoteUrl: { url: upcloud_base_common+'/dict/listbytype?dicttypeCodes=report_template', method: 'post' },
      replaceFields: {
        value: 'dictCode',
        label: 'dictName'
      },
      ...grid1
    },
    {
      type: 'radio',
      hidden: false,
      name: 'status',
      label: '是否启用',
      required: true,
      ...grid1,
      value: 1,
      options: [
        {
          label: '是',
          value: 1
        },
        {
          label: '否',
          value: 0
        }
      ]
    },
    {
      type: 'input',
      hidden: false,
      name: 'tempwidth',
      label: '模板宽度',
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      hidden: false,
      name: 'tempheight',
      label: '模板高度',
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      name: 'tempname',
      label: '模板文件名',
      disabled: true,
      required: true,
      value: '', 
      ...grid1
    },
    {
      type: 'input',
      name: 'temppath',
      label: '模板路径',
      disabled: true,
      value: '',
      required: true,
      ...grid1
    },
    {
      type: 'textarea',
      hidden: false,
      name: 'remark',
      label: '备注',
      value: '', 
      ...grid1
    },
  ]
}
export const tableColumnsConfig = [
  {
    title: 'tempid',
    hidden: true,
    dataIndex: 'tempid'
  }, 
  {
    title: '方案名称',
    width: 100,
    hidden: false,
    dataIndex: 'configname',
    className: 'v_top'
  },
  {
    title: '方案编号',
    width: 100,
    hidden: false,
    dataIndex: 'configid',
    className: 'v_top'
  },
  {
    title: '物流商',
    width: 100,
    hidden: false,
    dataIndex: 'shipvendorname',
    className: 'v_top'
  },
  {
    title: '打印服务地址',
    dataIndex: 'printServiceUrl',
    className: 'v_top'
  },
  {
    title: '模板路径',
    width: 180,
    hidden: true,
    dataIndex: 'temppath',
    className: 'v_top'
  },
  {
    title: '模板类型编码',
    width: 180,
    dataIndex: 'temptype1',
    className: 'v_top'
  },
  {
    title: '模板类型',
    width: 180,
    hidden: false,
    dataIndex: 'temptype',
    remoteUrl: { url: upcloud_base_common+'/dict/listbytype?dicttypeCodes=report_template', method: 'post' },
    replaceFields: {
      value: 'dictCode',
      label: 'dictName'
    },
    className: 'v_top'
  },
  {
    title: '模板名称',
    width: 180,
    hidden: false,
    dataIndex: 'tempname',
    className: 'v_top'
  },
  {
    title: '模板宽度',
    width: 100,
    hidden: true,
    dataIndex: 'tempwidth',
    className: 'v_top',
  },
  {
    title: '模板高度',
    width: 100,
    hidden: true,
    dataIndex: 'tempheight',
    className: 'v_top'
  },
  {
    dataIndex: 'status',
    title: '是否启用',
    width: 100,
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '备注',
    dataIndex: 'remark',
    className: 'v_top'
  },
  {
    title: '操作',
    key: 'operate',
    align: 'center',
    fixed: 'right',
    width: 150,
    scopedSlots: { customRender: 'action' }
  }
]
