import { Action, getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators';
import store from '@/store';
import http from '@/utils/request';
import { url } from '@/utils/url';
import { session } from '@/store/modules/session';
// import { page } from '@/utils/page';
import vm from '@/main';

class OrderInInfo {
  productDescZh?: string;
  qty?: string;
  custCode?: string;
  custCodeName?: string;
  productCode?: string;
  locCode?: string;
  costCenter?: string;
}

@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'product.warehouse.wholeCollect',
})
export class wholeCollect extends VuexModule {
  WlList = [];
  code: any = '';
  recordsList: any = [];
  choiceCodeList: any = [];
  dnNo = '';
  orderInInfo: OrderInInfo = new OrderInInfo();
  modelList: any = [];
  status: any = '';

  @MutationAction
  async queryLocation() {
    const result: any = await http.get(url.warehouse.wholeTransfer.list, {
      params: {
        factoryCode: session.factoryCode,
        loginName: session.loginName,
      },
    });
    // console.log('库位数据',result)
    const WlList = result.data.map((_: any) => ({
      label: _.locationCode,
      value: _.locationCode,
    }));
    return { WlList };
  }

  @MutationAction
  async queryScrapList(param: any) {
    const res: any = await http.post(url.warehouse.MaterialInventory.list, param);
    const code = res.code;
    const modelList = res.data;
    console.log('modelList', modelList);
    return { code, modelList };
  }
  /**
   * 查询单号
   * 查询DN单号
   * @param dnNo
   */
  @MutationAction
  async getProductCode(params: any) {
    const res: any = await http.post(url.warehouse.MaterialInventory.content, params);
    const code = res.code;
    console.log('resssss', res);
    return { code };
  }

  @MutationAction
  async onTakeoutConfirm(params: any) {
    const records: any = await http.post(url.warehouse.MaterialInventory.commit, params);
    const status = records.data.status;
    return { status };
  }

  @Action({ commit: 'updateCheckedOrderInInfoListKw' })
  async changeOrderInLocation(kw: string) {
    await http.post('/wmspda/material/orderin/enter', {
      loginName: session.loginName,
      warehouseCode: '',
      factoryCode: session.factoryCode,
      locationCode: kw,
    });
    return kw;
  }
}

export default getModule(wholeCollect);
