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 { auth } from '@/store/modules/auth';
import { session } from '@/store/modules/session';

@Module({
  namespaced: true,
  dynamic: true,
  store,
  name: 'product.outbound.foreign',
})
export class OutboundInternalModule extends VuexModule {
  /**
   * 退料类型列表
   */
  returningTypeList: any[] = [];

  /**
   * 查询退料类型列表
   */
  // @MutationAction
  // async queryReturningTypeList() {
  //   const { list = [] } = await http.post(url.tl.get.type, {
  //     factoryCode: session.factoryCode,
  //     loginName: session.loginName,
  //   });
  //   const returningTypeList = list.map((item: any) => ({
  //     label: item.name,
  //     value: item.code,
  //   }));
  //   return { returningTypeList };
  // }

  /**
   * 获取默认的工厂
   */
  @Action
  // async queryDefaultFactoryCode() {
  //   const { values = [] } = await http.post(url.auth.factory.sap, {
  //     factoryCode: session.factoryCode,
  //     loginName: session.loginName,
  //   });
  //   return values[0];
  // }

  /**
   * 退料上传
   */
  @Action
  async tluSubmit(params: any) {
    await auth.checkPassword({
      factoryCode: session.factoryCode as string,
      loginName: session.loginName as string,
      rfPwd: params.rfPwd,
    });
    await http.post(url.tl.u, {
      operatorPass: params.operator,
      factoryCode: session.factoryCode,
      loginName: session.loginName,
      unit: '',
      ...params,
    });
  }
}

export default getModule(OutboundInternalModule);
