StoreMachineApply_Admin.js 20 KB

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