/**
 * 菜单模块
 */
import { Module, VuexModule, Action, getModule } from 'vuex-module-decorators';
import store from '@/store';
import http from '@/utils/request';
import { url } from '@/utils/url';
import { User } from '@/store/modules/session';

// 看单
export interface Bill {
  warehouseCode?: string;
  warehouseName?: string;
  warehouseType?: string;
  loginName?: string;
  userName?: string;
  factoryCode?: string;
  factoryName?: string;
  sapFactoryCode?: string;
  locationCode?: string;
  workareaCode?: string;
  hideKdOrderNo?: any;
  documentNo?: string;
  carNo?: string;
  actualCarNo: string;
  appointmentTime?: string;
  arriveTime?: string;
  leaveTime: string;
  appointmentPlatform?: string;
  actualPlatform: string;
  sequenceNumber?: any;
  jobTimeout: any;
  jobTimeoutReason: any;
  sendSpot?: string;
}

@Module({
  dynamic: true,
  store,
  namespaced: true,
  name: 'checkout',
})
class CheckOutService extends VuexModule {
  // 获取看单
  @Action
  async getBillDetail({
    actualCarNo,
    factoryCode,
  }: {
    actualCarNo: Bill['actualCarNo'];
    factoryCode: User['factoryCode'];
  }): Promise<Bill> {
    const result: any = await http.post(url.appointmentreg.leave.carInfo, {
      actualCarNo,
      factoryCode,
    });
    return result.list[0];
  }

  // 提交看单
  @Action
  async submitBill(bill: Bill) {
    return await http.post(url.appointmentreg.leave.save, bill);
  }
}

export const checkout = getModule(CheckOutService);
