OrderRefundReason_Admin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/OrderRefundReason/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("导入成功", {
  11. time: 2000
  12. }, function () {
  13. window.location.reload();
  14. });
  15. } else {
  16. layer.msg(data);
  17. }
  18. }
  19. });
  20. }
  21. layui.config({
  22. base: '/layuiadmin/' //静态资源所在路径
  23. }).extend({
  24. myexcel: 'layui/lay/modules/excel',
  25. index: 'lib/index' //主入口模块
  26. }).use(['index', 'table', 'excel', 'laydate'], function () {
  27. var $ = layui.$,
  28. form = layui.form,
  29. table = layui.table;
  30. //- 筛选条件-日期
  31. var laydate = layui.laydate;
  32. //excel导入
  33. var excel = layui.excel;
  34. $('#ExcelFile').change(function (e) {
  35. var files = e.target.files;
  36. excel.importExcel(files, {}, function (data) {
  37. ExcelData = data[0].Sheet1;
  38. });
  39. });
  40. //监听单元格编辑
  41. table.on('edit(LAY-list-manage)', function (obj) {
  42. var value = obj.value //得到修改后的值
  43. ,
  44. data = obj.data //得到所在行所有键值
  45. ,
  46. field = obj.field; //得到字段
  47. if (field == "Sort") {
  48. $.ajax({
  49. type: "POST",
  50. url: "/Admin/OrderRefundReason/Sort?r=" + Math.random(1),
  51. data: "Id=" + data.Id + "&Sort=" + value,
  52. dataType: "text",
  53. success: function (data) {}
  54. });
  55. }
  56. });
  57. //列表数据
  58. table.render({
  59. elem: '#LAY-list-manage',
  60. url: '/Admin/OrderRefundReason/IndexData' //模拟接口
  61. ,
  62. cols: [
  63. [{
  64. type: 'checkbox',
  65. fixed: 'left'
  66. }, {
  67. field: 'Id',
  68. fixed: 'left',
  69. title: 'ID',
  70. width: 80,
  71. sort: true,
  72. unresize: true
  73. }, {
  74. field: 'Name',
  75. title: '名称',
  76. sort: true
  77. }, {
  78. field: 'Sort',
  79. fixed: 'right',
  80. title: '排序',
  81. width: 80,
  82. edit: 'text'
  83. }, {
  84. title: '操作',
  85. width: 150,
  86. align: 'center',
  87. fixed: 'right',
  88. toolbar: '#table-list-tools'
  89. }]
  90. ],
  91. page: true,
  92. limit: 30,
  93. height: 'full-' + String($('.layui-card-header').height() + 130),
  94. text: '对不起,加载出现异常!',
  95. done: function (res, curr, count) {
  96. $(".layui-none").text("无数据");
  97. }
  98. });
  99. //监听工具条
  100. table.on('tool(LAY-list-manage)', function (obj) {
  101. var data = obj.data;
  102. if (obj.event === 'del') {
  103. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  104. $.ajax({
  105. type: "POST",
  106. url: "/Admin/OrderRefundReason/Delete?r=" + Math.random(1),
  107. data: "Id=" + data.Id,
  108. dataType: "text",
  109. success: function (data) {
  110. if (data == "success") {
  111. obj.del();
  112. layer.close(index);
  113. } else {
  114. parent.layer.msg(data);
  115. }
  116. }
  117. });
  118. });
  119. } else if (obj.event === 'edit') {
  120. var tr = $(obj.tr);
  121. var perContent = layer.open({
  122. type: 2,
  123. title: '退款原因-编辑',
  124. content: 'Edit?Id=' + data.Id,
  125. maxmin: true,
  126. area: ['500px', '450px'],
  127. btn: ['确定', '取消'],
  128. yes: function (index, layero) {
  129. var iframeWindow = window['layui-layer-iframe' + index],
  130. submitID = 'LAY-list-front-submit',
  131. submit = layero.find('iframe').contents().find('#' + submitID);
  132. //监听提交
  133. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  134. var field = data.field; //获取提交的字段
  135. var userdata = "";
  136. for (var prop in field) {
  137. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  138. }
  139. //提交 Ajax 成功后,静态更新表格中的数据
  140. //$.ajax({});
  141. $.ajax({
  142. type: "POST",
  143. url: "/Admin/OrderRefundReason/Edit?r=" + Math.random(1),
  144. data: userdata,
  145. dataType: "text",
  146. success: function (data) {
  147. layer.close(index); //关闭弹层
  148. if (data == "success") {
  149. table.reload('LAY-list-manage'); //数据刷新
  150. } else {
  151. layer.msg(data);
  152. }
  153. }
  154. });
  155. });
  156. submit.trigger('click');
  157. },
  158. success: function (layero, index) {
  159. }
  160. });
  161. layer.full(perContent);
  162. }
  163. });
  164. //监听搜索
  165. form.on('submit(LAY-list-front-search)', function (data) {
  166. var field = data.field;
  167. //执行重载
  168. table.reload('LAY-list-manage', {
  169. where: field,
  170. page: {
  171. curr: 1
  172. }
  173. });
  174. });
  175. form.on('submit(LAY-list-front-searchall)', function (data) {
  176. table.reload('LAY-list-manage', {
  177. where: null,
  178. page: {
  179. curr: 1
  180. }
  181. });
  182. });
  183. //事件
  184. var active = {
  185. batchdel: function () {
  186. var checkStatus = table.checkStatus('LAY-list-manage'),
  187. data = checkStatus.data; //得到选中的数据
  188. if (data.length < 1) {
  189. parent.layer.msg("请选择要删除的项");
  190. } else {
  191. var ids = "";
  192. $.each(data, function (index, value) {
  193. ids += data[index].Id + ",";
  194. });
  195. ids = ids.substring(0, ids.length - 1);
  196. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  197. $.ajax({
  198. type: "POST",
  199. url: "/Admin/OrderRefundReason/Delete?r=" + Math.random(1),
  200. data: "Id=" + ids,
  201. dataType: "text",
  202. success: function (data) {
  203. layer.close(index);
  204. if (data == "success") {
  205. table.reload('LAY-list-manage');
  206. } else {
  207. layer.msg(data);
  208. }
  209. }
  210. });
  211. });
  212. }
  213. },
  214. add: function () {
  215. var perContent = layer.open({
  216. type: 2,
  217. title: '退款原因-添加',
  218. content: 'Add',
  219. maxmin: true,
  220. area: ['500px', '450px'],
  221. btn: ['确定', '取消'],
  222. yes: function (index, layero) {
  223. var iframeWindow = window['layui-layer-iframe' + index],
  224. submitID = 'LAY-list-front-submit',
  225. submit = layero.find('iframe').contents().find('#' + submitID);
  226. //监听提交
  227. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  228. var field = data.field; //获取提交的字段
  229. var userdata = "";
  230. for (var prop in field) {
  231. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  232. }
  233. //提交 Ajax 成功后,静态更新表格中的数据
  234. //$.ajax({});
  235. $.ajax({
  236. type: "POST",
  237. url: "/Admin/OrderRefundReason/Add?r=" + Math.random(1),
  238. data: userdata,
  239. dataType: "text",
  240. success: function (data) {
  241. layer.close(index); //关闭弹层
  242. if (data == "success") {
  243. table.reload('LAY-list-manage'); //数据刷新
  244. } else {
  245. layer.msg(data);
  246. }
  247. }
  248. });
  249. });
  250. submit.trigger('click');
  251. }
  252. });
  253. layer.full(perContent);
  254. },
  255. ImportData: function () {
  256. layer.open({
  257. type: 2,
  258. title: '导入',
  259. maxmin: false,
  260. area: ['460px', '180px'],
  261. content: $('#excelForm'),
  262. cancel: function () {}
  263. });
  264. },
  265. ExportExcel: function () {
  266. var userdata = $('#QueryForm').serialize();
  267. $.ajax({
  268. type: "POST",
  269. url: "/Admin/OrderRefundReason/ExportExcel?r=" + Math.random(1),
  270. data: userdata,
  271. dataType: "json",
  272. success: function (data) {
  273. data.Obj.unshift(data.Fields);
  274. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  275. }
  276. });
  277. },
  278. Open: function () {
  279. var checkStatus = table.checkStatus('LAY-list-manage'),
  280. data = checkStatus.data; //得到选中的数据
  281. if (data.length < 1) {
  282. parent.layer.msg("请选择要开启的项");
  283. } else {
  284. var ids = "";
  285. $.each(data, function (index, value) {
  286. ids += data[index].Id + ",";
  287. });
  288. ids = ids.substring(0, ids.length - 1);
  289. var index = layer.confirm('确定要开启吗?', function (index) {
  290. $.ajax({
  291. type: "POST",
  292. url: "/Admin/OrderRefundReason/Open?r=" + Math.random(1),
  293. data: "Id=" + ids,
  294. dataType: "text",
  295. success: function (data) {
  296. layer.close(index);
  297. if (data == "success") {
  298. table.reload('LAY-list-manage');
  299. } else {
  300. layer.msg(data);
  301. }
  302. }
  303. });
  304. });
  305. }
  306. },
  307. Close: 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/OrderRefundReason/Close?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. };
  337. $('.layui-btn').on('click', function () {
  338. var type = $(this).data('type');
  339. active[type] ? active[type].call(this) : '';
  340. });
  341. });