12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- /*
- * 版 本 Learun-ADMS V7.0.0 任联敏捷开发框架(http://www.renlian.cn)
- * Copyright (c) 2013-2017 前端技术开发小组
- * 创建人:任联-前端开发组
- * 日 期:2018.7.12
- * 描 述:任联移动端框架(ADMS) 任联移动框架方法扩展
- */
- (function ($, renlian) {
- "use strict";
- // http 方法(加了登录信息)
- renlian.httpget = function (url, data, callback) {
- var param = {};
- var logininfo = renlian.storage.get('logininfo');
- if (!logininfo) {
- //callback(null);
- return false;
- }
- param.token = logininfo.token;
- param.loginMark = renlian.deviceId();
- var type = renlian.type(data);
- if (type === 'object' || type === 'array') {
- param.data = data;
- }
- else if (type === 'string') {
- param.data = data;
- }
- renlian.http.get(url, param, function (res) {
- if (res === null) {
- renlian.layer.toast('无法连接服务器,请检测网络!');
- //callback(null);
- }
- else if (res.code === 410) {
- //callback(null);
- if (!renlian.isOutLogin) {
- renlian.isOutLogin = true;
- renlian.layer.toast('登录过期,请重新登录!');
- renlian.storage.set('logininfo', null);
- renlian.nav.go({ path: 'login', isBack: false, isHead: false });
- }
- } else {
- if (res.code === 200) {
- callback(res);
- } else {
- //callback(null);
- callback(res);
- //renlian.layer.toast(res.info);
- // renlian.layer.toast(res.message);
- }
- }
- });
- };
- renlian.httppost = function (url, data, callback) {
- var param = {};
- var logininfo = renlian.storage.get('logininfo');
- if (!logininfo) {
- //callback(null);
- return false;
- }
- param.token = logininfo.token;
- param.loginMark = renlian.deviceId();
- var type = renlian.type(data);
- if (type === 'object' || type === 'array') {
- param.data = data;
- }
- else if (type === 'string') {
- param.data = data;
- }
- renlian.http.post(url, param, function (res) {
- if (res === null) {
- renlian.layer.toast('无法连接服务器,请检测网络!');
- //callback(null);
- }
- else if (res.code === 410) {
- //callback(null);
- if (!renlian.isOutLogin) {
- renlian.isOutLogin = true;
- renlian.layer.toast('登录过期,请重新登录!');
- renlian.storage.set('logininfo', null);
- renlian.nav.go({ path: 'login', isBack: false, isHead: false });
- }
-
- } else {
- if (res.code === 200) {
- //callback(res.data, res.info);
- callback(res);
- } else {
- //callback(null);
- callback(res);
- //renlian.layer.toast(res.info);
- // renlian.layer.toast(res.message);
- }
- }
- });
- };
- // 获取后台信息(基础信息)
- var loadSate = {
- no: -1, // 还未加载
- yes: 1, // 已经加载成功
- ing: 0, // 正在加载中
- fail: 2 // 加载失败
- };
- var clientAsyncData = {};
- renlian.clientdata = {
- init: function () {
- clientAsyncData.company.init();
- },
- get: function (name, op) {//
- return clientAsyncData[name].get(op);
- },
- getAll: function (name, op) {//
- return clientAsyncData[name].getAll(op);
- },
- clear: function (name) {
- clientAsyncData[name].states = loadSate.no;
- }
- };
- // 公司信息
- clientAsyncData.company = {
- states: loadSate.no,
- init: function () {
- if (clientAsyncData.company.states === loadSate.no) {
- clientAsyncData.company.states = loadSate.ing;
- var data = renlian.storage.get("companyData") || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/company/map", { ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("companyData", data);
- }
- clientAsyncData.company.states = loadSate.yes;
- clientAsyncData.department.init();
- }
- else {
- clientAsyncData.company.states = loadSate.fail;
- }
- });
- }
- },
- get: function (op) {
- clientAsyncData.company.init();
- if (clientAsyncData.company.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.company.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("companyData") || {};
- var data = _dataTmp.data || {};
- op.callback(data[op.key] || {}, op);
- }
- },
- getAll: function (op) {
- clientAsyncData.company.init();
- if (clientAsyncData.company.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.company.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("companyData") || {};
- var data = _dataTmp.data || {};
- op.callback(data, op);
- }
- }
- };
- // 部门信息
- clientAsyncData.department = {
- states: loadSate.no,
- init: function () {
- if (clientAsyncData.department.states === loadSate.no) {
- clientAsyncData.department.states = loadSate.ing;
- var data = renlian.storage.get("departmentData") || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/department/map", { ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("departmentData", data);
- }
- clientAsyncData.department.states = loadSate.yes;
- clientAsyncData.user.init();
- }
- else {
- clientAsyncData.department.states = loadSate.fail;
- }
- });
- }
- },
- get: function (op) {
- clientAsyncData.department.init();
- if (clientAsyncData.department.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.department.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("departmentData") || {};
- var data = _dataTmp.data || {};
- op.callback(data[op.key] || {}, op);
- }
- },
- getAll: function (op) {
- clientAsyncData.department.init();
- if (clientAsyncData.department.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.department.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("departmentData") || {};
- var data = _dataTmp.data || {};
- op.callback(data, op);
- }
- }
- };
- // 人员信息
- clientAsyncData.user = {
- states: loadSate.no,
- init: function () {
- if (clientAsyncData.user.states === loadSate.no) {
- clientAsyncData.user.states = loadSate.ing;
- var data = renlian.storage.get("userData") || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/user/map", { ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("userData", data);
- }
- clientAsyncData.user.states = loadSate.yes;
- clientAsyncData.dataItem.init();
- }
- else {
- clientAsyncData.user.states = loadSate.fail;
- }
- });
- }
- },
- get: function (op) {
- clientAsyncData.user.init();
- if (clientAsyncData.user.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.user.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("userData") || {};
- var data = _dataTmp.data || {};
- op.callback(data[op.key] || {}, op);
- }
- },
- getAll: function (op) {
- clientAsyncData.user.init();
- if (clientAsyncData.user.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.user.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("userData") || {};
- var data = _dataTmp.data || {};
- op.callback(data, op);
- }
- }
- };
- // 数据字典
- clientAsyncData.dataItem = {
- states: loadSate.no,
- init: function () {
- if (clientAsyncData.dataItem.states === loadSate.no) {
- clientAsyncData.dataItem.states = loadSate.ing;
- var data = renlian.storage.get("dataItemData") || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/dataitem/map", { ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("dataItemData", data);
- }
- clientAsyncData.dataItem.states = loadSate.yes;
- }
- else {
- clientAsyncData.dataItem.states = loadSate.fail;
- }
- });
- }
- },
- get: function (op) {
- clientAsyncData.dataItem.init();
- if (clientAsyncData.dataItem.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.dataItem.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("dataItemData") || {};
- var data = _dataTmp.data || {};
- op.callback(clientAsyncData.dataItem.find(op.key, data[op.code] || {}) || {}, op);
- }
- },
- getAll: function (op) {
- clientAsyncData.dataItem.init();
- if (clientAsyncData.dataItem.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.dataItem.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _dataTmp = renlian.storage.get("dataItemData") || {};
- var data = _dataTmp.data || {};
- op.callback(data[op.code] || {}, op);
- }
- },
- find: function (key, data) {
- var res = {};
- for (var id in data) {
- if (data[id].value === key) {
- res = data[id];
- break;
- }
- }
- return res;
- }
- };
- // 数据源数据
- clientAsyncData.sourceData = {
- states: {},
- get: function (op) {
- if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) {
- clientAsyncData.sourceData.states[op.code] = loadSate.ing;
- clientAsyncData.sourceData.load(op.code);
- }
- if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.sourceData.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _tmpData = renlian.storage.get("sourceData_" + op.code) || {};
- var data = _tmpData.data || [];
- if (data) {
- op.callback(clientAsyncData.sourceData.find(op.key, op.keyId, data) || {}, op);
- } else {
- op.callback({}, op);
- }
- }
- },
- getAll: function (op) {
- if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) {
- clientAsyncData.sourceData.states[op.code] = loadSate.ing;
- clientAsyncData.sourceData.load(op.code);
- }
- if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.sourceData.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _tmpData = renlian.storage.get("sourceData_" + op.code) || {};
- var data = _tmpData.data || [];
- if (data) {
- op.callback(data, op);
- } else {
- op.callback({}, op);
- }
- }
- },
- load: function (code) {
- var data = renlian.storage.get("sourceData_" + code) || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/datasource/map", { code: code, ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("sourceData_" + code, data);
- }
- clientAsyncData.sourceData.states[code] = loadSate.yes;
- }
- else {
- clientAsyncData.sourceData.states[code] = loadSate.fail;
- }
- });
- },
- find: function (key, keyId, data) {
- var res = {};
- for (var i = 0, l = data.length; i < l; i++) {
- if (data[i][keyId] === key) {
- res = data[i];
- break;
- }
- }
- return res;
- }
- };
- // 自定义数据
- var custmerData = {};
- clientAsyncData.custmerData = {
- states: {},
- get: function (op) {
- if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) {
- clientAsyncData.custmerData.states[op.url] = loadSate.ing;
- clientAsyncData.custmerData.load(op.url);
- }
- if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.custmerData.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var data = custmerData[op.url];
- if (data) {
- op.callback(clientAsyncData.custmerData.find(op.key, op.keyId, data) || {}, op);
- } else {
- op.callback({}, op);
- }
- }
- },
- getAll: function (op) {
- if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) {
- clientAsyncData.custmerData.states[op.url] = loadSate.ing;
- clientAsyncData.custmerData.load(op.url);
- }
- if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.custmerData.getAll(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var data = custmerData[op.url];
- op.callback(data || [], op);
- }
- },
- load: function (url) {
- renlian.httpget(config.webapi + url, null, function (data) {
- if (data) {
- custmerData[url] = data;
- clientAsyncData.custmerData.states[url] = loadSate.yes;
- }
- else {
- clientAsyncData.custmerData.states[url] = loadSate.fail;
- }
- });
- },
- find: function (key, keyId, data) {
- var res = {};
- for (var i = 0, l = data.length; i < l; i++) {
- if (data[i][keyId] === key) {
- res = data[i];
- break;
- }
- }
- return res;
- }
- };
- // 获取功能列表
- clientAsyncData.module = {
- states: loadSate.no,
- init: function () {
- if (clientAsyncData.module.states === loadSate.no) {
- clientAsyncData.module.states = loadSate.ing;
- var data = renlian.storage.get("moduleData") || {};
- var ver = data.ver || "";
- renlian.httpget(config.webapi + "renlian/adms/function/list", { ver: ver }, function (data) {
- if (data) {
- if (data.ver) {
- renlian.storage.set("moduleData", data);
- }
- clientAsyncData.module.states = loadSate.yes;
- }
- else {
- clientAsyncData.module.states = loadSate.fail;
- }
- });
- }
- },
- get: function (op) {
- clientAsyncData.module.init();
- if (clientAsyncData.module.states === loadSate.ing) {
- setTimeout(function () {
- clientAsyncData.module.get(op);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- var _tmpData = renlian.storage.get("moduleData");
- var data = _tmpData.data || {};
- op.callback(data, op);
- }
- }
- };
- // 获取我的应用列表
- renlian.myModule = {
- states: loadSate.no,
- init: function (modules) {
- if (renlian.myModule.states === loadSate.no) {
- renlian.myModule.states = loadSate.ing;
- var mymoduleData = renlian.storage.get("mymoduleData");
- if (mymoduleData === null) {
- var len = 7;
- if (len > modules.length) {
- len = modules.length;
- }
- var list = [];
- for (var i = 0; i < len; i++) {
- var item = modules[i];
- list.push(item.F_Id);
- }
- renlian.storage.set("mymoduleData", list);
- renlian.httppost(config.webapi + "renlian/adms/function/mylist/update", String(list), (res) => {
- });
- renlian.myModule.states = loadSate.yes;
- }
- else {
- renlian.httpget(config.webapi + "renlian/adms/function/mylist", null, function (data) {
- if (data) {
- renlian.storage.set("mymoduleData", data);
- }
- renlian.myModule.states = loadSate.yes;
- });
- }
- }
- },
- get: function (modules, callback) {
- renlian.myModule.init(modules);
- if (renlian.myModule.states === loadSate.ing) {
- setTimeout(function () {
- renlian.myModule.get(modules, callback);
- }, 100);// 如果还在加载100ms后再检测
- }
- else {
- callback(renlian.storage.get("mymoduleData"));
- }
- }
- };
- // 获取单据编码
- renlian.getRuleCode = function (code, callback) {
- renlian.httpget(config.webapi + "renlian/adms/coderule/code", code, function (data) {
- if (data) {
- callback(data);
- }
- else {
- callback('');
- }
- });
- };
- /*选择框方法扩展(包含单选框)*/
- // 选择框扩展(url(后台数据地址),数据字典,数据源),
- $.fn.lrpickerex = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- if (!op.data) {
- op.data = [];
- switch (op.type) {
- case 'dataItem':
- $this.lrpicker(op);
- renlian.clientdata.getAll('dataItem', {
- code: op.code,
- callback: function (data) {
- var _tmpdata = [];
- $.each(data, function (_index, _item) {
- _tmpdata.push({ value: _item.value, text: _item.text });
- });
- $this.lrpickerSetData(_tmpdata);
- }
- });
- break;
- case 'sourceData':
- $this.lrpicker(op);
- renlian.clientdata.getAll('sourceData', {
- code: op.code,
- callback: function (data) {
- $this.lrpickerSetData(data);
- }
- });
- break;
- default:
- $this.lrpicker(op);
- if (op.url) {// 如果有连接地址
- renlian.clientdata.getAll('custmerData', {
- url: op.url,
- callback: function (data) {
- $this.lrpickerSetData(data);
- }
- });
- }
- break;
- }
- } else {
- $this.lrpicker(op);
- }
- return $this;
- };
- // 组织单位选择
- $.fn.lrselect = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- var dfop = {
- placeholder: '请选择',
- type: 'company',
- companyId: '',
- departmentId: '',
- change: false
- };
- $.extend(dfop, op || {});
- $this.attr('type', 'lrselect');
- $this.addClass('lr-select');
- $this.html('<div class="text">' + dfop.placeholder + '</div>');
- dfop.id = $this.attr('id');
- $this[0].dfop = dfop;
- $this.on('tap', function () {
- var $this = $(this);
- if ($this.attr('readonly') || $this.parents('.lr-form-row').attr('readonly')) {
- return false;
- }
- renlian.formblur();
- var op = $this[0].dfop;
- if (op.needPre) {
- renlian.layer.toast('请先选择上一级!');
- return false;
- }
- var name = '';
- switch (op.type) {
- case 'company':
- name = '选择公司';
- break;
- case 'department':
- name = '选择部门';
- break;
- case 'user':
- name = '选择人员';
- break;
- }
- renlian.nav.go({
- path: 'lrselect/' + op.type, title: name, type: 'right', param: {
- callback: function (data, _op, $this) {
- $this.find('.text').text(data.name);
- _op.value = data.id;
- _op.text = data.name;
- _op.change && _op.change(data);
- $this.trigger('change');
- },
- op: op,
- $this: $this
- }
- });
- });
- return $this;
- };
- $.fn.lrselectGet = function (type) {
- var $this = $(this);
- if ($this.length === 0) {
- return '';
- }
- var op = $this[0].dfop;
- $this = null;
- if (type === 'text') {
- return op.text;
- }
- else {
- return op.value;
- }
- };
- $.fn.lrselectSet = function (value) {
- var $this = $(this);
- if ($this.length === 0) {
- return '';
- }
- var op = $this[0].dfop;
- op.value = value;
- $this = null;
- renlian.clientdata.get(op.type, {
- key: value,
- set: op,
- callback: function (data, _op) {
- $('#' + _op.set.id).find('.text').text(data.name || '');
- _op.set.text = data.name || '';
- data.id = _op.key;
- _op.change && _op.change(data);
- $('#' + _op.set.id).trigger('change');
- }
- });
- };
- $.fn.lrselectUpdate = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- $.extend($this[0].dfop, op || {});
- $this[0].dfop.value = '';
- $this[0].dfop.text = '';
- $this.find('.text').text($this[0].dfop.placeholder);
- $this = null;
- };
- // 弹层选择框(数据字典和数据源)
- $.fn.layerSelect = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- var dfop = {
- placeholder: '请选择',
- type: 'dataItem',// sourceData
- layerData:[],
- callback: false
- };
- $.extend(dfop, op || {});
- $this.attr('type', 'lrlayerSelect');
- $this.addClass('lr-layerSelect');
- $this.html('<div class="text">' + dfop.placeholder + '</div>');
- dfop.id = $this.attr('id');
- $this[0].dfop = dfop;
- $this.on('tap', function () {
- var $this = $(this);
- if ($this.attr('readonly') || $this.parents('.lr-form-row').attr('readonly')) {
- return false;
- }
- renlian.formblur();
- var op = $this[0].dfop;
- renlian.nav.go({
- path: 'lrselect/layer', title: op.placeholder, type: 'right', param: {
- callback: function (data, _op, _$this) {
- _op.callback && _op.callback(data, _op.layerData, _$this);
- _$this = null;
- },
- op: op,
- $this: $this
- }
- });
- $this = null;
- return false;
- });
- return $this;
- };
- $.fn.layerSelectSet = function (value) {
- var $this = $(this);
- var op = $(this)[0].dfop;
- if (value) {
- $this.find('.text').text(value);
- op.value = value;
- }
- else {
- op.value = '';
- $(this).find('.text').text(op.placeholder);
- }
- };
- $.fn.layerSelectGet = function () {
- return $(this)[0].dfop.value;
- };
- /*多选框方法扩展*/
- $.fn.lrcheckboxex = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- if (!op.data) {
- op.data = [];
- switch (op.type) {
- case 'dataItem':
- $this.lrcheckbox(op);
- renlian.clientdata.getAll('dataItem', {
- code: op.code,
- callback: function (data) {
- var _tmpdata = [];
- $.each(data, function (_index, _item) {
- _tmpdata.push({ value: _item.value, text: _item.text });
- });
- $this.lrcheckboxSetData(_tmpdata);
- }
- });
- break;
- case 'sourceData':
- $this.lrcheckbox(op);
- renlian.clientdata('sourceData', {
- code: op.code,
- callback: function (data) {
- $this.lrcheckboxSetData(data);
- }
- });
- break;
- default:
- $this.lrcheckbox(op);
- if (op.url) {// 如果有连接地址
- renlian.clientdata('custmerData', {
- url: op.url,
- callback: function (data) {
- $this.lrcheckboxSetData(data);
- }
- });
- }
- break;
- }
- } else {
- $this.lrcheckbox(op);
- }
- return $this;
- };
- /*编辑表格方法扩展*/
- function setGridRowValue($block, id, type, value) {// 设置编辑表格每个块的值
- switch (type) {
- case 'label':
- case 'input':
- $block.find('#' + id).val(value);
- break;
- case 'radio':
- case 'select':
- $block.find('#' + id).lrpickerSet(value);
- break;
- case 'checkbox':
- $block.find('#' + id).lrcheckboxSet(value);
- break;
- case 'layer':
- $block.find('#' + id).layerSelectSet(value);
- break;
- case 'datetime':
- $block.find('#' + id).lrdateSet(value);
- break;
- }
- $block = null;
- }
- function getGridRowValue($block, id, type) {// 设置编辑表格每个块的值
- var v = '';
- switch (type) {
- case 'label':
- case 'input':
- v = $block.find('#' + id).val();
- break;
- case 'radio':
- case 'select':
- v = $block.find('#' + id).lrpickerGet();
- break;
- case 'checkbox':
- v = $block.find('#' + id).lrcheckboxGet();
- break;
- case 'layer':
- v = $block.find('#' + id).layerSelectGet();
- break;
- case 'datetime':
- v = $block.find('#' + id).lrdateGet();
- break;
- }
- $block = null;
- return v;
- }
- function addGridRow($this, op) {
- // 添加编辑集合块
- var $html = $('<div class="lr-edit-grid-block" ></div>');
- if (op.hasBtn) {
- $this.find('.lr-edit-grid-btn').before($html);
- }
- else {
- $this.append($html);
- }
- // 添加标题栏
- var $title = $('<div class="lr-edit-grid-title" >' + op.title + '(<span>' + op._index + '</span>)</div>');
- if (op._index > 1) {
- $title.append('<div class="lr-edit-grid-deletebtn" data-value="' + op._index + '">删除</div>');
- }
- $html.html($title);
- var _compontHtml = '';
- op.compontsMap = op.compontsMap || {};
- // 编辑表格-组件初始化
- $.each(op.componts, function (_index, _item) {
- if (op._index === 1) {
- op.compontsMap[_item.field] = _item;
- }
- switch (_item.type) {
- case 'label':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><input type="text" readonly id="' + _item.field + '" ></div>';
- $html.append(_compontHtml);
- break;
- case 'input':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><input type="text" id="' + _item.field + '" ></div>';
- $html.append(_compontHtml);
- // 值改变
- if (_item.change) {
- $html.find('#' + _item.field).on('input propertychange', { change: _item.change }, function (e) {
- e = e || window.event;
- var _change = e.data.change;
- var $this = $(this);
- var _$block = $this.parents('.lr-edit-grid-block');
- var v = $this.val();
- _change(v, _$block);
- $this = null;
- _$block = null;
- });
- }
- break;
- case 'radio':
- case 'select':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
- $html.append(_compontHtml);
- $html.find('#' + _item.field).lrpickerex({
- code: _item.code,
- type: _item.datatype,
- ivalue: _item.ivalue,
- itext: _item.itext,
- data: _item.data,
- url: _item.url,
- change: function (value, text, datalist, $self) {
- var _$block = $self.parents('.lr-edit-grid-block');
- _item.change && _item.change(value, text, datalist, _$block);
- $self = null;
- _$block = null;
- }
- });
- break;
- case 'checkbox':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
- $html.append(_compontHtml);
- $html.find('#' + _item.field).lrcheckboxex({
- code: _item.code,
- type: _item.datatype,
- ivalue: _item.ivalue,
- itext: _item.itext,
- data: _item.data,
- url: _item.url,
- change: function (value, text, datalist, $self) {
- var _$block = $self.parents('.lr-edit-grid-block');
- _item.change && _item.change(value, text, datalist, _$block);
- $self = null;
- _$block = null;
- }
- });
- break;
- case 'layer':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
- $html.append(_compontHtml);
- $html.find('#' + _item.field).layerSelect({
- code: _item.code,
- type: _item.datatype,
- layerData: _item.layerData,
- callback: function (data, layerData, _$this) {
- var $block = _$this.parents('.lr-edit-grid-block');
- $.each(layerData, function (_jindex, _jitem) {
- setGridRowValue($block, _jitem.value, op.compontsMap[_jitem.value].type, data[_jitem.name]);
- });
- _item.change && _item.change(data, $block);
- $block = null;
- _$this = null;
- }
- });
- break;
- case 'datetime':
- _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
- $html.append(_compontHtml);
- $html.find('#' + _item.field).lrdate({
- type: _item.datetime === 'date' ? 'date' : 'datetime',
- change: function (v, _$this) {
- var $block = _$this.parents('.lr-edit-grid-block');
- _item.change && _item.change(v, $block);
- $block = null;
- _$this = null;
- }
- });
- break;
- default:
- break;
- }
- });
- $title = null;
- $this = null;
- return $html;
- }
-
- $.fn.lrgrid = function (op) {
- var $this = $(this);
- if ($this.length === 0) {
- return $this;
- }
- if ($this[0].dfop) {
- return $this;
- }
- var dfop = {
- title: '编辑表格',
- componts: [],
- hasBtn: true,
- _index: 1
- };
- $.extend(dfop, op || {});
- $this[0].dfop = dfop;
- $this.addClass('lr-edit-gird');
- if (dfop.hasBtn) {
- // 添加增加按钮
- var $btn = $('<div class="lr-edit-grid-btn" ><i class="iconfont icon-add1" ></i>增加' + (dfop.title || '') + '</div>');
- $btn.on('tap', { op: dfop }, function (e) {// 添加一块编辑集合
- e = e || window.event;
- var _op = e.data.op;
- var $grid = $(this).parents('.lr-edit-gird');
- _op._index++;// 增加块数
- renlian.formblur();
- addGridRow($grid, _op);
- });
- $this.html($btn);
- // 注册删除按钮事件
- $this.delegate('.lr-edit-grid-deletebtn', 'tap', { op: dfop }, function (e) {
- e = e || window.event;
- var _op = e.data.op;
- var $my = $(this);
- var myIndex = $my.attr('data-value');
- renlian.formblur();
- renlian.layer.confirm('你确定要删除' + _op.title + myIndex + '吗?', function (isOk) {
- if (isOk === '1') {
- _op._index--;// 减少块数
-
- // 排在后面的块需要重新调整序号
- $my.parents('.lr-edit-gird').find('.lr-edit-grid-block:gt(' + (parseInt(myIndex) - 1) + ')').each(function () {
- var $this = $(this);
- var $deletebtn = $this.find('.lr-edit-grid-deletebtn');
- var _index = parseInt($deletebtn.attr('data-value')) - 1;
- $deletebtn.attr('data-value', _index);
- $this.find('.lr-edit-grid-title span').text(_index);
- $deletebtn = null;
- $this = null;
- });
- // 移除绑定在自己身上的弹层,选择框,单选框,多选框,日期
- var $block = $my.parents('.lr-edit-grid-block');
- $block.find('.lr-date,.lr-picker,.lr-checkbox').each(function () {
- var $this = $(this);
- var _op = $this[0].fop;
- $('#pop_' + _op.id).remove();
- $('#dt_' + _op.id).remove();
- });
- // 移除自己
- $block.remove();
- $block = null;
- }
- $my = null;
- }, '', ['取消', '确定']);
- });
- }
- addGridRow($this, dfop);
- return $this;
- };
- $.fn.lrgridSet = function (data) {
- var $this = $(this);
- var op = $this[0].dfop;
- $.each(data, function (_index, _item) {
- if (_index === 0) {
- // 如果是第一行数据
- $.each(op.componts, function (_jindex, jitem) {
- var _id = jitem.field;
- if (op.isToLowerCase) {
- _id = _id.toLowerCase();
- }
- setGridRowValue($this.find('.lr-edit-grid-block'), jitem.field, jitem.type, _item[_id]);
- });
- } else {
- // 如果不是第一行数据就先添加一行
- op._index++;// 增加块数
- var $block = addGridRow($this, op);
- $.each(op.componts, function (_jindex, jitem) {
- var _id = jitem.field;
- if (op.isToLowerCase) {
- _id = _id.toLowerCase();
- }
- setGridRowValue($block, jitem.field, jitem.type, _item[_id]);
- });
- }
- });
- $this = null;
- };
- $.fn.lrgridGet = function () {
- var $this = $(this);
- var op = $this[0].dfop;
- var data = [];
- $this.find('.lr-edit-grid-block').each(function () {
- var $block = $(this);
- var point = {};
- $.each(op.componts, function (_jindex, jitem) {
- point[jitem.field] = getGridRowValue($block, jitem.field, jitem.type);
- });
- data.push(point);
- });
- $this = null;
- return data;
- };
- // 设置表单组件为只读
- $.fn.setFormRead = function () {
- $(this).find('.lr-form-row').each(function () {
- $(this).attr('readonly', 'readonly');
- });
- }
- $.fn.setFormWrite = function () {
- $(this).find('.lr-form-row').each(function () {
- $(this).removeAttr('readonly');
- });
- }
- // 数据格式化
- $.fn.dataFormatter = function (op) {
- var $this = $(this);
- var _v = '';
- if (op.value === null || op.value === undefined || op.value === 'null' || op.value === 'undefined') {
- op.value = '';
- }
- op.value = op.value + '';
- switch (op.type) {
- case 'datetime':
- $this.append(renlian.date.format(op.value, op.dateformat));
- break;
- case 'dataItem':
- _v = op.value.split(',');
- $.each(_v || [], function (_index, _item) {
- if (_item) {
- renlian.clientdata.get('dataItem', {
- key: _item,
- code: op.code,
- $this: $this,
- callback: function (_data, _op) {
- _op.$this.append(_data.text);
- }
- });
- }
- });
- break;
- case 'dataSource':
- _v = op.value.split(',');
- $.each(_v || [], function (_index, _item) {
- if (_item) {
- renlian.clientdata.get('sourceData', {
- key: _item,
- keyId: op.keyId,
- code: op.code,
- set: op,
- $this: $this,
- callback: function (_data, _op) {
- _op.$this.append(_data[_op.set.text]);
- }
- });
- }
- });
- break;
- case 'dataCustmer':
- _v = op.value.split(',');
- $.each(_v || [], function (_index, _item) {
- if (_item) {
- renlian.clientdata.get('custmerData', {
- key: _item,
- keyId: op.keyId,
- url: op.url,
- set: op,
- $this: $this,
- callback: function (_data, _op) {
- _op.$this.append(_data[_op.set.text]);
- }
- });
- }
- });
- break;
- case 'organize':
- renlian.clientdata.get(op.dataType, {
- key: op.value,
- $this: $this,
- callback: function (_data,_op) {
- _op.$this.append(_data.name);
- }
- });
- break;
- default:
- $this.append(op.value);
- break;
- }
- return $this;
- }
- // 图片选择,上传,下载
- $.fn.lrImagepicker = function (op) {
- var dfop = {
- maxCount: 9,
- isOnlyCamera: false,
- uploadUrl: config.webapi + 'renlian/adms/annexes/upload',
- downUrl: config.webapi + 'renlian/adms/annexes/down?data=',
- getParams: function () {
- var param = {};
- var logininfo = renlian.storage.get('logininfo');
- param.token = logininfo.token;
- param.loginMark = renlian.deviceId();
- return param;
- },
- deleteImg: function (fileId) {
- renlian.httppost(config.webapi + 'renlian/adms/annexes/delete', fileId, function () { });
- },
- downFile: function (value, callback) {
- renlian.httpget(config.webapi + 'renlian/adms/annexes/list', value, function (data) {
- if (data) {
- var _data = [];
- $.each(data, function (_index, _item) {
- if (_item.F_FileType === 'jpg' || _item.F_FileType === 'png') {
- var _point = {
- id: _item.F_Id,
- name: _item.F_Id + '.' + _item.F_FileType
- };
- _data.push(_point);
- }
- });
- callback(_data);
- }
- });
- }
- };
- $.extend(dfop, op || {});
-
- return $(this).imagepicker(dfop);
- }
- })(window.jQuery, window.lrmui);
|