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

class OrderInInfo {
  checked?: boolean;
  poNo?: string;
  kw?: string;
  userDefined10?: string;
  orderStatus?: string;
}

@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'raw.warehouse.rowTransfer',
})
export class rowTransfer extends VuexModule {
  /**
   * sap库存地点列表
   */
  cboPlaceList = [];
  /**
   * 隐藏看单号
   */
  poNo = '';
  /**
   * 看单号查询结果
   */
  orderInInfo: OrderInInfo = new OrderInInfo();
  /**
   * 看单明细
   */
  orderInInfoList: OrderInInfo[] = [];
  materielList = [];
  code = '';
  /**
   * 看单明细未通过明细
   */
  // orderInInfoListEx: OrderInInfo[] = [];

  /**
  //  * 查询看单号
   * @param poNo 
   */
  @MutationAction
  async takeYKOrder(order3: any) {
    // console.log('获取来的数据咋啊啊啊');
    try {
      const records: any = await http.post(url.warehouse.rowTransfer.list, {
        ...order3,
        orderType: 'YK',
        page: 1,
        rows: 50,
        factoryCode: session.factoryCode,
        loginName: session.loginName,
      });
      console.log('records', records);
      const code = records.code;
      const orderInInfoList = records.data.records;
      const materielList = orderInInfoList.map((item: any) => ({
        label: item.productCode,
        value: item.stoItem,
        ...item,
      }));
      return { orderInInfoList, materielList, code };
    } catch {
      //uni.showToast({ icon: 'none', title: vm.$t('message.Warehouse_Tip11') as any });
      vm.customToast(vm.$t('message.Warehouse_Tip11') as any);
    }
  }

  @MutationAction
  async onTakeoutConfirm(list: any) {
    const records: any = await http.post(url.warehouse.rowTransfer.commit, list);
    const code = records.code;
    return { code };
  }
  //清除数据
  @MutationAction
  async empty() {
    const materielList = [];
    return { materielList };
  }
}

export default getModule(rowTransfer);
