/*
 * @Date: 2022-10-17 09:09:15
 * @LastEditors: 陈禹琨 cyk910622@163.com
 * @LastEditTime: 2023-02-06 09:59:32
 * @FilePath: \upcloud-wms-henanyiyao-web\src\views\kzyWMS\inBound\shelf\billEditor\config\detail\index.js
 * @Description: cyk
 */
import { basicData } from "./basic-data";
import { extendFormItems } from "./extend";
import { baseUrl } from "../../../../config/baseUrl";

var params = null;

let code = ["AGVL", "AGVSP", "AGVQX", "AGVZ", "MJK"]

export function detailConfig(self) {
  return [
    {
      key: "one",
      checkedKey: "main",
      height: "auto",
      btns: [
        {
          label: "上架",
          click() {
            self.toShelf();
          },
        },
      ],
      list: [
        {
          key: "main",
          tab: "主要信息",
          item: {
            type: "p-search-table",
            autoLoad: false,
            rowSelectType: 1,
            rowKey: "rcvHeaderId",
            config: basicData(self),
            remoteUrl: baseUrl + "/rcvInstockLines/extractRcvH",
            remoteParams: params,
            operators: [],
            doneBefore(response) {
              response.data.list = response.data.list.map((item) => {
                return {
                  ...item,
                  ...item.rcvHeadersDTO,
                  ...item.rcvHeadersProfilesDTO,
                };
              });
              return response;
            },
            selectChange(selectedRowKeys, selectedRows) {
              let ref = self.queryRefFromName("list");
              self.selectedMainItem = selectedRows[0];
              if (selectedRows.length < 1) {
                ref.data = [];
                return;
              }
              self.handleQuerySubList({ rcvHeaderId: selectedRowKeys[0] }).then((res) => {
                res.forEach((t) => {
                  t.warehouseLocatorName = t.whLocatorName;
                  t.realWhLocatorId = t.whLocatorId;
                  t.realWhLocatorCode = t.whLocatorCode;
                });
                ref.data = res;
              });
            },
          },
        },
      ],
    },
    {
      key: "two",
      checkedKey: "list",
      list: [
        {
          key: "list",
          tab: "商品明细",
          btns: [
            {
              label: "差异",
              click() {
                self.toErrorBill();
              },
            },
          ],
          item: {
            type: "p-table-edit",
            rowSelectType: 2,
            rowKey: "taskInboundId",
            config: extendFormItems(self),
            getCheckboxProps(record) {
              return {
                props: {
                  disabled: code.includes(record.whAreaCategoryCode),
                  name: record.name
                }
              }
            },
            operations: [
              {
                title: "拆分",
                click(record) {
                  self.showSplitBill(record);
                },
                show(record) {
                  let flag = code.includes(record.whAreaCategoryCode)
                  return !flag
                }
              },
            ],
            colChange({ record, name, value }) {},
            onClick(selectedRowKeys, selectedRows, data) { },
            // onSelectRow(p1, selectedRows) {
            //   let flag = selectedRows.some(item=>code.includes(item.whAreaCategoryCode))
            //   if (flag) {
            //     let ref = self.queryRefFromName('list')
            //     ref.selectedRowKeys = ref.data.filter(item => !code.includes(item.whAreaCategoryCode)).map(t=>t.taskInboundId)
            //     console.log(ref.selectedRowKeys,'ref.selectedRowKeys');
            //   }
            // },
          },
        },
      ],
    },
  ];
}
