entrust.js 23 KB

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