import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from "@/views/kzyWMS/SearchModal";
import qs from "qs";
import { upcloud_base_gsp, SERVICE_DATA_API_BASE } from "@/config/serviceSettings";

import store from "@/store";
console.log(store.state.user.warehouse);
const baseUrl = upcloud_base_gsp;
let dcId = null;
let warehouseId = store.state.user.warehouse.warehouseId || null;
let bldgId = null;
let warehouseRoomId = null;
let warehouseAreaId = null;
let warehouseLogicId = null;
import { changecargoOwnerfun } from "@/views/kzyWMS/utils/setCargoOwner";
import moment from "moment";
import { sorter } from "../../../utils/sort";
const tablecolumns = {
  gridform: {
    ref: "form",
    items: [
      { type: "input", name: "warehouseId", label: "仓库id", hidden: true },
      { type: "input", name: "status", label: "", hidden: true, value: 2 },
      ...genWarehouseAuthSearchModal(
        1,
        true,
        false,
        null,
        function (rowData, form) {
          form.setFieldsValue({
            cargoOwnerCode: null,
            cargoOwnerId: null,
            cargoOwnerName: null,
          });

          console.log(rowData);
          if (!rowData) {
            warehouseId = null;
          } else {
            warehouseId = rowData[0].companyId;
          }
        },
        {
          span: 6,
          labelCol: { span: 6 },
          wrapperCol: { span: 14 },
        }
      ),
      ...genCargoownerAuthSearchModal(1, false, false, null, null, {
        span: 6,
        labelCol: { span: 6 },
        wrapperCol: { span: 14 },
      }),

      {
        type: "input",
        name: "date",
        label: "商品",
        span: 6,
        value: "",
      },

      {
        span: 6,
        type: "buttonGroup",
        style: { textAlign: "left" },
        options: [
          {
            value: "查询",
            icon: "search",
            btnType: "primary",
            style: "margin-right:10px;margin-left:30px;",
            htmlType: "submit",
          },
          {
            value: "重置",
            name: "ccz",
            icon: "redo",
            on: {
              click(event, form) {
                form.resetFields();
              },
            },
          },
        ],
      },
    ],
  },

  //主表
  MainTable: {
    edit: true,
    // edit: true,
    title: "分页查询养护列表",
    // /strategy/v1/page
    scroll: { x: 2000 },
    remoteUrl: {
      url: baseUrl + "/gspUpkeepCheck/listPage",
      method: "get",
    },
    doneBefore(data) {
      console.log(data);
      if (data.data == null) {
        data.data = {};
        data.data.list = [];
        return data;
      }
      data.data.list.forEach((item) => {
        // item.recheckConclusion = '0'
      });
      return data;
    },
    remoteBefore(vn, params) {
      let p = { ...params, status: 4, billtype: "YHD" };
      p.params.status = 4;
      console.log(p, params, "====");

      return p;
    },
    ref: "MainTable",
    rowkey: "id",
    columns: sorter([
      {
        title: "养护编号",
        dataIndex: "code",
        ellipsis: true,
        type: "txt",
        key: "code",
        // slots: { title: 'warehouseName' }
      },
      {
        title: "养护人",
        dataIndex: "upkeepOperator",
        ellipsis: true,
        type: "txt",
        key: "upkeepOperator",
      },
      {
        title: "养护日期",
        dataIndex: "upkeepDate",
        type: "txt",
        key: "upkeepDate",
        ellipsis: true,
      },
      {
        title: "商品编号",
        dataIndex: "itemCode",
        type: "txt",
        key: "itemCode",
        width: 100,
        ellipsis: true,
      },
      {
        title: "商品名称",
        dataIndex: "itemName",
        type: "txt",
        key: "itemName",
      },
      {
        title: "货位",
        ellipsis: true,
        dataIndex: "locatorName",
        type: "txt",
        key: "locatorName",
      },
      {
        title: "托盘号",
        ellipsis: true,
        dataIndex: "inContainerCode",
        type: "txt",
        key: "inContainerCode",
      },
      {
        title: "养护数量",
        dataIndex: "upkeepQty",
        type: "number",
        // type:'edit',
        disabled: true,
        // type: "txt",
        key: "upkeepQty",
      },
      {
        title: "养护待处理数量",
        ellipsis: true,
        type: "number",
        // type: "txt",
        disabled: true,
        dataIndex: "pendingQty",
        key: "pendingQty",
      },
      {
        title: "养护结论",
        dataIndex: "upkeepConclusion",
        scopedSlots: { customRender: "upkeepConclusion" },
        type: "txt",
        key: "upkeepConclusion",
      },
      {
        title: "质检结论",
        dataIndex: "checkConclusion",
        type: "txt",
        key: "checkConclusion",
        customRender(text) {
          switch (text) {
            case "0":
              text = "待处理";
              break;
            case "1":
              text = "合格";
              break;
            case "2":
              text = "不合格";
              break;
          }
          return text;
        },
        options: [
          { value: "0", label: "待处理" },
          { value: "1", label: "合格" },
          { value: "2", label: "不合格" },
        ],
      },
      {
        title: "质检意见",
        dataIndex: "checkOpinion",
        type: "txt",
        key: "checkOpinion",
      },
      {
        title: "复检结论",
        required: true,
        dataIndex: "recheckConclusion",
        type: "select",
        key: "recheckConclusion",
        options: [
          //   { value: '0', label: '待处理' },
          //   合格、不合格入退货库、不合格入不合格库
          { value: "1", label: "合格" },
          { value: "2", label: "不合格入不合格库" },
          { value: "3", label: "不合格入退货库" },
        ],
      },
      {
        title: "复检意见",
        dataIndex: "recheckOpinion",
        type: "edit",
        key: "recheckOpinion",
      },
      {
        title: "上市许可持有人",
        dataIndex: "itemHealthListedLicensor",
        ellipsis: true,
        type: "txt",
        key: "itemHealthListedLicensor",
      },
      {
        title: "批号",
        dataIndex: "lotNum",
        type: "txt",
        key: "lotNo",
      },

      {
        title: "生产日期",
        dataIndex: "pdateFrom",
        type: "txt",
        key: "pdateFrom",
        customRender(text) {
          if (text) {
            return moment(text).format("YYYY-MM-DD");
          } else return;
        },
      },
      {
        title: "有效期至",
        dataIndex: "validUntil",
        type: "txt",
        key: "validUntil",
        customRender(text) {
          if (text) {
            return moment(text).format("YYYY-MM-DD");
          } else return;
        },
      },
      {
        title: "质量状况",
        dataIndex: "qualityStatus",
        type: "txt",
        key: "qualityStatus",
        customRender(text) {
          switch (text) {
            case "0":
              text = "未确定";
              break;
            case "1":
              text = "合格";
              break;
            case "2":
              text = "不合格";
              break;
          }
          //   console.log(text)
          return text;
        },
      },

      //   {
      //     title: '操作',
      //     key: 'operation',
      //     scopedSlots: { customRender: 'operation' },
      //     align: 'center'
      //   }
    ]),
  },
  //弹窗
  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: "gridformModelFormType",
    ref: "modelFormType",
    items: [
      ...genWarehouseAuthSearchModal(1, true, false, null, changecargoOwnerfun, {
        span: 6,
        labelCol: { span: 6 },
        wrapperCol: { span: 14 },
      }),
      ...genCargoownerAuthSearchModal(1, false, 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",
        ellipsis: true,
        key: "refBillDate",
      },
      {
        title: "原单据编号",
        dataIndex: "refBillId",
        ellipsis: true,
        key: "refBillId",
      },
      {
        title: "不合格品来源",
        dataIndex: "refBillType",
        ellipsis: true,
        key: "refBillType",
        width: 100,
      },
      {
        title: "不合格原因",
        dataIndex: "unqualifiedReason",
        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",
      },
      {
        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: "opinions",
          label: "所在部门意见",
          value: "", //初始化值
        },
      ],
    },
  },
};

export default tablecolumns;
