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/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: 'ApplyNo', width: 200, title: '申请单号', sort: true }
  97. , { field: 'ApplyNum', width: 200, title: '申请台数', sort: true }
  98. , { field: 'SendNum', width: 200, title: '发货台数', sort: true }
  99. , { field: 'UseAmount', width: 200, title: '使用额度', sort: true }
  100. , { field: 'SendMode', width: 200, title: '发货方式', sort: true }
  101. , { field: 'ErpCode', width: 200, title: '快递单号', sort: true }
  102. , { field: 'UserIdRealName', width: 200, title: '创客真实姓名', sort: true }
  103. , { field: 'UserIdMakerCode', width: 200, title: '创客创客编号', sort: true }
  104. , { title: '操作', align: 'center', width: 300, fixed: 'right', toolbar: '#table-list-tools' }
  105. ]]
  106. , where: {
  107. }
  108. , page: true
  109. , limit: 30
  110. , height: 'full-220'
  111. , text: '对不起,加载出现异常!'
  112. , done: function (res, curr, count) {
  113. $(".layui-none").text("无数据");
  114. }
  115. });
  116. //监听工具条
  117. table.on('tool(LAY-list-manage)', function (obj) {
  118. var data = obj.data;
  119. if (obj.event === 'del') {
  120. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  121. $.ajax({
  122. type: "POST",
  123. url: "/Admin/StoreMachineApply/Delete?r=" + Math.random(1),
  124. data: "Id=" + data.Id,
  125. dataType: "text",
  126. success: function (data) {
  127. if (data == "success") {
  128. obj.del();
  129. layer.close(index);
  130. } else {
  131. parent.layer.msg(data);
  132. }
  133. }
  134. });
  135. });
  136. } else if (obj.event === 'edit') {
  137. var tr = $(obj.tr);
  138. var perContent = layer.open({
  139. type: 2
  140. , title: '分仓机具申请记录-编辑'
  141. , content: 'Edit?Id=' + data.Id + ''
  142. , maxmin: true
  143. , area: ['500px', '450px']
  144. , btn: ['确定', '取消']
  145. , yes: function (index, layero) {
  146. var iframeWindow = window['layui-layer-iframe' + index]
  147. , submitID = 'LAY-list-front-submit'
  148. , submit = layero.find('iframe').contents().find('#' + submitID);
  149. setTimeout(function () {
  150. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  151. var errObj = $(this).find('.layui-form-danger');
  152. if (errObj.length > 0) {
  153. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  154. submit.click();
  155. }
  156. });
  157. }, 300);
  158. var SendSn = '[';
  159. var ApplyNums = layero.find('iframe').contents().find('.productlist input[type=text][name=ApplyNum]');
  160. layero.find('iframe').contents().find('.productlist input[type=hidden][name=BrandId]').each(function (i) {
  161. var BrandId = $(this).val();
  162. var ApplyNum = ApplyNums.eq(i).val();
  163. SendSn += '{"ApplyNum":' + ApplyNum + ',"BrandId":' + BrandId + '}';
  164. if (i < ApplyNums.length - 1) {
  165. SendSn += ',';
  166. }
  167. });
  168. SendSn += ']';
  169. layero.find('iframe').contents().find('#SendSn').val(SendSn);
  170. //监听提交
  171. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  172. var field = data.field; //获取提交的字段
  173. var userdata = "";
  174. for (var prop in field) {
  175. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  176. }
  177. //提交 Ajax 成功后,静态更新表格中的数据
  178. //$.ajax({});
  179. $.ajax({
  180. type: "POST",
  181. url: "/Admin/StoreMachineApply/Edit?r=" + Math.random(1),
  182. data: userdata,
  183. dataType: "text",
  184. success: function (data) {
  185. layer.close(index); //关闭弹层
  186. if (data == "success") {
  187. layer.msg("修改成功", { time: 500 }, function () {
  188. table.reload('LAY-list-manage'); //数据刷新
  189. });
  190. } else {
  191. layer.msg(data);
  192. }
  193. }
  194. });
  195. });
  196. submit.trigger('click');
  197. }
  198. , success: function (layero, index) {
  199. }
  200. });
  201. // layer.full(perContent);
  202. } else if (obj.event === 'Close') {
  203. var index = layer.confirm('是否确定驳回?驳回后使用额度将返回该创客的可用额度', function (index) {
  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. 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. });