lrmuiex.js 46 KB

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