StoreMachineApply_Admin.js 21 KB

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