MachineApply_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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: 'OutBatchNo',
  235. width: 100,
  236. title: 'WIFI设备押金',
  237. sort: true
  238. }, {
  239. field: 'ExpressInfo',
  240. width: 200,
  241. title: '快递单号-快递名称',
  242. sort: true
  243. }, {
  244. field: 'Remark',
  245. width: 200,
  246. title: '订单备注',
  247. sort: true
  248. }, {
  249. title: '操作',
  250. width: 260,
  251. align: 'center',
  252. fixed: 'right',
  253. toolbar: '#table-list-tools'
  254. }]
  255. ],
  256. where: {
  257. },
  258. page: true,
  259. limit: 30,
  260. height: 'full-' + String($('.layui-card-header').height() + 130),
  261. text: '对不起,加载出现异常!',
  262. done: function (res, curr, count) {
  263. $("#ApplyCount").text(res.other.ApplyCount);
  264. $("#SendCount").text(res.other.SendCount);
  265. $(".layui-none").text("无数据");
  266. }
  267. });
  268. //监听工具条
  269. table.on('tool(LAY-list-manage)', function (obj) {
  270. var data = obj.data;
  271. if (obj.event === 'del') {
  272. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  273. $.ajax({
  274. type: "POST",
  275. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  276. data: "Id=" + data.Id,
  277. dataType: "text",
  278. success: function (data) {
  279. if (data == "success") {
  280. obj.del();
  281. layer.close(index);
  282. } else {
  283. parent.layer.msg(data);
  284. }
  285. }
  286. });
  287. });
  288. } else if (obj.event === 'cancel') {
  289. var index = layer.confirm('确定要取消订单吗?取消后不能恢复!', function (index) {
  290. $.ajax({
  291. type: "POST",
  292. url: "/Admin/MachineApply/Cancel?r=" + Math.random(1),
  293. data: "Id=" + data.Id,
  294. dataType: "text",
  295. success: function (data) {
  296. if (data == "success") {
  297. obj.del();
  298. layer.close(index);
  299. parent.layer.msg('已取消');
  300. } else {
  301. parent.layer.msg(data);
  302. }
  303. }
  304. });
  305. });
  306. } else if (obj.event === 'detail') {
  307. var tr = $(obj.tr);
  308. var perContent = layer.open({
  309. type: 2,
  310. title: '订单详情',
  311. content: 'Edit?Id=' + data.Id + '',
  312. maxmin: true,
  313. area: ['500px', '450px'],
  314. btn: ['返回'],
  315. yes: function (index, layero) {
  316. layer.close(perContent);
  317. },
  318. success: function (layero, index) {
  319. }
  320. });
  321. layer.full(perContent);
  322. } else if (obj.event === 'send') {
  323. var tr = $(obj.tr);
  324. var perContent = layer.open({
  325. type: 2,
  326. title: '审核发货',
  327. content: 'AuditSend?Id=' + data.Id + '',
  328. maxmin: true,
  329. area: ['450px', '680px'],
  330. btn: ['确定发货', '取消'],
  331. yes: function (index, layero) {
  332. var iframeWindow = window['layui-layer-iframe' + index],
  333. submitID = 'LAY-list-front-submit',
  334. submit = layero.find('iframe').contents().find('#' + submitID);
  335. setTimeout(function () {
  336. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  337. var errObj = $(this).find('.layui-form-danger');
  338. if (errObj.length > 0) {
  339. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  340. submit.click();
  341. }
  342. });
  343. }, 300);
  344. //监听提交
  345. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  346. var field = data.field; //获取提交的字段
  347. var userdata = "";
  348. for (var prop in field) {
  349. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  350. }
  351. //提交 Ajax 成功后,静态更新表格中的数据
  352. //$.ajax({});
  353. $.ajax({
  354. type: "POST",
  355. url: "/Admin/MachineApply/AuditSend?r=" + Math.random(1),
  356. data: userdata,
  357. dataType: "text",
  358. success: function (data) {
  359. if (data == "success") {
  360. layer.close(index); //关闭弹层
  361. layer.msg('发货成功', {
  362. time: 1500
  363. }, function () {
  364. table.reload('LAY-list-manage'); //数据刷新
  365. });
  366. } else {
  367. layer.msg(data);
  368. }
  369. }
  370. });
  371. });
  372. submit.trigger('click');
  373. },
  374. success: function (layero, index) {
  375. }
  376. });
  377. }
  378. });
  379. //监听搜索
  380. form.on('submit(LAY-list-front-search)', function (data) {
  381. var field = data.field;
  382. //执行重载
  383. table.reload('LAY-list-manage', {
  384. where: field,
  385. page: {
  386. curr: 1
  387. }
  388. });
  389. });
  390. form.on('submit(LAY-list-front-searchall)', function (data) {
  391. table.reload('LAY-list-manage', {
  392. where: null,
  393. page: {
  394. curr: 1
  395. }
  396. });
  397. });
  398. //事件
  399. var active = {
  400. batchdel: function () {
  401. var checkStatus = table.checkStatus('LAY-list-manage'),
  402. data = checkStatus.data; //得到选中的数据
  403. if (data.length < 1) {
  404. parent.layer.msg("请选择要删除的项");
  405. } else {
  406. var ids = "";
  407. $.each(data, function (index, value) {
  408. ids += data[index].Id + ",";
  409. });
  410. ids = ids.substring(0, ids.length - 1);
  411. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  412. $.ajax({
  413. type: "POST",
  414. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  415. data: "Id=" + ids,
  416. dataType: "text",
  417. success: function (data) {
  418. layer.close(index);
  419. if (data == "success") {
  420. table.reload('LAY-list-manage');
  421. } else {
  422. layer.msg(data);
  423. }
  424. }
  425. });
  426. });
  427. }
  428. },
  429. add: function () {
  430. var perContent = layer.open({
  431. type: 2,
  432. title: '机具申请订单-添加',
  433. content: 'Add',
  434. maxmin: true,
  435. area: ['500px', '450px'],
  436. btn: ['确定', '取消'],
  437. yes: function (index, layero) {
  438. var iframeWindow = window['layui-layer-iframe' + index],
  439. submitID = 'LAY-list-front-submit',
  440. submit = layero.find('iframe').contents().find('#' + submitID);
  441. setTimeout(function () {
  442. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  443. var errObj = $(this).find('.layui-form-danger');
  444. if (errObj.length > 0) {
  445. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  446. submit.click();
  447. }
  448. });
  449. }, 300);
  450. //监听提交
  451. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  452. var field = data.field; //获取提交的字段
  453. var userdata = "";
  454. for (var prop in field) {
  455. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  456. }
  457. //提交 Ajax 成功后,静态更新表格中的数据
  458. //$.ajax({});
  459. $.ajax({
  460. type: "POST",
  461. url: "/Admin/MachineApply/Add?r=" + Math.random(1),
  462. data: userdata,
  463. dataType: "text",
  464. success: function (data) {
  465. layer.close(index); //关闭弹层
  466. if (data == "success") {
  467. table.reload('LAY-list-manage'); //数据刷新
  468. } else {
  469. layer.msg(data);
  470. }
  471. }
  472. });
  473. });
  474. submit.trigger('click');
  475. }
  476. });
  477. layer.full(perContent);
  478. },
  479. ImportData: function () {
  480. layer.open({
  481. type: 1,
  482. title: '导入',
  483. maxmin: false,
  484. area: ['460px', '180px'],
  485. content: $('#excelForm'),
  486. cancel: function () {}
  487. });
  488. },
  489. ExportExcel: function () {
  490. var userdata = '';
  491. $(".layuiadmin-card-header-auto input").each(function (i) {
  492. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  493. });
  494. $(".layuiadmin-card-header-auto select").each(function (i) {
  495. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  496. });
  497. $.ajax({
  498. type: "GET",
  499. url: "/Admin/MachineApply/ExportExcel?r=" + Math.random(1),
  500. data: userdata,
  501. dataType: "json",
  502. success: function (data) {
  503. data.Obj.unshift(data.Fields);
  504. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  505. }
  506. });
  507. },
  508. Open: function () {
  509. var checkStatus = table.checkStatus('LAY-list-manage'),
  510. data = checkStatus.data; //得到选中的数据
  511. if (data.length < 1) {
  512. parent.layer.msg("请选择要开启的项");
  513. } else {
  514. var ids = "";
  515. $.each(data, function (index, value) {
  516. ids += data[index].Id + ",";
  517. });
  518. ids = ids.substring(0, ids.length - 1);
  519. var index = layer.confirm('确定要开启吗?', function (index) {
  520. $.ajax({
  521. type: "POST",
  522. url: "/Admin/MachineApply/Open?r=" + Math.random(1),
  523. data: "Id=" + ids,
  524. dataType: "text",
  525. success: function (data) {
  526. layer.close(index);
  527. if (data == "success") {
  528. table.reload('LAY-list-manage');
  529. } else {
  530. layer.msg(data);
  531. }
  532. }
  533. });
  534. });
  535. }
  536. },
  537. Close: function () {
  538. var checkStatus = table.checkStatus('LAY-list-manage'),
  539. data = checkStatus.data; //得到选中的数据
  540. if (data.length < 1) {
  541. parent.layer.msg("请选择要关闭的项");
  542. } else {
  543. var ids = "";
  544. $.each(data, function (index, value) {
  545. ids += data[index].Id + ",";
  546. });
  547. ids = ids.substring(0, ids.length - 1);
  548. var index = layer.confirm('确定要关闭吗?', function (index) {
  549. $.ajax({
  550. type: "POST",
  551. url: "/Admin/MachineApply/Close?r=" + Math.random(1),
  552. data: "Id=" + ids,
  553. dataType: "text",
  554. success: function (data) {
  555. layer.close(index);
  556. if (data == "success") {
  557. table.reload('LAY-list-manage');
  558. } else {
  559. layer.msg(data);
  560. }
  561. }
  562. });
  563. });
  564. }
  565. }
  566. };
  567. $('.layui-btn').on('click', function () {
  568. var type = $(this).data('type');
  569. active[type] ? active[type].call(this) : '';
  570. });
  571. });