entrust.js 23 KB

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