82 lines
2.9 KiB
JavaScript
82 lines
2.9 KiB
JavaScript
import DebugClazz from './WechatMpShip.debug';
|
|
export default class WechatMpShip extends DebugClazz {
|
|
async eOrder(shipId, context) {
|
|
const data = await this.prepareOrder(shipId, context);
|
|
const instance = await this.getInstance(context);
|
|
const result = await instance.addExpressOrder(data);
|
|
return result.waybill_id;
|
|
}
|
|
async cancelOrder(shipId, context) {
|
|
const instance = await this.getInstance(context);
|
|
const data = await this.prepareCancelOrder(shipId, context);
|
|
await instance.cancelExpressOrder(data);
|
|
}
|
|
async syncState(shipId, context) {
|
|
const instance = await this.getInstance(context);
|
|
const data = await this.prepareGetPath(shipId, context);
|
|
const result = await instance.getExpressPath(data);
|
|
const { path_item_num, path_item_list } = result;
|
|
const latestPath = path_item_list[path_item_num - 1] || undefined;
|
|
const latestType = latestPath?.action_type;
|
|
const latestTime = latestPath?.action_time;
|
|
/**
|
|
* action_type:
|
|
* 100001 揽件阶段-揽件成功
|
|
* 100002 揽件阶段-揽件失败
|
|
* 100003 揽件阶段-分配业务员
|
|
* 200001 运输阶段-更新运输轨迹
|
|
* 300002 派送阶段-开始派送
|
|
* 300003 派送阶段-签收成功
|
|
* 300004 派送阶段-签收失败
|
|
* 400001 异常阶段-订单取消
|
|
* 400002 异常阶段-订单滞留
|
|
*/
|
|
let state = undefined;
|
|
switch (latestType) {
|
|
case 100001:
|
|
case 100003:
|
|
case 200001:
|
|
case 300002: {
|
|
state = 'shipping';
|
|
break;
|
|
}
|
|
case 300003: {
|
|
state = 'received';
|
|
break;
|
|
}
|
|
// case 400001: {
|
|
// state = 'reject';
|
|
// break;
|
|
// }
|
|
case 100002:
|
|
case 300004:
|
|
case 400002: {
|
|
state = 'unknow';
|
|
break;
|
|
}
|
|
}
|
|
return { state, time: latestTime };
|
|
}
|
|
async syncPaths(shipId, context) {
|
|
const instance = await this.getInstance(context);
|
|
const data = await this.prepareGetPath(shipId, context);
|
|
const result = await instance.getExpressPath(data);
|
|
const paths = result.path_item_list?.map((path) => ({
|
|
time: path.action_time,
|
|
action: path.action_msg,
|
|
}));
|
|
return paths;
|
|
}
|
|
async getPrintInfo(shipId, context) {
|
|
const instance = await this.getInstance(context);
|
|
const data = await this.prepareGetOrder(shipId, context);
|
|
const result = await instance.getExpressOrder(data);
|
|
const base64Html = result.print_html;
|
|
const html = decodeURIComponent(escape(window.atob(base64Html)));
|
|
return {
|
|
type: 'html',
|
|
data: html,
|
|
};
|
|
}
|
|
}
|