MachineApply_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/MachineApply/Import?r=" + Math.random(1),
  6. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  7. dataType: "text",
  8. success: function (data) {
  9. if (data == "success") {
  10. layer.msg("导入成功", {
  11. time: 2000
  12. }, function () {
  13. window.location.reload();
  14. });
  15. } else {
  16. layer.msg(data);
  17. }
  18. }
  19. });
  20. }
  21. var excel;
  22. layui.config({
  23. base: '/layuiadmin/' //静态资源所在路径
  24. }).extend({
  25. myexcel: 'layui/lay/modules/excel',
  26. index: 'lib/index' //主入口模块
  27. }).use(['index', 'table', 'excel', 'laydate'], function () {
  28. var $ = layui.$,
  29. form = layui.form,
  30. table = layui.table;
  31. //- 筛选条件-日期
  32. var laydate = layui.laydate;
  33. var layCreateDate = laydate.render({
  34. elem: '#CreateDate',
  35. type: 'date',
  36. range: true,
  37. trigger: 'click',
  38. change: function (value, date, endDate) {
  39. var op = true;
  40. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  41. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  42. op = false;
  43. layCreateDate.hint('日期范围请不要超过1个月');
  44. setTimeout(function () {
  45. $(".laydate-btns-confirm").addClass("laydate-disabled");
  46. }, 1);
  47. }
  48. } else {
  49. op = false;
  50. layCreateDate.hint('日期范围请不要超过1个月');
  51. setTimeout(function () {
  52. $(".laydate-btns-confirm").addClass("laydate-disabled");
  53. }, 1);
  54. }
  55. if (op) {
  56. $('#CreateDate').val(value);
  57. }
  58. }
  59. });
  60. var layApplyTime = laydate.render({
  61. elem: '#ApplyTime',
  62. trigger: 'click',
  63. type: 'date',
  64. range: true,
  65. change: function (value, date, endDate) {
  66. var op = true;
  67. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  68. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  69. op = false;
  70. layApplyTime.hint('日期范围请不要超过1个月');
  71. setTimeout(function () {
  72. $(".laydate-btns-confirm").addClass("laydate-disabled");
  73. }, 1);
  74. }
  75. } else {
  76. op = false;
  77. layApplyTime.hint('日期范围请不要超过1个月');
  78. setTimeout(function () {
  79. $(".laydate-btns-confirm").addClass("laydate-disabled");
  80. }, 1);
  81. }
  82. if (op) {
  83. $('#ApplyTime').val(value);
  84. }
  85. }
  86. });
  87. var laySendDate = laydate.render({
  88. elem: '#SendDate',
  89. trigger: 'click',
  90. type: 'date',
  91. range: true,
  92. change: function (value, date, endDate) {
  93. var op = true;
  94. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  95. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  96. op = false;
  97. laySendDate.hint('日期范围请不要超过1个月');
  98. setTimeout(function () {
  99. $(".laydate-btns-confirm").addClass("laydate-disabled");
  100. }, 1);
  101. }
  102. } else {
  103. op = false;
  104. laySendDate.hint('日期范围请不要超过1个月');
  105. setTimeout(function () {
  106. $(".laydate-btns-confirm").addClass("laydate-disabled");
  107. }, 1);
  108. }
  109. if (op) {
  110. $('#SendDate').val(value);
  111. }
  112. }
  113. });
  114. //excel导入
  115. excel = layui.excel;
  116. $('#ExcelFile').change(function (e) {
  117. var files = e.target.files;
  118. excel.importExcel(files, {}, function (data) {
  119. ExcelData = data[0].sheet1;
  120. });
  121. });
  122. //监听单元格编辑
  123. table.on('edit(LAY-list-manage)', function (obj) {
  124. var value = obj.value //得到修改后的值
  125. ,
  126. data = obj.data //得到所在行所有键值
  127. ,
  128. field = obj.field; //得到字段
  129. if (field == "Sort") {
  130. $.ajax({
  131. type: "POST",
  132. url: "/Admin/MachineApply/Sort?r=" + Math.random(1),
  133. data: "Id=" + data.Id + "&Sort=" + value,
  134. dataType: "text",
  135. success: function (data) {}
  136. });
  137. }
  138. });
  139. //列表数据
  140. table.render({
  141. elem: '#LAY-list-manage',
  142. url: '/Admin/MachineApply/IndexData' //模拟接口
  143. ,
  144. cols: [
  145. [{
  146. type: 'checkbox',
  147. fixed: 'left'
  148. }, {
  149. field: 'ApplyNo',
  150. width: 200,
  151. title: '申请单号',
  152. sort: true
  153. }, {
  154. field: 'StoreInfo',
  155. width: 200,
  156. title: '发货仓库信息',
  157. sort: true
  158. }, {
  159. field: 'StoreContact',
  160. width: 200,
  161. title: '仓库联系人信息',
  162. sort: true
  163. }, {
  164. field: 'StoreUser',
  165. width: 200,
  166. title: '仓库归属信息',
  167. sort: true
  168. }, {
  169. field: 'UserInfo',
  170. width: 200,
  171. title: '创客信息',
  172. sort: true
  173. }, {
  174. field: 'TopUserInfo',
  175. width: 200,
  176. title: '顶级创客信息',
  177. sort: true
  178. }, {
  179. field: 'BrandId',
  180. width: 200,
  181. title: '产品名称',
  182. sort: true
  183. }, {
  184. field: 'Areas',
  185. width: 200,
  186. title: '收货地址',
  187. sort: true
  188. }, {
  189. field: 'Address',
  190. width: 200,
  191. title: '收货地址',
  192. sort: true
  193. }, {
  194. field: 'ReceiveInfo',
  195. width: 200,
  196. title: '收件人姓名-联系电话',
  197. sort: true
  198. }, {
  199. field: 'StatusName',
  200. width: 200,
  201. title: '订单状态',
  202. sort: true
  203. }, {
  204. field: 'ApplyDeviceName',
  205. width: 200,
  206. title: '申请机具名称',
  207. sort: true
  208. }, {
  209. field: 'ApplyDeviceNum',
  210. width: 200,
  211. title: '申请机具数量',
  212. sort: true
  213. }, {
  214. field: 'ApplyTime',
  215. width: 200,
  216. title: '申请时间',
  217. sort: true
  218. }, {
  219. field: 'SendDate',
  220. width: 200,
  221. title: '发货时间',
  222. sort: true
  223. }, {
  224. field: 'DeliveryType',
  225. width: 200,
  226. title: '提货类型',
  227. sort: true
  228. }, {
  229. field: 'SendStatus',
  230. width: 200,
  231. title: '发货状态',
  232. sort: true
  233. }, {
  234. field: 'ExpressInfo',
  235. width: 200,
  236. title: '快递单号-快递名称',
  237. sort: true
  238. }, {
  239. field: 'Remark',
  240. width: 200,
  241. title: '订单备注',
  242. sort: true
  243. }, {
  244. title: '操作',
  245. width: 260,
  246. align: 'center',
  247. fixed: 'right',
  248. toolbar: '#table-list-tools'
  249. }]
  250. ],
  251. where: {
  252. },
  253. page: true,
  254. limit: 30,
  255. height: 'full-' + String($('.layui-card-header').height() + 130),
  256. text: '对不起,加载出现异常!',
  257. done: function (res, curr, count) {
  258. $("#ApplyCount").text(res.other.ApplyCount);
  259. $("#SendCount").text(res.other.SendCount);
  260. $(".layui-none").text("无数据");
  261. }
  262. });
  263. //监听工具条
  264. table.on('tool(LAY-list-manage)', function (obj) {
  265. var data = obj.data;
  266. if (obj.event === 'del') {
  267. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  268. $.ajax({
  269. type: "POST",
  270. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  271. data: "Id=" + data.Id,
  272. dataType: "text",
  273. success: function (data) {
  274. if (data == "success") {
  275. obj.del();
  276. layer.close(index);
  277. } else {
  278. parent.layer.msg(data);
  279. }
  280. }
  281. });
  282. });
  283. } else if (obj.event === 'cancel') {
  284. var index = layer.confirm('确定要取消订单吗?取消后不能恢复!', function (index) {
  285. $.ajax({
  286. type: "POST",
  287. url: "/Admin/MachineApply/Cancel?r=" + Math.random(1),
  288. data: "Id=" + data.Id,
  289. dataType: "text",
  290. success: function (data) {
  291. if (data == "success") {
  292. obj.del();
  293. layer.close(index);
  294. parent.layer.msg('已取消');
  295. } else {
  296. parent.layer.msg(data);
  297. }
  298. }
  299. });
  300. });
  301. } else if (obj.event === 'detail') {
  302. var tr = $(obj.tr);
  303. var perContent = layer.open({
  304. type: 2,
  305. title: '订单详情',
  306. content: 'Edit?Id=' + data.Id + '',
  307. maxmin: true,
  308. area: ['500px', '450px'],
  309. btn: ['返回'],
  310. yes: function (index, layero) {
  311. layer.close(perContent);
  312. },
  313. success: function (layero, index) {
  314. }
  315. });
  316. layer.full(perContent);
  317. } else if (obj.event === 'send') {
  318. var tr = $(obj.tr);
  319. var perContent = layer.open({
  320. type: 2,
  321. title: '审核发货',
  322. content: 'AuditSend?Id=' + data.Id + '',
  323. maxmin: true,
  324. area: ['450px', '680px'],
  325. btn: ['确定发货', '取消'],
  326. yes: function (index, layero) {
  327. var iframeWindow = window['layui-layer-iframe' + index],
  328. submitID = 'LAY-list-front-submit',
  329. submit = layero.find('iframe').contents().find('#' + submitID);
  330. setTimeout(function () {
  331. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  332. var errObj = $(this).find('.layui-form-danger');
  333. if (errObj.length > 0) {
  334. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  335. submit.click();
  336. }
  337. });
  338. }, 300);
  339. //监听提交
  340. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  341. var field = data.field; //获取提交的字段
  342. var userdata = "";
  343. for (var prop in field) {
  344. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  345. }
  346. //提交 Ajax 成功后,静态更新表格中的数据
  347. //$.ajax({});
  348. $.ajax({
  349. type: "POST",
  350. url: "/Admin/MachineApply/AuditSend?r=" + Math.random(1),
  351. data: userdata,
  352. dataType: "text",
  353. success: function (data) {
  354. if (data == "success") {
  355. layer.close(index); //关闭弹层
  356. layer.msg('发货成功', {
  357. time: 1500
  358. }, function () {
  359. table.reload('LAY-list-manage'); //数据刷新
  360. });
  361. } else {
  362. layer.msg(data);
  363. }
  364. }
  365. });
  366. });
  367. submit.trigger('click');
  368. },
  369. success: function (layero, index) {
  370. }
  371. });
  372. }
  373. });
  374. //监听搜索
  375. form.on('submit(LAY-list-front-search)', function (data) {
  376. var field = data.field;
  377. //执行重载
  378. table.reload('LAY-list-manage', {
  379. where: field,
  380. page: {
  381. curr: 1
  382. }
  383. });
  384. });
  385. form.on('submit(LAY-list-front-searchall)', function (data) {
  386. table.reload('LAY-list-manage', {
  387. where: null,
  388. page: {
  389. curr: 1
  390. }
  391. });
  392. });
  393. //事件
  394. var active = {
  395. batchdel: function () {
  396. var checkStatus = table.checkStatus('LAY-list-manage'),
  397. data = checkStatus.data; //得到选中的数据
  398. if (data.length < 1) {
  399. parent.layer.msg("请选择要删除的项");
  400. } else {
  401. var ids = "";
  402. $.each(data, function (index, value) {
  403. ids += data[index].Id + ",";
  404. });
  405. ids = ids.substring(0, ids.length - 1);
  406. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  407. $.ajax({
  408. type: "POST",
  409. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  410. data: "Id=" + ids,
  411. dataType: "text",
  412. success: function (data) {
  413. layer.close(index);
  414. if (data == "success") {
  415. table.reload('LAY-list-manage');
  416. } else {
  417. layer.msg(data);
  418. }
  419. }
  420. });
  421. });
  422. }
  423. },
  424. add: function () {
  425. var perContent = layer.open({
  426. type: 2,
  427. title: '机具申请订单-添加',
  428. content: 'Add',
  429. maxmin: true,
  430. area: ['500px', '450px'],
  431. btn: ['确定', '取消'],
  432. yes: function (index, layero) {
  433. var iframeWindow = window['layui-layer-iframe' + index],
  434. submitID = 'LAY-list-front-submit',
  435. submit = layero.find('iframe').contents().find('#' + submitID);
  436. setTimeout(function () {
  437. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  438. var errObj = $(this).find('.layui-form-danger');
  439. if (errObj.length > 0) {
  440. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  441. submit.click();
  442. }
  443. });
  444. }, 300);
  445. //监听提交
  446. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  447. var field = data.field; //获取提交的字段
  448. var userdata = "";
  449. for (var prop in field) {
  450. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  451. }
  452. //提交 Ajax 成功后,静态更新表格中的数据
  453. //$.ajax({});
  454. $.ajax({
  455. type: "POST",
  456. url: "/Admin/MachineApply/Add?r=" + Math.random(1),
  457. data: userdata,
  458. dataType: "text",
  459. success: function (data) {
  460. layer.close(index); //关闭弹层
  461. if (data == "success") {
  462. table.reload('LAY-list-manage'); //数据刷新
  463. } else {
  464. layer.msg(data);
  465. }
  466. }
  467. });
  468. });
  469. submit.trigger('click');
  470. }
  471. });
  472. layer.full(perContent);
  473. },
  474. ImportData: function () {
  475. layer.open({
  476. type: 1,
  477. title: '导入',
  478. maxmin: false,
  479. area: ['460px', '180px'],
  480. content: $('#excelForm'),
  481. cancel: function () {}
  482. });
  483. },
  484. ExportExcel: function () {
  485. var userdata = '';
  486. $(".layuiadmin-card-header-auto input").each(function (i) {
  487. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  488. });
  489. $(".layuiadmin-card-header-auto select").each(function (i) {
  490. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  491. });
  492. $.ajax({
  493. type: "GET",
  494. url: "/Admin/MachineApply/ExportExcel?r=" + Math.random(1),
  495. data: userdata,
  496. dataType: "json",
  497. success: function (data) {
  498. data.Obj.unshift(data.Fields);
  499. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  500. }
  501. });
  502. },
  503. Open: function () {
  504. var checkStatus = table.checkStatus('LAY-list-manage'),
  505. data = checkStatus.data; //得到选中的数据
  506. if (data.length < 1) {
  507. parent.layer.msg("请选择要开启的项");
  508. } else {
  509. var ids = "";
  510. $.each(data, function (index, value) {
  511. ids += data[index].Id + ",";
  512. });
  513. ids = ids.substring(0, ids.length - 1);
  514. var index = layer.confirm('确定要开启吗?', function (index) {
  515. $.ajax({
  516. type: "POST",
  517. url: "/Admin/MachineApply/Open?r=" + Math.random(1),
  518. data: "Id=" + ids,
  519. dataType: "text",
  520. success: function (data) {
  521. layer.close(index);
  522. if (data == "success") {
  523. table.reload('LAY-list-manage');
  524. } else {
  525. layer.msg(data);
  526. }
  527. }
  528. });
  529. });
  530. }
  531. },
  532. Close: function () {
  533. var checkStatus = table.checkStatus('LAY-list-manage'),
  534. data = checkStatus.data; //得到选中的数据
  535. if (data.length < 1) {
  536. parent.layer.msg("请选择要关闭的项");
  537. } else {
  538. var ids = "";
  539. $.each(data, function (index, value) {
  540. ids += data[index].Id + ",";
  541. });
  542. ids = ids.substring(0, ids.length - 1);
  543. var index = layer.confirm('确定要关闭吗?', function (index) {
  544. $.ajax({
  545. type: "POST",
  546. url: "/Admin/MachineApply/Close?r=" + Math.random(1),
  547. data: "Id=" + ids,
  548. dataType: "text",
  549. success: function (data) {
  550. layer.close(index);
  551. if (data == "success") {
  552. table.reload('LAY-list-manage');
  553. } else {
  554. layer.msg(data);
  555. }
  556. }
  557. });
  558. });
  559. }
  560. }
  561. };
  562. $('.layui-btn').on('click', function () {
  563. var type = $(this).data('type');
  564. active[type] ? active[type].call(this) : '';
  565. });
  566. });