OrderRefundReason_Admin.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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-220',
  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. });
  171. });
  172. form.on('submit(LAY-list-front-searchall)', function (data) {
  173. table.reload('LAY-list-manage', {
  174. where: null
  175. });
  176. });
  177. //事件
  178. var active = {
  179. batchdel: function () {
  180. var checkStatus = table.checkStatus('LAY-list-manage'),
  181. data = checkStatus.data; //得到选中的数据
  182. if (data.length < 1) {
  183. parent.layer.msg("请选择要删除的项");
  184. } else {
  185. var ids = "";
  186. $.each(data, function (index, value) {
  187. ids += data[index].Id + ",";
  188. });
  189. ids = ids.substring(0, ids.length - 1);
  190. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  191. $.ajax({
  192. type: "POST",
  193. url: "/Admin/OrderRefundReason/Delete?r=" + Math.random(1),
  194. data: "Id=" + ids,
  195. dataType: "text",
  196. success: function (data) {
  197. layer.close(index);
  198. if (data == "success") {
  199. table.reload('LAY-list-manage');
  200. } else {
  201. layer.msg(data);
  202. }
  203. }
  204. });
  205. });
  206. }
  207. },
  208. add: function () {
  209. var perContent = layer.open({
  210. type: 2,
  211. title: '退款原因-添加',
  212. content: 'Add',
  213. maxmin: true,
  214. area: ['500px', '450px'],
  215. btn: ['确定', '取消'],
  216. yes: function (index, layero) {
  217. var iframeWindow = window['layui-layer-iframe' + index],
  218. submitID = 'LAY-list-front-submit',
  219. submit = layero.find('iframe').contents().find('#' + submitID);
  220. //监听提交
  221. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  222. var field = data.field; //获取提交的字段
  223. var userdata = "";
  224. for (var prop in field) {
  225. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  226. }
  227. //提交 Ajax 成功后,静态更新表格中的数据
  228. //$.ajax({});
  229. $.ajax({
  230. type: "POST",
  231. url: "/Admin/OrderRefundReason/Add?r=" + Math.random(1),
  232. data: userdata,
  233. dataType: "text",
  234. success: function (data) {
  235. layer.close(index); //关闭弹层
  236. if (data == "success") {
  237. table.reload('LAY-list-manage'); //数据刷新
  238. } else {
  239. layer.msg(data);
  240. }
  241. }
  242. });
  243. });
  244. submit.trigger('click');
  245. }
  246. });
  247. layer.full(perContent);
  248. },
  249. ImportData: function () {
  250. layer.open({
  251. type: 2,
  252. title: '导入',
  253. maxmin: false,
  254. area: ['460px', '180px'],
  255. content: $('#excelForm'),
  256. cancel: function () {}
  257. });
  258. },
  259. ExportExcel: function () {
  260. var userdata = $('#QueryForm').serialize();
  261. $.ajax({
  262. type: "POST",
  263. url: "/Admin/OrderRefundReason/ExportExcel?r=" + Math.random(1),
  264. data: userdata,
  265. dataType: "json",
  266. success: function (data) {
  267. data.Obj.unshift(data.Fields);
  268. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  269. }
  270. });
  271. },
  272. Open: function () {
  273. var checkStatus = table.checkStatus('LAY-list-manage'),
  274. data = checkStatus.data; //得到选中的数据
  275. if (data.length < 1) {
  276. parent.layer.msg("请选择要开启的项");
  277. } else {
  278. var ids = "";
  279. $.each(data, function (index, value) {
  280. ids += data[index].Id + ",";
  281. });
  282. ids = ids.substring(0, ids.length - 1);
  283. var index = layer.confirm('确定要开启吗?', function (index) {
  284. $.ajax({
  285. type: "POST",
  286. url: "/Admin/OrderRefundReason/Open?r=" + Math.random(1),
  287. data: "Id=" + ids,
  288. dataType: "text",
  289. success: function (data) {
  290. layer.close(index);
  291. if (data == "success") {
  292. table.reload('LAY-list-manage');
  293. } else {
  294. layer.msg(data);
  295. }
  296. }
  297. });
  298. });
  299. }
  300. },
  301. Close: function () {
  302. var checkStatus = table.checkStatus('LAY-list-manage'),
  303. data = checkStatus.data; //得到选中的数据
  304. if (data.length < 1) {
  305. parent.layer.msg("请选择要关闭的项");
  306. } else {
  307. var ids = "";
  308. $.each(data, function (index, value) {
  309. ids += data[index].Id + ",";
  310. });
  311. ids = ids.substring(0, ids.length - 1);
  312. var index = layer.confirm('确定要关闭吗?', function (index) {
  313. $.ajax({
  314. type: "POST",
  315. url: "/Admin/OrderRefundReason/Close?r=" + Math.random(1),
  316. data: "Id=" + ids,
  317. dataType: "text",
  318. success: function (data) {
  319. layer.close(index);
  320. if (data == "success") {
  321. table.reload('LAY-list-manage');
  322. } else {
  323. layer.msg(data);
  324. }
  325. }
  326. });
  327. });
  328. }
  329. }
  330. };
  331. $('.layui-btn').on('click', function () {
  332. var type = $(this).data('type');
  333. active[type] ? active[type].call(this) : '';
  334. });
  335. });