Brak opisu

deliveryOrder.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /**
  2. * 配送工单
  3. * */
  4. var stateVal = ''; //0-当天;1-本周;2-本月;3-本年;4-累计
  5. $(function() {
  6. //项目下拉
  7. helper.getDropList.getProlistDrop($('#sc_pro'));
  8. laydate.render({
  9. elem: '#sc_times',
  10. range: '~',
  11. theme: '#249fea',
  12. });
  13. initTable();
  14. //搜索
  15. $("#sc_btns").click(function() {
  16. initTable();
  17. });
  18. $('#sc_statebtn').find('input[type="radio"]').on('change', function() {
  19. stateVal = $(this).val();
  20. initTable();
  21. });
  22. });
  23. function initTable() {
  24. //先销毁表格
  25. $('#table_all').bootstrapTable('destroy');
  26. //初始化表格,动态从服务器加载数据
  27. $('#table_all').bootstrapTable({
  28. method: "get", //使用get请求到服务器获取数据
  29. url: huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/getlistbypage", //获取数据的Servlet地址
  30. contentType: "application/x-www-form-urlencoded",
  31. striped: true, //表格显示条纹
  32. pagination: true, //启动分页
  33. pageSize: 10, //每页显示的记录数
  34. pageNumber: 1, //当前第几页
  35. pageList: [10, 20, 50, 100], //记录数可选列表
  36. search: false, //是否启用查询
  37. showColumns: false, //显示下拉框勾选要显示的列
  38. showRefresh: false, //显示刷新按钮
  39. sidePagination: "server", //表示服务端请求
  40. //设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
  41. //设置为limit可以获取limit, offset, search, sort, order
  42. queryParamsType: "undefined",
  43. queryParams: function queryParams(params) { //设置查询参数
  44. var param = {
  45. pageindex: params.pageNumber, //否 int 页码
  46. pagesize: params.pageSize, //否 int 条数
  47. projectid: $('#sc_pro').val(), // 否 string 项目id
  48. keyword: $('#sc_key').val(), // 否 string 模糊查询
  49. wosorts: $('#sc_wosorts').val(), // 否 int 工单分类(1随机工单,2计划工单,-1所有 )
  50. wostate: $('#sc_wostate').val(), // 否 int 配送工单状态:0创建工单,1转派或者接收(待取货),2已取货(配送中),3货物异常(异常),4已完结/待评价,5已取消,6挂起 ,9已评价 -1所有
  51. stime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[0], // 否 string 开始时间,“2018-03-27”
  52. etime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[1], // 否 string 结束时间,“2018-03-27”
  53. datetype: stateVal, // 否 int 0-当天;1-本周;2-本月;3-本年;4-累计
  54. };
  55. return param;
  56. },
  57. responseHandler: function(res) {
  58. return {
  59. "total": res.data && res.data.total, //总页数
  60. "rows": res.data && res.data.rows,
  61. }
  62. },
  63. onLoadSuccess: function() { //加载成功时执行
  64. //layer.msg("加载成功");
  65. $('.tool_down').authorizeOperateButton();
  66. },
  67. onLoadError: function() { //加载失败时执行
  68. //layer.msg("加载数据失败", { time: 1500, icon: 2 });
  69. }
  70. });
  71. }
  72. //格式化 操作
  73. function formatterOperate(val, row) {
  74. //int 0新工单,1转派或者接收(待取货),2已取货(配送中),3货物异常(异常) 4已完结/待评价,5已取消,6挂起 ,9已评价
  75. var str = '<div class="task_tools" onclick = helper.methods.taskTools(this)>' +
  76. '<a title="操作"><i class="fa fa-cogs" aria-hidden="true"></i></a>' +
  77. '<ul class="tool_down">' +
  78. '<li><a class="aBtn" authorize="yes" id="HY_details_' + row.id + '" onclick="btn_details(\'' + row.id +
  79. '\')"><i class="fa icon-detail tub"></i>详情</a><li>';
  80. if (row.wostate === 0) {
  81. str += '<li><a class="aBtn" authorize="yes" id="HY_edit_' + row.id + '" onclick="btn_edit(\'' + row.id +
  82. '\')"><i class="fa icon-edit tub"></i>编辑</a><li>' +
  83. '<li><a class="aBtn" authorize="yes" id="HY_transfer_' + row.id + '" onclick="btn_transfer(\'' + row.id + ',' + row.projectid +
  84. ',' + row.wocode + '\')"><i class="fa icon-transfer tub"></i>转派</a><li>';
  85. }
  86. if (row.wostate < 2) {
  87. str += '<li><a class="aBtn" authorize="yes" id="HY_cancel_' + row.id + '" onclick="btn_cancel(\'' + row.id +
  88. '\')"><i class="fa icon-lixian1 tub"></i>取消</a><li>' +
  89. '<li><a class="aBtn" authorize="yes" id="HY_hangup_' + row.id + '" onclick="btn_hangup(\'' + row.id +
  90. '\')"><i class="fa icon-manglu tub"></i>挂起</a><li>';
  91. }
  92. if (row.wostate === 4 && row.sended === 0) {
  93. str += '<li><a class="aBtn" authorize="yes" id="HY_evaluate_' + row.id + '" onclick="btn_evaluate(\'' + row.id +
  94. '\', \'' + row.wocode + '\')"><i class="fa icon-zan tub"></i>评价</a><li>';
  95. }
  96. if(row.isoffence === 1 && row.content_offence != '' && row.isaudit_offence <= 0){
  97. str += '<li><a class="aBtn" authorize="yes" id="HY_audit_' + row.id + '" onclick="btn_audit(\'' + row.id + '\',\''+ row.content_offence +'\')"><i class="fa icon-msnui-audit tub"></i>审核</a><li>';
  98. }
  99. str += '<li><a class="aBtn" authorize="yes" id="HY_delete_' + row.id + '" onclick="btn_delete(\'' + row.id +
  100. '\')"><i class="fa icon-delete tub"></i>删除</a><li>' +
  101. '</ul></div>'
  102. return str;
  103. }
  104. //格式化 工单状态
  105. function formatterwostate(val, row) {
  106. //int 0新工单,1转派或者接收(待取货),2已取货(配送中),3货物异常(异常) 4已完结/待评价,5已取消,6挂起 ,9已评价
  107. var stateClass, stateName;
  108. switch (val) {
  109. case 0:
  110. stateClass = 'state_audit_wait';
  111. stateName = '新工单';
  112. break;
  113. case 1:
  114. stateClass = 'state_audit_refuse';
  115. stateName = '待取货';
  116. break;
  117. case 2:
  118. stateClass = 'state_audit_doned';
  119. stateName = '配送中';
  120. break;
  121. case 3:
  122. stateClass = 'state_audit_refuse';
  123. stateName = '货物异常';
  124. break;
  125. case 4:
  126. if (row.sended === 1) {
  127. stateClass = 'state_audit_termination';
  128. stateName = '异常完结';
  129. } else {
  130. stateClass = 'state_audit_done';
  131. stateName = '已完结';
  132. }
  133. break;
  134. case 5:
  135. stateClass = 'state_audit_revoke';
  136. stateName = '已取消';
  137. break;
  138. case 6:
  139. stateClass = 'state_audit_hang';
  140. stateName = '已挂起';
  141. break;
  142. case 9:
  143. stateClass = 'state_audit_other';
  144. stateName = '已评价';
  145. break;
  146. default:
  147. stateClass = 'text-block';
  148. stateName = '-';
  149. break;
  150. }
  151. return '<a class="state_audit ' + stateClass + '" href="javascript:;">' + stateName + '</a>';
  152. }
  153. //格式化 工单类型
  154. function formatterwosorts(val, row) {
  155. var stateTxt = '-';
  156. switch (val) {
  157. case 1:
  158. stateTxt = '随机';
  159. break;
  160. case 2:
  161. stateTxt = '分送';
  162. break;
  163. default:
  164. break;
  165. }
  166. return '<span>' + stateTxt + '</span>';
  167. }
  168. //格式化 紧急程度
  169. function formatterEmergencyid(val, row) {
  170. var stateClass = 'timeout_default';
  171. var stateTxt = '-';
  172. switch (val) {
  173. case 1:
  174. stateClass = 'timeout_success';
  175. stateTxt = '一般';
  176. break;
  177. case 2:
  178. stateClass = 'timeout_termination';
  179. stateTxt = '紧急';
  180. break;
  181. default:
  182. break;
  183. }
  184. return '<span class="' + stateClass + '">' + stateTxt + '</span>';
  185. }
  186. //格式化 工单编号
  187. function formatterWocode(val, row) {
  188. var str = '-';
  189. var etext = '';
  190. if (row.isoffence === 1) {
  191. etext = '违规';
  192. //isaudit_offence int 违规是否审核通过 0无操作 1不通过 2通过
  193. if (row.content_offence != '' && row.isaudit_offence <= 0) {
  194. etext = '违规(已申诉)'; //需要审核
  195. }
  196. if (row.content_offence != '' && row.isaudit_offence === 1) {
  197. etext = '违规(未通过)'; //已审核 未通过
  198. }
  199. }
  200. // if (row.sended === 1) {
  201. // etext = '异常';
  202. // }
  203. str = '<span class="deliver_wocode">' + val +
  204. '<b>' + etext + '</b>' +
  205. '</span>';
  206. return str;
  207. }
  208. //格式化 物品名称
  209. function formatterGoodslist(val, row) {
  210. if (val && val.length > 1) {
  211. return val[0].goodsname + '(' + val[0].num + ')...';
  212. } else if (val && val.length === 1 && val[0] != "") {
  213. return val[0].goodsname + '(' + val[0].num + ')';
  214. } else {
  215. return '-';
  216. }
  217. }
  218. //格式化 内容
  219. function formatterContent(val, row) {
  220. if (val) {
  221. var codeContent = decodeURIComponent(val);
  222. codeContent = helper.filter.delHtmlTag(codeContent);
  223. codeContent = $.trim(codeContent);
  224. var cc = codeContent.length > 20 ? codeContent.substr(0, 20) + '...' : codeContent;
  225. return '<div title="' + codeContent + '">' + cc + '</div>';
  226. } else {
  227. return '-';
  228. }
  229. }
  230. //格式化 地址
  231. function formatterAddress(val, row) {
  232. if (val && val.length > 0) {
  233. return val[0].building_name + val[0].floor_name + val[0].department_name;
  234. } else {
  235. return '-';
  236. }
  237. }
  238. //格式化 渠道来源
  239. function formatterChannel(val, row) {
  240. //1表示PC 2表示安卓 3表示IOS 4表示微信
  241. var str = '-';
  242. switch (val) {
  243. case 1:
  244. str = 'PC';
  245. break;
  246. case 2:
  247. str = '安卓';
  248. break;
  249. case 3:
  250. str = 'IOS';
  251. break;
  252. case 4:
  253. str = '微信';
  254. break;
  255. default:
  256. break;
  257. }
  258. return str;
  259. }
  260. //格式化 时间
  261. function formatterCheckTime(val) {
  262. if (val == "0001-01-01 00:00:00" || val == "" || val == null || val == undefined) {
  263. return "-";
  264. } else {
  265. return val;
  266. }
  267. }
  268. //格式化创建人
  269. function formatterName(val, row){
  270. var str = '';
  271. if(row.channel === 4){
  272. str = row.createname;
  273. }else{
  274. str = val + '-' + row.createname;
  275. }
  276. return str;
  277. }
  278. //查看 详情
  279. function btn_details(edit_id) {
  280. layer.open({
  281. type: 2,
  282. content: "template/seeDeliveryOrderDetails.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
  283. title: '查看配送工单',
  284. resize: false,
  285. area: ['80%', '90%'], //宽高
  286. });
  287. }
  288. //取消
  289. function btn_cancel(edit_id) {
  290. layer.confirm('您确定要将当前配送工单取消吗?', {
  291. icon: 7,
  292. btn: ['确定', '取消'] //按钮
  293. }, function() {
  294. $.ajax({
  295. type: "post",
  296. url: huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/cancel",
  297. dataType: 'json',
  298. data: {
  299. id: edit_id, // 是 string 配送工单id
  300. channel: 1 // 是 int 渠道来源 1表示PC 2表示安卓 3表示IOS 4表示微信 默认1
  301. },
  302. async: true,
  303. success: function(data) {
  304. layer.msg("取消成功!");
  305. $('#table_all').bootstrapTable('refresh');
  306. }
  307. });
  308. });
  309. }
  310. //挂起
  311. function btn_hangup(edit_id) {
  312. layer.confirm('您确定要将当前配送工单挂起吗?', {
  313. icon: 7,
  314. btn: ['确定', '取消'] //按钮
  315. }, function() {
  316. $.ajax({
  317. type: "post",
  318. url: huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/hangup",
  319. dataType: 'json',
  320. data: {
  321. id: edit_id, // 是 string 配送工单id
  322. channel: 1 // 是 int 渠道来源 1表示PC 2表示安卓 3表示IOS 4表示微信 默认1
  323. },
  324. async: true,
  325. success: function(data) {
  326. layer.msg("挂起成功!");
  327. $('#table_all').bootstrapTable('refresh');
  328. }
  329. });
  330. });
  331. }
  332. //评价
  333. function btn_evaluate(edit_id, code) {
  334. layer.open({
  335. type: 2,
  336. content: "template/evaluateDeliveryOrder.html?edit_id=" + edit_id + "&code=" + code, //iframe的url,no代表不显示滚动条
  337. title: '评价配送工单',
  338. resize: false,
  339. area: ['80%', '90%'], //宽高
  340. });
  341. }
  342. //添加
  343. function btn_add() {
  344. isEvaluation().then(function(res) {
  345. if (res.state.toLowerCase() === "success") {
  346. layer.open({
  347. type: 2,
  348. content: "template/addOrEditDeliveryOrder.html", //iframe的url,no代表不显示滚动条
  349. title: '添加配送工单',
  350. resize: false,
  351. area: ['80%', '90%'], //宽高
  352. });
  353. }
  354. });
  355. }
  356. //编辑
  357. function btn_edit(edit_id) {
  358. layer.open({
  359. type: 2,
  360. content: "template/addOrEditDeliveryOrder.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
  361. title: '编辑配送工单',
  362. resize: false,
  363. area: ['80%', '90%'], //宽高
  364. });
  365. }
  366. //批量删除
  367. function btn_deletes() {
  368. var ids = $.map($('#table_all').bootstrapTable('getSelections'),
  369. function(row) {
  370. return row.id;
  371. });
  372. /*判断长度*/
  373. if (ids.length <= 0) {
  374. layer.confirm('请选择要删除的选项', {
  375. icon: 7,
  376. btn: ['确定'] //按钮
  377. });
  378. return;
  379. }
  380. btn_delete(ids);
  381. }
  382. //删除
  383. function btn_delete(del_id) {
  384. /*发送请求*/
  385. layer.confirm('您确定要删除当前配送工单吗?', {
  386. icon: 7,
  387. btn: ['确定', '取消'],
  388. yes: function(index, layero) {
  389. $.post(huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/delete", {
  390. ids: del_id,
  391. channel: 1,
  392. }, function(result) {
  393. result = JSON.parse(result);
  394. if (result.state.toLowerCase() == "success") {
  395. layer.msg("删除成功");
  396. $('#table_all').bootstrapTable('refresh');
  397. }
  398. })
  399. },
  400. });
  401. }
  402. //是否有未完成的评价
  403. function isEvaluation() {
  404. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  405. $.post(huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/isevaluation", {}, function(result) {
  406. result = JSON.parse(result);
  407. dtd.resolve(result); // 改变Deferred对象的执行状态
  408. });
  409. return dtd.promise(); // 返回promise对象
  410. }
  411. //批量转派
  412. function btn_transfers() {
  413. var wostates = $.map($('#table_all').bootstrapTable('getSelections'),
  414. function(row) {
  415. return row.wostate;
  416. });
  417. if (wostates.length <= 0) {
  418. layer.confirm('请选择要转派的工单', {
  419. icon: 7,
  420. btn: ['确定'] //按钮
  421. });
  422. return;
  423. }
  424. if (wostates.length >= 100) {
  425. layer.confirm('批量转派一次最多转派100个工单。', {
  426. icon: 7,
  427. btn: ['确定'] //按钮
  428. });
  429. return;
  430. }
  431. for (var i = 0; i < wostates.length; i++) {
  432. if (wostates[i] != 0) {
  433. console.count();
  434. layer.confirm('请确认您选择的工单是否是新工单,只有新工单可以转派!', {
  435. icon: 7,
  436. btn: ['确定'] //按钮
  437. });
  438. return;
  439. }
  440. }
  441. var ids = $.map($('#table_all').bootstrapTable('getSelections'),
  442. function(row) {
  443. return row.id + ',' + row.projectid + '|';
  444. });
  445. btn_transfer(ids);
  446. }
  447. //转派
  448. function btn_transfer(edit_id) {
  449. layer.open({
  450. type: 2,
  451. content: "template/transferDeliveryOrder.html?edit_id=" + encodeURIComponent(edit_id), //iframe的url,no代表不显示滚动条
  452. title: '转派配送工单',
  453. resize: false,
  454. area: ['50%', '60%'], //宽高
  455. });
  456. }
  457. //审核违规申诉
  458. function btn_audit(ids, content_offence) {
  459. var IsAudit = 1; //1不通过 2通过 默认不通过1
  460. layer.confirm('违规原因:<br/>' + content_offence, {
  461. title: '是否通过审核?',
  462. btn: ['通过', '拒绝'],
  463. }, function(index, layero) {
  464. //通过
  465. var value = '';
  466. IsAudit = 2;
  467. auditProject(ids, IsAudit, value);
  468. }, function(index) {
  469. //拒绝
  470. IsAudit = 1;
  471. layer.prompt({
  472. formType: 2,
  473. //value: '初始值',
  474. title: '请输入拒绝的原因',
  475. area: ['600px', '200px'] //自定义文本域宽高
  476. }, function(value, index, elem) {
  477. auditProject(ids, IsAudit, value);
  478. layer.close(index);
  479. });
  480. });
  481. }
  482. //审核
  483. function auditProject(ids, IsAudit, IsAuditNote) {
  484. $.post(huayi.config.callcenter_url + "distributionapi/api/DistriWorkOrder/auditoffence", {
  485. id: ids, // 是 string 配送工单id
  486. isaudit: IsAudit, // 是 int 是否审核通过 1不通过 2通过 默认不通过1
  487. content: IsAuditNote, // 是 string 驳回原因
  488. channel: 1, // 是 int 渠道来源 1表示PC 2表示安卓 3表示IOS 4表示微信 默认1
  489. }, function(data) {
  490. data = JSON.parse(data);
  491. if (data.state.toLowerCase() === "success") {
  492. $('#table_all').bootstrapTable('refresh');
  493. layer.msg("审核成功");
  494. }
  495. });
  496. }