ActiveReward_Admin.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/ActiveReward/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. var layCreateDate = laydate.render({
  32. elem: '#CreateDate',
  33. type: 'date',
  34. range: true,
  35. trigger: 'click',
  36. change: function (value, date, endDate) {
  37. var op = true;
  38. if (date.year == endDate.year && endDate.month - date.month <= 2) {
  39. if (endDate.month - date.month == 2 && endDate.date > date.date) {
  40. op = false;
  41. layCreateDate.hint('日期范围请不要超过2个月');
  42. setTimeout(function () {
  43. $(".laydate-btns-confirm").addClass("laydate-disabled");
  44. }, 1);
  45. }
  46. } else {
  47. op = false;
  48. layCreateDate.hint('日期范围请不要超过2个月');
  49. setTimeout(function () {
  50. $(".laydate-btns-confirm").addClass("laydate-disabled");
  51. }, 1);
  52. }
  53. if (op) {
  54. $('#CreateDate').val(value);
  55. }
  56. }
  57. });
  58. var layActDate = laydate.render({
  59. elem: '#ActDate',
  60. trigger: 'click',
  61. type: 'date',
  62. range: true,
  63. change: function (value, date, endDate) {
  64. var op = true;
  65. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  66. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  67. op = false;
  68. layActDate.hint('日期范围请不要超过1个月');
  69. setTimeout(function () {
  70. $(".laydate-btns-confirm").addClass("laydate-disabled");
  71. }, 1);
  72. }
  73. } else {
  74. op = false;
  75. layActDate.hint('日期范围请不要超过1个月');
  76. setTimeout(function () {
  77. $(".laydate-btns-confirm").addClass("laydate-disabled");
  78. }, 1);
  79. }
  80. if (op) {
  81. $('#ActDate').val(value);
  82. }
  83. }
  84. });
  85. //excel导入
  86. excel = layui.excel;
  87. $('#ExcelFile').change(function (e) {
  88. var files = e.target.files;
  89. excel.importExcel(files, { }, function (data) {
  90. ExcelData = data[0].sheet1;
  91. });
  92. });
  93. //监听单元格编辑
  94. table.on('edit(LAY-list-manage)', function(obj){
  95. var value = obj.value //得到修改后的值
  96. ,data = obj.data //得到所在行所有键值
  97. ,field = obj.field; //得到字段
  98. if(field == "Sort"){
  99. $.ajax({
  100. type: "POST",
  101. url: "/Admin/ActiveReward/Sort?r=" + Math.random(1),
  102. data: "Id=" + data.Id + "&Sort=" + value,
  103. dataType: "text",
  104. success: function (data) {
  105. }
  106. });
  107. }
  108. });
  109. //列表数据
  110. table.render({
  111. elem: '#LAY-list-manage'
  112. , url: '/Admin/ActiveReward/IndexData' //模拟接口
  113. , cols: [[
  114. { type: 'checkbox', fixed: 'left' }
  115. ,{field:'MerchantNo', width: 200, title:'商户编号', sort: true}
  116. ,{field:'MerchantName', width: 200, title:'商户名称', sort: true}
  117. ,{field:'ActDate', width: 200, title:'激活日期', sort: true}
  118. ,{field:'CreateDate', width: 200, title:'奖励时间', sort: true}
  119. ,{field:'MakerCode', width: 200, title:'奖励创客编号', sort: true}
  120. ,{field:'RealName', width: 200, title:'奖励创客名称', sort: true}
  121. ,{field:'MerMakerCode', width: 200, title:'直属创客编号', sort: true}
  122. ,{field:'MerRealName', width: 200, title:'直属创客名称', sort: true}
  123. ,{field:'ParentMakerCode', width: 200, title:'上级创客编码', sort: true}
  124. ,{field:'ParentRealName', width: 200, title:'上级创客名称', sort: true}
  125. ,{field:'ParentParentMakerCode', width: 200, title:'上上级创客编码', sort: true}
  126. ,{field:'ParentParentRealName', width: 200, title:'上上级创客名称', sort: true}
  127. // ,{field:'TopMakerCode', width: 200, title:'顶级创客编码', sort: true}
  128. // ,{field:'TopRealName', width: 200, title:'顶级创客名称', sort: true}
  129. ,{field:'KqMerNo', width: 200, title:'快钱商户编号', sort: true}
  130. ,{field:'KqSnNo', width: 200, title:'快钱SN号', sort: true}
  131. ,{field:'SnType', width: 200, title:'机具类型', sort: true}
  132. ,{field:'ActType', width: 200, title:'激活类型', sort: true}
  133. ,{field:'StoreNo', width: 200, title:'SN仓库编号', sort: true}
  134. ,{field:'StoreName', width: 200, title:'SN仓库名称', sort: true}
  135. ,{field:'SnApplyMakerCode', width: 200, title:'机具申请创客编号', sort: true}
  136. ,{field:'SnApplyRealName', width: 200, title:'机具申请创客姓名', sort: true}
  137. ,{field:'RewardAmount', width: 200, title:'奖励金额(元)', sort: true}
  138. ]]
  139. , where: {
  140. BrandId: BrandId
  141. }
  142. , page: true
  143. , limit: 30
  144. , height: 'full-' + String($('.layui-card-header').height() + 130)
  145. , text: '对不起,加载出现异常!'
  146. , done: function (res, curr, count) {
  147. $("#RewardAmount").text(res.other.RewardAmount);
  148. $(".layui-none").text("无数据");
  149. }
  150. });
  151. //监听工具条
  152. table.on('tool(LAY-list-manage)', function (obj) {
  153. var data = obj.data;
  154. if (obj.event === 'del') {
  155. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  156. $.ajax({
  157. type: "POST",
  158. url: "/Admin/ActiveReward/Delete?r=" + Math.random(1),
  159. data: "Id=" + data.Id,
  160. dataType: "text",
  161. success: function (data) {
  162. if (data == "success") {
  163. obj.del();
  164. layer.close(index);
  165. } else {
  166. parent.layer.msg(data);
  167. }
  168. }
  169. });
  170. });
  171. } else if (obj.event === 'edit') {
  172. var tr = $(obj.tr);
  173. var perContent = layer.open({
  174. type: 2
  175. , title: '激活奖励记录-编辑'
  176. , content: 'Edit?Id=' + data.Id + ''
  177. , maxmin: true
  178. , area: ['500px', '450px']
  179. , btn: ['确定', '取消']
  180. , yes: function (index, layero) {
  181. var iframeWindow = window['layui-layer-iframe' + index]
  182. , submitID = 'LAY-list-front-submit'
  183. , submit = layero.find('iframe').contents().find('#' + submitID);
  184. setTimeout(function () {
  185. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  186. var errObj = $(this).find('.layui-form-danger');
  187. if (errObj.length > 0) {
  188. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  189. submit.click();
  190. }
  191. });
  192. }, 300);
  193. //监听提交
  194. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  195. var field = data.field; //获取提交的字段
  196. var userdata = "";
  197. for (var prop in field) {
  198. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  199. }
  200. //提交 Ajax 成功后,静态更新表格中的数据
  201. //$.ajax({});
  202. $.ajax({
  203. type: "POST",
  204. url: "/Admin/ActiveReward/Edit?r=" + Math.random(1),
  205. data: userdata,
  206. dataType: "text",
  207. success: function (data) {
  208. layer.close(index); //关闭弹层
  209. if (data == "success") {
  210. table.reload('LAY-list-manage'); //数据刷新
  211. } else {
  212. layer.msg(data);
  213. }
  214. }
  215. });
  216. });
  217. submit.trigger('click');
  218. }
  219. , success: function (layero, index) {
  220. }
  221. });
  222. layer.full(perContent);
  223. }
  224. });
  225. //监听搜索
  226. form.on('submit(LAY-list-front-search)', function (data) {
  227. var field = data.field;
  228. //执行重载
  229. table.reload('LAY-list-manage', {
  230. where: field,
  231. page: {
  232. curr: 1
  233. }
  234. });
  235. });
  236. form.on('submit(LAY-list-front-searchall)', function (data) {
  237. table.reload('LAY-list-manage', {
  238. where: null,
  239. page: {
  240. curr: 1
  241. }
  242. });
  243. });
  244. //事件
  245. var active = {
  246. batchdel: function () {
  247. var checkStatus = table.checkStatus('LAY-list-manage')
  248. , data = checkStatus.data; //得到选中的数据
  249. if (data.length < 1) {
  250. parent.layer.msg("请选择要删除的项");
  251. } else {
  252. var ids = "";
  253. $.each(data, function (index, value) {
  254. ids += data[index].Id + ",";
  255. });
  256. ids = ids.substring(0, ids.length - 1);
  257. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  258. $.ajax({
  259. type: "POST",
  260. url: "/Admin/ActiveReward/Delete?r=" + Math.random(1),
  261. data: "Id=" + ids,
  262. dataType: "text",
  263. success: function (data) {
  264. layer.close(index);
  265. if (data == "success") {
  266. table.reload('LAY-list-manage');
  267. } else {
  268. layer.msg(data);
  269. }
  270. }
  271. });
  272. });
  273. }
  274. }
  275. , add: function () {
  276. var perContent = layer.open({
  277. type: 2
  278. , title: '激活奖励记录-添加'
  279. , content: 'Add'
  280. , maxmin: true
  281. , area: ['500px', '450px']
  282. , btn: ['确定', '取消']
  283. , yes: function (index, layero) {
  284. var iframeWindow = window['layui-layer-iframe' + index]
  285. , submitID = 'LAY-list-front-submit'
  286. , submit = layero.find('iframe').contents().find('#' + submitID);
  287. setTimeout(function () {
  288. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  289. var errObj = $(this).find('.layui-form-danger');
  290. if (errObj.length > 0) {
  291. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  292. submit.click();
  293. }
  294. });
  295. }, 300);
  296. //监听提交
  297. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  298. var field = data.field; //获取提交的字段
  299. var userdata = "";
  300. for (var prop in field) {
  301. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  302. }
  303. //提交 Ajax 成功后,静态更新表格中的数据
  304. //$.ajax({});
  305. $.ajax({
  306. type: "POST",
  307. url: "/Admin/ActiveReward/Add?r=" + Math.random(1),
  308. data: userdata,
  309. dataType: "text",
  310. success: function (data) {
  311. layer.close(index); //关闭弹层
  312. if (data == "success") {
  313. table.reload('LAY-list-manage'); //数据刷新
  314. } else {
  315. layer.msg(data);
  316. }
  317. }
  318. });
  319. });
  320. submit.trigger('click');
  321. }
  322. });
  323. layer.full(perContent);
  324. }
  325. , ImportData: function () {
  326. layer.open({
  327. type: 1,
  328. title: '导入',
  329. maxmin: false,
  330. area: ['460px', '180px'],
  331. content: $('#excelForm'),
  332. cancel: function () {
  333. }
  334. });
  335. }
  336. , ExportExcel: function () {
  337. var userdata = '';
  338. $(".layuiadmin-card-header-auto input").each(function (i) {
  339. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  340. });
  341. $(".layuiadmin-card-header-auto select").each(function (i) {
  342. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  343. });
  344. $.ajax({
  345. type: "GET",
  346. url: "/Admin/ActiveReward/ExportExcel?r=" + Math.random(1),
  347. data: userdata,
  348. dataType: "json",
  349. success: function (data) {
  350. data.Obj.unshift(data.Fields);
  351. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  352. }
  353. });
  354. }
  355. , Open: function () {
  356. var checkStatus = table.checkStatus('LAY-list-manage')
  357. , data = checkStatus.data; //得到选中的数据
  358. if(data.length < 1){
  359. parent.layer.msg("请选择要开启的项");
  360. }else{
  361. var ids = "";
  362. $.each(data, function (index, value) {
  363. ids += data[index].Id + ",";
  364. });
  365. ids = ids.substring(0, ids.length - 1);
  366. var index = layer.confirm('确定要开启吗?', function (index) {
  367. $.ajax({
  368. type: "POST",
  369. url: "/Admin/ActiveReward/Open?r=" + Math.random(1),
  370. data: "Id=" + ids,
  371. dataType: "text",
  372. success: function (data) {
  373. layer.close(index);
  374. if (data == "success") {
  375. table.reload('LAY-list-manage');
  376. } else {
  377. layer.msg(data);
  378. }
  379. }
  380. });
  381. });
  382. }
  383. }
  384. , Close: function () {
  385. var checkStatus = table.checkStatus('LAY-list-manage')
  386. , data = checkStatus.data; //得到选中的数据
  387. if(data.length < 1){
  388. parent.layer.msg("请选择要关闭的项");
  389. }else{
  390. var ids = "";
  391. $.each(data, function (index, value) {
  392. ids += data[index].Id + ",";
  393. });
  394. ids = ids.substring(0, ids.length - 1);
  395. var index = layer.confirm('确定要关闭吗?', function (index) {
  396. $.ajax({
  397. type: "POST",
  398. url: "/Admin/ActiveReward/Close?r=" + Math.random(1),
  399. data: "Id=" + ids,
  400. dataType: "text",
  401. success: function (data) {
  402. layer.close(index);
  403. if (data == "success") {
  404. table.reload('LAY-list-manage');
  405. } else {
  406. layer.msg(data);
  407. }
  408. }
  409. });
  410. });
  411. }
  412. }
  413. };
  414. $('.layui-btn').on('click', function () {
  415. var type = $(this).data('type');
  416. active[type] ? active[type].call(this) : '';
  417. });
  418. });