StoreMachineApply_Admin.js 24 KB

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