StoreMachineApply_Admin.js 21 KB

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