StoreMachineApplys1_Admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. var ExcelData, ExcelKind;
  2. var clickflag = 0;
  3. function ConfirmImport() {
  4. $.ajax({
  5. type: "POST",
  6. url: "/Admin/StoreMachineApplysOperate/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/StoreMachineApplysOperate/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/StoreMachineApplysOperate/Indexs1Data' //模拟接口
  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: 'RealName', 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/StoreMachineApplysOperate/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/StoreMachineApplysOperate/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. loadindex = layer.load(1, {
  208. shade: [0.5, '#000']
  209. });
  210. $.ajax({
  211. type: "POST",
  212. url: "/Admin/StoreMachineApplysOperate/Close?r=" + Math.random(1),
  213. data: "Id=" + data.Id,
  214. dataType: "text",
  215. success: function (data) {
  216. layer.close(index); //关闭弹层
  217. if (data == "success") {
  218. layer.msg("已驳回", { time: 1500 }, function () {
  219. table.reload('LAY-list-manage'); //数据刷新
  220. });
  221. } else {
  222. parent.layer.msg(data);
  223. }
  224. }
  225. });
  226. });
  227. } else if (obj.event === 'audit') {
  228. var tr = $(obj.tr);
  229. var perContent = layer.open({
  230. type: 2,
  231. title: '审核发货',
  232. content: 'AuditSend?Id=' + data.Id + '',
  233. maxmin: true,
  234. area: ['450px', '680px'],
  235. btn: ['确定发货', '取消'],
  236. yes: function (index, layero) {
  237. loadindex = layer.load(1, {
  238. shade: [0.5, '#000']
  239. });
  240. var iframeWindow = window['layui-layer-iframe' + index],
  241. submitID = 'LAY-list-front-submit',
  242. submit = layero.find('iframe').contents().find('#' + submitID);
  243. setTimeout(function () {
  244. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  245. var errObj = $(this).find('.layui-form-danger');
  246. if (errObj.length > 0) {
  247. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  248. submit.click();
  249. }
  250. });
  251. }, 300);
  252. //监听提交
  253. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  254. if (clickflag == 0) {
  255. clickflag = 1;
  256. var field = data.field; //获取提交的字段
  257. var userdata = "";
  258. for (var prop in field) {
  259. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  260. }
  261. //提交 Ajax 成功后,静态更新表格中的数据
  262. //$.ajax({});
  263. $.ajax({
  264. type: "POST",
  265. url: "/Admin/StoreMachineApplysOperate/AuditSend?r=" + Math.random(1),
  266. data: userdata,
  267. dataType: "text",
  268. success: function (data) {
  269. clickflag = 0;
  270. if (data == "success") {
  271. layer.close(index); //关闭弹层
  272. layer.msg('发货成功', {
  273. time: 1500
  274. }, function () {
  275. table.reload('LAY-list-manage'); //数据刷新
  276. });
  277. } else if (data.indexOf("Warning") == 0) {
  278. var datalist = data.split('|');
  279. layer.alert(datalist[1], { time: 20000 }, function () {
  280. window.location.reload();
  281. });
  282. } else {
  283. layer.close(index); //关闭弹层
  284. layer.msg('审核完成', {
  285. time: 1500
  286. }, function () {
  287. table.reload('LAY-list-manage'); //数据刷新
  288. });
  289. }
  290. }
  291. });
  292. }
  293. });
  294. submit.trigger('click');
  295. },
  296. success: function (layero, index) {
  297. }
  298. });
  299. }
  300. });
  301. //监听搜索
  302. form.on('submit(LAY-list-front-search)', function (data) {
  303. var field = data.field;
  304. //执行重载
  305. table.reload('LAY-list-manage', {
  306. where: field,
  307. page: {
  308. curr: 1
  309. }
  310. });
  311. });
  312. form.on('submit(LAY-list-front-searchall)', function (data) {
  313. table.reload('LAY-list-manage', {
  314. where: null,
  315. page: {
  316. curr: 1
  317. }
  318. });
  319. });
  320. //事件
  321. var active = {
  322. batchdel: function () {
  323. var checkStatus = table.checkStatus('LAY-list-manage')
  324. , data = checkStatus.data; //得到选中的数据
  325. if (data.length < 1) {
  326. parent.layer.msg("请选择要删除的项");
  327. } else {
  328. var ids = "";
  329. $.each(data, function (index, value) {
  330. ids += data[index].Id + ",";
  331. });
  332. ids = ids.substring(0, ids.length - 1);
  333. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  334. $.ajax({
  335. type: "POST",
  336. url: "/Admin/StoreMachineApplysOperate/Delete?r=" + Math.random(1),
  337. data: "Id=" + ids,
  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. }
  350. }
  351. , add: function () {
  352. var perContent = layer.open({
  353. type: 2
  354. , title: '分仓机具申请记录-添加'
  355. , content: 'Add'
  356. , maxmin: true
  357. , area: ['500px', '450px']
  358. , btn: ['确定', '取消']
  359. , yes: function (index, layero) {
  360. var iframeWindow = window['layui-layer-iframe' + index]
  361. , submitID = 'LAY-list-front-submit'
  362. , submit = layero.find('iframe').contents().find('#' + submitID);
  363. setTimeout(function () {
  364. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  365. var errObj = $(this).find('.layui-form-danger');
  366. if (errObj.length > 0) {
  367. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  368. submit.click();
  369. }
  370. });
  371. }, 300);
  372. //监听提交
  373. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  374. var field = data.field; //获取提交的字段
  375. var userdata = "";
  376. for (var prop in field) {
  377. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  378. }
  379. //提交 Ajax 成功后,静态更新表格中的数据
  380. //$.ajax({});
  381. $.ajax({
  382. type: "POST",
  383. url: "/Admin/StoreMachineApplysOperate/Add?r=" + Math.random(1),
  384. data: userdata,
  385. dataType: "text",
  386. success: function (data) {
  387. layer.close(index); //关闭弹层
  388. if (data == "success") {
  389. table.reload('LAY-list-manage'); //数据刷新
  390. } else {
  391. layer.msg(data);
  392. }
  393. }
  394. });
  395. });
  396. submit.trigger('click');
  397. }
  398. });
  399. layer.full(perContent);
  400. }
  401. , ImportData: function () {
  402. ExcelKind = 1;
  403. layer.open({
  404. type: 1,
  405. title: '导入',
  406. maxmin: false,
  407. area: ['460px', '280px'],
  408. content: $('#excelForm'),
  409. cancel: function () {
  410. }
  411. });
  412. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  413. }
  414. , ExportExcel: function () {
  415. var userdata = '';
  416. $(".layuiadmin-card-header-auto input").each(function (i) {
  417. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  418. });
  419. $(".layuiadmin-card-header-auto select").each(function (i) {
  420. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  421. });
  422. $.ajax({
  423. type: "GET",
  424. url: "/Admin/StoreMachineApplysOperate/ExportExcel?r=" + Math.random(1),
  425. data: userdata,
  426. dataType: "json",
  427. success: function (data) {
  428. data.Obj.unshift(data.Fields);
  429. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  430. }
  431. });
  432. }
  433. , Open: function () {
  434. var checkStatus = table.checkStatus('LAY-list-manage')
  435. , data = checkStatus.data; //得到选中的数据
  436. if (data.length < 1) {
  437. parent.layer.msg("请选择要开启的项");
  438. } else {
  439. var ids = "";
  440. $.each(data, function (index, value) {
  441. ids += data[index].Id + ",";
  442. });
  443. ids = ids.substring(0, ids.length - 1);
  444. var index = layer.confirm('确定要开启吗?', function (index) {
  445. $.ajax({
  446. type: "POST",
  447. url: "/Admin/StoreMachineApplysOperate/Open?r=" + Math.random(1),
  448. data: "Id=" + ids,
  449. dataType: "text",
  450. success: function (data) {
  451. layer.close(index);
  452. if (data == "success") {
  453. table.reload('LAY-list-manage');
  454. } else {
  455. layer.msg(data);
  456. }
  457. }
  458. });
  459. });
  460. }
  461. }
  462. , Close: function () {
  463. var checkStatus = table.checkStatus('LAY-list-manage')
  464. , data = checkStatus.data; //得到选中的数据
  465. if (data.length < 1) {
  466. parent.layer.msg("请选择要关闭的项");
  467. } else {
  468. var ids = "";
  469. $.each(data, function (index, value) {
  470. ids += data[index].Id + ",";
  471. });
  472. ids = ids.substring(0, ids.length - 1);
  473. var index = layer.confirm('确定要关闭吗?', function (index) {
  474. $.ajax({
  475. type: "POST",
  476. url: "/Admin/StoreMachineApplysOperate/Close?r=" + Math.random(1),
  477. data: "Id=" + ids,
  478. dataType: "text",
  479. success: function (data) {
  480. layer.close(index);
  481. if (data == "success") {
  482. table.reload('LAY-list-manage');
  483. } else {
  484. layer.msg(data);
  485. }
  486. }
  487. });
  488. });
  489. }
  490. }
  491. };
  492. $('.layui-btn').on('click', function () {
  493. var type = $(this).data('type');
  494. active[type] ? active[type].call(this) : '';
  495. });
  496. });