rlmuiex.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /*
  2. * 版 本 Learun-ADMS V7.0.0 任联敏捷开发框架(http://www.renlian.cn)
  3. * Copyright (c) 2013-2017 前端技术开发小组
  4. * 创建人:任联-前端开发组
  5. * 日 期:2018.7.12
  6. * 描 述:任联移动端框架(ADMS) 任联移动框架方法扩展
  7. */
  8. (function ($, renlian) {
  9. "use strict";
  10. // http 方法(加了登录信息)
  11. renlian.httpget = function (url, data, callback) {
  12. var param = {};
  13. var logininfo = renlian.storage.get('logininfo');
  14. if (!logininfo) {
  15. //callback(null);
  16. return false;
  17. }
  18. param.token = logininfo.token;
  19. param.loginMark = renlian.deviceId();
  20. var type = renlian.type(data);
  21. if (type === 'object' || type === 'array') {
  22. param.data = data;
  23. }
  24. else if (type === 'string') {
  25. param.data = data;
  26. }
  27. renlian.http.get(url, param, function (res) {
  28. if (res === null) {
  29. renlian.layer.toast('无法连接服务器,请检测网络!');
  30. //callback(null);
  31. }
  32. else if (res.code === 410) {
  33. //callback(null);
  34. if (!renlian.isOutLogin) {
  35. renlian.isOutLogin = true;
  36. renlian.layer.toast('登录过期,请重新登录!');
  37. renlian.storage.set('logininfo', null);
  38. renlian.nav.go({ path: 'login', isBack: false, isHead: false });
  39. }
  40. } else {
  41. if (res.code === 200) {
  42. callback(res);
  43. } else {
  44. //callback(null);
  45. callback(res);
  46. //renlian.layer.toast(res.info);
  47. // renlian.layer.toast(res.message);
  48. }
  49. }
  50. });
  51. };
  52. renlian.httppost = function (url, data, callback) {
  53. var param = {};
  54. var logininfo = renlian.storage.get('logininfo');
  55. if (!logininfo) {
  56. //callback(null);
  57. return false;
  58. }
  59. param.token = logininfo.token;
  60. param.loginMark = renlian.deviceId();
  61. var type = renlian.type(data);
  62. if (type === 'object' || type === 'array') {
  63. param.data = data;
  64. }
  65. else if (type === 'string') {
  66. param.data = data;
  67. }
  68. renlian.http.post(url, param, function (res) {
  69. if (res === null) {
  70. renlian.layer.toast('无法连接服务器,请检测网络!');
  71. //callback(null);
  72. }
  73. else if (res.code === 410) {
  74. //callback(null);
  75. if (!renlian.isOutLogin) {
  76. renlian.isOutLogin = true;
  77. renlian.layer.toast('登录过期,请重新登录!');
  78. renlian.storage.set('logininfo', null);
  79. renlian.nav.go({ path: 'login', isBack: false, isHead: false });
  80. }
  81. } else {
  82. if (res.code === 200) {
  83. //callback(res.data, res.info);
  84. callback(res);
  85. } else {
  86. //callback(null);
  87. callback(res);
  88. //renlian.layer.toast(res.info);
  89. // renlian.layer.toast(res.message);
  90. }
  91. }
  92. });
  93. };
  94. // 获取后台信息(基础信息)
  95. var loadSate = {
  96. no: -1, // 还未加载
  97. yes: 1, // 已经加载成功
  98. ing: 0, // 正在加载中
  99. fail: 2 // 加载失败
  100. };
  101. var clientAsyncData = {};
  102. renlian.clientdata = {
  103. init: function () {
  104. clientAsyncData.company.init();
  105. },
  106. get: function (name, op) {//
  107. return clientAsyncData[name].get(op);
  108. },
  109. getAll: function (name, op) {//
  110. return clientAsyncData[name].getAll(op);
  111. },
  112. clear: function (name) {
  113. clientAsyncData[name].states = loadSate.no;
  114. }
  115. };
  116. // 公司信息
  117. clientAsyncData.company = {
  118. states: loadSate.no,
  119. init: function () {
  120. if (clientAsyncData.company.states === loadSate.no) {
  121. clientAsyncData.company.states = loadSate.ing;
  122. var data = renlian.storage.get("companyData") || {};
  123. var ver = data.ver || "";
  124. renlian.httpget(config.webapi + "renlian/adms/company/map", { ver: ver }, function (data) {
  125. if (data) {
  126. if (data.ver) {
  127. renlian.storage.set("companyData", data);
  128. }
  129. clientAsyncData.company.states = loadSate.yes;
  130. clientAsyncData.department.init();
  131. }
  132. else {
  133. clientAsyncData.company.states = loadSate.fail;
  134. }
  135. });
  136. }
  137. },
  138. get: function (op) {
  139. clientAsyncData.company.init();
  140. if (clientAsyncData.company.states === loadSate.ing) {
  141. setTimeout(function () {
  142. clientAsyncData.company.get(op);
  143. }, 100);// 如果还在加载100ms后再检测
  144. }
  145. else {
  146. var _dataTmp = renlian.storage.get("companyData") || {};
  147. var data = _dataTmp.data || {};
  148. op.callback(data[op.key] || {}, op);
  149. }
  150. },
  151. getAll: function (op) {
  152. clientAsyncData.company.init();
  153. if (clientAsyncData.company.states === loadSate.ing) {
  154. setTimeout(function () {
  155. clientAsyncData.company.getAll(op);
  156. }, 100);// 如果还在加载100ms后再检测
  157. }
  158. else {
  159. var _dataTmp = renlian.storage.get("companyData") || {};
  160. var data = _dataTmp.data || {};
  161. op.callback(data, op);
  162. }
  163. }
  164. };
  165. // 部门信息
  166. clientAsyncData.department = {
  167. states: loadSate.no,
  168. init: function () {
  169. if (clientAsyncData.department.states === loadSate.no) {
  170. clientAsyncData.department.states = loadSate.ing;
  171. var data = renlian.storage.get("departmentData") || {};
  172. var ver = data.ver || "";
  173. renlian.httpget(config.webapi + "renlian/adms/department/map", { ver: ver }, function (data) {
  174. if (data) {
  175. if (data.ver) {
  176. renlian.storage.set("departmentData", data);
  177. }
  178. clientAsyncData.department.states = loadSate.yes;
  179. clientAsyncData.user.init();
  180. }
  181. else {
  182. clientAsyncData.department.states = loadSate.fail;
  183. }
  184. });
  185. }
  186. },
  187. get: function (op) {
  188. clientAsyncData.department.init();
  189. if (clientAsyncData.department.states === loadSate.ing) {
  190. setTimeout(function () {
  191. clientAsyncData.department.get(op);
  192. }, 100);// 如果还在加载100ms后再检测
  193. }
  194. else {
  195. var _dataTmp = renlian.storage.get("departmentData") || {};
  196. var data = _dataTmp.data || {};
  197. op.callback(data[op.key] || {}, op);
  198. }
  199. },
  200. getAll: function (op) {
  201. clientAsyncData.department.init();
  202. if (clientAsyncData.department.states === loadSate.ing) {
  203. setTimeout(function () {
  204. clientAsyncData.department.getAll(op);
  205. }, 100);// 如果还在加载100ms后再检测
  206. }
  207. else {
  208. var _dataTmp = renlian.storage.get("departmentData") || {};
  209. var data = _dataTmp.data || {};
  210. op.callback(data, op);
  211. }
  212. }
  213. };
  214. // 人员信息
  215. clientAsyncData.user = {
  216. states: loadSate.no,
  217. init: function () {
  218. if (clientAsyncData.user.states === loadSate.no) {
  219. clientAsyncData.user.states = loadSate.ing;
  220. var data = renlian.storage.get("userData") || {};
  221. var ver = data.ver || "";
  222. renlian.httpget(config.webapi + "renlian/adms/user/map", { ver: ver }, function (data) {
  223. if (data) {
  224. if (data.ver) {
  225. renlian.storage.set("userData", data);
  226. }
  227. clientAsyncData.user.states = loadSate.yes;
  228. clientAsyncData.dataItem.init();
  229. }
  230. else {
  231. clientAsyncData.user.states = loadSate.fail;
  232. }
  233. });
  234. }
  235. },
  236. get: function (op) {
  237. clientAsyncData.user.init();
  238. if (clientAsyncData.user.states === loadSate.ing) {
  239. setTimeout(function () {
  240. clientAsyncData.user.get(op);
  241. }, 100);// 如果还在加载100ms后再检测
  242. }
  243. else {
  244. var _dataTmp = renlian.storage.get("userData") || {};
  245. var data = _dataTmp.data || {};
  246. op.callback(data[op.key] || {}, op);
  247. }
  248. },
  249. getAll: function (op) {
  250. clientAsyncData.user.init();
  251. if (clientAsyncData.user.states === loadSate.ing) {
  252. setTimeout(function () {
  253. clientAsyncData.user.getAll(op);
  254. }, 100);// 如果还在加载100ms后再检测
  255. }
  256. else {
  257. var _dataTmp = renlian.storage.get("userData") || {};
  258. var data = _dataTmp.data || {};
  259. op.callback(data, op);
  260. }
  261. }
  262. };
  263. // 数据字典
  264. clientAsyncData.dataItem = {
  265. states: loadSate.no,
  266. init: function () {
  267. if (clientAsyncData.dataItem.states === loadSate.no) {
  268. clientAsyncData.dataItem.states = loadSate.ing;
  269. var data = renlian.storage.get("dataItemData") || {};
  270. var ver = data.ver || "";
  271. renlian.httpget(config.webapi + "renlian/adms/dataitem/map", { ver: ver }, function (data) {
  272. if (data) {
  273. if (data.ver) {
  274. renlian.storage.set("dataItemData", data);
  275. }
  276. clientAsyncData.dataItem.states = loadSate.yes;
  277. }
  278. else {
  279. clientAsyncData.dataItem.states = loadSate.fail;
  280. }
  281. });
  282. }
  283. },
  284. get: function (op) {
  285. clientAsyncData.dataItem.init();
  286. if (clientAsyncData.dataItem.states === loadSate.ing) {
  287. setTimeout(function () {
  288. clientAsyncData.dataItem.get(op);
  289. }, 100);// 如果还在加载100ms后再检测
  290. }
  291. else {
  292. var _dataTmp = renlian.storage.get("dataItemData") || {};
  293. var data = _dataTmp.data || {};
  294. op.callback(clientAsyncData.dataItem.find(op.key, data[op.code] || {}) || {}, op);
  295. }
  296. },
  297. getAll: function (op) {
  298. clientAsyncData.dataItem.init();
  299. if (clientAsyncData.dataItem.states === loadSate.ing) {
  300. setTimeout(function () {
  301. clientAsyncData.dataItem.getAll(op);
  302. }, 100);// 如果还在加载100ms后再检测
  303. }
  304. else {
  305. var _dataTmp = renlian.storage.get("dataItemData") || {};
  306. var data = _dataTmp.data || {};
  307. op.callback(data[op.code] || {}, op);
  308. }
  309. },
  310. find: function (key, data) {
  311. var res = {};
  312. for (var id in data) {
  313. if (data[id].value === key) {
  314. res = data[id];
  315. break;
  316. }
  317. }
  318. return res;
  319. }
  320. };
  321. // 数据源数据
  322. clientAsyncData.sourceData = {
  323. states: {},
  324. get: function (op) {
  325. if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) {
  326. clientAsyncData.sourceData.states[op.code] = loadSate.ing;
  327. clientAsyncData.sourceData.load(op.code);
  328. }
  329. if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) {
  330. setTimeout(function () {
  331. clientAsyncData.sourceData.get(op);
  332. }, 100);// 如果还在加载100ms后再检测
  333. }
  334. else {
  335. var _tmpData = renlian.storage.get("sourceData_" + op.code) || {};
  336. var data = _tmpData.data || [];
  337. if (data) {
  338. op.callback(clientAsyncData.sourceData.find(op.key, op.keyId, data) || {}, op);
  339. } else {
  340. op.callback({}, op);
  341. }
  342. }
  343. },
  344. getAll: function (op) {
  345. if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) {
  346. clientAsyncData.sourceData.states[op.code] = loadSate.ing;
  347. clientAsyncData.sourceData.load(op.code);
  348. }
  349. if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) {
  350. setTimeout(function () {
  351. clientAsyncData.sourceData.getAll(op);
  352. }, 100);// 如果还在加载100ms后再检测
  353. }
  354. else {
  355. var _tmpData = renlian.storage.get("sourceData_" + op.code) || {};
  356. var data = _tmpData.data || [];
  357. if (data) {
  358. op.callback(data, op);
  359. } else {
  360. op.callback({}, op);
  361. }
  362. }
  363. },
  364. load: function (code) {
  365. var data = renlian.storage.get("sourceData_" + code) || {};
  366. var ver = data.ver || "";
  367. renlian.httpget(config.webapi + "renlian/adms/datasource/map", { code: code, ver: ver }, function (data) {
  368. if (data) {
  369. if (data.ver) {
  370. renlian.storage.set("sourceData_" + code, data);
  371. }
  372. clientAsyncData.sourceData.states[code] = loadSate.yes;
  373. }
  374. else {
  375. clientAsyncData.sourceData.states[code] = loadSate.fail;
  376. }
  377. });
  378. },
  379. find: function (key, keyId, data) {
  380. var res = {};
  381. for (var i = 0, l = data.length; i < l; i++) {
  382. if (data[i][keyId] === key) {
  383. res = data[i];
  384. break;
  385. }
  386. }
  387. return res;
  388. }
  389. };
  390. // 自定义数据
  391. var custmerData = {};
  392. clientAsyncData.custmerData = {
  393. states: {},
  394. get: function (op) {
  395. if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) {
  396. clientAsyncData.custmerData.states[op.url] = loadSate.ing;
  397. clientAsyncData.custmerData.load(op.url);
  398. }
  399. if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) {
  400. setTimeout(function () {
  401. clientAsyncData.custmerData.get(op);
  402. }, 100);// 如果还在加载100ms后再检测
  403. }
  404. else {
  405. var data = custmerData[op.url];
  406. if (data) {
  407. op.callback(clientAsyncData.custmerData.find(op.key, op.keyId, data) || {}, op);
  408. } else {
  409. op.callback({}, op);
  410. }
  411. }
  412. },
  413. getAll: function (op) {
  414. if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) {
  415. clientAsyncData.custmerData.states[op.url] = loadSate.ing;
  416. clientAsyncData.custmerData.load(op.url);
  417. }
  418. if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) {
  419. setTimeout(function () {
  420. clientAsyncData.custmerData.getAll(op);
  421. }, 100);// 如果还在加载100ms后再检测
  422. }
  423. else {
  424. var data = custmerData[op.url];
  425. op.callback(data || [], op);
  426. }
  427. },
  428. load: function (url) {
  429. renlian.httpget(config.webapi + url, null, function (data) {
  430. if (data) {
  431. custmerData[url] = data;
  432. clientAsyncData.custmerData.states[url] = loadSate.yes;
  433. }
  434. else {
  435. clientAsyncData.custmerData.states[url] = loadSate.fail;
  436. }
  437. });
  438. },
  439. find: function (key, keyId, data) {
  440. var res = {};
  441. for (var i = 0, l = data.length; i < l; i++) {
  442. if (data[i][keyId] === key) {
  443. res = data[i];
  444. break;
  445. }
  446. }
  447. return res;
  448. }
  449. };
  450. // 获取功能列表
  451. clientAsyncData.module = {
  452. states: loadSate.no,
  453. init: function () {
  454. if (clientAsyncData.module.states === loadSate.no) {
  455. clientAsyncData.module.states = loadSate.ing;
  456. var data = renlian.storage.get("moduleData") || {};
  457. var ver = data.ver || "";
  458. renlian.httpget(config.webapi + "renlian/adms/function/list", { ver: ver }, function (data) {
  459. if (data) {
  460. if (data.ver) {
  461. renlian.storage.set("moduleData", data);
  462. }
  463. clientAsyncData.module.states = loadSate.yes;
  464. }
  465. else {
  466. clientAsyncData.module.states = loadSate.fail;
  467. }
  468. });
  469. }
  470. },
  471. get: function (op) {
  472. clientAsyncData.module.init();
  473. if (clientAsyncData.module.states === loadSate.ing) {
  474. setTimeout(function () {
  475. clientAsyncData.module.get(op);
  476. }, 100);// 如果还在加载100ms后再检测
  477. }
  478. else {
  479. var _tmpData = renlian.storage.get("moduleData");
  480. var data = _tmpData.data || {};
  481. op.callback(data, op);
  482. }
  483. }
  484. };
  485. // 获取我的应用列表
  486. renlian.myModule = {
  487. states: loadSate.no,
  488. init: function (modules) {
  489. if (renlian.myModule.states === loadSate.no) {
  490. renlian.myModule.states = loadSate.ing;
  491. var mymoduleData = renlian.storage.get("mymoduleData");
  492. if (mymoduleData === null) {
  493. var len = 7;
  494. if (len > modules.length) {
  495. len = modules.length;
  496. }
  497. var list = [];
  498. for (var i = 0; i < len; i++) {
  499. var item = modules[i];
  500. list.push(item.F_Id);
  501. }
  502. renlian.storage.set("mymoduleData", list);
  503. renlian.httppost(config.webapi + "renlian/adms/function/mylist/update", String(list), (res) => {
  504. });
  505. renlian.myModule.states = loadSate.yes;
  506. }
  507. else {
  508. renlian.httpget(config.webapi + "renlian/adms/function/mylist", null, function (data) {
  509. if (data) {
  510. renlian.storage.set("mymoduleData", data);
  511. }
  512. renlian.myModule.states = loadSate.yes;
  513. });
  514. }
  515. }
  516. },
  517. get: function (modules, callback) {
  518. renlian.myModule.init(modules);
  519. if (renlian.myModule.states === loadSate.ing) {
  520. setTimeout(function () {
  521. renlian.myModule.get(modules, callback);
  522. }, 100);// 如果还在加载100ms后再检测
  523. }
  524. else {
  525. callback(renlian.storage.get("mymoduleData"));
  526. }
  527. }
  528. };
  529. // 获取单据编码
  530. renlian.getRuleCode = function (code, callback) {
  531. renlian.httpget(config.webapi + "renlian/adms/coderule/code", code, function (data) {
  532. if (data) {
  533. callback(data);
  534. }
  535. else {
  536. callback('');
  537. }
  538. });
  539. };
  540. /*选择框方法扩展(包含单选框)*/
  541. // 选择框扩展(url(后台数据地址),数据字典,数据源),
  542. $.fn.lrpickerex = function (op) {
  543. var $this = $(this);
  544. if ($this.length === 0) {
  545. return $this;
  546. }
  547. if (!op.data) {
  548. op.data = [];
  549. switch (op.type) {
  550. case 'dataItem':
  551. $this.lrpicker(op);
  552. renlian.clientdata.getAll('dataItem', {
  553. code: op.code,
  554. callback: function (data) {
  555. var _tmpdata = [];
  556. $.each(data, function (_index, _item) {
  557. _tmpdata.push({ value: _item.value, text: _item.text });
  558. });
  559. $this.lrpickerSetData(_tmpdata);
  560. }
  561. });
  562. break;
  563. case 'sourceData':
  564. $this.lrpicker(op);
  565. renlian.clientdata.getAll('sourceData', {
  566. code: op.code,
  567. callback: function (data) {
  568. $this.lrpickerSetData(data);
  569. }
  570. });
  571. break;
  572. default:
  573. $this.lrpicker(op);
  574. if (op.url) {// 如果有连接地址
  575. renlian.clientdata.getAll('custmerData', {
  576. url: op.url,
  577. callback: function (data) {
  578. $this.lrpickerSetData(data);
  579. }
  580. });
  581. }
  582. break;
  583. }
  584. } else {
  585. $this.lrpicker(op);
  586. }
  587. return $this;
  588. };
  589. // 组织单位选择
  590. $.fn.lrselect = function (op) {
  591. var $this = $(this);
  592. if ($this.length === 0) {
  593. return $this;
  594. }
  595. var dfop = {
  596. placeholder: '请选择',
  597. type: 'company',
  598. companyId: '',
  599. departmentId: '',
  600. change: false
  601. };
  602. $.extend(dfop, op || {});
  603. $this.attr('type', 'lrselect');
  604. $this.addClass('lr-select');
  605. $this.html('<div class="text">' + dfop.placeholder + '</div>');
  606. dfop.id = $this.attr('id');
  607. $this[0].dfop = dfop;
  608. $this.on('tap', function () {
  609. var $this = $(this);
  610. if ($this.attr('readonly') || $this.parents('.lr-form-row').attr('readonly')) {
  611. return false;
  612. }
  613. renlian.formblur();
  614. var op = $this[0].dfop;
  615. if (op.needPre) {
  616. renlian.layer.toast('请先选择上一级!');
  617. return false;
  618. }
  619. var name = '';
  620. switch (op.type) {
  621. case 'company':
  622. name = '选择公司';
  623. break;
  624. case 'department':
  625. name = '选择部门';
  626. break;
  627. case 'user':
  628. name = '选择人员';
  629. break;
  630. }
  631. renlian.nav.go({
  632. path: 'lrselect/' + op.type, title: name, type: 'right', param: {
  633. callback: function (data, _op, $this) {
  634. $this.find('.text').text(data.name);
  635. _op.value = data.id;
  636. _op.text = data.name;
  637. _op.change && _op.change(data);
  638. $this.trigger('change');
  639. },
  640. op: op,
  641. $this: $this
  642. }
  643. });
  644. });
  645. return $this;
  646. };
  647. $.fn.lrselectGet = function (type) {
  648. var $this = $(this);
  649. if ($this.length === 0) {
  650. return '';
  651. }
  652. var op = $this[0].dfop;
  653. $this = null;
  654. if (type === 'text') {
  655. return op.text;
  656. }
  657. else {
  658. return op.value;
  659. }
  660. };
  661. $.fn.lrselectSet = function (value) {
  662. var $this = $(this);
  663. if ($this.length === 0) {
  664. return '';
  665. }
  666. var op = $this[0].dfop;
  667. op.value = value;
  668. $this = null;
  669. renlian.clientdata.get(op.type, {
  670. key: value,
  671. set: op,
  672. callback: function (data, _op) {
  673. $('#' + _op.set.id).find('.text').text(data.name || '');
  674. _op.set.text = data.name || '';
  675. data.id = _op.key;
  676. _op.change && _op.change(data);
  677. $('#' + _op.set.id).trigger('change');
  678. }
  679. });
  680. };
  681. $.fn.lrselectUpdate = function (op) {
  682. var $this = $(this);
  683. if ($this.length === 0) {
  684. return $this;
  685. }
  686. $.extend($this[0].dfop, op || {});
  687. $this[0].dfop.value = '';
  688. $this[0].dfop.text = '';
  689. $this.find('.text').text($this[0].dfop.placeholder);
  690. $this = null;
  691. };
  692. // 弹层选择框(数据字典和数据源)
  693. $.fn.layerSelect = function (op) {
  694. var $this = $(this);
  695. if ($this.length === 0) {
  696. return $this;
  697. }
  698. var dfop = {
  699. placeholder: '请选择',
  700. type: 'dataItem',// sourceData
  701. layerData:[],
  702. callback: false
  703. };
  704. $.extend(dfop, op || {});
  705. $this.attr('type', 'lrlayerSelect');
  706. $this.addClass('lr-layerSelect');
  707. $this.html('<div class="text">' + dfop.placeholder + '</div>');
  708. dfop.id = $this.attr('id');
  709. $this[0].dfop = dfop;
  710. $this.on('tap', function () {
  711. var $this = $(this);
  712. if ($this.attr('readonly') || $this.parents('.lr-form-row').attr('readonly')) {
  713. return false;
  714. }
  715. renlian.formblur();
  716. var op = $this[0].dfop;
  717. renlian.nav.go({
  718. path: 'lrselect/layer', title: op.placeholder, type: 'right', param: {
  719. callback: function (data, _op, _$this) {
  720. _op.callback && _op.callback(data, _op.layerData, _$this);
  721. _$this = null;
  722. },
  723. op: op,
  724. $this: $this
  725. }
  726. });
  727. $this = null;
  728. return false;
  729. });
  730. return $this;
  731. };
  732. $.fn.layerSelectSet = function (value) {
  733. var $this = $(this);
  734. var op = $(this)[0].dfop;
  735. if (value) {
  736. $this.find('.text').text(value);
  737. op.value = value;
  738. }
  739. else {
  740. op.value = '';
  741. $(this).find('.text').text(op.placeholder);
  742. }
  743. };
  744. $.fn.layerSelectGet = function () {
  745. return $(this)[0].dfop.value;
  746. };
  747. /*多选框方法扩展*/
  748. $.fn.lrcheckboxex = function (op) {
  749. var $this = $(this);
  750. if ($this.length === 0) {
  751. return $this;
  752. }
  753. if (!op.data) {
  754. op.data = [];
  755. switch (op.type) {
  756. case 'dataItem':
  757. $this.lrcheckbox(op);
  758. renlian.clientdata.getAll('dataItem', {
  759. code: op.code,
  760. callback: function (data) {
  761. var _tmpdata = [];
  762. $.each(data, function (_index, _item) {
  763. _tmpdata.push({ value: _item.value, text: _item.text });
  764. });
  765. $this.lrcheckboxSetData(_tmpdata);
  766. }
  767. });
  768. break;
  769. case 'sourceData':
  770. $this.lrcheckbox(op);
  771. renlian.clientdata('sourceData', {
  772. code: op.code,
  773. callback: function (data) {
  774. $this.lrcheckboxSetData(data);
  775. }
  776. });
  777. break;
  778. default:
  779. $this.lrcheckbox(op);
  780. if (op.url) {// 如果有连接地址
  781. renlian.clientdata('custmerData', {
  782. url: op.url,
  783. callback: function (data) {
  784. $this.lrcheckboxSetData(data);
  785. }
  786. });
  787. }
  788. break;
  789. }
  790. } else {
  791. $this.lrcheckbox(op);
  792. }
  793. return $this;
  794. };
  795. /*编辑表格方法扩展*/
  796. function setGridRowValue($block, id, type, value) {// 设置编辑表格每个块的值
  797. switch (type) {
  798. case 'label':
  799. case 'input':
  800. $block.find('#' + id).val(value);
  801. break;
  802. case 'radio':
  803. case 'select':
  804. $block.find('#' + id).lrpickerSet(value);
  805. break;
  806. case 'checkbox':
  807. $block.find('#' + id).lrcheckboxSet(value);
  808. break;
  809. case 'layer':
  810. $block.find('#' + id).layerSelectSet(value);
  811. break;
  812. case 'datetime':
  813. $block.find('#' + id).lrdateSet(value);
  814. break;
  815. }
  816. $block = null;
  817. }
  818. function getGridRowValue($block, id, type) {// 设置编辑表格每个块的值
  819. var v = '';
  820. switch (type) {
  821. case 'label':
  822. case 'input':
  823. v = $block.find('#' + id).val();
  824. break;
  825. case 'radio':
  826. case 'select':
  827. v = $block.find('#' + id).lrpickerGet();
  828. break;
  829. case 'checkbox':
  830. v = $block.find('#' + id).lrcheckboxGet();
  831. break;
  832. case 'layer':
  833. v = $block.find('#' + id).layerSelectGet();
  834. break;
  835. case 'datetime':
  836. v = $block.find('#' + id).lrdateGet();
  837. break;
  838. }
  839. $block = null;
  840. return v;
  841. }
  842. function addGridRow($this, op) {
  843. // 添加编辑集合块
  844. var $html = $('<div class="lr-edit-grid-block" ></div>');
  845. if (op.hasBtn) {
  846. $this.find('.lr-edit-grid-btn').before($html);
  847. }
  848. else {
  849. $this.append($html);
  850. }
  851. // 添加标题栏
  852. var $title = $('<div class="lr-edit-grid-title" >' + op.title + '(<span>' + op._index + '</span>)</div>');
  853. if (op._index > 1) {
  854. $title.append('<div class="lr-edit-grid-deletebtn" data-value="' + op._index + '">删除</div>');
  855. }
  856. $html.html($title);
  857. var _compontHtml = '';
  858. op.compontsMap = op.compontsMap || {};
  859. // 编辑表格-组件初始化
  860. $.each(op.componts, function (_index, _item) {
  861. if (op._index === 1) {
  862. op.compontsMap[_item.field] = _item;
  863. }
  864. switch (_item.type) {
  865. case 'label':
  866. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><input type="text" readonly id="' + _item.field + '" ></div>';
  867. $html.append(_compontHtml);
  868. break;
  869. case 'input':
  870. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><input type="text" id="' + _item.field + '" ></div>';
  871. $html.append(_compontHtml);
  872. // 值改变
  873. if (_item.change) {
  874. $html.find('#' + _item.field).on('input propertychange', { change: _item.change }, function (e) {
  875. e = e || window.event;
  876. var _change = e.data.change;
  877. var $this = $(this);
  878. var _$block = $this.parents('.lr-edit-grid-block');
  879. var v = $this.val();
  880. _change(v, _$block);
  881. $this = null;
  882. _$block = null;
  883. });
  884. }
  885. break;
  886. case 'radio':
  887. case 'select':
  888. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
  889. $html.append(_compontHtml);
  890. $html.find('#' + _item.field).lrpickerex({
  891. code: _item.code,
  892. type: _item.datatype,
  893. ivalue: _item.ivalue,
  894. itext: _item.itext,
  895. data: _item.data,
  896. url: _item.url,
  897. change: function (value, text, datalist, $self) {
  898. var _$block = $self.parents('.lr-edit-grid-block');
  899. _item.change && _item.change(value, text, datalist, _$block);
  900. $self = null;
  901. _$block = null;
  902. }
  903. });
  904. break;
  905. case 'checkbox':
  906. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
  907. $html.append(_compontHtml);
  908. $html.find('#' + _item.field).lrcheckboxex({
  909. code: _item.code,
  910. type: _item.datatype,
  911. ivalue: _item.ivalue,
  912. itext: _item.itext,
  913. data: _item.data,
  914. url: _item.url,
  915. change: function (value, text, datalist, $self) {
  916. var _$block = $self.parents('.lr-edit-grid-block');
  917. _item.change && _item.change(value, text, datalist, _$block);
  918. $self = null;
  919. _$block = null;
  920. }
  921. });
  922. break;
  923. case 'layer':
  924. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
  925. $html.append(_compontHtml);
  926. $html.find('#' + _item.field).layerSelect({
  927. code: _item.code,
  928. type: _item.datatype,
  929. layerData: _item.layerData,
  930. callback: function (data, layerData, _$this) {
  931. var $block = _$this.parents('.lr-edit-grid-block');
  932. $.each(layerData, function (_jindex, _jitem) {
  933. setGridRowValue($block, _jitem.value, op.compontsMap[_jitem.value].type, data[_jitem.name]);
  934. });
  935. _item.change && _item.change(data, $block);
  936. $block = null;
  937. _$this = null;
  938. }
  939. });
  940. break;
  941. case 'datetime':
  942. _compontHtml = '<div class="lr-edit-grid-row" ><label>' + _item.name + '</label><div id="' + _item.field + '" ></div></div>';
  943. $html.append(_compontHtml);
  944. $html.find('#' + _item.field).lrdate({
  945. type: _item.datetime === 'date' ? 'date' : 'datetime',
  946. change: function (v, _$this) {
  947. var $block = _$this.parents('.lr-edit-grid-block');
  948. _item.change && _item.change(v, $block);
  949. $block = null;
  950. _$this = null;
  951. }
  952. });
  953. break;
  954. default:
  955. break;
  956. }
  957. });
  958. $title = null;
  959. $this = null;
  960. return $html;
  961. }
  962. $.fn.lrgrid = function (op) {
  963. var $this = $(this);
  964. if ($this.length === 0) {
  965. return $this;
  966. }
  967. if ($this[0].dfop) {
  968. return $this;
  969. }
  970. var dfop = {
  971. title: '编辑表格',
  972. componts: [],
  973. hasBtn: true,
  974. _index: 1
  975. };
  976. $.extend(dfop, op || {});
  977. $this[0].dfop = dfop;
  978. $this.addClass('lr-edit-gird');
  979. if (dfop.hasBtn) {
  980. // 添加增加按钮
  981. var $btn = $('<div class="lr-edit-grid-btn" ><i class="iconfont icon-add1" ></i>增加' + (dfop.title || '') + '</div>');
  982. $btn.on('tap', { op: dfop }, function (e) {// 添加一块编辑集合
  983. e = e || window.event;
  984. var _op = e.data.op;
  985. var $grid = $(this).parents('.lr-edit-gird');
  986. _op._index++;// 增加块数
  987. renlian.formblur();
  988. addGridRow($grid, _op);
  989. });
  990. $this.html($btn);
  991. // 注册删除按钮事件
  992. $this.delegate('.lr-edit-grid-deletebtn', 'tap', { op: dfop }, function (e) {
  993. e = e || window.event;
  994. var _op = e.data.op;
  995. var $my = $(this);
  996. var myIndex = $my.attr('data-value');
  997. renlian.formblur();
  998. renlian.layer.confirm('你确定要删除' + _op.title + myIndex + '吗?', function (isOk) {
  999. if (isOk === '1') {
  1000. _op._index--;// 减少块数
  1001. // 排在后面的块需要重新调整序号
  1002. $my.parents('.lr-edit-gird').find('.lr-edit-grid-block:gt(' + (parseInt(myIndex) - 1) + ')').each(function () {
  1003. var $this = $(this);
  1004. var $deletebtn = $this.find('.lr-edit-grid-deletebtn');
  1005. var _index = parseInt($deletebtn.attr('data-value')) - 1;
  1006. $deletebtn.attr('data-value', _index);
  1007. $this.find('.lr-edit-grid-title span').text(_index);
  1008. $deletebtn = null;
  1009. $this = null;
  1010. });
  1011. // 移除绑定在自己身上的弹层,选择框,单选框,多选框,日期
  1012. var $block = $my.parents('.lr-edit-grid-block');
  1013. $block.find('.lr-date,.lr-picker,.lr-checkbox').each(function () {
  1014. var $this = $(this);
  1015. var _op = $this[0].fop;
  1016. $('#pop_' + _op.id).remove();
  1017. $('#dt_' + _op.id).remove();
  1018. });
  1019. // 移除自己
  1020. $block.remove();
  1021. $block = null;
  1022. }
  1023. $my = null;
  1024. }, '', ['取消', '确定']);
  1025. });
  1026. }
  1027. addGridRow($this, dfop);
  1028. return $this;
  1029. };
  1030. $.fn.lrgridSet = function (data) {
  1031. var $this = $(this);
  1032. var op = $this[0].dfop;
  1033. $.each(data, function (_index, _item) {
  1034. if (_index === 0) {
  1035. // 如果是第一行数据
  1036. $.each(op.componts, function (_jindex, jitem) {
  1037. var _id = jitem.field;
  1038. if (op.isToLowerCase) {
  1039. _id = _id.toLowerCase();
  1040. }
  1041. setGridRowValue($this.find('.lr-edit-grid-block'), jitem.field, jitem.type, _item[_id]);
  1042. });
  1043. } else {
  1044. // 如果不是第一行数据就先添加一行
  1045. op._index++;// 增加块数
  1046. var $block = addGridRow($this, op);
  1047. $.each(op.componts, function (_jindex, jitem) {
  1048. var _id = jitem.field;
  1049. if (op.isToLowerCase) {
  1050. _id = _id.toLowerCase();
  1051. }
  1052. setGridRowValue($block, jitem.field, jitem.type, _item[_id]);
  1053. });
  1054. }
  1055. });
  1056. $this = null;
  1057. };
  1058. $.fn.lrgridGet = function () {
  1059. var $this = $(this);
  1060. var op = $this[0].dfop;
  1061. var data = [];
  1062. $this.find('.lr-edit-grid-block').each(function () {
  1063. var $block = $(this);
  1064. var point = {};
  1065. $.each(op.componts, function (_jindex, jitem) {
  1066. point[jitem.field] = getGridRowValue($block, jitem.field, jitem.type);
  1067. });
  1068. data.push(point);
  1069. });
  1070. $this = null;
  1071. return data;
  1072. };
  1073. // 设置表单组件为只读
  1074. $.fn.setFormRead = function () {
  1075. $(this).find('.lr-form-row').each(function () {
  1076. $(this).attr('readonly', 'readonly');
  1077. });
  1078. }
  1079. $.fn.setFormWrite = function () {
  1080. $(this).find('.lr-form-row').each(function () {
  1081. $(this).removeAttr('readonly');
  1082. });
  1083. }
  1084. // 数据格式化
  1085. $.fn.dataFormatter = function (op) {
  1086. var $this = $(this);
  1087. var _v = '';
  1088. if (op.value === null || op.value === undefined || op.value === 'null' || op.value === 'undefined') {
  1089. op.value = '';
  1090. }
  1091. op.value = op.value + '';
  1092. switch (op.type) {
  1093. case 'datetime':
  1094. $this.append(renlian.date.format(op.value, op.dateformat));
  1095. break;
  1096. case 'dataItem':
  1097. _v = op.value.split(',');
  1098. $.each(_v || [], function (_index, _item) {
  1099. if (_item) {
  1100. renlian.clientdata.get('dataItem', {
  1101. key: _item,
  1102. code: op.code,
  1103. $this: $this,
  1104. callback: function (_data, _op) {
  1105. _op.$this.append(_data.text);
  1106. }
  1107. });
  1108. }
  1109. });
  1110. break;
  1111. case 'dataSource':
  1112. _v = op.value.split(',');
  1113. $.each(_v || [], function (_index, _item) {
  1114. if (_item) {
  1115. renlian.clientdata.get('sourceData', {
  1116. key: _item,
  1117. keyId: op.keyId,
  1118. code: op.code,
  1119. set: op,
  1120. $this: $this,
  1121. callback: function (_data, _op) {
  1122. _op.$this.append(_data[_op.set.text]);
  1123. }
  1124. });
  1125. }
  1126. });
  1127. break;
  1128. case 'dataCustmer':
  1129. _v = op.value.split(',');
  1130. $.each(_v || [], function (_index, _item) {
  1131. if (_item) {
  1132. renlian.clientdata.get('custmerData', {
  1133. key: _item,
  1134. keyId: op.keyId,
  1135. url: op.url,
  1136. set: op,
  1137. $this: $this,
  1138. callback: function (_data, _op) {
  1139. _op.$this.append(_data[_op.set.text]);
  1140. }
  1141. });
  1142. }
  1143. });
  1144. break;
  1145. case 'organize':
  1146. renlian.clientdata.get(op.dataType, {
  1147. key: op.value,
  1148. $this: $this,
  1149. callback: function (_data,_op) {
  1150. _op.$this.append(_data.name);
  1151. }
  1152. });
  1153. break;
  1154. default:
  1155. $this.append(op.value);
  1156. break;
  1157. }
  1158. return $this;
  1159. }
  1160. // 图片选择,上传,下载
  1161. $.fn.lrImagepicker = function (op) {
  1162. var dfop = {
  1163. maxCount: 9,
  1164. isOnlyCamera: false,
  1165. uploadUrl: config.webapi + 'renlian/adms/annexes/upload',
  1166. downUrl: config.webapi + 'renlian/adms/annexes/down?data=',
  1167. getParams: function () {
  1168. var param = {};
  1169. var logininfo = renlian.storage.get('logininfo');
  1170. param.token = logininfo.token;
  1171. param.loginMark = renlian.deviceId();
  1172. return param;
  1173. },
  1174. deleteImg: function (fileId) {
  1175. renlian.httppost(config.webapi + 'renlian/adms/annexes/delete', fileId, function () { });
  1176. },
  1177. downFile: function (value, callback) {
  1178. renlian.httpget(config.webapi + 'renlian/adms/annexes/list', value, function (data) {
  1179. if (data) {
  1180. var _data = [];
  1181. $.each(data, function (_index, _item) {
  1182. if (_item.F_FileType === 'jpg' || _item.F_FileType === 'png') {
  1183. var _point = {
  1184. id: _item.F_Id,
  1185. name: _item.F_Id + '.' + _item.F_FileType
  1186. };
  1187. _data.push(_point);
  1188. }
  1189. });
  1190. callback(_data);
  1191. }
  1192. });
  1193. }
  1194. };
  1195. $.extend(dfop, op || {});
  1196. return $(this).imagepicker(dfop);
  1197. }
  1198. })(window.jQuery, window.lrmui);