StoreMachineApply_Admin.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. 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/StoreMachineApplyOperate/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/StoreMachineApplyOperate/IndexData' //模拟接口
  92. , cols: [[
  93. { type: 'checkbox', fixed: 'left' }
  94. , { field: 'CreateDate', width: 150, title: '创建时间', sort: true }
  95. , { field: 'StatusName', width: 150, title: '状态', sort: true }
  96. , { field: 'ApplyNo', width: 150, title: '申请单号', sort: true }
  97. , { field: 'ApplyNum', width: 150, title: '申请台数', sort: true }
  98. , { field: 'SendNum', width: 150, title: '发货台数', sort: true }
  99. , { field: 'UseAmount', width: 150, title: '使用额度', sort: true }
  100. , { field: 'SendMode', width: 150, title: '发货方式', sort: true }
  101. , { field: 'ErpCode', width: 150, title: '快递单号', sort: true }
  102. , { field: 'MakerName', width: 150, title: '创客姓名', sort: true }
  103. , { field: 'MakerCode', width: 150, title: '创客编号', sort: true }
  104. , { field: 'OpCode', width: 150, title: '运营中心编号', sort: true }
  105. , { title: '操作', align: 'center', width: 500, 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/StoreMachineApplyOperate/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/StoreMachineApplyOperate/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/StoreMachineApplyOperate/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/StoreMachineApplyOperate/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. }
  275. }
  276. });
  277. }
  278. });
  279. submit.trigger('click');
  280. },
  281. success: function (layero, index) {
  282. }
  283. });
  284. }
  285. });
  286. //监听搜索
  287. form.on('submit(LAY-list-front-search)', function (data) {
  288. var field = data.field;
  289. //执行重载
  290. table.reload('LAY-list-manage', {
  291. where: field,
  292. page: {
  293. curr: 1
  294. }
  295. });
  296. });
  297. form.on('submit(LAY-list-front-searchall)', function (data) {
  298. table.reload('LAY-list-manage', {
  299. where: null,
  300. page: {
  301. curr: 1
  302. }
  303. });
  304. });
  305. //事件
  306. var active = {
  307. batchdel: function () {
  308. var checkStatus = table.checkStatus('LAY-list-manage')
  309. , data = checkStatus.data; //得到选中的数据
  310. if (data.length < 1) {
  311. parent.layer.msg("请选择要删除的项");
  312. } else {
  313. var ids = "";
  314. $.each(data, function (index, value) {
  315. ids += data[index].Id + ",";
  316. });
  317. ids = ids.substring(0, ids.length - 1);
  318. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  319. $.ajax({
  320. type: "POST",
  321. url: "/Admin/StoreMachineApplyOperate/Delete?r=" + Math.random(1),
  322. data: "Id=" + ids,
  323. dataType: "text",
  324. success: function (data) {
  325. layer.close(index);
  326. if (data == "success") {
  327. table.reload('LAY-list-manage');
  328. } else {
  329. layer.msg(data);
  330. }
  331. }
  332. });
  333. });
  334. }
  335. }
  336. , add: function () {
  337. var perContent = layer.open({
  338. type: 2
  339. , title: '分仓机具申请记录-添加'
  340. , content: 'Add'
  341. , maxmin: true
  342. , area: ['500px', '450px']
  343. , btn: ['确定', '取消']
  344. , yes: function (index, layero) {
  345. var iframeWindow = window['layui-layer-iframe' + index]
  346. , submitID = 'LAY-list-front-submit'
  347. , submit = layero.find('iframe').contents().find('#' + submitID);
  348. setTimeout(function () {
  349. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  350. var errObj = $(this).find('.layui-form-danger');
  351. if (errObj.length > 0) {
  352. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  353. submit.click();
  354. }
  355. });
  356. }, 300);
  357. //监听提交
  358. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  359. var field = data.field; //获取提交的字段
  360. var userdata = "";
  361. for (var prop in field) {
  362. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  363. }
  364. //提交 Ajax 成功后,静态更新表格中的数据
  365. //$.ajax({});
  366. $.ajax({
  367. type: "POST",
  368. url: "/Admin/StoreMachineApplyOperate/Add?r=" + Math.random(1),
  369. data: userdata,
  370. dataType: "text",
  371. success: function (data) {
  372. layer.close(index); //关闭弹层
  373. if (data == "success") {
  374. table.reload('LAY-list-manage'); //数据刷新
  375. } else {
  376. layer.msg(data);
  377. }
  378. }
  379. });
  380. });
  381. submit.trigger('click');
  382. }
  383. });
  384. layer.full(perContent);
  385. }
  386. , ImportData: function () {
  387. ExcelKind = 1;
  388. layer.open({
  389. type: 1,
  390. title: '导入',
  391. maxmin: false,
  392. area: ['460px', '280px'],
  393. content: $('#excelForm'),
  394. cancel: function () {
  395. }
  396. });
  397. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  398. }
  399. , ExportExcel: function () {
  400. var userdata = '';
  401. $(".layuiadmin-card-header-auto input").each(function (i) {
  402. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  403. });
  404. $(".layuiadmin-card-header-auto select").each(function (i) {
  405. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  406. });
  407. $.ajax({
  408. type: "GET",
  409. url: "/Admin/StoreMachineApplyOperate/ExportExcel?r=" + Math.random(1),
  410. data: userdata,
  411. dataType: "json",
  412. success: function (data) {
  413. data.Obj.unshift(data.Fields);
  414. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  415. }
  416. });
  417. }
  418. , Open: function () {
  419. var checkStatus = table.checkStatus('LAY-list-manage')
  420. , data = checkStatus.data; //得到选中的数据
  421. if (data.length < 1) {
  422. parent.layer.msg("请选择要开启的项");
  423. } else {
  424. var ids = "";
  425. $.each(data, function (index, value) {
  426. ids += data[index].Id + ",";
  427. });
  428. ids = ids.substring(0, ids.length - 1);
  429. var index = layer.confirm('确定要开启吗?', function (index) {
  430. $.ajax({
  431. type: "POST",
  432. url: "/Admin/StoreMachineApplyOperate/Open?r=" + Math.random(1),
  433. data: "Id=" + ids,
  434. dataType: "text",
  435. success: function (data) {
  436. layer.close(index);
  437. if (data == "success") {
  438. table.reload('LAY-list-manage');
  439. } else {
  440. layer.msg(data);
  441. }
  442. }
  443. });
  444. });
  445. }
  446. }
  447. , Close: function () {
  448. var checkStatus = table.checkStatus('LAY-list-manage')
  449. , data = checkStatus.data; //得到选中的数据
  450. if (data.length < 1) {
  451. parent.layer.msg("请选择要关闭的项");
  452. } else {
  453. var ids = "";
  454. $.each(data, function (index, value) {
  455. ids += data[index].Id + ",";
  456. });
  457. ids = ids.substring(0, ids.length - 1);
  458. var index = layer.confirm('确定要关闭吗?', function (index) {
  459. $.ajax({
  460. type: "POST",
  461. url: "/Admin/StoreMachineApplyOperate/Close?r=" + Math.random(1),
  462. data: "Id=" + ids,
  463. dataType: "text",
  464. success: function (data) {
  465. layer.close(index);
  466. if (data == "success") {
  467. table.reload('LAY-list-manage');
  468. } else {
  469. layer.msg(data);
  470. }
  471. }
  472. });
  473. });
  474. }
  475. }
  476. };
  477. $('.layui-btn').on('click', function () {
  478. var type = $(this).data('type');
  479. active[type] ? active[type].call(this) : '';
  480. });
  481. });