entrust.js 23 KB

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