StoreMachineApply_Admin.js 21 KB

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