StoreHouseStat_Admin.js 25 KB

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