StoreMachineApply_Admin.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. $.ajax({
  204. type: "POST",
  205. url: "/Admin/StoreMachineApply/Close?r=" + Math.random(1),
  206. data: "Id=" + data.Id,
  207. dataType: "text",
  208. success: function (data) {
  209. layer.close(index); //关闭弹层
  210. if (data == "success") {
  211. layer.msg("已驳回", { time: 1500 }, function () {
  212. table.reload('LAY-list-manage'); //数据刷新
  213. });
  214. } else {
  215. parent.layer.msg(data);
  216. }
  217. }
  218. });
  219. });
  220. } else if (obj.event === 'audit') {
  221. var tr = $(obj.tr);
  222. var perContent = layer.open({
  223. type: 2,
  224. title: '审核发货',
  225. content: 'AuditSend?Id=' + data.Id + '',
  226. maxmin: true,
  227. area: ['450px', '680px'],
  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. var clickflag = 0;
  244. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  245. if(clickflag == 0) {
  246. clickflag = 1;
  247. var field = data.field; //获取提交的字段
  248. var userdata = "";
  249. for (var prop in field) {
  250. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  251. }
  252. //提交 Ajax 成功后,静态更新表格中的数据
  253. //$.ajax({});
  254. $.ajax({
  255. type: "POST",
  256. url: "/Admin/StoreMachineApply/AuditSend?r=" + Math.random(1),
  257. data: userdata,
  258. dataType: "text",
  259. success: function (data) {
  260. clickflag = 0;
  261. if (data == "success") {
  262. layer.close(index); //关闭弹层
  263. layer.msg('发货成功', {
  264. time: 1500
  265. }, function () {
  266. table.reload('LAY-list-manage'); //数据刷新
  267. });
  268. } else if (data.indexOf("Warning") == 0) {
  269. var datalist = data.split('|');
  270. layer.alert(datalist[1], { time: 20000 }, function () {
  271. window.location.reload();
  272. });
  273. } else {
  274. layer.close(index); //关闭弹层
  275. layer.msg('审核完成', {
  276. time: 1500
  277. }, function () {
  278. table.reload('LAY-list-manage'); //数据刷新
  279. });
  280. }
  281. }
  282. });
  283. }
  284. });
  285. submit.trigger('click');
  286. },
  287. success: function (layero, index) {
  288. }
  289. });
  290. }
  291. });
  292. //监听搜索
  293. form.on('submit(LAY-list-front-search)', function (data) {
  294. var field = data.field;
  295. //执行重载
  296. table.reload('LAY-list-manage', {
  297. where: field,
  298. page: {
  299. curr: 1
  300. }
  301. });
  302. });
  303. form.on('submit(LAY-list-front-searchall)', function (data) {
  304. table.reload('LAY-list-manage', {
  305. where: null,
  306. page: {
  307. curr: 1
  308. }
  309. });
  310. });
  311. //事件
  312. var active = {
  313. batchdel: function () {
  314. var checkStatus = table.checkStatus('LAY-list-manage')
  315. , data = checkStatus.data; //得到选中的数据
  316. if (data.length < 1) {
  317. parent.layer.msg("请选择要删除的项");
  318. } else {
  319. var ids = "";
  320. $.each(data, function (index, value) {
  321. ids += data[index].Id + ",";
  322. });
  323. ids = ids.substring(0, ids.length - 1);
  324. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  325. $.ajax({
  326. type: "POST",
  327. url: "/Admin/StoreMachineApply/Delete?r=" + Math.random(1),
  328. data: "Id=" + ids,
  329. dataType: "text",
  330. success: function (data) {
  331. layer.close(index);
  332. if (data == "success") {
  333. table.reload('LAY-list-manage');
  334. } else {
  335. layer.msg(data);
  336. }
  337. }
  338. });
  339. });
  340. }
  341. }
  342. , add: function () {
  343. var perContent = layer.open({
  344. type: 2
  345. , title: '分仓机具申请记录-添加'
  346. , content: 'Add'
  347. , maxmin: true
  348. , area: ['500px', '450px']
  349. , btn: ['确定', '取消']
  350. , yes: function (index, layero) {
  351. var iframeWindow = window['layui-layer-iframe' + index]
  352. , submitID = 'LAY-list-front-submit'
  353. , submit = layero.find('iframe').contents().find('#' + submitID);
  354. setTimeout(function () {
  355. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  356. var errObj = $(this).find('.layui-form-danger');
  357. if (errObj.length > 0) {
  358. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  359. submit.click();
  360. }
  361. });
  362. }, 300);
  363. //监听提交
  364. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  365. var field = data.field; //获取提交的字段
  366. var userdata = "";
  367. for (var prop in field) {
  368. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  369. }
  370. //提交 Ajax 成功后,静态更新表格中的数据
  371. //$.ajax({});
  372. $.ajax({
  373. type: "POST",
  374. url: "/Admin/StoreMachineApply/Add?r=" + Math.random(1),
  375. data: userdata,
  376. dataType: "text",
  377. success: function (data) {
  378. layer.close(index); //关闭弹层
  379. if (data == "success") {
  380. table.reload('LAY-list-manage'); //数据刷新
  381. } else {
  382. layer.msg(data);
  383. }
  384. }
  385. });
  386. });
  387. submit.trigger('click');
  388. }
  389. });
  390. layer.full(perContent);
  391. }
  392. , ImportData: function () {
  393. ExcelKind = 1;
  394. layer.open({
  395. type: 1,
  396. title: '导入',
  397. maxmin: false,
  398. area: ['460px', '280px'],
  399. content: $('#excelForm'),
  400. cancel: function () {
  401. }
  402. });
  403. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  404. }
  405. , ExportExcel: function () {
  406. var userdata = '';
  407. $(".layuiadmin-card-header-auto input").each(function (i) {
  408. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  409. });
  410. $(".layuiadmin-card-header-auto select").each(function (i) {
  411. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  412. });
  413. $.ajax({
  414. type: "GET",
  415. url: "/Admin/StoreMachineApply/ExportExcel?r=" + Math.random(1),
  416. data: userdata,
  417. dataType: "json",
  418. success: function (data) {
  419. data.Obj.unshift(data.Fields);
  420. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  421. }
  422. });
  423. }
  424. , Open: function () {
  425. var checkStatus = table.checkStatus('LAY-list-manage')
  426. , data = checkStatus.data; //得到选中的数据
  427. if (data.length < 1) {
  428. parent.layer.msg("请选择要开启的项");
  429. } else {
  430. var ids = "";
  431. $.each(data, function (index, value) {
  432. ids += data[index].Id + ",";
  433. });
  434. ids = ids.substring(0, ids.length - 1);
  435. var index = layer.confirm('确定要开启吗?', function (index) {
  436. $.ajax({
  437. type: "POST",
  438. url: "/Admin/StoreMachineApply/Open?r=" + Math.random(1),
  439. data: "Id=" + ids,
  440. dataType: "text",
  441. success: function (data) {
  442. layer.close(index);
  443. if (data == "success") {
  444. table.reload('LAY-list-manage');
  445. } else {
  446. layer.msg(data);
  447. }
  448. }
  449. });
  450. });
  451. }
  452. }
  453. , Close: function () {
  454. var checkStatus = table.checkStatus('LAY-list-manage')
  455. , data = checkStatus.data; //得到选中的数据
  456. if (data.length < 1) {
  457. parent.layer.msg("请选择要关闭的项");
  458. } else {
  459. var ids = "";
  460. $.each(data, function (index, value) {
  461. ids += data[index].Id + ",";
  462. });
  463. ids = ids.substring(0, ids.length - 1);
  464. var index = layer.confirm('确定要关闭吗?', function (index) {
  465. $.ajax({
  466. type: "POST",
  467. url: "/Admin/StoreMachineApply/Close?r=" + Math.random(1),
  468. data: "Id=" + ids,
  469. dataType: "text",
  470. success: function (data) {
  471. layer.close(index);
  472. if (data == "success") {
  473. table.reload('LAY-list-manage');
  474. } else {
  475. layer.msg(data);
  476. }
  477. }
  478. });
  479. });
  480. }
  481. }
  482. };
  483. $('.layui-btn').on('click', function () {
  484. var type = $(this).data('type');
  485. active[type] ? active[type].call(this) : '';
  486. });
  487. });