Orders_Admin.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. var ExcelData,ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/Orders/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 {
  14. layer.msg(data);
  15. }
  16. }
  17. });
  18. }
  19. var excel;
  20. layui.config({
  21. base: '/layuiadmin/' //静态资源所在路径
  22. }).extend({
  23. myexcel: 'layui/lay/modules/excel',
  24. index: 'lib/index' //主入口模块
  25. }).use(['index', 'table', 'excel', 'laydate'], function () {
  26. var $ = layui.$
  27. , form = layui.form
  28. , table = layui.table;
  29. //- 筛选条件-日期
  30. var laydate = layui.laydate;
  31. var layCreateDate = laydate.render({
  32. elem: '#CreateDate',
  33. type: 'datetime',
  34. range: true,
  35. trigger: 'click',
  36. change: function (value, date, endDate) {
  37. var op = true;
  38. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  39. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  40. op = false;
  41. layCreateDate.hint('日期范围请不要超过1个月');
  42. setTimeout(function () {
  43. $(".laydate-btns-confirm").addClass("laydate-disabled");
  44. }, 1);
  45. }
  46. } else {
  47. op = false;
  48. layCreateDate.hint('日期范围请不要超过1个月');
  49. setTimeout(function () {
  50. $(".laydate-btns-confirm").addClass("laydate-disabled");
  51. }, 1);
  52. }
  53. if (op) {
  54. $('#CreateDate').val(value);
  55. }
  56. }
  57. });
  58. var laySendDate = laydate.render({
  59. elem: '#SendDate',
  60. trigger: 'click',
  61. type: 'datetime',
  62. range: true,
  63. change: function (value, date, endDate) {
  64. var op = true;
  65. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  66. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  67. op = false;
  68. laySendDate.hint('日期范围请不要超过1个月');
  69. setTimeout(function () {
  70. $(".laydate-btns-confirm").addClass("laydate-disabled");
  71. }, 1);
  72. }
  73. } else {
  74. op = false;
  75. laySendDate.hint('日期范围请不要超过1个月');
  76. setTimeout(function () {
  77. $(".laydate-btns-confirm").addClass("laydate-disabled");
  78. }, 1);
  79. }
  80. if (op) {
  81. $('#SendDate').val(value);
  82. }
  83. }
  84. });
  85. //excel导入
  86. excel = layui.excel;
  87. $('#ExcelFile').change(function (e) {
  88. var files = e.target.files;
  89. excel.importExcel(files, { }, function (data) {
  90. ExcelData = data[0].sheet1;
  91. });
  92. });
  93. //监听单元格编辑
  94. table.on('edit(LAY-list-manage)', function(obj){
  95. var value = obj.value //得到修改后的值
  96. ,data = obj.data //得到所在行所有键值
  97. ,field = obj.field; //得到字段
  98. if(field == "Sort"){
  99. $.ajax({
  100. type: "POST",
  101. url: "/Admin/Orders/Sort?r=" + Math.random(1),
  102. data: "Id=" + data.Id + "&Sort=" + value,
  103. dataType: "text",
  104. success: function (data) {
  105. }
  106. });
  107. }
  108. });
  109. //列表数据
  110. table.render({
  111. elem: '#LAY-list-manage'
  112. , url: '/Admin/Orders/IndexData' //模拟接口
  113. , cols: [[
  114. { type: 'checkbox', fixed: 'left' }
  115. , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
  116. ,{field:'OrderNo', width: 200, title:'平台订单号-渠道订单号', sort: true}
  117. ,{field:'Store', width: 200, title:'发货仓库信息', sort: true}
  118. ,{field:'StoreContact', width: 200, title:'仓库联系人信息', sort: true}
  119. ,{field:'StoreFrom', width: 200, title:'仓库归属信息', sort: true}
  120. ,{field:'UserInfo', width: 200, title:'创客信息', sort: true}
  121. ,{field:'TopUserInfo', width: 200, title:'顶级创客信息', sort: true}
  122. ,{field:'Address', width: 200, title:'收货地址', sort: true}
  123. ,{field:'RecieveInfo', width: 200, title:'收件人姓名-联系电话', sort: true}
  124. ,{field:'PayMode', width: 200, title:'支付渠道', sort: true}
  125. ,{field:'TotalPrice', width: 200, title:'订单金额', sort: true}
  126. ,{field:'PayStatus', width: 200, title:'支付状态', sort: true}
  127. ,{field:'DeliveryType', width: 200, title:'提货类型', sort: true}
  128. ,{field:'Remark', width: 200, title:'订单备注', sort: true}
  129. ,{field:'SendInfo', width: 200, title:'发货状态-发货时间', sort: true}
  130. ,{field:'RefundStatusName', width: 200, title:'退款状态', sort: true}
  131. ,{field:'ErpInfo', width: 200, title:'快递单号-快递名称', sort: true}
  132. ,{field:'CreateDate', width: 200, title:'下单时间', sort: true}
  133. , { title: '操作', align: 'center', width: 300, fixed: 'right', toolbar: '#table-list-tools' }
  134. ]]
  135. , where: {
  136. }
  137. , page: true
  138. , limit: 30
  139. , height: 'full-220'
  140. , text: '对不起,加载出现异常!'
  141. , done: function (res, curr, count) {
  142. $("#SuccessAmount").text(res.other.SuccessAmount.toFixed(2));
  143. $("#FailAmount").text(res.other.FailAmount.toFixed(2));
  144. $(".layui-none").text("无数据");
  145. }
  146. });
  147. //监听工具条
  148. table.on('tool(LAY-list-manage)', function (obj) {
  149. var data = obj.data;
  150. if (obj.event === 'del') {
  151. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  152. $.ajax({
  153. type: "POST",
  154. url: "/Admin/Orders/Delete?r=" + Math.random(1),
  155. data: "Id=" + data.Id,
  156. dataType: "text",
  157. success: function (data) {
  158. if (data == "success") {
  159. obj.del();
  160. layer.close(index);
  161. } else {
  162. parent.layer.msg(data);
  163. }
  164. }
  165. });
  166. });
  167. } else if (obj.event === 'edit') {
  168. var tr = $(obj.tr);
  169. var perContent = layer.open({
  170. type: 2
  171. , title: '创客订单-编辑'
  172. , content: 'Edit?Id=' + data.Id + ''
  173. , maxmin: true
  174. , area: ['500px', '450px']
  175. , btn: ['确定', '取消']
  176. , yes: function (index, layero) {
  177. var iframeWindow = window['layui-layer-iframe' + index]
  178. , submitID = 'LAY-list-front-submit'
  179. , submit = layero.find('iframe').contents().find('#' + submitID);
  180. setTimeout(function () {
  181. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  182. var errObj = $(this).find('.layui-form-danger');
  183. if (errObj.length > 0) {
  184. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  185. submit.click();
  186. }
  187. });
  188. }, 300);
  189. //监听提交
  190. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  191. var field = data.field; //获取提交的字段
  192. var userdata = "";
  193. for (var prop in field) {
  194. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  195. }
  196. //提交 Ajax 成功后,静态更新表格中的数据
  197. //$.ajax({});
  198. $.ajax({
  199. type: "POST",
  200. url: "/Admin/Orders/Edit?r=" + Math.random(1),
  201. data: userdata,
  202. dataType: "text",
  203. success: function (data) {
  204. layer.close(index); //关闭弹层
  205. if (data == "success") {
  206. table.reload('LAY-list-manage'); //数据刷新
  207. } else {
  208. layer.msg(data);
  209. }
  210. }
  211. });
  212. });
  213. submit.trigger('click');
  214. }
  215. , success: function (layero, index) {
  216. }
  217. });
  218. layer.full(perContent);
  219. } else if (obj.event === 'detail') {
  220. var tr = $(obj.tr);
  221. var perContent = layer.open({
  222. type: 2
  223. , title: '订单详情'
  224. , content: 'Detail?Id=' + data.Id + ''
  225. , maxmin: true
  226. , area: ['700px', '650px']
  227. , btn: ['关闭']
  228. , yes: function (index, layero) {
  229. layer.close(index);
  230. }
  231. , success: function (layero, index) {
  232. }
  233. });
  234. layer.full(perContent);
  235. } else if (obj.event === 'send') {
  236. var tr = $(obj.tr);
  237. var perContent = layer.open({
  238. type: 2
  239. , title: '创客订单-编辑'
  240. , content: 'Send?Id=' + data.Id + ''
  241. , maxmin: true
  242. , area: ['500px', '650px']
  243. , btn: ['提交', '取消']
  244. , yes: function (index, layero) {
  245. var iframeWindow = window['layui-layer-iframe' + index]
  246. , submitID = 'LAY-list-front-submit'
  247. , submit = layero.find('iframe').contents().find('#' + submitID);
  248. setTimeout(function () {
  249. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  250. var errObj = $(this).find('.layui-form-danger');
  251. if (errObj.length > 0) {
  252. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  253. submit.click();
  254. }
  255. });
  256. }, 300);
  257. //监听提交
  258. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  259. var field = data.field; //获取提交的字段
  260. var userdata = "";
  261. for (var prop in field) {
  262. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  263. }
  264. //提交 Ajax 成功后,静态更新表格中的数据
  265. //$.ajax({});
  266. var IdList = '';
  267. layero.find('iframe').contents().find('input[type=hidden][name=IdList]').each(function (i) {
  268. IdList += $(this).val() + "#";
  269. });
  270. userdata += "&IdList=" + IdList;
  271. var StoreIdList = '';
  272. layero.find('iframe').contents().find('select[name=StoreIdList]').each(function (i) {
  273. StoreIdList += $(this).val() + "#";
  274. });
  275. userdata += "&StoreIdList=" + StoreIdList;
  276. var SnNosList = '';
  277. layero.find('iframe').contents().find('textarea[name=SnNosList]').each(function (i) {
  278. SnNosList += $(this).val() + "#";
  279. });
  280. userdata += "&SnNosList=" + SnNosList;
  281. $.ajax({
  282. type: "POST",
  283. url: "/Admin/Orders/Send?r=" + Math.random(1),
  284. data: userdata,
  285. dataType: "text",
  286. success: function (data) {
  287. if (data == "success") {
  288. layer.close(index); //关闭弹层
  289. layer.msg('提交成功', { time: 1500 }, function () {
  290. table.reload('LAY-list-manage'); //数据刷新
  291. });
  292. } else {
  293. layer.msg(data);
  294. }
  295. }
  296. });
  297. });
  298. submit.trigger('click');
  299. }
  300. , success: function (layero, index) {
  301. }
  302. });
  303. } else if (obj.event === 'return') {
  304. var tr = $(obj.tr);
  305. var perContent = layer.open({
  306. type: 2
  307. , title: '退货'
  308. , content: 'Return?Id=' + data.Id + ''
  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/Orders/Return?r=" + Math.random(1),
  337. data: userdata,
  338. dataType: "text",
  339. success: function (data) {
  340. if (data == "success") {
  341. layer.close(index); //关闭弹层
  342. layer.msg('提交成功', { time: 1500 }, function () {
  343. table.reload('LAY-list-manage'); //数据刷新
  344. });
  345. } else {
  346. layer.msg(data);
  347. }
  348. }
  349. });
  350. });
  351. submit.trigger('click');
  352. }
  353. , success: function (layero, index) {
  354. }
  355. });
  356. } else if (obj.event === 'prize100') {
  357. var loadindex = layer.load(1, {
  358. shade: [0.5, '#000']
  359. });
  360. $.ajax({
  361. url: "/Admin/Orders/Prize100?r=" + Math.random(1),
  362. data: "Id=" + data.Id,
  363. dataType: "json",
  364. success: function (data) {
  365. layer.close(loadindex);
  366. if (data.code == '1') {
  367. layer.alert(data.result.replace(/\n/g, '<br />'), { area: ['680px', '460px'] });
  368. } else {
  369. var index = layer.confirm(data.result.replace(/\n/g, '<br />') + '<br />是否立即补发?', { area: ['500px', '460px'] }, function (index) {
  370. $.ajax({
  371. type: "POST",
  372. url: "/Admin/Orders/AddPrize100?r=" + Math.random(1),
  373. data: "Id=" + data.Id,
  374. dataType: "text",
  375. success: function (data) {
  376. if (data == "success") {
  377. layer.close(index);
  378. layer.msg("补发成功");
  379. } else {
  380. layer.msg(data);
  381. }
  382. }
  383. });
  384. });
  385. }
  386. }
  387. });
  388. }
  389. });
  390. //监听搜索
  391. form.on('submit(LAY-list-front-search)', function (data) {
  392. var field = data.field;
  393. //执行重载
  394. table.reload('LAY-list-manage', {
  395. where: field
  396. });
  397. });
  398. form.on('submit(LAY-list-front-searchall)', function (data) {
  399. table.reload('LAY-list-manage', {
  400. where: null
  401. });
  402. });
  403. //事件
  404. var active = {
  405. batchdel: function () {
  406. var checkStatus = table.checkStatus('LAY-list-manage')
  407. , data = checkStatus.data; //得到选中的数据
  408. if (data.length < 1) {
  409. parent.layer.msg("请选择要删除的项");
  410. } else {
  411. var ids = "";
  412. $.each(data, function (index, value) {
  413. ids += data[index].Id + ",";
  414. });
  415. ids = ids.substring(0, ids.length - 1);
  416. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  417. $.ajax({
  418. type: "POST",
  419. url: "/Admin/Orders/Delete?r=" + Math.random(1),
  420. data: "Id=" + ids,
  421. dataType: "text",
  422. success: function (data) {
  423. layer.close(index);
  424. if (data == "success") {
  425. table.reload('LAY-list-manage');
  426. } else {
  427. layer.msg(data);
  428. }
  429. }
  430. });
  431. });
  432. }
  433. }
  434. , add: function () {
  435. var perContent = layer.open({
  436. type: 2
  437. , title: '创客订单-添加'
  438. , content: 'Add'
  439. , maxmin: true
  440. , area: ['500px', '450px']
  441. , btn: ['确定', '取消']
  442. , yes: function (index, layero) {
  443. var iframeWindow = window['layui-layer-iframe' + index]
  444. , submitID = 'LAY-list-front-submit'
  445. , submit = layero.find('iframe').contents().find('#' + submitID);
  446. setTimeout(function () {
  447. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  448. var errObj = $(this).find('.layui-form-danger');
  449. if (errObj.length > 0) {
  450. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  451. submit.click();
  452. }
  453. });
  454. }, 300);
  455. //监听提交
  456. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  457. var field = data.field; //获取提交的字段
  458. var userdata = "";
  459. for (var prop in field) {
  460. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  461. }
  462. //提交 Ajax 成功后,静态更新表格中的数据
  463. //$.ajax({});
  464. $.ajax({
  465. type: "POST",
  466. url: "/Admin/Orders/Add?r=" + Math.random(1),
  467. data: userdata,
  468. dataType: "text",
  469. success: function (data) {
  470. layer.close(index); //关闭弹层
  471. if (data == "success") {
  472. table.reload('LAY-list-manage'); //数据刷新
  473. } else {
  474. layer.msg(data);
  475. }
  476. }
  477. });
  478. });
  479. submit.trigger('click');
  480. }
  481. });
  482. layer.full(perContent);
  483. }
  484. , ImportData: function () {
  485. ExcelKind = 1;
  486. layer.open({
  487. type: 1,
  488. title: '导入',
  489. maxmin: false,
  490. area: ['460px', '280px'],
  491. content: $('#excelForm'),
  492. cancel: function () {
  493. }
  494. });
  495. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  496. }
  497. , ExportExcel: function () {
  498. var userdata = '';
  499. $(".layuiadmin-card-header-auto input").each(function (i) {
  500. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  501. });
  502. $(".layuiadmin-card-header-auto select").each(function (i) {
  503. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  504. });
  505. var index = layer.load(1, {
  506. shade: [0.8, '#000'],
  507. content: '',
  508. success: function (layero) {
  509. var obj = layero.find('.layui-layer-content').css({
  510. 'padding-top': '10px',
  511. 'width': '200px',
  512. 'color': '#fff',
  513. 'text-align': 'center'
  514. });
  515. var st = setInterval(function () {
  516. $.ajax({
  517. type: "GET",
  518. url: "/Admin/Orders/CheckExport?r=" + Math.random(1),
  519. dataType: "text",
  520. success: function (data) {
  521. if (data == "finish") {
  522. clearInterval(st);
  523. } else {
  524. obj.text(data);
  525. }
  526. }
  527. });
  528. }, 1000);
  529. }
  530. });
  531. $.ajax({
  532. type: "GET",
  533. url: "/Admin/Orders/ExportExcel?r=" + Math.random(1),
  534. data: userdata,
  535. dataType: "text",
  536. success: function (data) {
  537. layer.close(index);
  538. if (data.indexOf("success|") > -1) {
  539. var datalist = data.split('|');
  540. window.location.href = datalist[1];
  541. } else {
  542. layer.msg('导出失败');
  543. }
  544. // data.Obj.unshift(data.Fields);
  545. // excel.exportExcel(data.Obj, data.Info, 'xlsx');
  546. }
  547. });
  548. }
  549. , Open: function () {
  550. var checkStatus = table.checkStatus('LAY-list-manage')
  551. , data = checkStatus.data; //得到选中的数据
  552. if(data.length < 1){
  553. parent.layer.msg("请选择要开启的项");
  554. }else{
  555. var ids = "";
  556. $.each(data, function (index, value) {
  557. ids += data[index].Id + ",";
  558. });
  559. ids = ids.substring(0, ids.length - 1);
  560. var index = layer.confirm('确定要开启吗?', function (index) {
  561. $.ajax({
  562. type: "POST",
  563. url: "/Admin/Orders/Open?r=" + Math.random(1),
  564. data: "Id=" + ids,
  565. dataType: "text",
  566. success: function (data) {
  567. layer.close(index);
  568. if (data == "success") {
  569. table.reload('LAY-list-manage');
  570. } else {
  571. layer.msg(data);
  572. }
  573. }
  574. });
  575. });
  576. }
  577. }
  578. , Close: function () {
  579. var checkStatus = table.checkStatus('LAY-list-manage')
  580. , data = checkStatus.data; //得到选中的数据
  581. if(data.length < 1){
  582. parent.layer.msg("请选择要关闭的项");
  583. }else{
  584. var ids = "";
  585. $.each(data, function (index, value) {
  586. ids += data[index].Id + ",";
  587. });
  588. ids = ids.substring(0, ids.length - 1);
  589. var index = layer.confirm('确定要关闭吗?', function (index) {
  590. $.ajax({
  591. type: "POST",
  592. url: "/Admin/Orders/Close?r=" + Math.random(1),
  593. data: "Id=" + ids,
  594. dataType: "text",
  595. success: function (data) {
  596. layer.close(index);
  597. if (data == "success") {
  598. table.reload('LAY-list-manage');
  599. } else {
  600. layer.msg(data);
  601. }
  602. }
  603. });
  604. });
  605. }
  606. }
  607. };
  608. $('.layui-btn').on('click', function () {
  609. var type = $(this).data('type');
  610. active[type] ? active[type].call(this) : '';
  611. });
  612. });