UserProfit_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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:'BrandId', width: 200, title:'品牌', sort: true}
  65. ,{field:'CardType', width: 200, title:'交易卡类型', sort: true}
  66. ,{field:'ProfitRate', width: 200, title:'创客预设分润比例', sort: true}
  67. ,{field:'ProfitPercent', width: 200, title:'创客预设分润百分比', sort: true}
  68. ,{field:'AddOrSubRate', width: 200, title:'浮动空间', sort: true}
  69. ,{field:'ProfitRateBase', width: 200, title:'分润比例基数', sort: true}
  70. ,{field:'Remark', width: 200, title:'备注', sort: true}
  71. ,{field:'TopUserIdMakerCode', width: 200, title:'顶级创客创客编号', sort: true}
  72. ,{field:'TopUserIdRealName', width: 200, title:'顶级创客真实姓名', sort: true}
  73. ,{field:'HelpAddOrSubRate', width: 200, title:'扶持期浮动空间', sort: true}
  74. ,{field:'HelpProfitPercent', width: 200, title:'扶持期创客预设分润百分比', sort: true}
  75. ,{field:'HelpProfitRate', width: 200, title:'扶持期创客预设分润比例', sort: true}
  76. ,{field:'HelpProfitRateBase', width: 200, title:'扶持期分润比例基数', sort: true}
  77. , {field:'Sort', fixed: 'right', title:'排序', width:80, edit: 'text'}
  78. , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  79. ]]
  80. , where: {
  81. UserId: UserId
  82. }
  83. , page: true
  84. , limit: 30
  85. , height: 'full-220'
  86. , text: '对不起,加载出现异常!'
  87. , done: function (res, curr, count) {
  88. $(".layui-none").text("无数据");
  89. }
  90. });
  91. //监听工具条
  92. table.on('tool(LAY-list-manage)', function (obj) {
  93. var data = obj.data;
  94. if (obj.event === 'del') {
  95. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  96. $.ajax({
  97. type: "POST",
  98. url: "/Admin/UserProfit/Delete?r=" + Math.random(1),
  99. data: "Id=" + data.Id,
  100. dataType: "text",
  101. success: function (data) {
  102. if (data == "success") {
  103. obj.del();
  104. layer.close(index);
  105. } else {
  106. parent.layer.msg(data);
  107. }
  108. }
  109. });
  110. });
  111. } else if (obj.event === 'edit') {
  112. var tr = $(obj.tr);
  113. var perContent = layer.open({
  114. type: 2
  115. , title: '创客分润规则-编辑'
  116. , content: 'Edit?Id=' + data.Id + '&UserId=' + UserId + ''
  117. , maxmin: true
  118. , area: ['500px', '450px']
  119. , btn: ['确定', '取消']
  120. , yes: function (index, layero) {
  121. var iframeWindow = window['layui-layer-iframe' + index]
  122. , submitID = 'LAY-list-front-submit'
  123. , submit = layero.find('iframe').contents().find('#' + submitID);
  124. setTimeout(function () {
  125. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  126. var errObj = $(this).find('.layui-form-danger');
  127. if (errObj.length > 0) {
  128. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  129. submit.click();
  130. }
  131. });
  132. }, 300);
  133. //监听提交
  134. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  135. var field = data.field; //获取提交的字段
  136. var userdata = "";
  137. for (var prop in field) {
  138. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  139. }
  140. //提交 Ajax 成功后,静态更新表格中的数据
  141. //$.ajax({});
  142. $.ajax({
  143. type: "POST",
  144. url: "/Admin/UserProfit/Edit?r=" + Math.random(1),
  145. data: userdata,
  146. dataType: "text",
  147. success: function (data) {
  148. layer.close(index); //关闭弹层
  149. if (data == "success") {
  150. table.reload('LAY-list-manage'); //数据刷新
  151. } else {
  152. layer.msg(data);
  153. }
  154. }
  155. });
  156. });
  157. submit.trigger('click');
  158. }
  159. , success: function (layero, index) {
  160. }
  161. });
  162. layer.full(perContent);
  163. }
  164. });
  165. //监听搜索
  166. form.on('submit(LAY-list-front-search)', function (data) {
  167. var field = data.field;
  168. //执行重载
  169. table.reload('LAY-list-manage', {
  170. where: field
  171. });
  172. });
  173. form.on('submit(LAY-list-front-searchall)', function (data) {
  174. table.reload('LAY-list-manage', {
  175. where: null
  176. });
  177. });
  178. //事件
  179. var active = {
  180. batchdel: function () {
  181. var checkStatus = table.checkStatus('LAY-list-manage')
  182. , data = checkStatus.data; //得到选中的数据
  183. if (data.length < 1) {
  184. parent.layer.msg("请选择要删除的项");
  185. } else {
  186. var ids = "";
  187. $.each(data, function (index, value) {
  188. ids += data[index].Id + ",";
  189. });
  190. ids = ids.substring(0, ids.length - 1);
  191. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  192. $.ajax({
  193. type: "POST",
  194. url: "/Admin/UserProfit/Delete?r=" + Math.random(1),
  195. data: "Id=" + ids,
  196. dataType: "text",
  197. success: function (data) {
  198. layer.close(index);
  199. if (data == "success") {
  200. table.reload('LAY-list-manage');
  201. } else {
  202. layer.msg(data);
  203. }
  204. }
  205. });
  206. });
  207. }
  208. }
  209. , add: function () {
  210. var perContent = layer.open({
  211. type: 2
  212. , title: '创客分润规则-添加'
  213. , content: 'Add?UserId=' + UserId + ''
  214. , maxmin: true
  215. , area: ['500px', '450px']
  216. , btn: ['确定', '取消']
  217. , yes: function (index, layero) {
  218. var iframeWindow = window['layui-layer-iframe' + index]
  219. , submitID = 'LAY-list-front-submit'
  220. , submit = layero.find('iframe').contents().find('#' + submitID);
  221. setTimeout(function () {
  222. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  223. var errObj = $(this).find('.layui-form-danger');
  224. if (errObj.length > 0) {
  225. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  226. submit.click();
  227. }
  228. });
  229. }, 300);
  230. //监听提交
  231. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  232. var field = data.field; //获取提交的字段
  233. var userdata = "";
  234. for (var prop in field) {
  235. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  236. }
  237. //提交 Ajax 成功后,静态更新表格中的数据
  238. //$.ajax({});
  239. $.ajax({
  240. type: "POST",
  241. url: "/Admin/UserProfit/Add?r=" + Math.random(1),
  242. data: userdata,
  243. dataType: "text",
  244. success: function (data) {
  245. layer.close(index); //关闭弹层
  246. if (data == "success") {
  247. table.reload('LAY-list-manage'); //数据刷新
  248. } else {
  249. layer.msg(data);
  250. }
  251. }
  252. });
  253. });
  254. submit.trigger('click');
  255. }
  256. });
  257. layer.full(perContent);
  258. }
  259. , ImportData: function () {
  260. ExcelKind = 1;
  261. layer.open({
  262. type: 1,
  263. title: '导入',
  264. maxmin: false,
  265. area: ['460px', '280px'],
  266. content: $('#excelForm'),
  267. cancel: function () {
  268. }
  269. });
  270. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  271. }
  272. , ExportExcel: function () {
  273. var userdata = '';
  274. $(".layuiadmin-card-header-auto input").each(function (i) {
  275. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  276. });
  277. $(".layuiadmin-card-header-auto select").each(function (i) {
  278. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  279. });
  280. $.ajax({
  281. type: "GET",
  282. url: "/Admin/UserProfit/ExportExcel?r=" + Math.random(1),
  283. data: userdata,
  284. dataType: "json",
  285. success: function (data) {
  286. data.Obj.unshift(data.Fields);
  287. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  288. }
  289. });
  290. }
  291. , Open: function () {
  292. var checkStatus = table.checkStatus('LAY-list-manage')
  293. , data = checkStatus.data; //得到选中的数据
  294. if(data.length < 1){
  295. parent.layer.msg("请选择要开启的项");
  296. }else{
  297. var ids = "";
  298. $.each(data, function (index, value) {
  299. ids += data[index].Id + ",";
  300. });
  301. ids = ids.substring(0, ids.length - 1);
  302. var index = layer.confirm('确定要开启吗?', function (index) {
  303. $.ajax({
  304. type: "POST",
  305. url: "/Admin/UserProfit/Open?r=" + Math.random(1),
  306. data: "Id=" + ids,
  307. dataType: "text",
  308. success: function (data) {
  309. layer.close(index);
  310. if (data == "success") {
  311. table.reload('LAY-list-manage');
  312. } else {
  313. layer.msg(data);
  314. }
  315. }
  316. });
  317. });
  318. }
  319. }
  320. , Close: function () {
  321. var checkStatus = table.checkStatus('LAY-list-manage')
  322. , data = checkStatus.data; //得到选中的数据
  323. if(data.length < 1){
  324. parent.layer.msg("请选择要关闭的项");
  325. }else{
  326. var ids = "";
  327. $.each(data, function (index, value) {
  328. ids += data[index].Id + ",";
  329. });
  330. ids = ids.substring(0, ids.length - 1);
  331. var index = layer.confirm('确定要关闭吗?', function (index) {
  332. $.ajax({
  333. type: "POST",
  334. url: "/Admin/UserProfit/Close?r=" + Math.random(1),
  335. data: "Id=" + ids,
  336. dataType: "text",
  337. success: function (data) {
  338. layer.close(index);
  339. if (data == "success") {
  340. table.reload('LAY-list-manage');
  341. } else {
  342. layer.msg(data);
  343. }
  344. }
  345. });
  346. });
  347. }
  348. }
  349. };
  350. $('.layui-btn').on('click', function () {
  351. var type = $(this).data('type');
  352. active[type] ? active[type].call(this) : '';
  353. });
  354. });