captain-ui
Version:
有赞vue wap业务组件库
175 lines (151 loc) • 4.2 kB
JavaScript
import "vant/es/dialog/style";
import _Dialog from "vant/es/dialog";
import "vant/es/toast/style";
import _Toast from "vant/es/toast";
import _extends from "@babel/runtime/helpers/esm/extends";
import ajax from '../../../common/ajax';
import Config from '../config';
/**
* 发货服务:
* 1. 延长收货
* 2. 确认收货
* 3. 提醒发货
*/
var ExpressService =
/*#__PURE__*/
function () {
function ExpressService() {}
var _proto = ExpressService.prototype;
/**
* 延长收货
* @param
*/
_proto.extend = function extend(options) {
var _this = this;
var _option = {
checkUrl: options.checkUrl || Config.EXTEND_RECEIVE.CHECK_EXTEND_URL,
extendUrl: options.url || Config.EXTEND_RECEIVE.DO_EXTEND_URL,
data: options.data || {}
};
return new Promise(function (resolve, reject) {
ajax({
url: options.checkUrl,
data: options.data
}).then(function (res) {
if (res && res.code === 0) {
_this._startExtend(_extends(_option, {
resolve: resolve,
reject: reject
}));
} else {
if (res.code === Config.STATUS_MAP.TIME_NOT_ENOUGH || res.code === Config.STATUS_MAP.ALREADY_EXTENDED) {
_this._showInfoTips(res.msg);
} else {
_Toast(res.msg);
}
reject(res);
}
}, function (err) {
return reject(err);
});
});
};
/**
* 确认收货
* @param {*} options
*/
_proto.confirm = function confirm(options) {
var confirmUrl = options.url || Config.CONFIRM_RECEIVE.CONFIRM_URL;
var comfirmMessage = options.message || '确认收货后,订单交易完成,钱款将立即到达商家账户。';
return new Promise(function (resolve, reject) {
_Dialog.confirm({
title: '确认收货',
message: comfirmMessage,
confirmButtonText: '确认收货'
}).then(function (action) {
if (action === 'confirm') {
// loading
_Toast({
type: 'loading'
}); // request
ajax({
url: confirmUrl,
method: 'POST',
data: options.data
}).then(function (res) {
if (res.code === 0) {
_Toast('收货成功');
resolve();
} else {
_Toast(res.msg);
reject(res);
}
}, function (err) {
_Toast(err.msg);
reject(err);
});
} else {
reject();
}
});
});
};
/**
* 提醒发货
* @param {*} options
*/
_proto.remindSend = function remindSend(options) {
var remindSendUrl = options.remindSendUrl || Config.REMIND_SEND.REMIND_SEND_URL;
return new Promise(function (resolve, reject) {
ajax({
url: remindSendUrl,
method: 'POST',
data: options.data
}).then(function (res) {
if (res.code === 0) {
_Toast('提醒发货成功。');
resolve();
} else {
_Toast(res.msg);
reject(res);
}
}, function (err) {
return reject(err);
});
});
};
_proto._startExtend = function _startExtend(options) {
var _this2 = this;
_Dialog.confirm({
title: '延长收货时间',
message: '每笔订单只能延长一次收货时间,如需多次延长请联系商家。',
cancelButtonText: '确定延长',
confirmButtonText: '取消'
}).catch(function () {
ajax({
url: options.extendUrl,
data: options.data
}).then(function (res) {
if (res && res.code === 0) {
_this2._showInfoTips(res.msg);
options.resolve && options.resolve();
} else {
_Toast(res.msg);
options.reject && options.reject();
}
});
});
};
_proto._showInfoTips = function _showInfoTips(msg) {
if (msg === void 0) {
msg = '';
}
_Dialog.alert({
title: '延长收货时间',
message: msg,
confirmButtonText: '我知道了'
});
};
return ExpressService;
}();
export default ExpressService;