entrust.js 23 KB

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