entrust.js 24 KB

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