selector.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. (function(exports) {
  2. var Selectors = {
  3. createSupplierTypeSelect: function(el, dirctory) {
  4. $(el).bsSuggest({
  5. url: httpRequest.server + "/svr-iot/systemDict/findDictByCode?dictName=" + dirctory,
  6. getDataMethod: "firstByUrl",
  7. effectiveFields: ["value"],
  8. idField: "code",
  9. keyField: "value",
  10. fnProcessData: function(res) {
  11. return {
  12. value: [{
  13. code: "0",
  14. value: "全部"
  15. }].concat(res.detailModelList)
  16. }
  17. }
  18. });
  19. },
  20. createDictSelect: function(el, dirctory, option) {
  21. $(el).bsSuggest({
  22. url: httpRequest.server + "/svr-iot/systemDict/findDictByCode?dictName=" + dirctory,
  23. getDataMethod: "firstByUrl",
  24. effectiveFields: ["value"],
  25. idField: "code",
  26. keyField: "value",
  27. fnProcessData: function(res) {
  28. return (option && option.fnProcessData)?option.fnProcessData(res): res.detailModelList
  29. }
  30. })
  31. },
  32. // 获取当下企业证书
  33. createCertificate: function(el, companyId, option) {
  34. $(el).bsSuggest({
  35. url: httpRequest.server + "/svr-iot/company/findCompanyCertByCompanyId?companyId=" + companyId,
  36. getDataMethod: "firstByUrl",
  37. effectiveFields: ["name"],
  38. idField: "id",
  39. keyField: "name",
  40. fnProcessData: function(res) {
  41. return (option && option.fnProcessData)?option.fnProcessData(res): res.detailModelList
  42. }
  43. })
  44. },
  45. createJudgeStatusSelect: function(el) {
  46. $(el).bsSuggest({
  47. data: {
  48. value: [{
  49. code: "001",
  50. name: "已审核"
  51. },
  52. {
  53. code: "002",
  54. name: "未审核"
  55. }]
  56. },
  57. getDataMethod: "data",
  58. effectiveFields: ["name"],
  59. idField: "code",
  60. keyField: "name"
  61. });
  62. },
  63. createDeviceBindSelect: function(el) {
  64. $(el).bsSuggest({
  65. data: {
  66. value: [
  67. {
  68. code: "",
  69. name: "全部"
  70. },
  71. {
  72. code: "1",
  73. name: "已绑定"
  74. },
  75. {
  76. code: "2",
  77. name: "未绑定"
  78. }]
  79. },
  80. getDataMethod: "data",
  81. effectiveFields: ["name"],
  82. idField: "code",
  83. keyField: "name"
  84. });
  85. },
  86. createDeviceTypeSelect: function(el) {
  87. $(el).bsSuggest({
  88. data: {
  89. value: [{
  90. code: "001",
  91. name: "血糖仪"
  92. },
  93. {
  94. code: "002",
  95. name: "血压仪"
  96. }]
  97. },
  98. getDataMethod: "data",
  99. effectiveFields: ["name"],
  100. idField: "code",
  101. keyField: "name"
  102. });
  103. },
  104. createDeviceStatusSelect: function(el) {
  105. $(el).bsSuggest({
  106. data: {
  107. value: [{
  108. code: "001",
  109. name: "状态1"
  110. },
  111. {
  112. code: "002",
  113. name: "状态2"
  114. }]
  115. },
  116. getDataMethod: "data",
  117. effectiveFields: ["code","name"],
  118. idField: "code",
  119. keyField: "name",
  120. effectiveFieldsAlias: {
  121. code: "编号",
  122. name: "名称"
  123. }
  124. });
  125. },
  126. createOrderStatusSelect: function(el) {
  127. $(el).bsSuggest({
  128. data: {
  129. value: [{
  130. code: "001",
  131. name: "状态1"
  132. },
  133. {
  134. code: "002",
  135. name: "状态2"
  136. }]
  137. },
  138. getDataMethod: "data",
  139. effectiveFields: ["code","name"],
  140. idField: "code",
  141. keyField: "name",
  142. effectiveFieldsAlias: {
  143. code: "编号",
  144. name: "名称"
  145. }
  146. });
  147. },
  148. createDeviceSelect: function(el) {
  149. $(el).bsSuggest({
  150. data: {
  151. value: [{
  152. code: "001",
  153. name: "设备1"
  154. },
  155. {
  156. code: "002",
  157. name: "设备2"
  158. }]
  159. },
  160. getDataMethod: "data",
  161. effectiveFields: ["name"],
  162. idField: "code",
  163. keyField: "name"
  164. });
  165. },
  166. createIsSureSelect: function(el, option) {
  167. $(el).bsSuggest({
  168. data: {
  169. value: [{
  170. code: "1",
  171. name: "是"
  172. },
  173. {
  174. code: "0",
  175. name: "否"
  176. }]
  177. },
  178. getDataMethod: "data",
  179. effectiveFields: ["name"],
  180. idField: "code",
  181. keyField: "name"
  182. }).on('onSetSelectValue', function (e, keyword) {
  183. option && option.onSetSelectValue && option.onSetSelectValue(e, keyword)
  184. });
  185. },
  186. createDeviceSupplierSelect2: function(el, option) {
  187. $(el).bsSuggest({
  188. data: {
  189. value: [{
  190. code: "001",
  191. name: "供应商1"
  192. },
  193. {
  194. code: "002",
  195. name: "供应商2"
  196. },
  197. {
  198. code: "",
  199. name: "+没有找到设备供应商?点击新增"
  200. }]
  201. },
  202. getDataMethod: "data",
  203. effectiveFields: ["name"],
  204. idField: "code",
  205. keyField: "name",
  206. processData: function(json){ // url 获取数据时,对数据的处理,作为 getData 的回调函数
  207. // var i, len, data = {value: []};
  208. //
  209. // if(!json || !json.result || json.result.length == 0) {
  210. // return false;
  211. // }
  212. //
  213. // console.log(json);
  214. // len = json.result.length;
  215. //
  216. // for (i = 0; i < len; i++) {
  217. // data.value.push({
  218. // "Id": (i + 1),
  219. // "Keyword": json.result[i][0],
  220. // "Count": json.result[i][1]
  221. // });
  222. // }
  223. // console.log(data);
  224. return data;
  225. }
  226. }).on('onSetSelectValue', function (e, keyword) {
  227. option && option.onSetSelectValue && option.onSetSelectValue(e, keyword)
  228. });
  229. },
  230. createDeviceManufacturerSelect2: function(el, option) {
  231. $(el).bsSuggest({
  232. data: {
  233. value: [{
  234. code: "001",
  235. name: "厂商1"
  236. },
  237. {
  238. code: "002",
  239. name: "厂商2"
  240. },
  241. {
  242. code: "",
  243. name: "+没有找到设备厂商?点击新增"
  244. }]
  245. },
  246. getDataMethod: "data",
  247. effectiveFields: ["name"],
  248. idField: "code",
  249. keyField: "name",
  250. processData: function(json){ // url 获取数据时,对数据的处理,作为 getData 的回调函数
  251. // var i, len, data = {value: []};
  252. //
  253. // if(!json || !json.result || json.result.length == 0) {
  254. // return false;
  255. // }
  256. //
  257. // console.log(json);
  258. // len = json.result.length;
  259. //
  260. // for (i = 0; i < len; i++) {
  261. // data.value.push({
  262. // "Id": (i + 1),
  263. // "Keyword": json.result[i][0],
  264. // "Count": json.result[i][1]
  265. // });
  266. // }
  267. // console.log(data);
  268. return data;
  269. }
  270. }).on('onSetSelectValue', function (e, keyword) {
  271. option && option.onSetSelectValue && option.onSetSelectValue(e, keyword)
  272. });
  273. },
  274. createDataTransModeSelect: function(el) {
  275. $(el).bsSuggest({
  276. data: {
  277. value: [{
  278. code: "1",
  279. name: "WIFI"
  280. },
  281. {
  282. code: "2",
  283. name: "蓝牙"
  284. },
  285. {
  286. code: "3",
  287. name: "SIM卡"
  288. }]
  289. },
  290. getDataMethod: "data",
  291. effectiveFields: ["name"],
  292. idField: "code",
  293. keyField: "name"
  294. });
  295. },
  296. createPurchasingDeviceSelect2: function(el, option) {
  297. $(el).bsSuggest({
  298. data: {
  299. value: [{
  300. code: "001",
  301. name: "厂商1"
  302. },
  303. {
  304. code: "002",
  305. name: "厂商2"
  306. },
  307. {
  308. code: "",
  309. name: "+没有找到设备?点击新增"
  310. }]
  311. },
  312. getDataMethod: "data",
  313. effectiveFields: ["name"],
  314. idField: "code",
  315. keyField: "name",
  316. processData: function(json){ // url 获取数据时,对数据的处理,作为 getData 的回调函数
  317. // var i, len, data = {value: []};
  318. //
  319. // if(!json || !json.result || json.result.length == 0) {
  320. // return false;
  321. // }
  322. //
  323. // console.log(json);
  324. // len = json.result.length;
  325. //
  326. // for (i = 0; i < len; i++) {
  327. // data.value.push({
  328. // "Id": (i + 1),
  329. // "Keyword": json.result[i][0],
  330. // "Count": json.result[i][1]
  331. // });
  332. // }
  333. // console.log(data);
  334. return data;
  335. }
  336. }).on('onSetSelectValue', function (e, keyword) {
  337. option && option.onSetSelectValue && option.onSetSelectValue(e, keyword)
  338. });
  339. },
  340. createCompanySelect: function(el, option) {
  341. $(el).bsSuggest({
  342. url: httpRequest.server + "/svr-iot/company/findCompanyPage?size=100",
  343. getDataMethod: "url",
  344. effectiveFields: ["value"],
  345. idField: "code",
  346. keyField: "value",
  347. adjustAjaxParam: function(keyword) {
  348. return {
  349. name: keyword,
  350. size: 100
  351. }
  352. },
  353. fnProcessData: function(json){
  354. var data = {}
  355. data.value = _.map(json.detailModelList, function(v) {
  356. return {
  357. code: v.id,
  358. value: v.name
  359. }
  360. })
  361. return data
  362. }
  363. }).on('onSetSelectValue', function (e, keyword) {
  364. option && option.onSetSelectValue && option.onSetSelectValue(e, keyword)
  365. });
  366. },
  367. //获取API类别
  368. createShareInterfaceTypeSelect: function(el) {
  369. $(el).bsSuggest({
  370. url: httpRequest.openServer + "/apiCategory/page?page=1&&size=10000",
  371. getDataMethod: "url",
  372. effectiveFields: ["name"],
  373. idField: "id",
  374. keyField: "name",
  375. fnProcessData: function(res) {
  376. var data = {}
  377. data.value = _.map(res.datas, function(v) {
  378. return {
  379. id: v.id,
  380. name: v.name
  381. }
  382. })
  383. return data
  384. }
  385. })
  386. },
  387. createDefinedSelect: function(el,datas) {
  388. $(el).bsSuggest("destroy");
  389. $(el).bsSuggest({
  390. data: {
  391. value: datas
  392. },
  393. getDataMethod: "data",
  394. effectiveFields: ["name"],
  395. idField: "code",
  396. keyField: "name"
  397. });
  398. },
  399. }
  400. exports.Selectors = Selectors;
  401. })(window)