StoreHouse_Admin.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. var ExcelData, ExcelKind;
  2. var clickflag = 0;
  3. function ConfirmImport() {
  4. var index = layer.load(1, {
  5. shade: [0.5, '#000']
  6. });
  7. $.ajax({
  8. type: "POST",
  9. url: "/Admin/StoreHouse/Import?r=" + Math.random(1),
  10. data: "Kind=" + ExcelKind + "&ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  11. dataType: "text",
  12. success: function (data) {
  13. layer.close(index);
  14. if (data.indexOf("success") == 0) {
  15. layer.msg("成功操作" + data.split('|')[1] + "部机具", {
  16. time: 2000
  17. }, function () {
  18. window.location.reload();
  19. });
  20. } else {
  21. layer.msg(data);
  22. }
  23. }
  24. });
  25. }
  26. function ConfirmRejectImport() {
  27. $.ajax({
  28. type: "POST",
  29. url: "/Admin/StoreHouse/RejectStore?r=" + Math.random(1),
  30. data: "ExcelKind=" + ExcelKind + "&ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  31. dataType: "text",
  32. success: function (data) {
  33. if (data == "success") {
  34. layer.msg("导入成功", { time: 2000 }, function () {
  35. window.location.reload();
  36. });
  37. } else if (data.indexOf("warning") == 0) {
  38. var datalist = data.split('|');
  39. layer.alert(datalist[0], { time: 20000 }, function () {
  40. window.location.reload();
  41. });
  42. } else {
  43. layer.msg(data);
  44. }
  45. }
  46. });
  47. }
  48. function CheckImport(table, key, loadindex, index) {
  49. $.ajax({
  50. url: "/Admin/StoreHouse/CheckImportV2?r=" + Math.random(1),
  51. data: "key=" + key,
  52. dataType: "json",
  53. success: function (data) {
  54. if (data.status == 1) {
  55. layer.msg("成功操作" + data.data + "部机具", {
  56. time: 2000
  57. }, function () {
  58. layer.close(index); //关闭弹层
  59. layer.close(loadindex);
  60. table.reload('LAY-list-manage'); //数据刷新
  61. });
  62. } else if (data.status == 2) {
  63. layer.close(index); //关闭弹层
  64. layer.close(loadindex);
  65. var content = '';
  66. for (var i = 0; i < data.errList.length; i++) {
  67. content += data.errList[i] + '<br/>'
  68. }
  69. layer.alert(content);
  70. } else {
  71. layer.msg(data.data, {
  72. time: 1000
  73. }, function () {
  74. CheckImport(table, key, loadindex, index);
  75. });
  76. }
  77. }
  78. });
  79. }
  80. var excel;
  81. layui.config({
  82. base: '/layuiadmin/' //静态资源所在路径
  83. }).extend({
  84. myexcel: 'layui/lay/modules/excel',
  85. index: 'lib/index' //主入口模块
  86. }).use(['index', 'table', 'excel', 'laydate'], function () {
  87. var $ = layui.$,
  88. form = layui.form,
  89. table = layui.table;
  90. //- 筛选条件-日期
  91. var laydate = layui.laydate;
  92. var layCreateDate = laydate.render({
  93. elem: '#CreateDate',
  94. type: 'datetime',
  95. range: true,
  96. trigger: 'click',
  97. change: function (value, date, endDate) {
  98. var op = true;
  99. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  100. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  101. op = false;
  102. layCreateDate.hint('日期范围请不要超过1个月');
  103. setTimeout(function () {
  104. $(".laydate-btns-confirm").addClass("laydate-disabled");
  105. }, 1);
  106. }
  107. } else {
  108. op = false;
  109. layCreateDate.hint('日期范围请不要超过1个月');
  110. setTimeout(function () {
  111. $(".laydate-btns-confirm").addClass("laydate-disabled");
  112. }, 1);
  113. }
  114. if (op) {
  115. $('#CreateDate').val(value);
  116. }
  117. }
  118. });
  119. //excel导入
  120. excel = layui.excel;
  121. $('#ExcelFile').change(function (e) {
  122. var files = e.target.files;
  123. excel.importExcel(files, {}, function (data) {
  124. ExcelData = data[0].Sheet1;
  125. });
  126. });
  127. //监听单元格编辑
  128. table.on('edit(LAY-list-manage)', function (obj) {
  129. var value = obj.value //得到修改后的值
  130. ,
  131. data = obj.data //得到所在行所有键值
  132. ,
  133. field = obj.field; //得到字段
  134. if (field == "Sort") {
  135. $.ajax({
  136. type: "POST",
  137. url: "/Admin/StoreHouse/Sort?r=" + Math.random(1),
  138. data: "Id=" + data.Id + "&Sort=" + value,
  139. dataType: "text",
  140. success: function (data) { }
  141. });
  142. }
  143. });
  144. //列表数据
  145. table.render({
  146. elem: '#LAY-list-manage',
  147. url: '/Admin/StoreHouse/IndexData' //模拟接口
  148. ,
  149. cols: [
  150. [{
  151. type: 'checkbox',
  152. fixed: 'left'
  153. }, {
  154. field: 'StoreNo',
  155. width: 110,
  156. title: '仓库编号',
  157. sort: true
  158. }, {
  159. field: 'StoreName',
  160. width: 110,
  161. title: '仓库名称',
  162. sort: true
  163. }, {
  164. field: 'ManageUserIdMakerCode',
  165. width: 145,
  166. title: '仓库负责人编号',
  167. sort: true,
  168. templet: '#ManageTpl'
  169. }, {
  170. field: 'ManageUserIdRealName',
  171. width: 120,
  172. title: '仓库管理员',
  173. sort: true
  174. }, {
  175. field: 'UserIdMakerCode',
  176. width: 160,
  177. title: '仓库归属创客编号',
  178. sort: true,
  179. templet: '#MakerCodeTpl'
  180. }, {
  181. field: 'UserIdRealName',
  182. width: 175,
  183. title: '仓库归属人真实姓名',
  184. sort: true
  185. }, {
  186. field: 'BrandId',
  187. width: 110,
  188. title: '产品类型',
  189. sort: true
  190. }, {
  191. field: 'Address',
  192. width: 110,
  193. title: '仓库地址',
  194. sort: true
  195. }, {
  196. field: 'ManageUserIdMobile',
  197. width: 160,
  198. title: '仓库管理员手机号',
  199. sort: true
  200. }, {
  201. field: 'ManagerEmail',
  202. width: 120,
  203. title: '管理者邮箱',
  204. sort: true
  205. }, {
  206. field: 'StoreType',
  207. width: 110,
  208. title: '仓库类型',
  209. sort: true
  210. }, {
  211. field: 'TotalNum',
  212. width: 110,
  213. title: '总库存数',
  214. sort: true
  215. }, {
  216. field: 'LaveNum',
  217. width: 120,
  218. title: '剩余库存数',
  219. sort: true
  220. }, {
  221. field: 'PreNum',
  222. width: 120,
  223. title: '小分仓数',
  224. sort: true
  225. }, {
  226. field: 'OutNum',
  227. width: 100,
  228. title: '出库数',
  229. sort: true
  230. }, {
  231. field: 'LimitTopUserId',
  232. width: 160,
  233. title: '限制创客特殊仓库',
  234. sort: true
  235. }, {
  236. field: 'Status',
  237. width: 110,
  238. title: '仓库状态',
  239. sort: true
  240. }, {
  241. field: 'OpIdStatus',
  242. width: 130,
  243. title: '关联运营中心',
  244. sort: true
  245. }, {
  246. field: 'StoreKind',
  247. width: 130,
  248. title: '仓库归属类型',
  249. sort: true
  250. }, {
  251. field: 'CreateMan',
  252. width: 130,
  253. title: '创建/修改人',
  254. sort: true
  255. }, {
  256. field: 'CreateDate',
  257. width: 110,
  258. title: '创建时间',
  259. sort: true
  260. }, {
  261. field: 'Deposit',
  262. width: 110,
  263. title: '押金',
  264. sort: true
  265. }, {
  266. field: 'ValidAmount',
  267. width: 110,
  268. title: '可用额度',
  269. sort: true
  270. }, {
  271. field: 'FixedAmount',
  272. width: 110,
  273. title: '固定额度',
  274. sort: true
  275. }, {
  276. field: 'TempAmount',
  277. width: 110,
  278. title: '临时额度',
  279. sort: true
  280. }, {
  281. field: 'PromissAmount',
  282. width: 110,
  283. title: '担保额度',
  284. sort: true
  285. }, {
  286. field: 'ThisMonthPreAmount',
  287. width: 150,
  288. title: '本月小分仓额度',
  289. sort: true
  290. }, {
  291. field: 'ValidPreAmount',
  292. width: 150,
  293. title: '可用小分仓额度',
  294. sort: true
  295. }, {
  296. title: '操作',
  297. width: 300,
  298. align: 'center',
  299. fixed: 'right',
  300. toolbar: '#table-list-tools'
  301. }
  302. ]
  303. ],
  304. where: {
  305. },
  306. page: true,
  307. limit: 30,
  308. height: 'full-' + String($('.layui-card-header').height() + 130),
  309. text: '对不起,加载出现异常!',
  310. done: function (res, curr, count) {
  311. $(".layui-none").text("无数据");
  312. }
  313. });
  314. //监听工具条
  315. table.on('tool(LAY-list-manage)', function (obj) {
  316. var data = obj.data;
  317. if (obj.event === 'del') {
  318. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  319. $.ajax({
  320. type: "POST",
  321. url: "/Admin/StoreHouse/Delete?r=" + Math.random(1),
  322. data: "Id=" + data.Id,
  323. dataType: "text",
  324. success: function (data) {
  325. if (data == "success") {
  326. obj.del();
  327. layer.close(index);
  328. } else {
  329. parent.layer.msg(data);
  330. }
  331. }
  332. });
  333. });
  334. } else if (obj.event === 'sycn') {
  335. var index = layer.confirm('确定要同步该仓库的库存数据吗?', function (index) {
  336. layer.close(index);
  337. var loadindex = layer.load(1, {
  338. shade: [0.5, '#000']
  339. });
  340. $.ajax({
  341. type: "POST",
  342. url: "/Admin/StoreHouse/SycnData?r=" + Math.random(1),
  343. data: "Id=" + data.Id,
  344. dataType: "text",
  345. success: function (data) {
  346. layer.close(loadindex);
  347. if (data == "success") {
  348. layer.msg('同步成功');
  349. table.reload('LAY-list-manage');
  350. } else {
  351. layer.msg(data);
  352. }
  353. }
  354. });
  355. });
  356. } else if (obj.event === 'edit') {
  357. var tr = $(obj.tr);
  358. var perContent = layer.open({
  359. type: 2,
  360. title: '仓库-编辑',
  361. content: 'Edit?Id=' + data.Id + '',
  362. maxmin: true,
  363. area: ['800px', '650px'],
  364. btn: ['确定', '取消'],
  365. yes: function (index, layero) {
  366. var iframeWindow = window['layui-layer-iframe' + index],
  367. submitID = 'LAY-list-front-submit',
  368. submit = layero.find('iframe').contents().find('#' + submitID);
  369. setTimeout(function () {
  370. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  371. var errObj = $(this).find('.layui-form-danger');
  372. if (errObj.length > 0) {
  373. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  374. submit.click();
  375. }
  376. });
  377. }, 300);
  378. //监听提交
  379. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  380. var field = data.field; //获取提交的字段
  381. var userdata = "";
  382. for (var prop in field) {
  383. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  384. }
  385. //提交 Ajax 成功后,静态更新表格中的数据
  386. //$.ajax({});
  387. $.ajax({
  388. type: "POST",
  389. url: "/Admin/StoreHouse/Edit?r=" + Math.random(1),
  390. data: userdata,
  391. dataType: "text",
  392. success: function (data) {
  393. if (data == "success") {
  394. layer.close(index); //关闭弹层
  395. table.reload('LAY-list-manage'); //数据刷新
  396. } else {
  397. layer.msg(data);
  398. }
  399. }
  400. });
  401. });
  402. submit.trigger('click');
  403. },
  404. success: function (layero, index) {
  405. }
  406. });
  407. } else if (obj.event === 'edits') {
  408. var tr = $(obj.tr);
  409. var perContent = layer.open({
  410. type: 2,
  411. title: '一键新建仓库',
  412. content: 'Edits?Id=' + data.Id + '',
  413. maxmin: true,
  414. area: ['860px', '650px'],
  415. btn: ['确定', '取消'],
  416. yes: function (index, layero) {
  417. var iframeWindow = window['layui-layer-iframe' + index],
  418. submitID = 'LAY-list-front-submit',
  419. submit = layero.find('iframe').contents().find('#' + submitID);
  420. setTimeout(function () {
  421. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  422. var errObj = $(this).find('.layui-form-danger');
  423. if (errObj.length > 0) {
  424. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  425. submit.click();
  426. }
  427. });
  428. }, 300);
  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. $.ajax({
  439. type: "POST",
  440. url: "/Admin/StoreHouse/Edits?r=" + Math.random(1),
  441. data: userdata,
  442. dataType: "text",
  443. success: function (data) {
  444. if (data == "success") {
  445. layer.close(index); //关闭弹层
  446. table.reload('LAY-list-manage'); //数据刷新
  447. } else {
  448. layer.msg(data);
  449. }
  450. }
  451. });
  452. });
  453. submit.trigger('click');
  454. },
  455. success: function (layero, index) {
  456. }
  457. });
  458. }
  459. });
  460. //监听搜索
  461. form.on('submit(LAY-list-front-search)', function (data) {
  462. var field = data.field;
  463. field.ShowFlag = 1;
  464. if (field.StoreNo == "" && field.StoreName == "" && field.UserIdMakerCode == "" && field.UserIdRealName == "" && field.ManageUserIdRealName == "" && field.ManageUserIdMobile == "" && field.ManageUserIdMakerCode == "" && field.ManagerEmail == "" && field.StoreStatusSelect == "" && field.CreateDateData == "" && field.MakerCode == "" && field.YZOpCode == "" && field.OpStatusSelect == "" && field.StoreKindSelect == "") {
  465. layer.alert('请输入查询条件');
  466. }
  467. else {
  468. //执行重载
  469. table.reload('LAY-list-manage', {
  470. where: field,
  471. page: {
  472. curr: 1
  473. }
  474. });
  475. }
  476. });
  477. form.on('submit(LAY-list-front-searchall)', function (data) {
  478. var field = data.field;
  479. field.ShowFlag = 1;
  480. console.log(field.ShowFlag)
  481. field.StoreNo = "";
  482. field.StoreName = "";
  483. field.ManagerEmail = "";
  484. field.UserIdMakerCode = "";
  485. field.UserIdRealName = "";
  486. field.ManageUserIdRealName = "";
  487. field.ManageUserIdMobile = "";
  488. field.ManageUserIdMakerCode = "";
  489. field.StoreStatusSelect = "";
  490. field.CreateDateData = "";
  491. table.reload('LAY-list-manage', {
  492. where: field,
  493. page: {
  494. curr: 1
  495. }
  496. });
  497. });
  498. //事件
  499. var active = {
  500. batchdel: function () {
  501. var checkStatus = table.checkStatus('LAY-list-manage'),
  502. data = checkStatus.data; //得到选中的数据
  503. if (data.length < 1) {
  504. parent.layer.msg("请选择要删除的项");
  505. } else {
  506. var ids = "";
  507. $.each(data, function (index, value) {
  508. ids += data[index].Id + ",";
  509. });
  510. ids = ids.substring(0, ids.length - 1);
  511. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  512. $.ajax({
  513. type: "POST",
  514. url: "/Admin/StoreHouse/Delete?r=" + Math.random(1),
  515. data: "Id=" + ids,
  516. dataType: "text",
  517. success: function (data) {
  518. layer.close(index);
  519. if (data == "success") {
  520. table.reload('LAY-list-manage');
  521. } else {
  522. layer.msg(data);
  523. }
  524. }
  525. });
  526. });
  527. }
  528. },
  529. add: function () {
  530. var perContent = layer.open({
  531. type: 2,
  532. title: '仓库-添加',
  533. content: 'Add',
  534. maxmin: true,
  535. area: ['950px', '650px'],
  536. btn: ['确定', '取消'],
  537. yes: function (index, layero) {
  538. var iframeWindow = window['layui-layer-iframe' + index],
  539. submitID = 'LAY-list-front-submit',
  540. submit = layero.find('iframe').contents().find('#' + submitID);
  541. setTimeout(function () {
  542. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  543. var errObj = $(this).find('.layui-form-danger');
  544. if (errObj.length > 0) {
  545. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  546. submit.click();
  547. }
  548. });
  549. }, 300);
  550. //监听提交
  551. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  552. var field = data.field; //获取提交的字段
  553. var userdata = "";
  554. for (var prop in field) {
  555. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  556. }
  557. //提交 Ajax 成功后,静态更新表格中的数据
  558. //$.ajax({});
  559. $.ajax({
  560. type: "POST",
  561. url: "/Admin/StoreHouse/Add?r=" + Math.random(1),
  562. data: userdata,
  563. dataType: "text",
  564. success: function (data) {
  565. if (data == "success") {
  566. layer.close(index); //关闭弹层
  567. table.reload('LAY-list-manage'); //数据刷新
  568. } else {
  569. layer.msg(data);
  570. }
  571. }
  572. });
  573. });
  574. submit.trigger('click');
  575. }
  576. });
  577. },
  578. ImportMachine: function () {
  579. var perContent = layer.open({
  580. type: 2,
  581. title: '机具入库',
  582. content: 'Import?ExcelKind=1',
  583. maxmin: true,
  584. area: ['650px', '350px'],
  585. btn: ['确定', '取消'],
  586. yes: function (index, layero) {
  587. var iframeWindow = window['layui-layer-iframe' + index],
  588. submitID = 'LAY-list-front-submit',
  589. submit = layero.find('iframe').contents().find('#' + submitID);
  590. //监听提交
  591. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  592. var field = data.field; //获取提交的字段
  593. var userdata = "";
  594. for (var prop in field) {
  595. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  596. }
  597. //提交 Ajax 成功后,静态更新表格中的数据
  598. //$.ajax({});
  599. var loadindex = layer.load(1, {
  600. shade: [0.5, '#000']
  601. });
  602. $.ajax({
  603. type: "POST",
  604. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  605. data: userdata,
  606. dataType: "text",
  607. success: function (data) {
  608. if (data.indexOf("success") == 0) {
  609. var datalist = data.split('|');
  610. var key = datalist[1];
  611. CheckImport(table, key, loadindex, index);
  612. } else {
  613. layer.msg(data);
  614. }
  615. }
  616. });
  617. });
  618. submit.trigger('click');
  619. }
  620. });
  621. },
  622. ImportChange: function () {
  623. var perContent = layer.open({
  624. type: 2,
  625. title: '仓库调拨',
  626. content: 'Import?ExcelKind=2',
  627. maxmin: true,
  628. area: ['650px', '350px'],
  629. btn: ['确定', '取消'],
  630. yes: function (index, layero) {
  631. var iframeWindow = window['layui-layer-iframe' + index],
  632. submitID = 'LAY-list-front-submit',
  633. submit = layero.find('iframe').contents().find('#' + submitID);
  634. //监听提交
  635. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  636. var field = data.field; //获取提交的字段
  637. var userdata = "";
  638. for (var prop in field) {
  639. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  640. }
  641. //提交 Ajax 成功后,静态更新表格中的数据
  642. //$.ajax({});
  643. var loadindex = layer.load(1, {
  644. shade: [0.5, '#000']
  645. });
  646. $.ajax({
  647. type: "POST",
  648. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  649. data: userdata,
  650. dataType: "text",
  651. success: function (data) {
  652. if (data.indexOf("success") == 0) {
  653. var datalist = data.split('|');
  654. var key = datalist[1];
  655. CheckImport(table, key, loadindex, index);
  656. } else {
  657. layer.msg(data);
  658. }
  659. }
  660. });
  661. });
  662. submit.trigger('click');
  663. }
  664. });
  665. },
  666. ImportSend: function () {
  667. var perContent = layer.open({
  668. type: 2,
  669. title: '仓库发货至创客',
  670. content: 'Import?ExcelKind=3',
  671. maxmin: true,
  672. area: ['650px', '350px'],
  673. btn: ['确定', '取消'],
  674. yes: function (index, layero) {
  675. var iframeWindow = window['layui-layer-iframe' + index],
  676. submitID = 'LAY-list-front-submit',
  677. submit = layero.find('iframe').contents().find('#' + submitID);
  678. //监听提交
  679. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  680. var field = data.field; //获取提交的字段
  681. var userdata = "";
  682. for (var prop in field) {
  683. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  684. }
  685. //提交 Ajax 成功后,静态更新表格中的数据
  686. //$.ajax({});
  687. var loadindex = layer.load(1, {
  688. shade: [0.5, '#000']
  689. });
  690. $.ajax({
  691. type: "POST",
  692. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  693. data: userdata,
  694. dataType: "text",
  695. success: function (data) {
  696. if (data.indexOf("success") == 0) {
  697. var datalist = data.split('|');
  698. var key = datalist[1];
  699. CheckImport(table, key, loadindex, index);
  700. } else {
  701. layer.msg(data);
  702. }
  703. }
  704. });
  705. });
  706. submit.trigger('click');
  707. }
  708. });
  709. },
  710. ImportBack: function () {
  711. var perContent = layer.open({
  712. type: 2,
  713. title: '机具回仓库',
  714. content: 'Import?ExcelKind=4',
  715. maxmin: true,
  716. area: ['650px', '350px'],
  717. btn: ['确定', '取消'],
  718. yes: function (index, layero) {
  719. var iframeWindow = window['layui-layer-iframe' + index],
  720. submitID = 'LAY-list-front-submit',
  721. submit = layero.find('iframe').contents().find('#' + submitID);
  722. //监听提交
  723. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  724. var field = data.field; //获取提交的字段
  725. var userdata = "";
  726. for (var prop in field) {
  727. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  728. }
  729. //提交 Ajax 成功后,静态更新表格中的数据
  730. //$.ajax({});
  731. var loadindex = layer.load(1, {
  732. shade: [0.5, '#000']
  733. });
  734. $.ajax({
  735. type: "POST",
  736. url: "/Admin/StoreHouse/ImportPost?r=" + Math.random(1),
  737. data: userdata,
  738. dataType: "text",
  739. success: function (data) {
  740. if (data.indexOf("success") == 0) {
  741. var datalist = data.split('|');
  742. var key = datalist[1];
  743. CheckImport(table, key, loadindex, index);
  744. } else {
  745. layer.msg(data);
  746. }
  747. }
  748. });
  749. });
  750. submit.trigger('click');
  751. }
  752. });
  753. }, ImportRejectStore: function () {
  754. ExcelKind = 1;
  755. layer.open({
  756. type: 1,
  757. title: '导入',
  758. maxmin: false,
  759. area: ['650px', '350px'],
  760. // btn: ['确定', '取消'],
  761. content: $('#excelForm'),
  762. cancel: function () {
  763. }
  764. });
  765. $("#excelTemp").html('<a href="/users/创客机具驳回仓库模版.xlsx">点击下载创客机具驳回仓库模版</a>');
  766. },
  767. ExportExcel: function () {
  768. var userdata = '';
  769. $(".layuiadmin-card-header-auto input").each(function (i) {
  770. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  771. });
  772. $(".layuiadmin-card-header-auto select").each(function (i) {
  773. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  774. });
  775. $.ajax({
  776. type: "GET",
  777. url: "/Admin/StoreHouse/ExportExcel?r=" + Math.random(1),
  778. data: userdata,
  779. dataType: "json",
  780. success: function (data) {
  781. data.Obj.unshift(data.Fields);
  782. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  783. }
  784. });
  785. }, BatchSetting: function () {
  786. var checkStatus = table.checkStatus('LAY-list-manage'),
  787. data = checkStatus.data; //得到选中的数据
  788. if (data.length < 1) {
  789. parent.layer.msg("请选择要关联的分仓");
  790. } else {
  791. var ids = "";
  792. $.each(data, function (index, value) {
  793. ids += data[index].Id + ",";
  794. });
  795. ids = ids.substring(0, ids.length - 1);
  796. var perContent = layer.open({
  797. type: 2,
  798. title: '关联分仓',
  799. content: 'BatchSetting?StoreIds=' + ids,
  800. maxmin: true,
  801. area: ['550px', '350px'],
  802. btn: ['确定', '取消'],
  803. yes: function (index, layero) {
  804. var iframeWindow = window['layui-layer-iframe' + index],
  805. submitID = 'LAY-list-front-submit',
  806. submit = layero.find('iframe').contents().find('#' + submitID);
  807. setTimeout(function () {
  808. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  809. var errObj = $(this).find('.layui-form-danger');
  810. if (errObj.length > 0) {
  811. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  812. submit.click();
  813. }
  814. });
  815. }, 300);
  816. //监听提交
  817. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  818. if (clickflag == 0) {
  819. clickflag = 1;
  820. var field = data.field; //获取提交的字段
  821. var userdata = "";
  822. for (var prop in field) {
  823. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  824. }
  825. //提交 Ajax 成功后,静态更新表格中的数据
  826. //$.ajax({});
  827. $.ajax({
  828. type: "POST",
  829. url: "/Admin/StoreHouse/BatchSetting?r=" + Math.random(1),
  830. data: userdata + "Id=" + ids,
  831. dataType: "text",
  832. success: function (data) {
  833. clickflag = 0;
  834. layer.close(index);
  835. if (data == "success") {
  836. layer.msg('关联成功', {
  837. time: 1000
  838. }, function () {
  839. table.reload('LAY-list-manage'); //数据刷新
  840. });
  841. }
  842. else if (data.indexOf("Warning") == 0) {
  843. var datalist = data.split('|');
  844. layer.alert(datalist[1], { time: 20000 }, function () {
  845. window.location.reload();
  846. });
  847. }
  848. else {
  849. layer.msg(data);
  850. }
  851. }
  852. });
  853. }
  854. });
  855. submit.trigger('click');
  856. }
  857. });
  858. }
  859. },
  860. BatchCancle: function () {
  861. var checkStatus = table.checkStatus('LAY-list-manage'),
  862. data = checkStatus.data; //得到选中的数据
  863. if (data.length < 1) {
  864. parent.layer.msg("请选择要取消关联的分仓");
  865. } else {
  866. var ids = "";
  867. $.each(data, function (index, value) {
  868. ids += data[index].Id + ",";
  869. });
  870. ids = ids.substring(0, ids.length - 1);
  871. var perContent = layer.open({
  872. type: 2,
  873. title: '取消关联',
  874. content: 'BatchCancle?StoreIds=' + ids,
  875. maxmin: true,
  876. area: ['650px', '550px'],
  877. btn: ['确定', '取消'],
  878. yes: function (index, layero) {
  879. var iframeWindow = window['layui-layer-iframe' + index],
  880. submitID = 'LAY-list-front-submit',
  881. submit = layero.find('iframe').contents().find('#' + submitID);
  882. setTimeout(function () {
  883. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  884. var errObj = $(this).find('.layui-form-danger');
  885. if (errObj.length > 0) {
  886. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  887. submit.click();
  888. }
  889. });
  890. }, 300);
  891. //监听提交
  892. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  893. if (clickflag == 0) {
  894. clickflag = 1;
  895. var field = data.field; //获取提交的字段
  896. var userdata = "";
  897. for (var prop in field) {
  898. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  899. }
  900. //提交 Ajax 成功后,静态更新表格中的数据
  901. //$.ajax({});
  902. $.ajax({
  903. type: "POST",
  904. url: "/Admin/StoreHouse/BatchCancle?r=" + Math.random(1),
  905. data: userdata + "Id=" + ids,
  906. dataType: "text",
  907. success: function (data) {
  908. clickflag = 0;
  909. layer.close(index);
  910. if (data == "success") {
  911. layer.msg('取消成功', {
  912. time: 1000
  913. }, function () {
  914. table.reload('LAY-list-manage'); //数据刷新
  915. });
  916. }
  917. else if (data.indexOf("Warning") == 0) {
  918. var datalist = data.split('|');
  919. layer.alert(datalist[1], { time: 20000 }, function () {
  920. window.location.reload();
  921. });
  922. }
  923. else {
  924. layer.msg(data);
  925. }
  926. }
  927. });
  928. }
  929. });
  930. submit.trigger('click');
  931. }
  932. });
  933. }
  934. },
  935. Open: function () {
  936. var checkStatus = table.checkStatus('LAY-list-manage'),
  937. data = checkStatus.data; //得到选中的数据
  938. if (data.length < 1) {
  939. parent.layer.msg("请选择要开启的项");
  940. } else {
  941. var ids = "";
  942. $.each(data, function (index, value) {
  943. ids += data[index].Id + ",";
  944. });
  945. ids = ids.substring(0, ids.length - 1);
  946. var index = layer.confirm('确定要开启吗?', function (index) {
  947. $.ajax({
  948. type: "POST",
  949. url: "/Admin/StoreHouse/Open?r=" + Math.random(1),
  950. data: "Id=" + ids,
  951. dataType: "text",
  952. success: function (data) {
  953. layer.close(index);
  954. if (data == "success") {
  955. table.reload('LAY-list-manage');
  956. } else {
  957. layer.msg(data);
  958. }
  959. }
  960. });
  961. });
  962. }
  963. },
  964. Close: function () {
  965. var checkStatus = table.checkStatus('LAY-list-manage'),
  966. data = checkStatus.data; //得到选中的数据
  967. if (data.length < 1) {
  968. parent.layer.msg("请选择要关闭的项");
  969. } else {
  970. var ids = "";
  971. $.each(data, function (index, value) {
  972. ids += data[index].Id + ",";
  973. });
  974. ids = ids.substring(0, ids.length - 1);
  975. var index = layer.confirm('确定要关闭吗?', function (index) {
  976. $.ajax({
  977. type: "POST",
  978. url: "/Admin/StoreHouse/Close?r=" + Math.random(1),
  979. data: "Id=" + ids,
  980. dataType: "text",
  981. success: function (data) {
  982. layer.close(index);
  983. if (data == "success") {
  984. table.reload('LAY-list-manage');
  985. } else {
  986. layer.msg(data);
  987. }
  988. }
  989. });
  990. });
  991. }
  992. },
  993. SycnData: function () {
  994. var index = layer.confirm('确定要同步所有仓库的库存数据吗?', function (index) {
  995. layer.close(index);
  996. var loadindex = layer.load(1, {
  997. shade: [0.5, '#000']
  998. });
  999. $.ajax({
  1000. type: "POST",
  1001. url: "/Admin/StoreHouse/SycnData?r=" + Math.random(1),
  1002. data: "Id=0",
  1003. dataType: "text",
  1004. success: function (data) {
  1005. layer.close(loadindex);
  1006. if (data == "success") {
  1007. layer.msg('同步成功');
  1008. table.reload('LAY-list-manage');
  1009. } else {
  1010. layer.msg(data);
  1011. }
  1012. }
  1013. });
  1014. });
  1015. },
  1016. };
  1017. $('.layui-btn').on('click', function () {
  1018. var type = $(this).data('type');
  1019. active[type] ? active[type].call(this) : '';
  1020. });
  1021. });