ProfitObjects_Admin.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/ProfitObjects/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/ProfitObjects/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/ProfitObjects/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: 'MaxFloor',
  79. title: '最大层级',
  80. sort: true
  81. }, {
  82. field: 'MaxLevel',
  83. title: '最大等级',
  84. sort: true
  85. }, {
  86. field: 'MaxLevelContinue',
  87. title: '到顶级是否继续',
  88. sort: true
  89. }, {
  90. field: 'MinProfitVal',
  91. title: '最小分润值',
  92. sort: true
  93. }, {
  94. field: 'Status',
  95. title: '状态',
  96. sort: true
  97. }
  98. , {
  99. field: 'Sort',
  100. fixed: 'right',
  101. title: '排序',
  102. width: 80,
  103. edit: 'text'
  104. }, {
  105. title: '操作',
  106. align: 'center',
  107. fixed: 'right',
  108. width: 450,
  109. toolbar: '#table-list-tools'
  110. }
  111. ]
  112. ],
  113. where: {
  114. },
  115. page: true,
  116. limit: 30,
  117. height: 'full-220',
  118. text: '对不起,加载出现异常!',
  119. done: function (res, curr, count) {
  120. $(".layui-none").text("无数据");
  121. }
  122. });
  123. //监听工具条
  124. table.on('tool(LAY-list-manage)', function (obj) {
  125. var data = obj.data;
  126. if (obj.event === 'del') {
  127. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  128. $.ajax({
  129. type: "POST",
  130. url: "/Admin/ProfitObjects/Delete?r=" + Math.random(1),
  131. data: "Id=" + data.Id,
  132. dataType: "text",
  133. success: function (data) {
  134. if (data == "success") {
  135. obj.del();
  136. layer.close(index);
  137. } else {
  138. parent.layer.msg(data);
  139. }
  140. }
  141. });
  142. });
  143. } else if (obj.event === 'edit') {
  144. var tr = $(obj.tr);
  145. var perContent = layer.open({
  146. type: 2,
  147. title: '分润对象-编辑',
  148. content: 'Edit?Id=' + data.Id + '',
  149. maxmin: true,
  150. area: ['500px', '450px'],
  151. btn: ['确定', '取消'],
  152. yes: function (index, layero) {
  153. var iframeWindow = window['layui-layer-iframe' + index],
  154. submitID = 'LAY-list-front-submit',
  155. submit = layero.find('iframe').contents().find('#' + submitID);
  156. setTimeout(function () {
  157. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  158. var errObj = $(this).find('.layui-form-danger');
  159. if (errObj.length > 0) {
  160. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  161. submit.click();
  162. }
  163. });
  164. }, 300);
  165. //监听提交
  166. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  167. var field = data.field; //获取提交的字段
  168. var userdata = "";
  169. for (var prop in field) {
  170. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  171. }
  172. //提交 Ajax 成功后,静态更新表格中的数据
  173. //$.ajax({});
  174. $.ajax({
  175. type: "POST",
  176. url: "/Admin/ProfitObjects/Edit?r=" + Math.random(1),
  177. data: userdata,
  178. dataType: "text",
  179. success: function (data) {
  180. layer.close(index); //关闭弹层
  181. if (data == "success") {
  182. table.reload('LAY-list-manage'); //数据刷新
  183. } else {
  184. layer.msg(data);
  185. }
  186. }
  187. });
  188. });
  189. submit.trigger('click');
  190. },
  191. success: function (layero, index) {
  192. }
  193. });
  194. layer.full(perContent);
  195. }
  196. });
  197. //监听搜索
  198. form.on('submit(LAY-list-front-search)', function (data) {
  199. var field = data.field;
  200. //执行重载
  201. table.reload('LAY-list-manage', {
  202. where: field
  203. });
  204. });
  205. form.on('submit(LAY-list-front-searchall)', function (data) {
  206. table.reload('LAY-list-manage', {
  207. where: null
  208. });
  209. });
  210. //事件
  211. var active = {
  212. batchdel: function () {
  213. var checkStatus = table.checkStatus('LAY-list-manage'),
  214. data = checkStatus.data; //得到选中的数据
  215. if (data.length < 1) {
  216. parent.layer.msg("请选择要删除的项");
  217. } else {
  218. var ids = "";
  219. $.each(data, function (index, value) {
  220. ids += data[index].Id + ",";
  221. });
  222. ids = ids.substring(0, ids.length - 1);
  223. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  224. $.ajax({
  225. type: "POST",
  226. url: "/Admin/ProfitObjects/Delete?r=" + Math.random(1),
  227. data: "Id=" + ids,
  228. dataType: "text",
  229. success: function (data) {
  230. layer.close(index);
  231. if (data == "success") {
  232. table.reload('LAY-list-manage');
  233. } else {
  234. layer.msg(data);
  235. }
  236. }
  237. });
  238. });
  239. }
  240. },
  241. add: function () {
  242. var perContent = layer.open({
  243. type: 2,
  244. title: '分润对象-添加',
  245. content: 'Add',
  246. maxmin: true,
  247. area: ['500px', '450px'],
  248. btn: ['确定', '取消'],
  249. yes: function (index, layero) {
  250. var iframeWindow = window['layui-layer-iframe' + index],
  251. submitID = 'LAY-list-front-submit',
  252. submit = layero.find('iframe').contents().find('#' + submitID);
  253. setTimeout(function () {
  254. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  255. var errObj = $(this).find('.layui-form-danger');
  256. if (errObj.length > 0) {
  257. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  258. submit.click();
  259. }
  260. });
  261. }, 300);
  262. //监听提交
  263. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  264. var field = data.field; //获取提交的字段
  265. var userdata = "";
  266. for (var prop in field) {
  267. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  268. }
  269. //提交 Ajax 成功后,静态更新表格中的数据
  270. //$.ajax({});
  271. $.ajax({
  272. type: "POST",
  273. url: "/Admin/ProfitObjects/Add?r=" + Math.random(1),
  274. data: userdata,
  275. dataType: "text",
  276. success: function (data) {
  277. layer.close(index); //关闭弹层
  278. if (data == "success") {
  279. table.reload('LAY-list-manage'); //数据刷新
  280. } else {
  281. layer.msg(data);
  282. }
  283. }
  284. });
  285. });
  286. submit.trigger('click');
  287. }
  288. });
  289. layer.full(perContent);
  290. },
  291. ImportData: function () {
  292. layer.open({
  293. type: 2,
  294. title: '导入',
  295. maxmin: false,
  296. area: ['460px', '180px'],
  297. content: $('#excelForm'),
  298. cancel: function () {}
  299. });
  300. },
  301. ExportExcel: function () {
  302. var userdata = $('#QueryForm').serialize();
  303. $.ajax({
  304. type: "POST",
  305. url: "/Admin/ProfitObjects/ExportExcel?r=" + Math.random(1),
  306. data: userdata,
  307. dataType: "json",
  308. success: function (data) {
  309. data.Obj.unshift(data.Fields);
  310. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  311. }
  312. });
  313. },
  314. Open: function () {
  315. var checkStatus = table.checkStatus('LAY-list-manage'),
  316. data = checkStatus.data; //得到选中的数据
  317. if (data.length < 1) {
  318. parent.layer.msg("请选择要开启的项");
  319. } else {
  320. var ids = "";
  321. $.each(data, function (index, value) {
  322. ids += data[index].Id + ",";
  323. });
  324. ids = ids.substring(0, ids.length - 1);
  325. var index = layer.confirm('确定要开启吗?', function (index) {
  326. $.ajax({
  327. type: "POST",
  328. url: "/Admin/ProfitObjects/Open?r=" + Math.random(1),
  329. data: "Id=" + ids,
  330. dataType: "text",
  331. success: function (data) {
  332. layer.close(index);
  333. if (data == "success") {
  334. table.reload('LAY-list-manage');
  335. } else {
  336. layer.msg(data);
  337. }
  338. }
  339. });
  340. });
  341. }
  342. },
  343. Close: function () {
  344. var checkStatus = table.checkStatus('LAY-list-manage'),
  345. data = checkStatus.data; //得到选中的数据
  346. if (data.length < 1) {
  347. parent.layer.msg("请选择要关闭的项");
  348. } else {
  349. var ids = "";
  350. $.each(data, function (index, value) {
  351. ids += data[index].Id + ",";
  352. });
  353. ids = ids.substring(0, ids.length - 1);
  354. var index = layer.confirm('确定要关闭吗?', function (index) {
  355. $.ajax({
  356. type: "POST",
  357. url: "/Admin/ProfitObjects/Close?r=" + Math.random(1),
  358. data: "Id=" + ids,
  359. dataType: "text",
  360. success: function (data) {
  361. layer.close(index);
  362. if (data == "success") {
  363. table.reload('LAY-list-manage');
  364. } else {
  365. layer.msg(data);
  366. }
  367. }
  368. });
  369. });
  370. }
  371. },
  372. syncredis: function () {
  373. $.ajax({
  374. type: "POST",
  375. url: "/Admin/ProfitObjects/SyncRedis?r=" + Math.random(1),
  376. dataType: "text",
  377. success: function (data) {
  378. if (data == "success") {
  379. layer.msg('同步成功');
  380. } else {
  381. layer.msg(data);
  382. }
  383. }
  384. });
  385. }
  386. };
  387. $('.layui-btn').on('click', function () {
  388. var type = $(this).data('type');
  389. active[type] ? active[type].call(this) : '';
  390. });
  391. });