StoreMachineApplys_Admin.js 21 KB

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