entrust.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'entrust/index' + location.search,
  8. add_url: 'entrust/add',
  9. edit_url: 'entrust/edit',
  10. del_url: 'entrust/del',
  11. multi_url: 'entrust/multi',
  12. import_url: 'entrust/import',
  13. printing_url: 'entrust/printing',
  14. table: 'entrust',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id'),operate:false},
  29. {field: 'no', title: __('No'), operate: 'LIKE'},
  30. {field: 'name', title: __('Name'), operate: 'LIKE'},
  31. {field: 'bach', title: __('Bach'), operate: 'LIKE'},
  32. {field: 'sell_bach', title: __('Sell_bach'), operate: 'LIKE'},
  33. {field: 'company', title: __('送样单位')},
  34. {field: 'sample_no', title: __('Sample_no'), operate: 'LIKE'},
  35. {field: 'is_two', title: __('是否双样'),operate:false,formatter: function (value,row,index) {
  36. if (value == 0){
  37. value = '单样';
  38. return '<span style="color: #18bc9c">' +value+ '</span>';
  39. }else {
  40. value = '双样';
  41. return '<span style="color: #f75444">' + value + '</span>';
  42. }
  43. }},
  44. {field: 'standard_name', title: __('Standard_name'), operate:false},
  45. {field: 'sample_status', title: __('Sample_status'), operate:false, formatter: Table.api.formatter.status},
  46. {field: 'create', title: __('Create'), operate:false, addclass:'datetimerange', autocomplete:false},
  47. {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5')}, formatter: Table.api.formatter.status},
  48. {field: 'remark', title: __('Remark'), operate:false},
  49. // {field: 'report_id', title: __('Report_id')},
  50. // {field: 'user_id', title: __('User_id')},
  51. // {field: 'user_name', title: __('User_name'), operate: 'LIKE'},
  52. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  53. buttons: [
  54. {
  55. name: 'detail',
  56. text: __('提交'),
  57. title: __('提交'),
  58. classname: 'btn btn-xs btn-primary btn-dialog',
  59. icon: 'fa fa-list',
  60. extend:'data-area=["50%","40%"]',
  61. url: 'entrust/submit/id/{ids}',
  62. callback: function (data) {
  63. },
  64. visible: function (row) {
  65. //返回true时按钮显示,返回false隐藏
  66. return true;
  67. }
  68. },
  69. {
  70. name: 'log',
  71. text: __('操作日志'),
  72. title: __('操作日志'),
  73. classname: 'btn btn-xs btn-primary btn-dialog',
  74. icon: 'fa fa-list',
  75. extend:'data-area=["80%","70%"]',
  76. url: 'entrust/log',
  77. callback: function (data) {
  78. },
  79. visible: function (row) {
  80. //返回true时按钮显示,返回false隐藏
  81. return true;
  82. }
  83. },
  84. {
  85. name: 'data',
  86. text: __('检测数据'),
  87. title: __('检测数据'),
  88. classname: 'btn btn-xs btn-primary btn-dialog',
  89. icon: 'fa fa-list',
  90. extend:'data-area=["100%","100%"]',
  91. url: 'entrust/data/id/{ids}',
  92. callback: function (data) {
  93. },
  94. visible: function (row) {
  95. //返回true时按钮显示,返回false隐藏
  96. return true;
  97. }
  98. }
  99. ,
  100. {
  101. name: 'entrust',
  102. text: __('委托单'),
  103. title: __('委托单'),
  104. classname: 'btn btn-xs btn-primary btn-dialog',
  105. icon: 'fa fa-list',
  106. extend:'data-area=["100%","100%"]',
  107. url: 'entrust/commissionSheet/id/{ids}',
  108. callback: function (data) {
  109. },
  110. visible: function (row) {
  111. //返回true时按钮显示,返回false隐藏
  112. return true;
  113. }
  114. }
  115. ],
  116. formatter: Table.api.formatter.operate}
  117. ]
  118. ]
  119. });
  120. $(".btn-add").data("area", ["100%","100%"]);
  121. $(".btn-edit").data("area", ["100%","100%"]);
  122. $(".btn-printing").data("area", ["100%","100%"]);
  123. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  124. $(".btn-editone").data("area", ["100%", "100%"]);
  125. });
  126. // 为表格绑定事件
  127. Table.api.bindevent(table);
  128. },
  129. add: function () {
  130. // $('#c-name').blur(function () {
  131. // var str = $(this).val()
  132. // str = str.replace(/\s+/g,'');//去除所有空格
  133. // var bach = str.substr(str.length - 7);
  134. // $('#c-bach').val(bach)
  135. // $('#c-sell_bach').val(bach)
  136. // })
  137. $('.mark').change(function () {
  138. var mark = parseInt($(this).val());
  139. var company = $('.company option:selected').val();
  140. switch (mark) {
  141. case 1:
  142. mark = 'A';
  143. break;
  144. case 2:
  145. mark = 'B';
  146. break;
  147. case 3:
  148. mark = 'C';
  149. break;
  150. case 4:
  151. mark = 'D';
  152. break;
  153. }
  154. Fast.api.ajax({
  155. url: "entrust/getNo",
  156. type: "post",
  157. data:{temp: mark,company:company}
  158. }, function (data) {
  159. var last_sample_no = mark + data;
  160. $('#c-sample_no').val(last_sample_no);
  161. var no = 'JC-'+last_sample_no;
  162. $('#c-no').val(no);
  163. return false;
  164. },function () {
  165. return false;
  166. });
  167. })
  168. Controller.api.bindevent();
  169. },
  170. edit: function () {
  171. $('.is_two').attr('disabled','disabled');
  172. Controller.api.bindevent();
  173. },
  174. submit:function () {
  175. $('.submit').click(function () {
  176. var temp = parseInt($('.mark').val());
  177. var id = $('#id').val();
  178. if (temp == 0 || temp == ''){
  179. layer.confirm('请选择判定标准!');
  180. return false;
  181. }
  182. if (id == 0 || id == ''){
  183. layer.confirm('未获取到参数!');
  184. return false;
  185. }
  186. Fast.api.ajax({
  187. url:'entrust/submit',
  188. data:{temp:temp,id:id}
  189. },function (data,ret) {
  190. //成功回调
  191. parent.Toastr.success("提交成功");
  192. Fast.api.close();
  193. parent.Fast.api.refreshmenu();
  194. return false;
  195. },function (data,ret) {
  196. parent.Toastr.error("提交失败");
  197. Fast.api.close();
  198. return false;
  199. });
  200. return false;
  201. })
  202. Controller.api.bindevent();
  203. },
  204. log:function () {
  205. // 初始化表格参数配置
  206. Table.api.init({
  207. extend: {
  208. index_url: 'entrust/log',
  209. }
  210. });
  211. var table = $("#table");
  212. var eid = $('#e_id').val();
  213. // 初始化表格
  214. table.bootstrapTable({
  215. url: 'entrust/log/ids/'+eid,
  216. // url: $.fn.bootstrapTable.defaults.extend.index_url,
  217. pk: 'id',
  218. sortName: 'id',
  219. columns: [
  220. [
  221. {checkbox: true},
  222. {field: 'id', title: '序号'},
  223. {field: 'username', title: __('username'), align: 'left'},
  224. {field: 'operate', title: __('operate'), align: 'left'},
  225. {field: 'content', title: __('content'), align: 'left'},
  226. {field: 'create', title: __('操作时间'), align: 'left'},
  227. ]
  228. ]
  229. });
  230. Controller.api.bindevent();
  231. },
  232. data:function () {
  233. $('.submit').click(function () {
  234. console.log(1111)
  235. var id = $('#id').val();
  236. if (id == 0 || id == ''){
  237. layer.confirm('未获取到参数!');
  238. return false;
  239. }
  240. Fast.api.ajax({
  241. url:'entrust/dataSure',
  242. data:{id:id}
  243. },function (data,ret) {
  244. //成功回调
  245. parent.Toastr.success("确认成功");
  246. Fast.api.close();
  247. parent.Fast.api.refreshmenu();
  248. return false;
  249. },function (data,ret) {
  250. parent.Toastr.error("确认失败");
  251. Fast.api.close();
  252. return false;
  253. });
  254. return false;
  255. })
  256. Controller.api.bindevent();
  257. },
  258. commissionsheet:function () {
  259. Controller.api.bindevent();
  260. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  261. Toastr.success("成功");
  262. }, function (data, ret) {
  263. Toastr.success("失败");
  264. }, function (success, error) {
  265. // 判断委托编号是否为空
  266. var entrust_id = $('#c-entrust_id').val();
  267. if (entrust_id == '' || entrust_id == undefined) {
  268. layer.confirm('委托编号不能为空');
  269. return false;
  270. }
  271. // 判断委托方是否为空
  272. var entrust_user = $('#c-entrust_user').val();
  273. if (entrust_user == '' || entrust_user == undefined) {
  274. layer.confirm('委托方不能为空');
  275. return false;
  276. }
  277. // 判断委托日期是否为空
  278. var entrust_time = $('#c-entrust_time').val();
  279. if (entrust_time == '' || entrust_time == undefined) {
  280. layer.confirm('委托日期不能为空');
  281. return false;
  282. }
  283. // 判断样品名称是否为空
  284. var name = $('#c-name').text();
  285. if (name == '' || name == undefined) {
  286. layer.confirm('样品名称不能为空');
  287. return false;
  288. }
  289. // 判断样品数量是否为空
  290. var num = $('#c-num').val();
  291. if (num == '' || num == undefined) {
  292. layer.confirm('样品数量不能为空');
  293. return false;
  294. }
  295. // 判断检测项目是否为空
  296. var project = $('#c-project').val();
  297. if (project == '' || project == undefined) {
  298. layer.confirm('检测项目不能为空');
  299. return false;
  300. }
  301. // 判断样品编号是否为空
  302. var no = $('#c-no').val();
  303. if (no == '' || no == undefined) {
  304. layer.confirm('样品编号不能为空');
  305. return false;
  306. }
  307. // 获取备注选中值
  308. var requirement = '';
  309. $("input[name='requirement']:checked").each(function(){
  310. requirement += $(this).val()+"、";
  311. });
  312. // 获取检后样品处理要求选中值
  313. var deal = '';
  314. $("input[name='deal']:checked").each(function(){
  315. deal += $(this).val()+"、";
  316. });
  317. // 获取样品保存条件选中值
  318. var condition = '';
  319. $("input[name='condition']:checked").each(function (){
  320. condition += $(this).val()+"、";
  321. });
  322. // 获取报告发放选中值
  323. var isue = '';
  324. $("input[name='isue']:checked").each(function (){
  325. isue += $(this).val()+"、";
  326. });
  327. // 获取检测依据标准选中值
  328. var standard = '';
  329. $("input[name='standard']:checked").each(function(){
  330. standard += $(this).val()+"、";
  331. });
  332. Fast.api.ajax({
  333. url: 'entrust/commissionsheetup',
  334. data: {
  335. entrust_user:entrust_user,
  336. entrust_time:entrust_time,
  337. entrust_id:entrust_id,
  338. name:name,
  339. num:num,
  340. project:project,
  341. no:no,
  342. status:$("input[name='status']:checked").val(),
  343. requirement:requirement,
  344. reportnumber:$('#c-reportnumber').val(),
  345. deal:deal,
  346. condition:condition,
  347. isue:isue,
  348. testcost:$('#c-testcost').val(),
  349. standard:standard
  350. },
  351. }, function (data, ret) {
  352. if (ret.code === 1){
  353. window.print();
  354. }
  355. parent.Toastr.success('添加成功');
  356. Fast.api.close();
  357. parent.Fast.api.refreshmenu();
  358. return false;
  359. }, function (data, ret) {
  360. parent.Toastr.error(ret.msg);
  361. Fast.api.close();
  362. parent.Fast.api.refreshmenu();
  363. return false;
  364. });
  365. return false;
  366. });
  367. },
  368. printing: function (){
  369. Controller.api.bindevent();
  370. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  371. Toastr.success("成功");
  372. }, function (data, ret) {
  373. Toastr.success("失败");
  374. }, function (success, error) {
  375. // 判断委托编号是否为空
  376. var entrust_id = $('#c-entrust_id').val();
  377. if (entrust_id == '' || entrust_id == undefined) {
  378. layer.confirm('委托编号不能为空');
  379. return false;
  380. }
  381. // 判断委托方是否为空
  382. var entrust_user = $('#c-entrust_user').val();
  383. if (entrust_user == '' || entrust_user == undefined) {
  384. layer.confirm('委托方不能为空');
  385. return false;
  386. }
  387. // 判断委托日期是否为空
  388. var entrust_time = $('#c-entrust_time').val();
  389. if (entrust_time == '' || entrust_time == undefined) {
  390. layer.confirm('委托日期不能为空');
  391. return false;
  392. }
  393. // 循环获取样品信息
  394. var sampledata = [];
  395. var samplelist = $('#tableprint').find("tr");//样品种数
  396. for (var i=4;i<samplelist.length-8;i++){
  397. var samdata = [];
  398. var name = $(samplelist).eq(i).find('#c-name').text();
  399. var status = $(samplelist).eq(i).find("input[name='status']:checked").val();
  400. var num = $(samplelist).eq(i).find('#c-num').val();
  401. if (num == '' || num == undefined) {
  402. layer.confirm('样品数量不能为空');
  403. return false;
  404. }
  405. var object = $(samplelist).eq(i).find('#c-project').val();
  406. var no = $(samplelist).eq(i).find('#c-no').val();
  407. samdata.push(name);
  408. samdata.push(status);
  409. samdata.push(num);
  410. samdata.push(object);
  411. samdata.push(no);
  412. sampledata.push(samdata);
  413. }
  414. console.log(sampledata);
  415. // 获取备注选中值
  416. var requirement = '';
  417. $("input[name='requirement']:checked").each(function(){
  418. requirement += $(this).val()+"、";
  419. });
  420. // 获取检后样品处理要求选中值
  421. var deal = '';
  422. $("input[name='deal']:checked").each(function(){
  423. deal += $(this).val()+"、";
  424. });
  425. // 获取样品保存条件选中值
  426. var condition = '';
  427. $("input[name='condition']:checked").each(function (){
  428. condition += $(this).val()+"、";
  429. });
  430. // 获取报告发放选中值
  431. var isue = '';
  432. $("input[name='isue']:checked").each(function (){
  433. isue += $(this).val()+"、";
  434. });
  435. // 获取检测依据标准选中值
  436. var standard = '';
  437. $("input[name='standard']:checked").each(function(){
  438. standard += $(this).val()+"、";
  439. });
  440. Fast.api.ajax({
  441. url: 'entrust/printingup',
  442. data: {
  443. entrust_user:entrust_user,
  444. entrust_time:entrust_time,
  445. entrust_id:entrust_id,
  446. sampledata:sampledata,
  447. requirement:requirement,
  448. reportnumber:$('#c-reportnumber').val(),
  449. deal:deal,
  450. condition:condition,
  451. isue:isue,
  452. testcost:$('#c-testcost').val(),
  453. standard:standard
  454. },
  455. }, function (data, ret) {
  456. if (ret.code === 1){
  457. window.print();
  458. }
  459. parent.Toastr.success('添加成功');
  460. Fast.api.close();
  461. parent.Fast.api.refreshmenu();
  462. return false;
  463. }, function (data, ret) {
  464. parent.Toastr.error(ret.msg);
  465. Fast.api.close();
  466. parent.Fast.api.refreshmenu();
  467. return false;
  468. });
  469. return false;
  470. });
  471. },
  472. api: {
  473. bindevent: function () {
  474. Form.api.bindevent($("form[role=form]"));
  475. }
  476. }
  477. };
  478. return Controller;
  479. });