StoreMachineApply_Admin.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. });
  345. });
  346. form.on('submit(LAY-list-front-searchall)', function (data) {
  347. table.reload('LAY-list-manage', {
  348. where: null
  349. });
  350. });
  351. //事件
  352. var active = {
  353. batchdel: function () {
  354. var checkStatus = table.checkStatus('LAY-list-manage'),
  355. data = checkStatus.data; //得到选中的数据
  356. if (data.length < 1) {
  357. parent.layer.msg("请选择要删除的项");
  358. } else {
  359. var ids = "";
  360. $.each(data, function (index, value) {
  361. ids += data[index].Id + ",";
  362. });
  363. ids = ids.substring(0, ids.length - 1);
  364. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  365. $.ajax({
  366. type: "POST",
  367. url: "/Admin/StoreMachineApply/Delete?r=" + Math.random(1),
  368. data: "Id=" + ids,
  369. dataType: "text",
  370. success: function (data) {
  371. layer.close(index);
  372. if (data == "success") {
  373. table.reload('LAY-list-manage');
  374. } else {
  375. layer.msg(data);
  376. }
  377. }
  378. });
  379. });
  380. }
  381. },
  382. add: function () {
  383. var perContent = layer.open({
  384. type: 2,
  385. title: '仓库机具申请记录-添加',
  386. content: 'Add',
  387. maxmin: true,
  388. area: ['500px', '450px'],
  389. btn: ['确定', '取消'],
  390. yes: function (index, layero) {
  391. var iframeWindow = window['layui-layer-iframe' + index],
  392. submitID = 'LAY-list-front-submit',
  393. submit = layero.find('iframe').contents().find('#' + submitID);
  394. setTimeout(function () {
  395. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  396. var errObj = $(this).find('.layui-form-danger');
  397. if (errObj.length > 0) {
  398. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  399. submit.click();
  400. }
  401. });
  402. }, 300);
  403. //监听提交
  404. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  405. var field = data.field; //获取提交的字段
  406. var userdata = "";
  407. for (var prop in field) {
  408. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  409. }
  410. //提交 Ajax 成功后,静态更新表格中的数据
  411. //$.ajax({});
  412. $.ajax({
  413. type: "POST",
  414. url: "/Admin/StoreMachineApply/Add?r=" + Math.random(1),
  415. data: userdata,
  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. submit.trigger('click');
  428. }
  429. });
  430. layer.full(perContent);
  431. },
  432. ImportChange: function () {
  433. var perContent = layer.open({
  434. type: 2,
  435. title: '添加机具SN',
  436. content: 'Import?ExcelKind=2',
  437. maxmin: true,
  438. area: ['650px', '350px'],
  439. btn: ['确定', '取消'],
  440. yes: function (index, layero) {
  441. var iframeWindow = window['layui-layer-iframe' + index],
  442. submitID = 'LAY-list-front-submit',
  443. submit = layero.find('iframe').contents().find('#' + submitID);
  444. //监听提交
  445. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  446. var field = data.SwapSnExpand; //获取提交的字段
  447. var userdata = "";
  448. for (var prop in field) {
  449. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  450. }
  451. //提交 Ajax 成功后,静态更新表格中的数据
  452. //$.ajax({});
  453. var loadindex = layer.load(1, {
  454. shade: [0.5, '#000']
  455. });
  456. $.ajax({
  457. type: "POST",
  458. url: "/Admin/StoreMachineApply/ImportPost?r=" + Math.random(1),
  459. data: userdata,
  460. dataType: "text",
  461. success: function (data) {
  462. if (data.indexOf("success") == 0) {
  463. var datalist = data.split('|');
  464. var key = datalist[1];
  465. CheckImport(table, key, loadindex, index);
  466. } else {
  467. layer.msg(data);
  468. }
  469. }
  470. });
  471. });
  472. submit.trigger('click');
  473. }
  474. });
  475. },
  476. ImportData: function () {
  477. layer.open({
  478. type: 1,
  479. title: '导入',
  480. maxmin: false,
  481. area: ['460px', '180px'],
  482. content: $('#excelForm'),
  483. cancel: function () {}
  484. });
  485. },
  486. ExportExcel: function () {
  487. var userdata = '';
  488. $(".layuiadmin-card-header-auto input").each(function (i) {
  489. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  490. });
  491. $(".layuiadmin-card-header-auto select").each(function (i) {
  492. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  493. });
  494. $.ajax({
  495. type: "GET",
  496. url: "/Admin/StoreMachineApply/ExportExcel?r=" + Math.random(1),
  497. data: userdata,
  498. dataType: "json",
  499. success: function (data) {
  500. data.Obj.unshift(data.Fields);
  501. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  502. }
  503. });
  504. },
  505. Open: function () {
  506. var checkStatus = table.checkStatus('LAY-list-manage'),
  507. data = checkStatus.data; //得到选中的数据
  508. if (data.length < 1) {
  509. parent.layer.msg("请选择要开启的项");
  510. } else {
  511. var ids = "";
  512. $.each(data, function (index, value) {
  513. ids += data[index].Id + ",";
  514. });
  515. ids = ids.substring(0, ids.length - 1);
  516. var index = layer.confirm('确定要开启吗?', function (index) {
  517. $.ajax({
  518. type: "POST",
  519. url: "/Admin/StoreMachineApply/Open?r=" + Math.random(1),
  520. data: "Id=" + ids,
  521. dataType: "text",
  522. success: function (data) {
  523. layer.close(index);
  524. if (data == "success") {
  525. table.reload('LAY-list-manage');
  526. } else {
  527. layer.msg(data);
  528. }
  529. }
  530. });
  531. });
  532. }
  533. },
  534. Close: function () {
  535. var checkStatus = table.checkStatus('LAY-list-manage'),
  536. data = checkStatus.data; //得到选中的数据
  537. if (data.length < 1) {
  538. parent.layer.msg("请选择要关闭的项");
  539. } else {
  540. var ids = "";
  541. $.each(data, function (index, value) {
  542. ids += data[index].Id + ",";
  543. });
  544. ids = ids.substring(0, ids.length - 1);
  545. var index = layer.confirm('确定要关闭吗?', function (index) {
  546. $.ajax({
  547. type: "POST",
  548. url: "/Admin/StoreMachineApply/Close?r=" + Math.random(1),
  549. data: "Id=" + ids,
  550. dataType: "text",
  551. success: function (data) {
  552. layer.close(index);
  553. if (data == "success") {
  554. table.reload('LAY-list-manage');
  555. } else {
  556. layer.msg(data);
  557. }
  558. }
  559. });
  560. });
  561. }
  562. }
  563. };
  564. $('.layui-btn').on('click', function () {
  565. var type = $(this).data('type');
  566. active[type] ? active[type].call(this) : '';
  567. });
  568. });