import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from '@/views/kzyWMS/SearchModal'
import { changecargoOwnerfun } from '@/views/kzyWMS/utils/setCargoOwner'
import qs from 'qs'
import request from '@/utils/request'
import { sorter } from '../../../utils/sort'
import { upcloud_base_strategy,upcloud_base_gsp,SERVICE_DATA_API_BASE } from "@/config/serviceSettings";

function gettype(parameter) {
  //  批量录入销毁信息 POST
  return request({
    method: 'get',
    url: upcloud_base_strategy+'/registry/by-code',
    params: parameter
  })
}
let a = [
  { label: '待审核', value: '10' },
  { label: '通过', value: '20' },
  { label: '驳回', value: '30' },
  { label: '销毁', value: '40' }
]
let b = [
  { label: '待审核', value: '10' },
  { label: '通过', value: '20' },
  { label: '销毁', value: '40' }
]
const tablecolumns = function(that) {
  return {
    gridform: {
      ref: 'form',
      items: [
        //genWarehouseAuthSearchModal 仓库

        ...genWarehouseAuthSearchModal(1, true, false, null, changecargoOwnerfun, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        ...genCargoownerAuthSearchModal(1, true, false, null, null, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        {
          type: 'radio',
          span: 6,
          name: 'status',
          label: '状态',
          value: '20', //初始化值
          hidden: true,
          options: [
            { label: '待审核', value: '10' },
            { label: '通过', value: '20' },
            { label: '驳回', value: '30' },
            { label: '销毁', value: '40' }
          ]
        },
        {
          span: 6,
          type: 'buttonGroup',
          style: { textAlign: 'left' },
          options: [
            {
              value: '查询',
              icon: 'search',
              btnType: 'primary',
              style: 'margin-right:10px;margin-left:10px;',
              htmlType: 'submit'
            },
            {
              value: '重置',

              name: 'ccz',
              icon: 'redo',
              on: {
                click(event, form) {
                  form.resetFields()
                }
              }
            }
          ]
        }
      ]
    },

    //主表
    MainTable: {
      edit: false,
      // edit: true,
      title: '明细列表',
      // /strategy/v1/page
      remoteUrl: {
        url: upcloud_base_gsp+ '/gspUnqualifiedDestroy/listPage',
        headers: {
          'Content-Type': 'application/JSON'
        },
        method: 'get'
      },
      ref: 'MainTable',
      rowkey: 'id',
      columns: sorter([
        {
          title: '单据编号',
          dataIndex: 'code',
          key: 'code'
        },

        {
          title: '仓库',
          dataIndex: 'warehouseName',
          ellipsis: true,
          key: 'warehouseName'
        },
        {
          title: '货主',
          dataIndex: 'cargoOwnerName',
          ellipsis: true,
          key: 'cargoOwnerName'
        },
        {
          title: '状态',
          dataIndex: 'status',
          key: 'status',
          scopedSlots: { customRender: 'status' },
          customRender(text) {
            //   console.log(text, '=====')
            if (text) {
              switch (text) {
                case '10':
                  text = '待审核'
                  break
                case '20':
                  text = '已审批'
                  break
                case '30':
                  text = '已驳回'
                  break
              }
              return text
            } else return
          }
        },
        {
          title: '申请人',
          key: 'creatorName',
          dataIndex: 'creatorName'
        },
        {
          title: '申请时间',
          key: 'gmtCreate',
          dataIndex: 'gmtCreate'
        },

        //   {
        //     title: '意见',
        //     key: 'opinions',
        //     dataIndex: 'opinions'
        //   },

        {
          title: '销毁时间',
          key: 'destroyDate',
          hidden: true,
          dataIndex: 'destroyDate'
        },
        {
          title: '销毁方式',
          key: 'destroyMode',
          hidden: true,
          dataIndex: 'destroyMode'
        },
        {
          title: '销毁图片',
          hidden: true,
          key: 'destroyPic',
          dataIndex: 'destroyPic',
          scopedSlots: { customRender: 'destroyPic' }
        },
        {
          title: '意见',
          key: 'opinion',
          hidden: true,
          dataIndex: 'opinion'
        },
        {
          title: '审核时间',
          key: 'auditDate',
          dataIndex: 'auditDate'
        },
        {
          title: '审核意见',
          key: 'auditText',
          dataIndex: 'auditText',
          width: 100
          //   scopedSlots: { customRender: 'auditText1' }
        },
        {
          title: '操作',
          key: 'operation',
          fixed: 'right',
          width: 100,
          scopedSlots: { customRender: 'operation' },
          align: 'center'
        }
      ])
    },
    //   详情表
    SubTable: {
      title: '明细列表',
      remoteUrl: {
        url: upcloud_base_gsp+ '/gspUnqualifiedDestroy/findDetailByMstId',
        headers: {
          'Content-Type': 'application/JSON'
        },
        method: 'get'
      },
      ref: 'rule',
      rowkey: 'id',
      columns: sorter([
        {
          title: '商品编码',
          key: 'itemCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemCode'
        },
        {
          title: '商品名称',
          key: 'itemName',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemName'
        },
        {
          title: '商品大类',
          key: 'itemHealthCategory',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthCategory'
        },
        {
          title: '商品规格',
          key: 'specification',
          width: 150,
          ellipsis: true,
          dataIndex: 'specification'
        },
        {
          title: '生产厂家',
          key: 'manufacturerName',
          width: 150,
          ellipsis: true,
          dataIndex: 'manufacturerName'
        },
        {
          title: '产地',
          key: 'countryOriginName',
          width: 150,
          ellipsis: true,
          dataIndex: 'countryOriginName'
        },
        {
          title: '包装数量',
          key: 'caseConversionRate',
          width: 150,
          ellipsis: true,
          dataIndex: 'caseConversionRate'
        },
        {
          title: '包装单位',
          key: 'caseUom',
          width: 150,
          ellipsis: true,
          dataIndex: 'caseUom'
        },
        {
          title: '是否追溯',
          key: 'itemHealthSuperviseflag',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemHealthSuperviseflag',
          customRender(text, record, index) {
            text ? (text = '是') : (text = '否')
            return text
          }
        },
        {
          title: '货位',
          key: 'locatorCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'locatorCode'
        },
        {
          title: '货位ID',
          key: 'locatorId',
          ellipsis: true,
          hidden: true,
          dataIndex: 'locatorId'
        },
        {
          title: '报损数量',
          key: 'lossQty',
          dataIndex: 'lossQty',
          width: 100,
          scopedSlots: { customRender: 'number' }
        },
        {
          title: '所在部门意见',
          width: 150,
          key: 'opinion',
          ellipsis: true,
          dataIndex: 'opinion'
        },
        {
          title: '批准文号',
          key: 'itemHealthApprovalNbr',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthApprovalNbr'
        },
        {
          title: '上市许可持有人',
          key: 'itemHealthListedLicensor',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthListedLicensor'
        },
        {
          title: '注册证号',
          key: 'itemHealthRegisterNbr',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthRegisterNbr'
        },
        {
          title: '日期',
          dataIndex: 'refBillDate',
          hidden: true,
          ellipsis: true,
          key: 'refBillDate'
        },
        {
          title: '原单据编号',
          dataIndex: 'refBillId',

          hidden: true,
          ellipsis: true,
          key: 'refBillId'
        },
        {
          title: '不合格品来源',
          dataIndex: 'refBillType',
          hidden: true,
          ellipsis: true,
          key: 'refBillType',
          width: 100,
          customRender(text, record, index) {
            text == 1 ? ((text = '入库') ? text == 2 : (text = '移库')) : (text = '暂无')
            return text
          }
        },
        {
          title: '不合格原因',
          dataIndex: 'unqualifiedReason',
          hidden: true,
          ellipsis: true,
          key: 'unqualifiedReason'
        },
        {
          title: '不合格数量',
          dataIndex: 'unqualifiedQty',
          key: 'unqualifiedQty',
          hidden: true
        },

        {
          title: '助记码',
          key: 'itemAssistantCode',
          width: 150,
          ellipsis: true,
          dataIndex: 'itemAssistantCode'
        },

        {
          title: '批号',
          key: 'lotNum',
          width: 150,
          ellipsis: true,
          dataIndex: 'lotNum'
        }

      ])

    },
    modalItems: {
      rowkey: 'locatorId',
      remoteUrl: {
        url: SERVICE_DATA_API_BASE+'/search/page',
        method: 'post'
      },
      remoteBefore(vn, params) {
        let p = { ...params }
        p.data = {
          num: '589130005049643008',
          pageNum: params.data.pageNum,
          pageSize: params.data.pageSize,
          params: params.data
        }
        return p
      },
      title: '销毁详情',
      gridformref: 'form',
      ref: 'modelFormType',
      items: [
        //genWarehouseAuthSearchModal 仓库

        ...genWarehouseAuthSearchModal(1, true, false, null, changecargoOwnerfun, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),
        ...genCargoownerAuthSearchModal(1, true, false, null, null, {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 }
        }),

        {
          type: 'select',
          span: 6,
          name: 'refBillType',
          label: '不合格品来源',
          value: '', //初始化值
          options: [
            { label: '所有', value: '' },
            { label: '入库', value: '1' },
            { label: '移库', value: '2' }
          ]
        },
        {
          type: 'input',
          span: 6,
          name: 'itemId',
          label: '商品',
          placeholder: '请输入产品名称或助记码或产品编',
          value: '' //初始化值
        },
        {
          span: 24,
          type: 'buttonGroup',
          style: { textAlign: 'right' },
          options: [
            {
              value: '查询',
              icon: 'search',
              btnType: 'primary',
              style: 'margin-right:10px;margin-left:10px;',
              htmlType: 'submit'
            },
            {
              value: '重置',

              name: 'ccz',
              icon: 'redo',
              on: {
                click(event, form) {
                  form.resetFields()
                }
              }
            }
          ]
        }
      ],
      columns: [
        {
          title: '日期',
          dataIndex: 'refBillDate',
          hidden: true,
          ellipsis: true,
          key: 'refBillDate'
        },
        {
          title: '原单据编号',
          dataIndex: 'refBillId',
          hidden: true,
          ellipsis: true,
          key: 'refBillId'
        },
        {
          title: '不合格品来源',
          dataIndex: 'refBillType',
          hidden: true,
          ellipsis: true,
          key: 'refBillType',
          width: 100,
          customRender(text, record, index) {
            text == 1 ? ((text = '入库') ? text == 2 : (text = '移库')) : (text = '暂无')
            return text
          }
        },
        {
          title: '不合格原因',
          dataIndex: 'unqualifiedReason',
          hidden: true,
          ellipsis: true,
          key: 'unqualifiedReason'
        },
        {
          title: '不合格数量',
          dataIndex: 'unqualifiedQty',
          key: 'unqualifiedQty',
          hidden: true
        },

        {
          title: '数量',
          key: 'lossQty',
          dataIndex: 'lossQty',
          width: 100,
          scopedSlots: { customRender: 'number' }
        },
        {
          title: '商品编码',
          key: 'itemCode',
          ellipsis: true,
          dataIndex: 'itemCode'
        },
        {
          title: '商品名称',
          key: 'itemName',
          ellipsis: true,
          dataIndex: 'itemName'
        },
        {
          title: '助记码',
          key: 'itemAssistantCode',
          ellipsis: true,
          dataIndex: 'itemAssistantCode'
        },
        {
          title: '生产厂家',
          key: 'manufacturerName',
          ellipsis: true,
          dataIndex: 'manufacturerName'
        },
        {
          title: '货位',
          key: 'locatorCode',
          ellipsis: true,
          dataIndex: 'locatorCode'
        },
        {
          title: '货位ID',
          key: 'locatorId',
          hidden: true,
          ellipsis: true,
          dataIndex: 'locatorId'
        },
        {
          title: '批号',
          key: 'lotNum',
          ellipsis: true,
          dataIndex: 'lotNum'
        },
        {
          title: '是否追溯',
          key: 'itemHealthSuperviseflag',
          ellipsis: true,
          dataIndex: 'itemHealthSuperviseflag',
          customRender(text, record, index) {
            text ? (text = '是') : (text = '否')
            return text
          }
        },
        {
          title: '商品规格',
          key: 'specification',
          ellipsis: true,
          dataIndex: 'specification'
        },
        {
          title: '产地',
          key: 'countryOriginName',
          ellipsis: true,
          dataIndex: 'countryOriginName'
        },

        {
          title: '上市许可持有人',
          key: 'itemHealthListedLicensor',
          ellipsis: true,
          width: 150,
          dataIndex: 'itemHealthListedLicensor'
        },
        {
          title: '包装数量',
          key: 'caseConversionRate',
          ellipsis: true,
          dataIndex: 'caseConversionRate'
        },
        {
          title: '包装单位',
          key: 'caseUom',
          ellipsis: true,
          dataIndex: 'caseUom'
        }
      ],
      ModalItemsOpinion: {
        ref: 'Opinion',
        items: [
          {
            type: 'input',
            span: 12,
            name: 'opinion',
            label: '意见',
            value: '' //初始化值
          }
        ]
      },
      destroyvisible: {
        items: [
          {
            type: 'date',
            format: 'YYYY-MM-DD',
            span: 6,
            required: true,
            name: 'destroyDate',
            label: '销毁日期',
            value: '' //初始化值
          },
          {
            type: 'input',
            span: 6,
            required: true,
            name: 'destroySituation',
            label: '销毁后现场情况',
            value: '' //初始化值
          },
          {
            type: 'input',
            span: 6,
            required: true,
            name: 'destroyExecutor',
            label: '销毁执行人签字',
            value: '' //初始化值
          },
          {
            type: 'input',
            span: 6,
            required: true,
            name: 'destroySupervisor',
            label: '销毁监督人签字',
            value: '' //初始化值
          },
          {
            type: 'input',
            span: 6,
            // required: true,
            name: 'nmpaOfficer',
            label: '监管部门人员签字',
            value: '' //初始化值
          },
          {
            type: 'input',
            span: 6,
            required: true,
            name: 'destroyPic',
            label: '销毁图片上传',
            hidden: true,
            value: '' //初始化值
          },
          {
            type: 'buttonGroup',
            span: 6,
            style: {
              textAlign: 'left'
            },
            options: [
              {
                value: '销毁图片上传',
                icon: 'search',
                btnType: 'primary',
                on: {
                  click: function(event, form) {
                    that.isUpload = true
                  }
                }
              }
            ]
          }
        ]
      }
    },
    details: {
      auditDate: '审核日期',
      //   auditOperator: '审核员',
      //   auditText: '审核意见',
      //   cargoOwnerId: '货主id',
      code: '单据编号',
      //   creator: '创建人',
      //   creatorName: '创建人',
      //   dcId: '仓配中心ID',
      destroyDate: '销毁日期',
      destroyExecutor: '销毁执行人',
      destroyMode: '销毁方式',
      destroyPic: '销毁图片',
      destroyReason: '销毁原因',
      destroySite: '销毁地点',
      destroySituation: '销毁后现场情况',
      destroySupervisor: '销毁监督人',
      //   enterpriseId: '企业ID',
      //   gmtCreate: '创建日期',
      //   gmtModified: '最后修改日期',
      //   id: '单据ID',
      //   modifier: '最后修改人',
      //   modifierName: '最后修改人',
      nmpaOfficer: '药监部门人员',
      remark: '备注',
      //   source: '数据来源',
      //   status: '状态',
      transportTool: '运输工具',
      transportor: '运输人员'
      //   warehouseId: '仓ID'
    }
  }
}

export default tablecolumns
