vesh-cli
Version:
码农村nodejs版本VESH框架脚手架搭建器
673 lines (666 loc) • 40.1 kB
JavaScript
(function (V, M, $) {
new function () {
var _ = this, __ = {};
{
V.watch();
V.isDebug = true;
var config = V.merge(window.config, {
Middler: {
'VESH.view': {
titlepart: { type: 'SHI.view.NavList', path: '../../style/module/part/title.css;../../Scripts/module/part/title.js' },
receipts: { type: 'SHI.view.Receipts', path: '../../style/module/part/receipts.css;../../Scripts/module/part/receipts.js', params: ["Receipt.part"] },
receiptlist: {
type: 'SHI.view.ReceiptList', path: '../../style/module/part/receiptlist.css;../../Scripts/module/part/receiptlist.js', params: [
{ type: 'VJ.middler.getTypeByAppName', params: [{ self: true }, 'VESH.view', 'scrollpanel'], method: 'factory', mode: 'static' },
{ type: 'VJ.middler.getTypeByAppName', params: [{ self: true }, 'VESH.view', 'panel'], method: 'factory', mode: 'static' },
'', '', 200, false
]
},
orderlist: {
type: 'SHI.view.OrderList', path: '../../style/module/part/orderlist.css;../../Scripts/module/part/orderlist.js', params: [
{ type: 'VJ.middler.getTypeByAppName', params: [{ self: true }, 'VESH.view', 'scrollpanel'], method: 'factory', mode: 'static' },
{ type: 'VJ.middler.getTypeByAppName', params: [{ self: true }, 'VESH.view', 'panel'], method: 'factory', mode: 'static' },
'', '', 200, false
]
},
orders: {
type: 'SHI.view.Orders', path: '../../style/module/part/orders.css;../../Scripts/module/part/orders.js', params: [{ middler: true }, '', '', 200, false]
},
receiptpage: { type: 'SHI.view.ReceiptDetail', path: '../../style/module/part/receipt.css;../../scripts/module/part/receipt.js', params: ["ReceiptDetail.part"] },
pay: { type: 'SHI.view.Pay', path: '../../style/module/part/pay.css;../../Scripts/module/part/paynew.js', params: ["pay.part"] },
orderdetail: { type: 'SHI.view.OrderDetail', path: '../../style/module/part/orderDetail.css;../../Scripts/module/part/orderDetail.js', params: ["OrderDetail.part"] },
rangepanel: { type: '.Panel', path: 'hammer.min.js', params: ['', {}, 0.3, true] },
buttonbox: { type: 'SHI.view.ButtonBox', path: '../../style/module/part/buttonbox.css;../../Scripts/module/part/buttonbox.js', params: [] },
button: { type: '.Button', path: '../../Scripts/VJ.view.extend.js', params: ['<div><span style="display:none;"></span><input type="button"></input></div>'] },
timer: { type: 'SHI.view.Timer', path: '../../Scripts/module/part/timer.js' },
appobject: { type: 'SHI.view.AppObject', path: '../../Scripts/module/part/app.js' }
}
}
});
var vm = {
title: {
data: { value: 0, values: [{ index: 0, name: '电子小票' }, { index: 1, name: '未支付' }, { index: 2, name: '已支付'}] },
onLoad: function (data, self) {
V.registEvent("RPIndex.submitsuccess", function () {
self.update({ value: 1 });
V.callEvent('RPIndex.change', [1]);
});
V.registEvent('RPIndex.paysuccess', function (orderId) {
self.update({ value: 2 });
V.callEvent('RPIndex.change', [2]);
});
V.registEvent("unpayorders.end", function () {
self.update({ value: 0 });
V.callEvent('RPIndex.change', [0]);
});
},
onChange: function (data, self) {
this.pages.update({ value: data.value });
V.callEvent('RPIndex.change', [data.value]);
return data;
}
},
pages: {
data: { lock: true },
onLoad: function (data, self) {
V.registEvent('RPIndex.paysuccess', function (orderId) {
self.update({ value: 2 });
});
V.registEvent("RPIndex.submitsuccess", function () {
self.update({ value: 1 });
});
V.registEvent("unpayorders.end", function () {
self.update({ value: 0 });
});
},
onChange: function (data, self) {
this.title.update({ value: data.value });
V.callEvent('RPIndex.change', [data.value]);
}
},
receipts: {
data: { value: 0 },
onLoad: function (data, self) {
V.registEvent('RPIndex.change', function (index) {
if ((index + '') == '0') {
self.call('active', { userId: _.page.data.userId, firstShow: true });
} else {
self.call('noactive');
}
});
V.registEvent(['RPIndex.closeReceipt', "RPIndex.submitfail", 'RPIndex.paysuccess'], function () {
V.once(function () {
self.call('active', { userId: _.page.data.userId, firstShow: true });
}, 500);
});
V.registEvent(["unpayorders.end"], function () {
self.call('active', { userId: _.page.data.userId, firstShow: true, isPassed: false });
});
V.registEvent(["receipt.passed"], function () {
self.call('active', { userId: _.page.data.userId, firstShow: true, isPassed: true });
});
},
onSubmit: function (data, self) {
V.callEvent('receipt.submit', [data.ids]);
//this.pay.call("init", { orderId: data.value });
}
},
unpayorders: {
data: { value: 0 },
onLoad: function (data, self) {
V.registEvent('RPIndex.change', function (index) {
if ((index + '') == '1') {
self.call('active', { userId: _.page.data.userId });
}
});
V.registEvent("RPIndex.submitsuccess", function () {
V.once(function () {
self.call('active', { firstShow: true, userId: _.page.data.userId });
}, 400);
});
V.registEvent("RPIndex.paysuccess", function () {
V.once(function () {
self.call('active', { firstShow: true, userId: _.page.data.userId });
}, 500);
});
},
onSubmit: function (data, self) {
console.log('unpayorder.submit:' + data.value);
V.callEvent("unpayorders.submit", [data.value]);
},
onDetail: function (data, self) {
console.log('unpayorder.detail:' + data.value);
V.callEvent("unpayorders.detail", [data.value]);
},
onCancle: function (data, self) {
console.log('unpayorder.end:' + data.value);
V.callEvent("unpayorders.end", [data.value]);
},
onLoading: function (data, self) {
V.callEvent('unpayorders.loading', [data.msg]);
},
onLoadEnd: function (data, self) {
V.callEvent('unpayorders.loadend', [data.msg]);
}
},
realpayorders: {
data: { value: 0 },
onLoad: function (data, self) {
V.registEvent('RPIndex.change', function (index) {
if ((index + '') == '2') {
self.call('active', { userId: _.page.data.userId });
}
});
V.registEvent("RPIndex.paysuccess", function () {
V.once(function () {
self.call('active', { firstShow: true, userId: _.page.data.userId });
}, 500);
});
},
onBringUp: function (data, self) {
console.log('realpayorders.bringup:' + data.value);
V.callEvent('realpayorders.bringup', [data.value]);
},
onDetail: function (data, self) {
console.log('realpayorders.detail:' + data.value);
V.callEvent("realpayorders.detail", [data.value]);
},
onLoading: function (data, self) {
V.callEvent('realpayorders.loading', [data.msg]);
},
onLoadEnd: function (data, self) {
V.callEvent('realpayorders.loadend', [data.msg]);
}
},
receipt: {
data: { value: 0, firstShow: true, visible: false },
onLoad: function (data, self) {
console.log('receipt');
var _this = this;
V.registEvent('RPIndex.change', function (index) {
console.log('receipt:' + index);
if (data.firstShow && _.page.data.userId && (index + '') == '0') {
data.firstShow = false;
var receiptid = V.qs.get('receiptid');
if (receiptid) {
self.call('active', { value: receiptid, userId: _.page.data.userId, Mobile: _.page.data.Mobile, Name: _.page.data.Name, RealUserID: _.page.data.RealUserID, show: 'fadeInRight' });
V.callEvent('RPIndex.bindReceipt', [receiptid, _.page.data.userId]);
} else if (V.qs.get('receiptid1')) {
V.callEvent("receipt.passed", ['因技术升级,小票扫码支付功能将暂停一段时间,敬请期待']);
}
}
});
V.registEvent("RPIndex.submitsuccess", function () {
self.update({ hide: 'fadeOutRight' });
});
V.registEvent("RPIndex.submitfail", function () {
if (data.visible) {
self.update({ hide: 'fadeOutRight' });
}
});
},
onPassed: function (data, self) {
V.callEvent("receipt.passed", [data.msg]);
},
onSaleFlag: function (data, self) {
V.callEvent("receipt.saleflag", [data.msg]);
},
onNext: function (data, self) {
self.update({ hide: 'fadeOutRight' });
V.callEvent("RPIndex.nextReceipt");
},
onSubmit: function (data, self) {
//事件改为去结算
V.callEvent('RPIndex.submitReceipt', [data.value]);
},
onClose: function (data, self) {
console.log('关闭小票详情');
//window.history.go(-1);
self.update({ hide: 'fadeOutRight' });
V.callEvent('RPIndex.closeReceipt', [data.value]);
}
},
orderDetail: {
data: { value: 0 },
onLoad: function (data, self) {
V.registEvent("unpayorders.detail", function (orderId) {
self.call("init", { orderId: orderId, userId: _.page.data.userId });
});
V.registEvent("realpayorders.detail", function (orderId) {
self.call("init", { orderId: orderId, userId: _.page.data.userId });
});
V.registEvent("realpayorders.bringup", function (orderId) {
self.call("init", { orderId: orderId, userId: _.page.data.userId });
});
V.registEvent('RPIndex.paysuccess', function (orderId) {
//订单支付成功显示界面
if (!orderId || orderId.length == 0) {
V.callCommand('receipt.message', ["没有获取到订单号"]);
return;
}
self.call("init", { orderId: orderId, userId: _.page.data.userId });
});
},
onInit: function (data, self) {
if ((data.orderId + "").length < 1) {
console.log("订单号格式错误");
} else {
self.update({ orderId: data.orderId, userId: _.page.data.userId });
V.callEvent('orderDetail.detail', [data.orderId]);
}
},
onBack: function (data, self) {
V.callEvent("orderDetail.hide");
self.update({ hide: 'fadeOutRight' });
},
onPay: function (data, self) {
var paycode = data.payCode, paytype = data.payType;
if (!paycode || paycode.length == 0 || paytype.length == 0) {
return; //有误的情况或没有获取到订单信息的时候
}
if (paytype.split(";").length == 1 && paycode.indexOf(";") < 0) {
V.callEvent('orderDetail.submitApp', [data.orderId]);
} else {
V.callEvent('orderDetail.submit', [data.orderId]);
}
self.update({ hide: 'fadeOutRight' });
//V.callEvent('RPOrderDetail.change', ["orderDetaiHide:"]);
},
onNoData: function (data, self) {
V.callEvent("orderDetail.hide");
self.update({ hide: 'fadeOutRight' });
V.callEvent('receipt.message', [data.msg]);
},
onNoCode: function (data, self) {
self.update({ hide: 'fadeOutRight' });
V.callCommand('receipt.message', [data.msg]);
},
onLoadEnd: function (data, self) {
V.callEvent('order.loadend', [data.msg]);
}
},
pay: {
onLoad: function (data, self) {
V.registEvent("unpayorders.submit", function (orderId) {
self.call("init", { orderId: orderId });
});
V.registEvent("orderDetail.submit", function (orderId) {
self.call("init", { orderId: orderId });
});
V.registEvent("pay.vipCode", function (vipCode) {
data.vipCode = vipCode.code;
data.mobile = vipCode.mobile;
});
},
onInit: function (data, self) {
if ((data.orderId + "").length < 1) {
console.log("结算页面订单号格式错误");
} else {
V.callEvent("pay.title", ["结算"]);
self.update({ orderId: data.orderId, userId: _.page.data.userId, ispay: false, show: 'fadeInRight' });
V.callEvent('pay.detail', [data.orderId]);
}
},
onBack: function (data, self) {
self.update({ hide: 'fadeOutRight' });
V.callEvent('Pay.Close');
//V.callEvent('RPOrderDetail.change', ["orderDetaiHide:"]);
},
onPay: function (data, self) {
if (data.payType && data.payType.length > 0) {
var updateOrderPayType = "updateOrderPayType";
if (data.isYG) {
updateOrderPayType = "updateOrderPayTypeYG";
}
if (data.ispay) {//已经选择过支付方式
V.callEvent('pay.submitApp', [data.orderId]);
self.update({ hide: 'fadeOutRight' });
return;
}
V.callEvent("RPIndex.paystart");
_.ni.excute('template', updateOrderPayType, { orderId: data.orderId, payType: data.payType, payCode: data.payCode, mobile: data.mobile, vipno: data.vipCode, r: new Date().getTime() }, function (res) {
V.callEvent("RPIndex.payend");
var ret = res.last();
if (ret && ret.length > 0 && ret[0].length > 0 && ret[0][0].status == "true") {
V.callEvent('pay.submitApp', [data.orderId]);
self.update({ hide: 'fadeOutRight' });
} else {
if (data.isYG) {
V.callCommand('receipt.message', ["请输入有效的银泰会员卡号绑定的手机号"]);
} else {
V.callCommand('receipt.message', ["提交数据错误,请重新提交"]);
}
}
});
} else {
V.callEvent('receipt.message', ["请选择支付方式!"]);
}
},
onNoData: function (data, self) {
self.update({ hide: 'fadeOutRight' });
//V.callEvent('receipt.message', [data.msg]);
V.callEvent('Pay.Close');
},
onLoadEnd: function (data, self) {
V.callEvent("pay.loadend");
}
},
his: {
data: { value: 0 },
onLoad: function (data, self) {
// V.registEvent('RPIndex.change', function (index) {
// self.update({ add: 'title:' + index });
// });
self.update({ add: 'index:' }); //把首页也加进来
V.registEvent('RPIndex.bindReceipt', function (orderId) {
//处理订单详情变化
self.update({ add: 'receiptHide:' });
});
V.registEvent('orderDetail.detail', function (orderId) {
//处理订单详情变化
self.update({ add: 'orderDetaiHide:' + orderId });
});
V.registEvent('RPIndex.closeReceipt', function (orderId) {
self.update({ back: true });
});
V.registEvent('pay.detail', function (orderId) {
//处理订单详情变化
self.update({ add: 'payHide:' });
});
V.registEvent("orderDetail.submit", function () {
console.log(self.get().history);
self.update({ remove: true });
setTimeout(function () { console.log(self.get().history); }, 500);
});
V.registEvent("orderDetail.submitapp", function () {
self.update({ remove: true });
});
V.registEvent("orderDetail.hide", function () {
self.update({ remove: true });
});
V.registEvent("Pay.Close", function () {
self.update({ remove: true });
});
},
onChange: function (data, self) {
console.log(data);
var _ = this;
var order = data.hash.split(':');
if (order.length == 0) return;
// switch (order[0]) {
// case 'title':
// _.title.update({ value: order[1] });
// _.pages.update({ value: order[1] });
// V.callEvent("RPIndex.change", order[1]);
// break;
// }
var action = data.lastAction ? data.lastAction.split(':') : "";
switch (action[0]) {
case 'orderDetaiHide':
if (this.orderDetail.data.visible) {
this.orderDetail.update({ hide: 'fadeOutRight' });
}
break;
case 'receiptHide':
if (this.receipt.data.visible) {
this.receipt.update({ hide: 'fadeOutRight' });
V.callEvent('RPIndex.change', 0);
}
break;
case 'payHide':
if (this.pay.data.visible) {
this.pay.update({ hide: 'fadeOutRight' });
}
break;
}
}
},
appobject: {
data: { userId: { test: "22"} },
onLoad: function (data, self) {
/*
self.update({ settitlebar:"yintaimobile://SetTitleBar?position=right&isShow=false&value=首页" });
yintaimobile://ShieldTopBottom?state=true 设置屏蔽顶部和底部的点击事件
*/
V.registEvent("RPIndex.change", function (value) {
switch (value + "") {
case "0":
self.update({ settitle: '我的电子小票' });
break;
case "1":
self.update({ settitle: '未支付订单' });
break;
case "2":
self.update({ settitle: '已支付订单' });
break;
}
});
V.registEvent("pay.title", function (value) {
self.update({ settitle: value });
});
V.registEvent("orderDetail.detail", function (value) {
self.update({ settitle: "订单详情" });
});
V.registEvent("RPIndex.nextReceipt", function () {
self.update({ scan: true, close: true });
});
//外部调用app接口,在此加
V.registEvent("pay.submitApp", function (orderId) {
self.update({ startpaynow: orderId });
console.log("pay.submitApp" + orderId);
});
V.registEvent("orderDetail.submitApp", function (orderId) {
self.update({ startpaynow: orderId });
console.log("orderDetail.submitApp" + orderId);
});
V.registEvent("RPIndex.submitfail", function () {
self.update({ showdialog: '该小票已生成订单或已支付过,请勿重复提交!' });
});
V.registEvent(["receipt.passed", "receipt.saleflag"], function (value) {
self.update({ showdialog: value });
});
//统一入口:弹出提示
V.registEvent("receipt.message", function (value) {
self.update({ showdialog: value });
});
V.registCommand("receipt.message", function (value) {
console.log('message' + value);
self.update({ showdialog: value });
});
V.registEvent(["RPIndex.submitstart", "unpayorders.detail", "realpayorders.detail", "realpayorders.bringup", "RPIndex.paystart", "RPIndex.paysuccess", "unpayorders.submit", "orderDetail.submit", "unpayorders.loading", "realpayorders.loading"], function (value) {
self.update({ pageload: true });
});
V.registEvent(["RPIndex.submitfail", "RPIndex.submitsuccess", "order.loadend", "RPIndex.payend", "pay.loadend", "unpayorders.loadend", "realpayorders.loadend"], function (value) {
V.once(function () {
self.update({ pageload: false });
}, 1000);
});
},
onUserInfo: function (data, self) {
console.log(data.userInfo.userid);
//self.update({ showdialog: '获取用户信息去也' + data.userInfo.userid });
self.ni.excute("template", "getUserInfo", { userID: data.userInfo.userid }, function (res) {
var ret = res.last();
if (!ret || ret[0].length < 1) {
//app.login();
self.update({ 'showdialog': '网络连接失败,请重新进入页面' });
V.once(function () {
self.update({ close: true });
}, 2000);
} else if (ret && ret.length > 0) {
if (ret[0][0].Mobile == "500") {
self.update({ 'showdialog': '用戶信息解析失败,请重新进入小票界面' });
console.log('用戶信息解析失败,错误信息:' + ret[0][0].Name);
V.once(function () {
self.update({ close: true });
}, 2000);
return;
}
_.page.data.userInfo = data.userInfo;
data.userInfo.userid = ret[0][0].UserID;
data.userInfo.Mobile = ret[0][0].Mobile;
data.userInfo.Name = ret[0][0].Name;
data.userInfo.RealUserID = ret[0][0].RealUserID;
_.page.data.userId = data.userInfo.userid;
_.page.data.Mobile = data.userInfo.Mobile;
_.page.data.Name = data.userInfo.Name;
_.page.data.RealUserID = data.userInfo.RealUserID;
V.once(function () {
V.callEvent('RPIndex.change', [0]);
//建议少使用异步加载part的情况 调试状态下 慢10倍 需要500ms返回一个页面
//todo 等待其part部分加载完成onLoad事件 part需要优化 或者start方法需要等待加载完成
}, 20);
}
})
},
onOperatecallback: function (data, self) {
//处理app调用h5回调
//支付结果:params:yintaimobile://PayResult?orerId=125544
//登陆结果:params: yintaimobile://LoginResult
var param = data.params;
if (param.indexOf("yintaimobile://PayResult?") > -1) {
V.callEvent('RPIndex.paysuccess', [2]);
} else if (param.indexOf("yintaimobile://ClickTitleBar?position=left&") > -1) {
window.history.go(-1);
}
},
onBack: function (data, self) {
if (this.his.get().history.length > 0) {
//self.update({ showdialog: this.his.get().history.length });
this.his.update({ remove: true });
window.history.go(-1);
} else {
self.update({ close: true });
}
},
onPay: function (data, self) {
if (data.paysuccess && data.value) {
V.callEvent('RPIndex.paysuccess', [data.value]);
//todo 通知我们伟大的网关查看一下 订单是否成功
}
}
},
page: {
data: {
title: '小票SPA版本'
},
submit: function (data, self) {
V.callEvent('RPIndex.submitstart');
_.ni.excute('template', 'submit', { receipts: data.submitids, userID: data.userId }, function (res) {
var ret = res.last();
if (!ret) {
V.callEvent('RPIndex.submitfail');
} else if (ret && ret.length > 0) {
V.callEvent("RPIndex.submitsuccess");
}
});
},
onResize: function (data, self) {
self.resizeheight(data, self);
},
resizeheight: function (data, self) {
var heights = {
pageHeight: (function () {
//if (window.innerHeight)
// return window.innerHeight;
//else if ((document.body) && (document.body.clientHeight))
// return document.body.clientHeight;
////通过深入Document内部对body进行检测,获取窗口大小
//if (document.documentElement && document.documentElement.clientHeight)
if (document.body && document.body.clientHeight > 0)
return document.body.clientHeight;
else
return document.documentElement.clientHeight;
})()
};
//三栏下的高度
heights.pagesHeight = heights.pageHeight - this.title.v.node.height();
$('.g_pages').height(heights.pagesHeight);
$('.p_list3').height(heights.pagesHeight);
heights.listHeight = heights.pagesHeight - this.receipts.controls.bunNext.v.node.height();
$('.p_receipt_list').height(heights.listHeight);
$('.p_receiptdetail').height(heights.pageHeight);
heights.list2Height = heights.pageHeight - this.receipt.controls.notice.v.node.parent().height() - this.receipt.controls.bunNext.v.node.parent().height();
console.log(heights.pageHeight, this.receipt.controls.notice.v.node.parent().height(), this.receipt.controls.bunNext.v.node.parent().height(), (heights.pageHeight - this.receipt.controls.notice.v.node.parent().height() - this.receipt.controls.bunNext.v.node.parent().height()));
this.receipt.controls.rp.v.node.height(heights.list2Height);
$('.p_orderdetail,.p_orderdetail>div').height(heights.pageHeight);
heights.payHeight = heights.pageHeight - 55;
$('#panPayDetail,#payp').height(heights.payHeight);
//$('#sp').height(heights.payHeight - $('.pay-codeinfo').height() - $('.pay-head').height() - 10 - 10 - $('.pay-info-gopay').height());
//现在根据页面信息计算.g_window的高度,.g_background的高度
//计算p_list的高度
heights.backgroundHeight = heights.pageHeight;
data.heights = heights;
console.log(heights);
},
onStart: function (data, self) {
V.watch();
V.registEvent("receipt.submit", function (id) {
data.submitids = id;
console.log('receipt.submit' + id);
self.submit(data, self);
});
V.registEvent('RPIndex.submitReceipt', function (id) {
data.submitids = id;
self.submit(data, self);
});
/*特殊代码段 重新计算屏幕高度*/
self.resizeheight.apply(this, [data, self]);
},
isYG: function (shopId, dateTime) {//dateTime字符串格式
var _shopId = ",1,4,5,";
try {
var minDate = new Date('2015/10/26 8:00:00').getTime();
var maxDate = new Date('2015/10/28 8:00:00').getTime();
dateTime = new Date(dateTime.replace(/-/g, "/")).getTime();
if (_shopId.indexOf("," + shopId + ",") > -1 && ((dateTime >= minDate && dateTime < maxDate) || (dateTime >= new Date('2015/11/2 8:00:00').getTime() && dateTime < new Date('2015/11/10 0:00:00').getTime()))) {
return true;
} else {
return false;
}
} catch (e) {
V.callCommand('receipt.message', ["日期格式不正确"]);
return false;
}
},
isPaiedOrder: function (orderInfo) { //已支付
if (orderInfo && orderInfo.status && ",2,4,5,6,".indexOf("," + orderInfo.status + ",") > -1) {
return true;
} else {
return false;
}
},
isTakeOrder: function (orderInfo) { //已提货
if (orderInfo && (orderInfo.status == "5" || orderInfo.status == "6")) {
return true;
} else {
return false;
}
},
isTakeingOrder: function (orderInfo) { //部分提货
if (orderInfo && orderInfo.status == "4") {
return true;
} else {
return false;
}
},
isInvoiceOrder: function (orderInfo) { //已开发票
if (orderInfo && (orderInfo.status == "6" || orderInfo.hasBill == '1')) {
return true;
} else {
return false;
}
},
isGiftOrder: function (orderInfo) { //已开发票
if (orderInfo && (orderInfo.hasGift == '1')) {
return true;
} else {
return false;
}
}
}
};
V.inherit.apply(_, [M.Page, [config, vm]]);
}
};
})(VJ, VJ.viewmodel, jQuery);