StoreMachineApply_Admin.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/StoreMachineApply/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/StoreMachineApply/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/StoreMachineApply/IndexData' //模拟接口
  143. ,
  144. cols: [[
  145. {type: 'checkbox',fixed: 'left'},
  146. {field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true },
  147. {field: 'ApplyNo',width: 200,title: '申请单号',sort: true},
  148. {field: 'BrandId', width: 200,title: '产品名称',sort: true},
  149. {field: 'UserInfo',width: 200,title: '创客信息',sort: true},
  150. {field: 'StoreInfo',width: 200,title: '申请仓库信息',sort: true},
  151. {field: 'StoreAddressInfo',width: 300,title: '仓库收货地址',sort: true},
  152. // {field: 'StoreContact',width: 200,title: '仓库联系人信息',sort: true},
  153. // {field: 'StoreUser',width: 200,title: '仓库归属信息',sort: true},
  154. {field: 'Status',width: 200,title: '申请状态',sort: true},
  155. {field: 'ApplyTime',width: 200,title: '申请时间',sort: true},
  156. {title: '操作', width: 260,align: 'center',fixed: 'right',toolbar: '#table-list-tools'}
  157. ]],
  158. where: {
  159. },
  160. page: true,
  161. limit: 30,
  162. height: 'full-' + String($('.layui-card-header').height() + 130),
  163. text: '对不起,加载出现异常!',
  164. done: function (res, curr, count) {
  165. $("#ApplyCount").text(res.other.ApplyCount);
  166. $("#SendCount").text(res.other.SendCount);
  167. $(".layui-none").text("无数据");
  168. }
  169. });
  170. //监听工具条
  171. table.on('tool(LAY-list-manage)', function (obj) {
  172. var data = obj.data;
  173. if (obj.event === 'del') {
  174. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  175. $.ajax({
  176. type: "POST",
  177. url: "/Admin/StoreMachineApply/Delete?r=" + Math.random(1),
  178. data: "Id=" + data.Id,
  179. dataType: "text",
  180. success: function (data) {
  181. if (data == "success") {
  182. obj.del();
  183. layer.close(index);
  184. } else {
  185. parent.layer.msg(data);
  186. }
  187. }
  188. });
  189. });
  190. } else if (obj.event === 'cancel') {
  191. var index = layer.confirm('确定要取消订单吗?取消后不能恢复!', function (index) {
  192. $.ajax({
  193. type: "POST",
  194. url: "/Admin/StoreMachineApply/Cancel?r=" + Math.random(1),
  195. data: "Id=" + data.Id,
  196. dataType: "text",
  197. success: function (data) {
  198. if (data == "success") {
  199. obj.del();
  200. layer.close(index);
  201. parent.layer.msg('已取消');
  202. } else {
  203. parent.layer.msg(data);
  204. }
  205. }
  206. });
  207. });
  208. } else if (obj.event === 'detail') {
  209. var tr = $(obj.tr);
  210. var perContent = layer.open({
  211. type: 2,
  212. title: '订单详情',
  213. content: 'Edit?Id=' + data.Id + '',
  214. maxmin: true,
  215. area: ['500px', '450px'],
  216. btn: ['返回'],
  217. yes: function (index, layero) {
  218. layer.close(perContent);
  219. },
  220. success: function (layero, index) {
  221. }
  222. });
  223. layer.full(perContent);
  224. } else if (obj.event === 'send') {
  225. var tr = $(obj.tr);
  226. var perContent = layer.open({
  227. type: 2,
  228. title: '审核发货',
  229. content: 'AuditSend?Id=' + data.Id + '',
  230. maxmin: true,
  231. area: ['450px', '680px'],
  232. btn: ['确定发货', '取消'],
  233. yes: function (index, layero) {
  234. var iframeWindow = window['layui-layer-iframe' + index],
  235. submitID = 'LAY-list-front-submit',
  236. submit = layero.find('iframe').contents().find('#' + submitID);
  237. setTimeout(function () {
  238. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  239. var errObj = $(this).find('.layui-form-danger');
  240. if (errObj.length > 0) {
  241. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  242. submit.click();
  243. }
  244. });
  245. }, 300);
  246. //监听提交
  247. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  248. var field = data.field; //获取提交的字段
  249. var userdata = "";
  250. for (var prop in field) {
  251. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  252. }
  253. //提交 Ajax 成功后,静态更新表格中的数据
  254. //$.ajax({});
  255. $.ajax({
  256. type: "POST",
  257. url: "/Admin/StoreMachineApply/AuditSend?r=" + Math.random(1),
  258. data: userdata,
  259. dataType: "text",
  260. success: function (data) {
  261. if (data == "success") {
  262. layer.close(index); //关闭弹层
  263. layer.msg('发货成功', {
  264. time: 1500
  265. }, function () {
  266. table.reload('LAY-list-manage'); //数据刷新
  267. });
  268. } else {
  269. layer.close(index); //关闭弹层
  270. layer.msg('审核完成', {
  271. time: 1500
  272. }, function () {
  273. table.reload('LAY-list-manage'); //数据刷新
  274. });
  275. }
  276. }
  277. });
  278. });
  279. submit.trigger('click');
  280. },
  281. success: function (layero, index) {
  282. }
  283. });
  284. }else if (obj.event === 'edit') {
  285. var tr = $(obj.tr);
  286. var perContent = layer.open({
  287. type: 2,
  288. title: '机具申请记录-编辑',
  289. content: 'Edit?Id=' + data.Id + '',
  290. maxmin: true,
  291. area: ['800px', '650px'],
  292. btn: ['确定', '取消'],
  293. yes: function (index, layero) {
  294. var iframeWindow = window['layui-layer-iframe' + index],
  295. submitID = 'LAY-list-front-submit',
  296. submit = layero.find('iframe').contents().find('#' + submitID);
  297. setTimeout(function () {
  298. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  299. var errObj = $(this).find('.layui-form-danger');
  300. if (errObj.length > 0) {
  301. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  302. submit.click();
  303. }
  304. });
  305. }, 300);
  306. //监听提交
  307. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  308. var field = data.field; //获取提交的字段
  309. var userdata = "";
  310. for (var prop in field) {
  311. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  312. }
  313. //提交 Ajax 成功后,静态更新表格中的数据
  314. //$.ajax({});
  315. $.ajax({
  316. type: "POST",
  317. url: "/Admin/StoreMachineApply/Edit?r=" + Math.random(1),
  318. data: userdata,
  319. dataType: "text",
  320. success: function (data) {
  321. if (data == "success") {
  322. layer.close(index); //关闭弹层
  323. table.reload('LAY-list-manage'); //数据刷新
  324. } else {
  325. layer.msg(data);
  326. }
  327. }
  328. });
  329. });
  330. submit.trigger('click');
  331. },
  332. success: function (layero, index) {
  333. }
  334. });
  335. }
  336. });
  337. //监听搜索
  338. form.on('submit(LAY-list-front-search)', function (data) {
  339. var field = data.field;
  340. //执行重载
  341. table.reload('LAY-list-manage', {
  342. where: field
  343. });
  344. });
  345. form.on('submit(LAY-list-front-searchall)', function (data) {
  346. table.reload('LAY-list-manage', {
  347. where: null
  348. });
  349. });
  350. //事件
  351. var active = {
  352. batchdel: function () {
  353. var checkStatus = table.checkStatus('LAY-list-manage'),
  354. data = checkStatus.data; //得到选中的数据
  355. if (data.length < 1) {
  356. parent.layer.msg("请选择要删除的项");
  357. } else {
  358. var ids = "";
  359. $.each(data, function (index, value) {
  360. ids += data[index].Id + ",";
  361. });
  362. ids = ids.substring(0, ids.length - 1);
  363. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  364. $.ajax({
  365. type: "POST",
  366. url: "/Admin/StoreMachineApply/Delete?r=" + Math.random(1),
  367. data: "Id=" + ids,
  368. dataType: "text",
  369. success: function (data) {
  370. layer.close(index);
  371. if (data == "success") {
  372. table.reload('LAY-list-manage');
  373. } else {
  374. layer.msg(data);
  375. }
  376. }
  377. });
  378. });
  379. }
  380. },
  381. add: function () {
  382. var perContent = layer.open({
  383. type: 2,
  384. title: '仓库机具申请记录-添加',
  385. content: 'Add',
  386. maxmin: true,
  387. area: ['500px', '450px'],
  388. btn: ['确定', '取消'],
  389. yes: function (index, layero) {
  390. var iframeWindow = window['layui-layer-iframe' + index],
  391. submitID = 'LAY-list-front-submit',
  392. submit = layero.find('iframe').contents().find('#' + submitID);
  393. setTimeout(function () {
  394. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  395. var errObj = $(this).find('.layui-form-danger');
  396. if (errObj.length > 0) {
  397. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  398. submit.click();
  399. }
  400. });
  401. }, 300);
  402. //监听提交
  403. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  404. var field = data.field; //获取提交的字段
  405. var userdata = "";
  406. for (var prop in field) {
  407. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  408. }
  409. //提交 Ajax 成功后,静态更新表格中的数据
  410. //$.ajax({});
  411. $.ajax({
  412. type: "POST",
  413. url: "/Admin/StoreMachineApply/Add?r=" + Math.random(1),
  414. data: userdata,
  415. dataType: "text",
  416. success: function (data) {
  417. layer.close(index); //关闭弹层
  418. if (data == "success") {
  419. table.reload('LAY-list-manage'); //数据刷新
  420. } else {
  421. layer.msg(data);
  422. }
  423. }
  424. });
  425. });
  426. submit.trigger('click');
  427. }
  428. });
  429. layer.full(perContent);
  430. },
  431. ImportChange: function () {
  432. var perContent = layer.open({
  433. type: 2,
  434. title: '添加机具SN',
  435. content: 'Import?ExcelKind=2',
  436. maxmin: true,
  437. area: ['650px', '350px'],
  438. btn: ['确定', '取消'],
  439. yes: function (index, layero) {
  440. var iframeWindow = window['layui-layer-iframe' + index],
  441. submitID = 'LAY-list-front-submit',
  442. submit = layero.find('iframe').contents().find('#' + submitID);
  443. //监听提交
  444. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  445. var field = data.SwapSnExpand; //获取提交的字段
  446. var userdata = "";
  447. for (var prop in field) {
  448. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  449. }
  450. //提交 Ajax 成功后,静态更新表格中的数据
  451. //$.ajax({});
  452. var loadindex = layer.load(1, {
  453. shade: [0.5, '#000']
  454. });
  455. $.ajax({
  456. type: "POST",
  457. url: "/Admin/StoreMachineApply/ImportPost?r=" + Math.random(1),
  458. data: userdata,
  459. dataType: "text",
  460. success: function (data) {
  461. if (data.indexOf("success") == 0) {
  462. var datalist = data.split('|');
  463. var key = datalist[1];
  464. CheckImport(table, key, loadindex, index);
  465. } else {
  466. layer.msg(data);
  467. }
  468. }
  469. });
  470. });
  471. submit.trigger('click');
  472. }
  473. });
  474. },
  475. ImportData: function () {
  476. layer.open({
  477. type: 1,
  478. title: '导入',
  479. maxmin: false,
  480. area: ['460px', '180px'],
  481. content: $('#excelForm'),
  482. cancel: function () {}
  483. });
  484. },
  485. ExportExcel: function () {
  486. var userdata = '';
  487. $(".layuiadmin-card-header-auto input").each(function (i) {
  488. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  489. });
  490. $(".layuiadmin-card-header-auto select").each(function (i) {
  491. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  492. });
  493. $.ajax({
  494. type: "GET",
  495. url: "/Admin/StoreMachineApply/ExportExcel?r=" + Math.random(1),
  496. data: userdata,
  497. dataType: "json",
  498. success: function (data) {
  499. data.Obj.unshift(data.Fields);
  500. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  501. }
  502. });
  503. },
  504. Open: function () {
  505. var checkStatus = table.checkStatus('LAY-list-manage'),
  506. data = checkStatus.data; //得到选中的数据
  507. if (data.length < 1) {
  508. parent.layer.msg("请选择要开启的项");
  509. } else {
  510. var ids = "";
  511. $.each(data, function (index, value) {
  512. ids += data[index].Id + ",";
  513. });
  514. ids = ids.substring(0, ids.length - 1);
  515. var index = layer.confirm('确定要开启吗?', function (index) {
  516. $.ajax({
  517. type: "POST",
  518. url: "/Admin/StoreMachineApply/Open?r=" + Math.random(1),
  519. data: "Id=" + ids,
  520. dataType: "text",
  521. success: function (data) {
  522. layer.close(index);
  523. if (data == "success") {
  524. table.reload('LAY-list-manage');
  525. } else {
  526. layer.msg(data);
  527. }
  528. }
  529. });
  530. });
  531. }
  532. },
  533. Close: function () {
  534. var checkStatus = table.checkStatus('LAY-list-manage'),
  535. data = checkStatus.data; //得到选中的数据
  536. if (data.length < 1) {
  537. parent.layer.msg("请选择要关闭的项");
  538. } else {
  539. var ids = "";
  540. $.each(data, function (index, value) {
  541. ids += data[index].Id + ",";
  542. });
  543. ids = ids.substring(0, ids.length - 1);
  544. var index = layer.confirm('确定要关闭吗?', function (index) {
  545. $.ajax({
  546. type: "POST",
  547. url: "/Admin/StoreMachineApply/Close?r=" + Math.random(1),
  548. data: "Id=" + ids,
  549. dataType: "text",
  550. success: function (data) {
  551. layer.close(index);
  552. if (data == "success") {
  553. table.reload('LAY-list-manage');
  554. } else {
  555. layer.msg(data);
  556. }
  557. }
  558. });
  559. });
  560. }
  561. }
  562. };
  563. $('.layui-btn').on('click', function () {
  564. var type = $(this).data('type');
  565. active[type] ? active[type].call(this) : '';
  566. });
  567. });