StoreHouse_Admin.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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: 'datetime',
  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/IndexData' //模拟接口
  117. ,
  118. cols: [
  119. [{
  120. type: 'checkbox',
  121. fixed: 'left'
  122. }, {
  123. field: 'Id',
  124. fixed: 'left',
  125. title: 'ID',
  126. width: 80,
  127. sort: true,
  128. unresize: true
  129. }, {
  130. field: 'StoreNo',
  131. width: 200,
  132. title: '仓库编号',
  133. sort: true
  134. }, {
  135. field: 'StoreName',
  136. width: 200,
  137. title: '仓库名称',
  138. sort: true
  139. }, {
  140. field: 'ManageUserIdMakerCode',
  141. width: 200,
  142. title: '仓库负责人编号',
  143. sort: true,
  144. templet: '#ManageTpl'
  145. }, {
  146. field: 'ManageUserIdRealName',
  147. width: 200,
  148. title: '仓库管理员',
  149. sort: true
  150. }, {
  151. field: 'UserIdMakerCode',
  152. width: 200,
  153. title: '仓库归属创客编号',
  154. sort: true,
  155. templet: '#MakerCodeTpl'
  156. }, {
  157. field: 'UserIdRealName',
  158. width: 200,
  159. title: '仓库归属人真实姓名',
  160. sort: true
  161. }, {
  162. field: 'BrandId',
  163. width: 300,
  164. title: '产品类型',
  165. sort: true
  166. }, {
  167. field: 'Address',
  168. width: 200,
  169. title: '仓库地址',
  170. sort: true
  171. }, {
  172. field: 'ManageUserIdMobile',
  173. width: 200,
  174. title: '仓库管理员手机号',
  175. sort: true
  176. }, {
  177. field: 'ManagerEmail',
  178. width: 200,
  179. title: '管理者邮箱',
  180. sort: true
  181. }, {
  182. field: 'StoreType',
  183. width: 200,
  184. title: '仓库类型',
  185. sort: true
  186. }, {
  187. field: 'TotalNum',
  188. width: 200,
  189. title: '总库存数',
  190. sort: true
  191. }, {
  192. field: 'LaveNum',
  193. width: 200,
  194. title: '剩余库存数',
  195. sort: true
  196. }, {
  197. field: 'OutNum',
  198. width: 200,
  199. title: '出库数',
  200. sort: true
  201. }, {
  202. field: 'LimitTopUserId',
  203. width: 200,
  204. title: '限制创客特殊仓库',
  205. sort: true
  206. }, {
  207. field: 'StoreStatus',
  208. width: 200,
  209. title: '仓库状态',
  210. sort: true
  211. }, {
  212. field: 'StoreKind',
  213. width: 200,
  214. title: '仓库归属类型',
  215. sort: true
  216. }, {
  217. field: 'CreateMan',
  218. width: 200,
  219. title: '创建人',
  220. sort: true
  221. }, {
  222. field: 'CreateDate',
  223. width: 200,
  224. title: '创建时间',
  225. sort: true
  226. }
  227. , {
  228. field: 'Sort',
  229. fixed: 'right',
  230. title: '排序',
  231. width: 80,
  232. edit: 'text'
  233. }, {
  234. title: '操作',
  235. width: 200,
  236. align: 'center',
  237. fixed: 'right',
  238. toolbar: '#table-list-tools'
  239. }
  240. ]
  241. ],
  242. where: {
  243. },
  244. page: true,
  245. limit: 30,
  246. height: 'full-' + String($('.layui-card-header').height() + 130),
  247. text: '对不起,加载出现异常!',
  248. done: function (res, curr, count) {
  249. $(".layui-none").text("无数据");
  250. }
  251. });
  252. //监听工具条
  253. table.on('tool(LAY-list-manage)', function (obj) {
  254. var data = obj.data;
  255. if (obj.event === 'del') {
  256. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  257. $.ajax({
  258. type: "POST",
  259. url: "/Admin/StoreHouse/Delete?r=" + Math.random(1),
  260. data: "Id=" + data.Id,
  261. dataType: "text",
  262. success: function (data) {
  263. if (data == "success") {
  264. obj.del();
  265. layer.close(index);
  266. } else {
  267. parent.layer.msg(data);
  268. }
  269. }
  270. });
  271. });
  272. } else if (obj.event === 'sycn') {
  273. var index = layer.confirm('确定要同步该仓库的库存数据吗?', function (index) {
  274. layer.close(index);
  275. var loadindex = layer.load(1, {
  276. shade: [0.5, '#000']
  277. });
  278. $.ajax({
  279. type: "POST",
  280. url: "/Admin/StoreHouse/SycnData?r=" + Math.random(1),
  281. data: "Id=" + data.Id,
  282. dataType: "text",
  283. success: function (data) {
  284. layer.close(loadindex);
  285. if (data == "success") {
  286. layer.msg('同步成功');
  287. table.reload('LAY-list-manage');
  288. } else {
  289. layer.msg(data);
  290. }
  291. }
  292. });
  293. });
  294. } else if (obj.event === 'edit') {
  295. var tr = $(obj.tr);
  296. var perContent = layer.open({
  297. type: 2,
  298. title: '仓库-编辑',
  299. content: 'Edit?Id=' + data.Id + '',
  300. maxmin: true,
  301. area: ['800px', '650px'],
  302. btn: ['确定', '取消'],
  303. yes: function (index, layero) {
  304. var iframeWindow = window['layui-layer-iframe' + index],
  305. submitID = 'LAY-list-front-submit',
  306. submit = layero.find('iframe').contents().find('#' + submitID);
  307. setTimeout(function () {
  308. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  309. var errObj = $(this).find('.layui-form-danger');
  310. if (errObj.length > 0) {
  311. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  312. submit.click();
  313. }
  314. });
  315. }, 300);
  316. //监听提交
  317. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  318. var field = data.field; //获取提交的字段
  319. var userdata = "";
  320. for (var prop in field) {
  321. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  322. }
  323. //提交 Ajax 成功后,静态更新表格中的数据
  324. //$.ajax({});
  325. $.ajax({
  326. type: "POST",
  327. url: "/Admin/StoreHouse/Edit?r=" + Math.random(1),
  328. data: userdata,
  329. dataType: "text",
  330. success: function (data) {
  331. if (data == "success") {
  332. layer.close(index); //关闭弹层
  333. table.reload('LAY-list-manage'); //数据刷新
  334. } else {
  335. layer.msg(data);
  336. }
  337. }
  338. });
  339. });
  340. submit.trigger('click');
  341. },
  342. success: function (layero, index) {
  343. }
  344. });
  345. }
  346. });
  347. //监听搜索
  348. form.on('submit(LAY-list-front-search)', function (data) {
  349. var field = data.field;
  350. //执行重载
  351. table.reload('LAY-list-manage', {
  352. where: field
  353. });
  354. });
  355. form.on('submit(LAY-list-front-searchall)', function (data) {
  356. table.reload('LAY-list-manage', {
  357. where: null
  358. });
  359. });
  360. //事件
  361. var active = {
  362. batchdel: function () {
  363. var checkStatus = table.checkStatus('LAY-list-manage'),
  364. data = checkStatus.data; //得到选中的数据
  365. if (data.length < 1) {
  366. parent.layer.msg("请选择要删除的项");
  367. } else {
  368. var ids = "";
  369. $.each(data, function (index, value) {
  370. ids += data[index].Id + ",";
  371. });
  372. ids = ids.substring(0, ids.length - 1);
  373. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  374. $.ajax({
  375. type: "POST",
  376. url: "/Admin/StoreHouse/Delete?r=" + Math.random(1),
  377. data: "Id=" + ids,
  378. dataType: "text",
  379. success: function (data) {
  380. layer.close(index);
  381. if (data == "success") {
  382. table.reload('LAY-list-manage');
  383. } else {
  384. layer.msg(data);
  385. }
  386. }
  387. });
  388. });
  389. }
  390. },
  391. add: function () {
  392. var perContent = layer.open({
  393. type: 2,
  394. title: '仓库-添加',
  395. content: 'Add',
  396. maxmin: true,
  397. area: ['950px', '650px'],
  398. btn: ['确定', '取消'],
  399. yes: function (index, layero) {
  400. var iframeWindow = window['layui-layer-iframe' + index],
  401. submitID = 'LAY-list-front-submit',
  402. submit = layero.find('iframe').contents().find('#' + submitID);
  403. setTimeout(function () {
  404. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  405. var errObj = $(this).find('.layui-form-danger');
  406. if (errObj.length > 0) {
  407. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  408. submit.click();
  409. }
  410. });
  411. }, 300);
  412. //监听提交
  413. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  414. var field = data.field; //获取提交的字段
  415. var userdata = "";
  416. for (var prop in field) {
  417. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  418. }
  419. //提交 Ajax 成功后,静态更新表格中的数据
  420. //$.ajax({});
  421. $.ajax({
  422. type: "POST",
  423. url: "/Admin/StoreHouse/Add?r=" + Math.random(1),
  424. data: userdata,
  425. dataType: "text",
  426. success: function (data) {
  427. if (data == "success") {
  428. layer.close(index); //关闭弹层
  429. table.reload('LAY-list-manage'); //数据刷新
  430. } else {
  431. layer.msg(data);
  432. }
  433. }
  434. });
  435. });
  436. submit.trigger('click');
  437. }
  438. });
  439. },
  440. ImportMachine: function () {
  441. var perContent = layer.open({
  442. type: 2,
  443. title: '机具入库',
  444. content: 'Import?ExcelKind=1',
  445. maxmin: true,
  446. area: ['650px', '350px'],
  447. btn: ['确定', '取消'],
  448. yes: function (index, layero) {
  449. var iframeWindow = window['layui-layer-iframe' + index],
  450. submitID = 'LAY-list-front-submit',
  451. submit = layero.find('iframe').contents().find('#' + submitID);
  452. //监听提交
  453. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  454. var field = data.field; //获取提交的字段
  455. var userdata = "";
  456. for (var prop in field) {
  457. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  458. }
  459. //提交 Ajax 成功后,静态更新表格中的数据
  460. //$.ajax({});
  461. var loadindex = layer.load(1, {
  462. shade: [0.5, '#000']
  463. });
  464. $.ajax({
  465. type: "POST",
  466. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  467. data: userdata,
  468. dataType: "text",
  469. success: function (data) {
  470. if (data.indexOf("success") == 0) {
  471. var datalist = data.split('|');
  472. var key = datalist[1];
  473. CheckImport(table, key, loadindex, index);
  474. } else {
  475. layer.msg(data);
  476. }
  477. }
  478. });
  479. });
  480. submit.trigger('click');
  481. }
  482. });
  483. },
  484. ImportChange: function () {
  485. var perContent = layer.open({
  486. type: 2,
  487. title: '仓库调拨',
  488. content: 'Import?ExcelKind=2',
  489. maxmin: true,
  490. area: ['650px', '350px'],
  491. btn: ['确定', '取消'],
  492. yes: function (index, layero) {
  493. var iframeWindow = window['layui-layer-iframe' + index],
  494. submitID = 'LAY-list-front-submit',
  495. submit = layero.find('iframe').contents().find('#' + submitID);
  496. //监听提交
  497. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  498. var field = data.field; //获取提交的字段
  499. var userdata = "";
  500. for (var prop in field) {
  501. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  502. }
  503. //提交 Ajax 成功后,静态更新表格中的数据
  504. //$.ajax({});
  505. var loadindex = layer.load(1, {
  506. shade: [0.5, '#000']
  507. });
  508. $.ajax({
  509. type: "POST",
  510. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  511. data: userdata,
  512. dataType: "text",
  513. success: function (data) {
  514. if (data.indexOf("success") == 0) {
  515. var datalist = data.split('|');
  516. var key = datalist[1];
  517. CheckImport(table, key, loadindex, index);
  518. } else {
  519. layer.msg(data);
  520. }
  521. }
  522. });
  523. });
  524. submit.trigger('click');
  525. }
  526. });
  527. },
  528. ImportSend: function () {
  529. var perContent = layer.open({
  530. type: 2,
  531. title: '仓库发货至创客',
  532. content: 'Import?ExcelKind=3',
  533. maxmin: true,
  534. area: ['650px', '350px'],
  535. btn: ['确定', '取消'],
  536. yes: function (index, layero) {
  537. var iframeWindow = window['layui-layer-iframe' + index],
  538. submitID = 'LAY-list-front-submit',
  539. submit = layero.find('iframe').contents().find('#' + submitID);
  540. //监听提交
  541. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  542. var field = data.field; //获取提交的字段
  543. var userdata = "";
  544. for (var prop in field) {
  545. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  546. }
  547. //提交 Ajax 成功后,静态更新表格中的数据
  548. //$.ajax({});
  549. var loadindex = layer.load(1, {
  550. shade: [0.5, '#000']
  551. });
  552. $.ajax({
  553. type: "POST",
  554. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  555. data: userdata,
  556. dataType: "text",
  557. success: function (data) {
  558. if (data.indexOf("success") == 0) {
  559. var datalist = data.split('|');
  560. var key = datalist[1];
  561. CheckImport(table, key, loadindex, index);
  562. } else {
  563. layer.msg(data);
  564. }
  565. }
  566. });
  567. });
  568. submit.trigger('click');
  569. }
  570. });
  571. },
  572. ExportExcel: function () {
  573. var userdata = '';
  574. $(".layuiadmin-card-header-auto input").each(function (i) {
  575. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  576. });
  577. $(".layuiadmin-card-header-auto select").each(function (i) {
  578. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  579. });
  580. $.ajax({
  581. type: "GET",
  582. url: "/Admin/StoreHouse/ExportExcel?r=" + Math.random(1),
  583. data: userdata,
  584. dataType: "json",
  585. success: function (data) {
  586. data.Obj.unshift(data.Fields);
  587. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  588. }
  589. });
  590. },
  591. Open: function () {
  592. var checkStatus = table.checkStatus('LAY-list-manage'),
  593. data = checkStatus.data; //得到选中的数据
  594. if (data.length < 1) {
  595. parent.layer.msg("请选择要开启的项");
  596. } else {
  597. var ids = "";
  598. $.each(data, function (index, value) {
  599. ids += data[index].Id + ",";
  600. });
  601. ids = ids.substring(0, ids.length - 1);
  602. var index = layer.confirm('确定要开启吗?', function (index) {
  603. $.ajax({
  604. type: "POST",
  605. url: "/Admin/StoreHouse/Open?r=" + Math.random(1),
  606. data: "Id=" + ids,
  607. dataType: "text",
  608. success: function (data) {
  609. layer.close(index);
  610. if (data == "success") {
  611. table.reload('LAY-list-manage');
  612. } else {
  613. layer.msg(data);
  614. }
  615. }
  616. });
  617. });
  618. }
  619. },
  620. Close: function () {
  621. var checkStatus = table.checkStatus('LAY-list-manage'),
  622. data = checkStatus.data; //得到选中的数据
  623. if (data.length < 1) {
  624. parent.layer.msg("请选择要关闭的项");
  625. } else {
  626. var ids = "";
  627. $.each(data, function (index, value) {
  628. ids += data[index].Id + ",";
  629. });
  630. ids = ids.substring(0, ids.length - 1);
  631. var index = layer.confirm('确定要关闭吗?', function (index) {
  632. $.ajax({
  633. type: "POST",
  634. url: "/Admin/StoreHouse/Close?r=" + Math.random(1),
  635. data: "Id=" + ids,
  636. dataType: "text",
  637. success: function (data) {
  638. layer.close(index);
  639. if (data == "success") {
  640. table.reload('LAY-list-manage');
  641. } else {
  642. layer.msg(data);
  643. }
  644. }
  645. });
  646. });
  647. }
  648. },
  649. SycnData: function () {
  650. var index = layer.confirm('确定要同步所有仓库的库存数据吗?', function (index) {
  651. layer.close(index);
  652. var loadindex = layer.load(1, {
  653. shade: [0.5, '#000']
  654. });
  655. $.ajax({
  656. type: "POST",
  657. url: "/Admin/StoreHouse/SycnData?r=" + Math.random(1),
  658. data: "Id=0",
  659. dataType: "text",
  660. success: function (data) {
  661. layer.close(loadindex);
  662. if (data == "success") {
  663. layer.msg('同步成功');
  664. table.reload('LAY-list-manage');
  665. } else {
  666. layer.msg(data);
  667. }
  668. }
  669. });
  670. });
  671. },
  672. };
  673. $('.layui-btn').on('click', function () {
  674. var type = $(this).data('type');
  675. active[type] ? active[type].call(this) : '';
  676. });
  677. });