"success" : function(data) { var data = self.comp("informationdata"); data.newData({ "defaultValues" : [ { "id" : justep.UUID.createUUID(), "userid" : self._userID, "username" : self._userDefaultName, "state" : "0", "picture" : serverId, "number" : $(".block.n").html(), "consignee" : $("#name").val(), "telephone" : $("#telephone").val(), "area" : $("#province").val() + $("#city").val(), "address" : $("#address").val(), "remarks" : $("#attention").val(), "ordertime" : new Date() } ] }) data.saveData({ "onSuccess" : function() { swal({ title : "下单成功", text : "我们会在第一时间处理您的订单", type : "success", showCancelButton : false, closeOnConfirm : false }, function() { wx.closeWindow(); }); } }) }
Model.prototype.saveBtnClick = function(event){//debugger; var id = justep.UUID.createUUID(); var row = this.comp("newOrgData").find(['sParent'], [null]).length+1; var SSEQUENCE; if(10>row>=0){ SSEQUENCE = '00'+row; }else if (99>=row>=10){ SSEQUENCE = '0'+row; }else{ SSEQUENCE = row; } this.comp("newOrgData").newData({ 'defaultValues' : [ { 'sID' : id,//ok 'sName' : this.comp("nameInput").value, 'sCode' : this.comp("numInput").value, 'sFName' : '/'+this.comp("nameInput").value, 'sFCode' : '/'+this.comp("numInput").value, 'sFID' : '/'+id+'.ogn', 'sOrgKindID' : 'ogn', 'sSequence' : '/'+SSEQUENCE, 'sParent' : null, 'version' : 990 } ] }) this.comp("newOrgData").saveData(); this.comp("newOrgData").refreshData(); this.close(); };
Model.prototype.voteStartDataAfterRefresh = function(event) { this.comp("voteStartData").newData({ defaultValues : [ { fID : justep.UUID.createUUID() } ] }) };
buildTemplate: function(config){ /* <div component="$UI/system/components/justep/picker/popPicker" class="x-popPicker" xid="popPicker" dismissible="true"> <div class="x-popPicker-overlay" xid="div4"/> <div class="x-popPicker-content"> <div class="x-poppicker-header"> <button class="btn btn-default x-btn-ok">确定 </button> </div> </div> </div> */ if(!config.xid) config.xid = justep.UUID.createUUID(); var ret = $('<div component="'+url+'" class="'+(config['class']||this.baseCls)+'">' +'<div class="'+this.overlayCls+'"/>' +'<div class="'+this.contentCls+'">' +'<div class="'+this.headerCls+'">' +' <button class="btn btn-default x-btn-ok">'+justep.Message.getMessage(justep.Message.JUSTEP231079)+' </button>' +'</div>' +'</div>' +'</div>'); if(config.xid) ret.attr('xid', config.xid); if(config.style) ret.attr('style', config.style); return ret; },
Model.prototype.windowReceiverReceive = function(event){ ; keyWord = event.data.keyWord; var data = this.comp("dTemp"); var keyWordView = ""; var keyWordFirst = ""; var keyWordSencond = ""; var keyWordEnd = ""; if(keyWord != undefined && keyWord != ""){ keyWordView = keyWord.replace(/(^\s*)|(\s*$)/g, ""); keyWordFirst = keyWord.substring(0,keyWord.indexOf(" ")); keyWordSencond = keyWord.substring(keyWord.indexOf(" ")+1,keyWord.lastIndexOf(" ")).replace(/(^\s*)|(\s*$)/g, ""); keyWordEnd = keyWord.substring(keyWord.lastIndexOf(" ")+1,keyWord.length); } data.newData({ index : 0, defaultValues : [ { "id" : justep.UUID.createUUID(), "keyWordFirst" : keyWordFirst, "keyWordSencond" : keyWordSencond, "keyWordEnd" : keyWordEnd, "keyWordView" : keyWordView } ] }); };
Model.prototype.save = function() { var baasData = this.comp("baasData"); var baasRow = baasData.getCurrentRow(); var user = JSON.parse(localStorage.getItem("userUUID")); var data = this.comp('data'); var row = data.getCurrentRow(); var jsonList = eval("(" + row.val('fileName') + ")"); var self = this; console.log(baasData.count()); if (baasData.count() < 1) { var json = { "fid" : justep.UUID.createUUID(), "faccountID" : user.fid, "fcity" : this.comp("txt_city").val(), "fphoneTel" : this.comp("txt_phone").val(), "faddress" : this.comp("txt_address").val(), "fmphone" : this.comp("txt_phone").val(), "ffoxtel" : this.comp("txt_fox").val(), "fimg0" : JSON.stringify(jsonList[0]), "fimg1" : JSON.stringify(jsonList[1]), "fimg2" : JSON.stringify(jsonList[2]) }; DataUtils.genData(baasData, json, 0); baasData.saveData({ "onSuccess" : function(info) { self.comp("messageDialog").show({ message : "资料已提交" }); }, "onError" : function(msg, xhr) { console.log("注册失败,请稍后再试"); } }); } else { baasData.setValue("fcity", this.comp("txt_city").val(), baasRow); baasData.setValue("fphoneTel", this.comp("txt_phone").val(), baasRow); baasData.setValue("faddress", this.comp("txt_address").val(), baasRow); baasData.setValue("fmphone", this.comp("txt_phone").val(), baasRow); baasData.setValue("ffoxtel", this.comp("txt_fox").val(), baasRow); baasData.setValue("fimg0", JSON.stringify(jsonList[0]), baasRow); baasData.setValue("fimg1", JSON.stringify(jsonList[1]), baasRow); baasData.setValue("fimg2", JSON.stringify(jsonList[2]), baasRow); console.log(baasData.toJson()); baasData.saveData({ "onSuccess" : function(event) { baasData.refreshData(); self.comp("messageDialog").show({ message : "资料已更新" }); } }); //justep.Util.hint("已经提交认证,请勿重复提交"); } };
Model.prototype.comments_baasDataBeforeSave = function(event){ var cid = justep.UUID.createUUID(); this.comp('input_cid').set("value",cid); this.comp('input_gid').set("value",GID); this.comp('input_uid').set("value",localStorage.getItem("userID")); this.comp('input_name').set("value",localStorage.getItem("userName")); this.comp('input_addtime').set("value",justep.Date.toString(new Date(), justep.Date.STANDART_FORMAT)); };
buildTemplate : function(cfg) { if (!cfg) cfg = {}; var xid = cfg.xid || justep.UUID.createUUID(); this.set(cfg); return $('<span xid="' + xid + '" component="' + url + '">' + '<div class="x-dialog-overlay">' + '</div>' + '<div class="x-dialog" style="display:none;" showTitle="' + !!cfg.showTitle + '">' + '<div class="x-dialog-title">' + '<button type="button" class="close"><span>×</span></button>' + '<h4 class="x-dialog-title-text">' + (cfg.title ? cfg.title : '') + '</h4>' + '</div>' + '<div class="x-dialog-body">' + (cfg.content ? cfg.content : '') + '</div>' + '</div>' + '</span>'); },
Model.prototype.addTodo = function() { var titleInput = this.comp("titleInput"); if ($.trim(titleInput.domNode.value) != "") { this.comp("todoData").newData({ "defaultValues" : [ { "id" : justep.UUID.createUUID(), "title" : titleInput.domNode.value, "completed" : false } ] }); titleInput.domNode.value = ""; } };
Model.prototype.addLastRowClick = function(event) { this.comp('employeeData').newData({ defaultValues : [ { "id" : justep.UUID.createUUID(), "name" : "新员工", "sex" : "女", "dept" : "新部门", "enducation" : "无学历" } ] }) this.comp('employeeGrid').refresh(); };
Model.prototype.okBtnClick = function(event) { var self = this; var userPassword = this.comp("userPassword").val(); var passWordAgain = this.comp("passwordAgain").val(); var userName = this.comp("nameInput").val(); var phoneNumber = this.comp("phonenumber").val(); if (phoneNumber === '' || userName === '' || passWordAgain === '' || userPassword === '') { justep.Util.hint('请将信息填写完整!', { 'type' : 'danger' }); } else { var pId = justep.UUID.createUUID(); var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{8,16}$/; if (userPassword === passWordAgain) { if (reg.test(userPassword)) { if (numbers === this.comp("verifyCode").val()&&this.comp("verifyCode").val() != '') { justep.Baas.sendRequest({ "url" : "/work/org", "action" : "queryIsActivation", "async" : false, "params" : { "phone" : this.comp("phonenumber").val(), "name" : this.comp("nameInput").val(), "password" : md5.hex_md5_salt(userPassword), "uuid" : pId }, "success" : function(data) { justep.Util.hint(data.status); if (data.status === "注册成功!") { self.close(); } } }); } else { justep.Util.hint('验证码输入错误', { 'type' : 'danger' }); } } else { justep.Util.hint('密码格式错误', { 'type' : 'danger' }); } } else { justep.Util.hint('密码输入不一致', { 'type' : 'danger' }); } } };
Model.prototype.windowReceiverReceive = function(event){ var data = event.data; this.comp('orderData').clear(); if(typeof(data) === 'string'){ this.comp('orderData').newData({ defaultValues : [{ fUserName : data, fID : justep.UUID.createUUID() }] }) }else{ var a = this.comp('orderData').add(); a.assign(data); } };
Model.prototype.windowReceiverReceive = function(event){ var userData = this.comp("userData"); userData.clear(); this.operator = event.data.operator; if (this.operator == "new") { userData.newData({ "defaultValues" : [ { "fID" : justep.UUID.createUUID() } ] }); } else if (this.operator == "edit") { userData.loadData([ event.data.rowData ]); userData.first(); } };
Model.prototype.createOrderBtnClick = function(event) { var self = this; var orderData = this.comp("orderData"); var cartData = this.comp("cartData"); var userData = this.comp("userData"); var orderID = justep.UUID.createUUID(); // 数据校验 if ($.trim(userData.val("fName")) === "" || $.trim(userData.val("fPhoneNumber")) === "" || $.trim(userData.val("fAddress")) === "") { justep.Util.hint("请填写完整的用户信息", { "type" : "danger" }); return; } // 合并订单内容 var content = ""; cartData.each(function(options) { var row = options.row; content = content + row.val("fName") + "(" + row.val("fCount") + ") "; }); orderData.newData({ index : 0, defaultValues : [ { "fID" : orderID, "fCreateTime" : justep.Date.toString(new Date(), justep.Date.STANDART_FORMAT), "fContent" : content, "fUserID" : userData.val("fID"), "fUserName" : userData.val("fName"), "fPhoneNumber" : userData.val("fPhoneNumber"), "fAddress" : userData.val("fAddress"), "fSum" : cartData.sum("calcMoney") + "", "fPayState" : 1 } ] }); orderData.saveData({ "onSuccess" : function() { justep.Util.hint("下单成功,谢谢您的订餐!"); cartData.clear(); userData.applyUpdates(); self.comp("contents1").to("orderContent"); } }); };
buildTemplate : function(config) { if (!config) config = {}; this.set(config); if (!config['class']) config['class'] = 'x-list'; var xid = config.xid || justep.UUID.createUUID(); var $list = "<div class='" + config['class'] + "' " + (config.style ? (" style='" + config.style + "' ") : "") + (xid ? (" xid='" + xid + "' ") : "") + " component='" + url + "' " + " >" + (config.template ? config.template : '') + "</div>"; var $tpl = $list.find('.x-list-template:first'); if(config.data){ var foreachFunc = "$model.foreach_"+xid+"($element)"; var foreachAfterRenderFunc = "$model.foreach_afterRender_"+xid+".bind($model,$element)"; $tpl.addClass('hide').attr('bind-foreach',"{data:"+foreachFunc+",afterRender:"+foreachAfterRenderFunc+"}"); } return $list; },
Model.prototype.beforeRowClick = function(event) { var arr = this.comp('employeeGrid').getCheckeds(); if (arr.length != 1) { justep.Util.hint("请先选中一行数据"); return; } var index = this.comp('employeeData').getRowByID(arr[0]).index(); this.comp('employeeData').newData({ index : index, defaultValues : [ { "id" : justep.UUID.createUUID(), "name" : "新员工", "sex" : "女", "dept" : "新部门", "enducation" : "无学历" } ] }) this.comp('employeeGrid').refresh(); };
Model.prototype.modelParamsReceive = function(event){ // 对话框接收参数后,新增或编辑 var accountData = this.comp("accountData"); accountData.clear(); this.operator = event.params.operator; if (this.operator == "new") { accountData.newData({ "defaultValues" : [ { "fID" : justep.UUID.createUUID(), "fCreateTime" : new Date(), "fDate" : new Date(), "fType" : "支出", "fClass" : this.getDefaultClass("支出") } ] }); } else if (this.operator == "edit") { accountData.loadData([ event.params.rowData ]); accountData.first(); } };
doInit : function(value, bindingContext) { var $label = this._getLabel(), $input = this._getInput(), inputID = $input.attr('id'); if (!inputID) $input.attr('id', justep.UUID.createUUID()); $label.attr("for", $input.attr('id')).click(function(e){e.stopPropagation();});//阻止label组件click事件冒泡,浏览器会触发两次 this._clickHandle = this._doClick.bind(this); $input.on('change', this._clickHandle); var name = this.$domNode.attr('name'); if(name) $input.attr('name',name); if (value && !value.hasOwnProperty('ref')) { var o = {}; if(justep.Bind.isObservable(value.value)) o.value = value.value.get(); if(justep.Bind.isObservable(value.label)) o.label = value.label.get(); this.set(o); } },
$.each(emoji, function(i, v) { if (!created[v.category]) { var xid = justep.UUID.createUUID(); created[v.category] = { content : contents.add({ xid : xid }), html : [] }; new Button({ target : xid, label : v.category, 'class' : 'btn btn-link', parentNode : btnGroup.domNode }); } var ret = created[v.category].html; ret.push('<div class="col cell col-xs-2">'); ret.push(v.value); ret.push('</div>'); });
buildTemplate : function(config) { this._cfg = config || {}; this.data = this._cfg.data; if(!this._cfg.xid) this._cfg.xid=justep.UUID.createUUID(); var str = '<table xid="'+this._cfg.xid+'" component="'+url+'"' +(this._cfg['style']?(' style="'+this._cfg['style']+'"'):'') +(this._cfg['class']?(' class="'+this._cfg['class']+'"'):'') +'>'; if(this._cfg.useFooter===true){ var tf = '<tfoot><tr>'; var size = $.isArray(this._cfg.columns)?this._cfg.columns.length:0; if(this._cfg.multiSelect) size++; if(this._cfg.showRowNumber) size++; for(var i=0;i<size;i++){ tf += '<th/>'; } tf += '</tr></tfoot>'; str += tf; } str += '</table>'; return $(str); },
Model.prototype.payOrderByWeixin = function(payDtd, orderID) { if (!navigator.weixin) { payDtd.reject(-13); return; } var notifyUrl = location.origin; var traceID = justep.UUID.createUUID(); var traceNo = orderID; var weixin = navigator.weixin; weixin.generatePrepayId({ "body" : "x5外卖", "feeType" : "1", "notifyUrl" : notifyUrl, "totalFee" : "1", "traceId" : traceID, "tradeNo" : traceNo }, function(prepayId) { weixin.sendPayReq(prepayId, function(message) { var responseCode = parseInt(message); if (responseCode === 0) { payDtd.resolve(1); } else if (!isNaN(responseCode)) { payDtd.reject((-13) + responseCode); } else { payDtd.reject(-10); } }, function(message) { justep.Util.hint("微信支付失败!"); payDtd.reject(-10); }); }, function(message) { justep.Util.hint("微信支付失败!"); payDtd.reject(-11); }); };
Model.prototype.saveOrderBtnClick = function(event) { var self = this; var orderData = this.comp("orderData"); var cartData = this.comp("cartData"); var userData = this.comp("userData"); // 数据校验 if ($.trim(userData.val("fName")) === "" || $.trim(userData.val("fPhoneNumber")) === "" || $.trim(userData.val("fAddress")) === "") { justep.Util.hint("请填写完整的用户信息", { "type" : "danger" }); return; } // 合并订单内容 var content = ""; cartData.each(function(options) { var row = options.row; content = content + row.val("fName") + "(" + row.val("fCount") + ") "; }); var orderID = justep.UUID.createUUID(); // 生成订单数据 var orderRows = orderData.newData({ index : 0, defaultValues : [ { "fID" : orderID, "fCreateTime" : justep.Date.toString(new Date(), justep.Date.STANDART_FORMAT0), //justep.Date.toString(new Date(), justep.Date.STANDART_FORMAT), "fContent" : content, "fUserID" : userData.val("fID"), "fUserName" : userData.val("fName"), "fPhoneNumber" : userData.val("fPhoneNumber"), "fAddress" : userData.val("fAddress"), "fSum" : cartData.sum("calcMoney") + "" //"fPayState" : 0 } ] }); var success = function(resultData) { // 保存成功清除购物车,并跳转到订单页 cartData.clear(); justep.Util.hint("下单成功,谢谢您的订餐!"); userData.applyUpdates(); // 开始支付 var payDtd = self.payOrder(orderID); payDtd.always(function(code) { orderData.setValue("fPayState", code); orderData.saveData({"onSuccess" : function() { self.comp("contents").to("orderContent"); }}); self.sendOrderPushMessage(); }).fail(function(code) { justep.Util.hint("支付遇到问题!"); }); }; var error = function(msg) { // 保存失败后清除订单数据 orderData.deleteData(orderRows); Baas.showError(msg); }; // 保存数据 orderData.saveData({ "onSuccess" : success, "onError" : error}); };
_createPickers: function(){ if(!this._isPickersCreated){ var self = this; this._createTitle(); //创建picker的数据 this._dayData = justep.Bind.computed(function() { var yearValue = self._yearValue.get(); var monthValue = self._monthValue.get(); if (yearValue && monthValue) { var ret = []; var oldv = self._dayValue.peek(); var max = justep.Date.MaxDay(yearValue,monthValue); if(max<oldv){ self._dayValue.set(max); self._setPickerValue('day',max); } for(var i=1;i<=max;i++){ ret.push(justep.String.zeros(i,2)); } //显示刺激day日期列表,bind-each有优化当数据对象没有变化时不重新渲染导致,数据变化后没有刺激doAfterRender() if(self._dayComp) self._dayComp.doAfterRender(); return ret; } else return []; }); this._yearData = justep.Bind.computed(function() { var yearValue = self._yearValue.get(); var ret = [],MaxYear = self._getMaxYear(),MinYear = self._getMinYear(); for(var i=0;i<40;i++){ var v = yearValue+i-20; if(v>=MinYear && v<=MaxYear) ret.push(v);//前后20年 } return ret; }); this._monthData = []; for(var i=1;i<=12;i++){ this._monthData.push(justep.String.zeros(i,2)); } this._hourData = []; for(i=0;i<24;i++){ this._hourData.push(justep.String.zeros(i,2)); } this._minuteData = []; this._secondData = []; for(i=0;i<60;i++){ var v = justep.String.zeros(i,2); this._minuteData.push(v); this._secondData.push(v); } //创建picker,把data写入model,便于picker组件data部分bind var model = this.getModel(); if (!model['__justep__']) model['__justep__'] = {}; if(!model.__justep__.datepicker) model.__justep__.datepicker = {}; var xid = this.$domNode.attr('xid'); if(!xid) xid = justep.UUID.createUUID(); model.__justep__.datepicker[xid+'_dayData_'] = this._dayData; model.__justep__.datepicker[xid+'_monthData_'] = this._monthData; model.__justep__.datepicker[xid+'_yearData_'] = this._yearData; model.__justep__.datepicker[xid+'_hourData_'] = this._hourData; model.__justep__.datepicker[xid+'_minuteData_'] = this._minuteData; model.__justep__.datepicker[xid+'_secondData_'] = this._secondData; this._yearComp = this.addPicker({'class':'x-picker x-year',data:'$model.__justep__.datepicker["'+xid+'_yearData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._yearComp._value = this._yearValue; this._monthComp = this.addPicker({'class':'x-picker x-month',data:'$model.__justep__.datepicker["'+xid+'_monthData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._monthComp._value = this._monthValue; this._dayComp = this.addPicker({'class':'x-picker x-day',data:'$model.__justep__.datepicker["'+xid+'_dayData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._dayComp._value = this._dayValue; this._hourComp = this.addPicker({'class':'x-picker x-hour',data:'$model.__justep__.datepicker["'+xid+'_hourData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._hourComp._value = this._hourValue; this._minuteComp = this.addPicker({'class':'x-picker x-minute',data:'$model.__justep__.datepicker["'+xid+'_minuteData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._minuteComp._value = this._minuteValue; this._secondComp = this.addPicker({'class':'x-picker x-second',data:'$model.__justep__.datepicker["'+xid+'_secondData_"]','bind-itemText':'$object',onChange:this._doChange.bind(this)}); this._secondComp._value = this._secondValue; this._isPickersCreated = true; this.updatePickerValue(); } },
Model.prototype.mainDataBeforeNew = function(event){ //grid组件要求新增数据必须有主键 event.option.defaultValues = [{fID:justep.UUID.createUUID()}]; };