UserProfit_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. var ExcelData,ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/UserProfit/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. //excel导入
  32. excel = layui.excel;
  33. $('#ExcelFile').change(function (e) {
  34. var files = e.target.files;
  35. excel.importExcel(files, { }, function (data) {
  36. ExcelData = data[0].sheet1;
  37. });
  38. });
  39. //监听单元格编辑
  40. table.on('edit(LAY-list-manage)', function(obj){
  41. var value = obj.value //得到修改后的值
  42. ,data = obj.data //得到所在行所有键值
  43. ,field = obj.field; //得到字段
  44. if(field == "Sort"){
  45. $.ajax({
  46. type: "POST",
  47. url: "/Admin/UserProfit/Sort?r=" + Math.random(1),
  48. data: "Id=" + data.Id + "&Sort=" + value,
  49. dataType: "text",
  50. success: function (data) {
  51. }
  52. });
  53. }
  54. });
  55. //列表数据
  56. table.render({
  57. elem: '#LAY-list-manage'
  58. , url: '/Admin/UserProfit/IndexData' //模拟接口
  59. , cols: [[
  60. { type: 'checkbox', fixed: 'left' }
  61. , {field:'Id', fixed: 'left', title:'ID', width:80, sort: true, unresize: true}
  62. ,{field:'UserIdMakerCode', width: 200, title:'创客编号', sort: true}
  63. ,{field:'UserIdRealName', width: 200, title:'创客姓名', sort: true}
  64. ,{field:'TopUserIdMakerCode', width: 200, title:'顶级创客编号', sort: true}
  65. ,{field:'TopUserIdRealName', width: 200, title:'顶级创客姓名', sort: true}
  66. ,{field:'CardType', width: 200, title:'交易卡类型', sort: true}
  67. ,{field:'ProfitRate', width: 200, title:'创客预设分润比例', sort: true}
  68. ,{field:'ProfitPercent', width: 200, title:'创客预设分润百分比', sort: true}
  69. ,{field:'AddOrSubRate', width: 200, title:'浮动空间', sort: true}
  70. ,{field:'ProfitRateBase', width: 200, title:'分润比例基数', sort: true}
  71. ,{field:'Remark', width: 200, title:'备注', sort: true}
  72. ,{field:'HelpAddOrSubRate', width: 200, title:'扶持期浮动空间', sort: true}
  73. ,{field:'HelpProfitPercent', width: 200, title:'扶持期创客预设分润百分比', sort: true}
  74. ,{field:'HelpProfitRate', width: 200, title:'扶持期创客预设分润比例', sort: true}
  75. ,{field:'HelpProfitRateBase', width: 200, title:'扶持期分润比例基数', sort: true}
  76. , {field:'Sort', fixed: 'right', title:'排序', width:80, edit: 'text'}
  77. , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  78. ]]
  79. , where: {
  80. UserId: UserId
  81. }
  82. , page: true
  83. , limit: 30
  84. , height: 'full-220'
  85. , text: '对不起,加载出现异常!'
  86. , done: function (res, curr, count) {
  87. $(".layui-none").text("无数据");
  88. }
  89. });
  90. //监听工具条
  91. table.on('tool(LAY-list-manage)', function (obj) {
  92. var data = obj.data;
  93. if (obj.event === 'del') {
  94. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  95. $.ajax({
  96. type: "POST",
  97. url: "/Admin/UserProfit/Delete?r=" + Math.random(1),
  98. data: "Id=" + data.Id,
  99. dataType: "text",
  100. success: function (data) {
  101. if (data == "success") {
  102. obj.del();
  103. layer.close(index);
  104. } else {
  105. parent.layer.msg(data);
  106. }
  107. }
  108. });
  109. });
  110. } else if (obj.event === 'edit') {
  111. var tr = $(obj.tr);
  112. var perContent = layer.open({
  113. type: 2
  114. , title: '创客分润规则-编辑'
  115. , content: 'Edit?Id=' + data.Id + '&UserId=' + UserId + ''
  116. , maxmin: true
  117. , area: ['500px', '450px']
  118. , btn: ['确定', '取消']
  119. , yes: function (index, layero) {
  120. var iframeWindow = window['layui-layer-iframe' + index]
  121. , submitID = 'LAY-list-front-submit'
  122. , submit = layero.find('iframe').contents().find('#' + submitID);
  123. setTimeout(function () {
  124. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  125. var errObj = $(this).find('.layui-form-danger');
  126. if (errObj.length > 0) {
  127. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  128. submit.click();
  129. }
  130. });
  131. }, 300);
  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/UserProfit/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/UserProfit/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?UserId=' + UserId + ''
  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. setTimeout(function () {
  227. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  228. var errObj = $(this).find('.layui-form-danger');
  229. if (errObj.length > 0) {
  230. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  231. submit.click();
  232. }
  233. });
  234. }, 300);
  235. //监听提交
  236. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  237. var field = data.field; //获取提交的字段
  238. var userdata = "";
  239. for (var prop in field) {
  240. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  241. }
  242. //提交 Ajax 成功后,静态更新表格中的数据
  243. //$.ajax({});
  244. $.ajax({
  245. type: "POST",
  246. url: "/Admin/UserProfit/Add?r=" + Math.random(1),
  247. data: userdata,
  248. dataType: "text",
  249. success: function (data) {
  250. layer.close(index); //关闭弹层
  251. if (data == "success") {
  252. table.reload('LAY-list-manage'); //数据刷新
  253. } else {
  254. layer.msg(data);
  255. }
  256. }
  257. });
  258. });
  259. submit.trigger('click');
  260. }
  261. });
  262. layer.full(perContent);
  263. }
  264. , ImportData: function () {
  265. ExcelKind = 1;
  266. layer.open({
  267. type: 1,
  268. title: '导入',
  269. maxmin: false,
  270. area: ['460px', '280px'],
  271. content: $('#excelForm'),
  272. cancel: function () {
  273. }
  274. });
  275. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  276. }
  277. , ExportExcel: function () {
  278. var userdata = '';
  279. $(".layuiadmin-card-header-auto input").each(function (i) {
  280. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  281. });
  282. $(".layuiadmin-card-header-auto select").each(function (i) {
  283. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  284. });
  285. $.ajax({
  286. type: "GET",
  287. url: "/Admin/UserProfit/ExportExcel?r=" + Math.random(1),
  288. data: userdata,
  289. dataType: "json",
  290. success: function (data) {
  291. data.Obj.unshift(data.Fields);
  292. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  293. }
  294. });
  295. }
  296. , Open: function () {
  297. var checkStatus = table.checkStatus('LAY-list-manage')
  298. , data = checkStatus.data; //得到选中的数据
  299. if(data.length < 1){
  300. parent.layer.msg("请选择要开启的项");
  301. }else{
  302. var ids = "";
  303. $.each(data, function (index, value) {
  304. ids += data[index].Id + ",";
  305. });
  306. ids = ids.substring(0, ids.length - 1);
  307. var index = layer.confirm('确定要开启吗?', function (index) {
  308. $.ajax({
  309. type: "POST",
  310. url: "/Admin/UserProfit/Open?r=" + Math.random(1),
  311. data: "Id=" + ids,
  312. dataType: "text",
  313. success: function (data) {
  314. layer.close(index);
  315. if (data == "success") {
  316. table.reload('LAY-list-manage');
  317. } else {
  318. layer.msg(data);
  319. }
  320. }
  321. });
  322. });
  323. }
  324. }
  325. , Close: function () {
  326. var checkStatus = table.checkStatus('LAY-list-manage')
  327. , data = checkStatus.data; //得到选中的数据
  328. if(data.length < 1){
  329. parent.layer.msg("请选择要关闭的项");
  330. }else{
  331. var ids = "";
  332. $.each(data, function (index, value) {
  333. ids += data[index].Id + ",";
  334. });
  335. ids = ids.substring(0, ids.length - 1);
  336. var index = layer.confirm('确定要关闭吗?', function (index) {
  337. $.ajax({
  338. type: "POST",
  339. url: "/Admin/UserProfit/Close?r=" + Math.random(1),
  340. data: "Id=" + ids,
  341. dataType: "text",
  342. success: function (data) {
  343. layer.close(index);
  344. if (data == "success") {
  345. table.reload('LAY-list-manage');
  346. } else {
  347. layer.msg(data);
  348. }
  349. }
  350. });
  351. });
  352. }
  353. }
  354. };
  355. $('.layui-btn').on('click', function () {
  356. var type = $(this).data('type');
  357. active[type] ? active[type].call(this) : '';
  358. });
  359. });