entrust.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. Controller.api.bindevent();
  199. },
  200. // submit:function () {
  201. // $('.submit').click(function () {
  202. // var temp = parseInt($('.mark').val());
  203. // var id = $('#id').val();
  204. // if (temp == 0 || temp == ''){
  205. // layer.confirm('请选择判定标准!');
  206. // return false;
  207. // }
  208. // if (id == 0 || id == ''){
  209. // layer.confirm('未获取到参数!');
  210. // return false;
  211. // }
  212. // Fast.api.ajax({
  213. // url:'entrust/submit',
  214. // data:{temp:temp,id:id}
  215. // },function (data,ret) {
  216. // //成功回调
  217. // parent.Toastr.success("提交成功");
  218. // Fast.api.close();
  219. // parent.Fast.api.refreshmenu();
  220. // return false;
  221. // },function (data,ret) {
  222. // parent.Toastr.error(ret.msg);
  223. // Fast.api.close();
  224. // return false;
  225. // });
  226. // return false;
  227. // });
  228. // Controller.api.bindevent();
  229. // },
  230. log:function () {
  231. // 初始化表格参数配置
  232. Table.api.init({
  233. extend: {
  234. index_url: 'entrust/log',
  235. }
  236. });
  237. var table = $("#table");
  238. var eid = $('#e_id').val();
  239. // 初始化表格
  240. table.bootstrapTable({
  241. url: 'entrust/log/ids/'+eid,
  242. // url: $.fn.bootstrapTable.defaults.extend.index_url,
  243. pk: 'id',
  244. sortName: 'id',
  245. columns: [
  246. [
  247. {checkbox: true},
  248. {field: 'id', title: '序号'},
  249. {field: 'username', title: __('username'), align: 'left'},
  250. {field: 'operate', title: __('operate'), align: 'left'},
  251. {field: 'content', title: __('content'), align: 'left'},
  252. {field: 'create', title: __('操作时间'), align: 'left'},
  253. ]
  254. ]
  255. });
  256. Controller.api.bindevent();
  257. },
  258. data:function () {
  259. $('.submit').click(function () {
  260. console.log(1111)
  261. var id = $('#id').val();
  262. if (id == 0 || id == ''){
  263. layer.confirm('未获取到参数!');
  264. return false;
  265. }
  266. Fast.api.ajax({
  267. url:'entrust/dataSure',
  268. data:{id:id}
  269. },function (data,ret) {
  270. //成功回调
  271. parent.Toastr.success("确认成功");
  272. Fast.api.close();
  273. parent.Fast.api.refreshmenu();
  274. return false;
  275. },function (data,ret) {
  276. parent.Toastr.error("确认失败");
  277. Fast.api.close();
  278. return false;
  279. });
  280. return false;
  281. })
  282. Controller.api.bindevent();
  283. },
  284. commissionsheet:function () {
  285. Controller.api.bindevent();
  286. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  287. Toastr.success("成功");
  288. }, function (data, ret) {
  289. Toastr.success("失败");
  290. }, function (success, error) {
  291. // 判断委托编号是否为空
  292. var entrust_id = $('#c-entrust_id').val();
  293. if (entrust_id == '' || entrust_id == undefined) {
  294. layer.confirm('委托编号不能为空');
  295. return false;
  296. }
  297. // 判断委托方是否为空
  298. var entrust_user = $('#c-entrust_user').val();
  299. if (entrust_user == '' || entrust_user == undefined) {
  300. layer.confirm('委托方不能为空');
  301. return false;
  302. }
  303. // 判断委托日期是否为空
  304. var entrust_time = $('#c-entrust_time').val();
  305. if (entrust_time == '' || entrust_time == undefined) {
  306. layer.confirm('委托日期不能为空');
  307. return false;
  308. }
  309. // 判断样品名称是否为空
  310. var name = $('#c-name').text();
  311. if (name == '' || name == undefined) {
  312. layer.confirm('样品名称不能为空');
  313. return false;
  314. }
  315. // 判断样品数量是否为空
  316. var num = $('#c-num').val();
  317. if (num == '' || num == undefined) {
  318. layer.confirm('样品数量不能为空');
  319. return false;
  320. }
  321. // 判断检测项目是否为空
  322. var project = $('#c-project').val();
  323. if (project == '' || project == undefined) {
  324. layer.confirm('检测项目不能为空');
  325. return false;
  326. }
  327. // 判断样品编号是否为空
  328. var no = $('#c-no').val();
  329. if (no == '' || no == undefined) {
  330. layer.confirm('样品编号不能为空');
  331. return false;
  332. }
  333. // 获取备注选中值
  334. var requirement = '';
  335. $("input[name='requirement']:checked").each(function(){
  336. requirement += $(this).val()+"、";
  337. });
  338. // 获取检后样品处理要求选中值
  339. var deal = '';
  340. $("input[name='deal']:checked").each(function(){
  341. deal += $(this).val()+"、";
  342. });
  343. // 获取样品保存条件选中值
  344. var condition = '';
  345. $("input[name='condition']:checked").each(function (){
  346. condition += $(this).val()+"、";
  347. });
  348. // 获取报告发放选中值
  349. var isue = '';
  350. $("input[name='isue']:checked").each(function (){
  351. isue += $(this).val()+"、";
  352. });
  353. // 获取检测依据标准选中值
  354. var standard = '';
  355. $("input[name='standard']:checked").each(function(){
  356. standard += $(this).val()+"、";
  357. });
  358. Fast.api.ajax({
  359. url: 'entrust/commissionsheetup',
  360. data: {
  361. entrust_user:entrust_user,
  362. entrust_time:entrust_time,
  363. entrust_id:entrust_id,
  364. name:name,
  365. num:num,
  366. project:project,
  367. no:no,
  368. status:$("input[name='status']:checked").val(),
  369. requirement:requirement,
  370. reportnumber:$('#c-reportnumber').val(),
  371. deal:deal,
  372. condition:condition,
  373. isue:isue,
  374. testcost:$('#c-testcost').val(),
  375. standard:standard
  376. },
  377. }, function (data, ret) {
  378. if (ret.code === 1){
  379. window.print();
  380. }
  381. parent.Toastr.success('添加成功');
  382. Fast.api.close();
  383. parent.Fast.api.refreshmenu();
  384. return false;
  385. }, function (data, ret) {
  386. parent.Toastr.error(ret.msg);
  387. Fast.api.close();
  388. parent.Fast.api.refreshmenu();
  389. return false;
  390. });
  391. return false;
  392. });
  393. },
  394. printing: function (){
  395. Controller.api.bindevent();
  396. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  397. Toastr.success("成功");
  398. }, function (data, ret) {
  399. Toastr.success("失败");
  400. }, function (success, error) {
  401. // 判断委托编号是否为空
  402. var entrust_id = $('#c-entrust_id').val();
  403. if (entrust_id == '' || entrust_id == undefined) {
  404. layer.confirm('委托编号不能为空');
  405. return false;
  406. }
  407. // 判断委托方是否为空
  408. var entrust_user = $('#c-entrust_user').val();
  409. if (entrust_user == '' || entrust_user == undefined) {
  410. layer.confirm('委托方不能为空');
  411. return false;
  412. }
  413. // 判断委托日期是否为空
  414. var entrust_time = $('#c-entrust_time').val();
  415. if (entrust_time == '' || entrust_time == undefined) {
  416. layer.confirm('委托日期不能为空');
  417. return false;
  418. }
  419. // 循环获取样品信息
  420. var sampledata = [];
  421. var samplelist = $('#tableprint').find("tr");//样品种数
  422. for (var i=4;i<samplelist.length-8;i++){
  423. var samdata = [];
  424. var name = $(samplelist).eq(i).find('#c-name').text();
  425. var status = $(samplelist).eq(i).find("input[name='status']:checked").val();
  426. var num = $(samplelist).eq(i).find('#c-num').val();
  427. if (num == '' || num == undefined) {
  428. layer.confirm('样品数量不能为空');
  429. return false;
  430. }
  431. var object = $(samplelist).eq(i).find('#c-project').val();
  432. var no = $(samplelist).eq(i).find('#c-no').val();
  433. samdata.push(name);
  434. samdata.push(status);
  435. samdata.push(num);
  436. samdata.push(object);
  437. samdata.push(no);
  438. sampledata.push(samdata);
  439. }
  440. console.log(sampledata);
  441. // 获取备注选中值
  442. var requirement = '';
  443. $("input[name='requirement']:checked").each(function(){
  444. requirement += $(this).val()+"、";
  445. });
  446. // 获取检后样品处理要求选中值
  447. var deal = '';
  448. $("input[name='deal']:checked").each(function(){
  449. deal += $(this).val()+"、";
  450. });
  451. // 获取样品保存条件选中值
  452. var condition = '';
  453. $("input[name='condition']:checked").each(function (){
  454. condition += $(this).val()+"、";
  455. });
  456. // 获取报告发放选中值
  457. var isue = '';
  458. $("input[name='isue']:checked").each(function (){
  459. isue += $(this).val()+"、";
  460. });
  461. // 获取检测依据标准选中值
  462. var standard = '';
  463. $("input[name='standard']:checked").each(function(){
  464. standard += $(this).val()+"、";
  465. });
  466. Fast.api.ajax({
  467. url: 'entrust/printingup',
  468. data: {
  469. entrust_user:entrust_user,
  470. entrust_time:entrust_time,
  471. entrust_id:entrust_id,
  472. sampledata:sampledata,
  473. requirement:requirement,
  474. reportnumber:$('#c-reportnumber').val(),
  475. deal:deal,
  476. condition:condition,
  477. isue:isue,
  478. testcost:$('#c-testcost').val(),
  479. standard:standard
  480. },
  481. }, function (data, ret) {
  482. if (ret.code === 1){
  483. window.print();
  484. }
  485. parent.Toastr.success('添加成功');
  486. Fast.api.close();
  487. parent.Fast.api.refreshmenu();
  488. return false;
  489. }, function (data, ret) {
  490. parent.Toastr.error(ret.msg);
  491. Fast.api.close();
  492. parent.Fast.api.refreshmenu();
  493. return false;
  494. });
  495. return false;
  496. });
  497. },
  498. api: {
  499. bindevent: function () {
  500. Form.api.bindevent($("form[role=form]"));
  501. }
  502. }
  503. };
  504. return Controller;
  505. });