import { Columns, TabColumns } from "../add/column";
import { initColumns, initParams } from "@/utils/init";
import deepCopy from "@gby/deep-copy";
// import {deepCopy} from "../dist/deep-copy.es"


export const editColumns = initColumns(Columns);

export const editTabColumns = TabColumns.map((element) => ({
  ...element,
  tableColumns: initColumns(element.tableColumns),
}));

export const SelectColumns = editColumns.filter(column => column.inputType === 'Select')

editTabColumns.forEach(column => {

  SelectColumns.push(...column.tableColumns.filter(cColumn => cColumn.inputType === 'Select'))

});


// 禁用项
export const forbidden = (isEdit) => {

  let updateColumns = deepCopy(editColumns);
  let updateTabColumns = deepCopy(editTabColumns);

  console.log(isEdit, 'isEdit');
  
  if(!isEdit){  

    console.log('修订');
    // 修订
    updateColumns.forEach(item => {

      if (item.key == 'buyerName' || item.key == 'puDeptName' || item.key == 'deductionMoney' ||
        item.key == 'supplierContactsName' || item.key == 'agentName' || item.key == 'isInvoice' ||
        item.key == 'rebateMoney' || t.key == 'remark') {
        item.disabled = false;
        item.readonly = false;
      } else {
        item.disabled = true;
        item.readonly = true;
      }
    })

    updateTabColumns.forEach(item => {

      item.tableColumns.forEach(t => {

        if (t.key == 'unit' || t.key == 'qty' ||
          t.key == 'place' || t.key == 'arrivalDatePlan' || t.key == 'storageCondition' ||
          t.key == 'carriageCondition' || t.key == 'customerName' || t.key == 'isBatchLock' ||
          t.key == 'isReplenishment' || t.key == 'originalQty' || t.key == 'originalMoney' 
        ) {

          t.disabled = false;
          t.readonly = false;
        } else {
          t.disabled = true;
          t.readonly = true;
        }
      })
    })

  }

  return { updateColumns, updateTabColumns }

}
