ProfitObjectLevels_Admin.js 16 KB

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