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';
import { removeDuplicates } from '@/utils/filter';

class OrderInInfo {
  productDescZh?: string;
  qty?: string;
  custCode?: string;
}

@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'product.warehouse.wholeLnventory',
})
export class wholeLnventory extends VuexModule {
  /**
   * 库位地点列表
   */
  WlList = [];
  WlListaa = [];
  productCode: any = '';
  productDescZh: any = '';
  code: any = '';
  /**
   * 物料型号类型
   */
  // modelType = [
  //   { label: '内销', value: '0' },
  //   { label: '外销', value: '1' },
  //   { label: '样机', value: '2' },
  //   { label: '半成品', value: '4' },
  // ];
  /**
   * 隐藏看单号
   */
  dnNo = '';
  records = {
    code: '',
  };
  /**
   * 看单号查询结果
   */
  orderInInfo: OrderInInfo = new OrderInInfo();
  /**
   * 查询单号
   * 查询DN单号
   * @param dnNo
   */
  @MutationAction
  async getProductCode(pddNo: string) {
    const res: any = await http.post(url.warehouse.wholeLnventory.content, {
      pddNo,
      factoryCode: session.factoryCode,
      // factoryCode: '1999',
      // loginName: '1999',
      loginName: session.loginName,
    });
    const WlListaa = res.data;
    let arr: any = [];
    const code = res.code;
    // 去重
    arr = removeDuplicates([...res.data], 'locCode');
    const WlList = arr.map((item: any) => ({
      label: item.locCode,
      value: item.locCode,
    }));
    // WlList select结构，只有lbael,value
    // WlListaa 原始结构
    return { WlList, WlListaa, code };
  }

  @MutationAction
  async onTakeoutConfirm(list: any) {
    const records: any = await http.post(url.warehouse.wholeLnventory.commit, list);
    if (records.code == 1) {
      uni.showToast({
        icon: 'success',
        title: 'success',
      });
      // uni.navigateTo({ url: page.product.warehouse.index });
    }
    return {};
  }

  @MutationAction
  async toScanCode(list: any) {
    const records: any = await http.post(url.warehouse.wholeLnventory.scanCode, list);
    if (records.code == 1) {
      console.log('数据啊啊啊', records);
      // uni.showToast({
      //   icon: 'none',
      //   title: vm.$t('message.Warehouse_Tip9') as any,
      // });
      vm.customToast(vm.$t('message.Warehouse_Tip9') as any);
      this.productCode = records.data.productCode;
      this.productDescZh = records.data.productDescZh;
      return { records };
    }
    // if (records.code == 0) {
    //   console.log('woqunimade');
    // }
  }

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

export default getModule(wholeLnventory);
