ActiveReward_Admin.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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 <= 1) {
  39. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  40. op = false;
  41. layCreateDate.hint('日期范围请不要超过1个月');
  42. setTimeout(function () {
  43. $(".laydate-btns-confirm").addClass("laydate-disabled");
  44. }, 1);
  45. }
  46. } else {
  47. op = false;
  48. layCreateDate.hint('日期范围请不要超过1个月');
  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.toFixed(2));
  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. });
  232. });
  233. form.on('submit(LAY-list-front-searchall)', function (data) {
  234. table.reload('LAY-list-manage', {
  235. where: {
  236. BrandId: BrandId
  237. }
  238. });
  239. });
  240. //事件
  241. var active = {
  242. batchdel: function () {
  243. var checkStatus = table.checkStatus('LAY-list-manage')
  244. , data = checkStatus.data; //得到选中的数据
  245. if (data.length < 1) {
  246. parent.layer.msg("请选择要删除的项");
  247. } else {
  248. var ids = "";
  249. $.each(data, function (index, value) {
  250. ids += data[index].Id + ",";
  251. });
  252. ids = ids.substring(0, ids.length - 1);
  253. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  254. $.ajax({
  255. type: "POST",
  256. url: "/Admin/ActiveReward/Delete?r=" + Math.random(1),
  257. data: "Id=" + ids,
  258. dataType: "text",
  259. success: function (data) {
  260. layer.close(index);
  261. if (data == "success") {
  262. table.reload('LAY-list-manage');
  263. } else {
  264. layer.msg(data);
  265. }
  266. }
  267. });
  268. });
  269. }
  270. }
  271. , add: function () {
  272. var perContent = layer.open({
  273. type: 2
  274. , title: '激活奖励记录-添加'
  275. , content: 'Add'
  276. , maxmin: true
  277. , area: ['500px', '450px']
  278. , btn: ['确定', '取消']
  279. , yes: function (index, layero) {
  280. var iframeWindow = window['layui-layer-iframe' + index]
  281. , submitID = 'LAY-list-front-submit'
  282. , submit = layero.find('iframe').contents().find('#' + submitID);
  283. setTimeout(function () {
  284. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  285. var errObj = $(this).find('.layui-form-danger');
  286. if (errObj.length > 0) {
  287. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  288. submit.click();
  289. }
  290. });
  291. }, 300);
  292. //监听提交
  293. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  294. var field = data.field; //获取提交的字段
  295. var userdata = "";
  296. for (var prop in field) {
  297. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  298. }
  299. //提交 Ajax 成功后,静态更新表格中的数据
  300. //$.ajax({});
  301. $.ajax({
  302. type: "POST",
  303. url: "/Admin/ActiveReward/Add?r=" + Math.random(1),
  304. data: userdata,
  305. dataType: "text",
  306. success: function (data) {
  307. layer.close(index); //关闭弹层
  308. if (data == "success") {
  309. table.reload('LAY-list-manage'); //数据刷新
  310. } else {
  311. layer.msg(data);
  312. }
  313. }
  314. });
  315. });
  316. submit.trigger('click');
  317. }
  318. });
  319. layer.full(perContent);
  320. }
  321. , ImportData: function () {
  322. layer.open({
  323. type: 1,
  324. title: '导入',
  325. maxmin: false,
  326. area: ['460px', '180px'],
  327. content: $('#excelForm'),
  328. cancel: function () {
  329. }
  330. });
  331. }
  332. , ExportExcel: function () {
  333. var userdata = '';
  334. $(".layuiadmin-card-header-auto input").each(function (i) {
  335. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  336. });
  337. $(".layuiadmin-card-header-auto select").each(function (i) {
  338. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  339. });
  340. $.ajax({
  341. type: "GET",
  342. url: "/Admin/ActiveReward/ExportExcel?r=" + Math.random(1),
  343. data: userdata,
  344. dataType: "json",
  345. success: function (data) {
  346. data.Obj.unshift(data.Fields);
  347. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  348. }
  349. });
  350. }
  351. , Open: function () {
  352. var checkStatus = table.checkStatus('LAY-list-manage')
  353. , data = checkStatus.data; //得到选中的数据
  354. if(data.length < 1){
  355. parent.layer.msg("请选择要开启的项");
  356. }else{
  357. var ids = "";
  358. $.each(data, function (index, value) {
  359. ids += data[index].Id + ",";
  360. });
  361. ids = ids.substring(0, ids.length - 1);
  362. var index = layer.confirm('确定要开启吗?', function (index) {
  363. $.ajax({
  364. type: "POST",
  365. url: "/Admin/ActiveReward/Open?r=" + Math.random(1),
  366. data: "Id=" + ids,
  367. dataType: "text",
  368. success: function (data) {
  369. layer.close(index);
  370. if (data == "success") {
  371. table.reload('LAY-list-manage');
  372. } else {
  373. layer.msg(data);
  374. }
  375. }
  376. });
  377. });
  378. }
  379. }
  380. , Close: function () {
  381. var checkStatus = table.checkStatus('LAY-list-manage')
  382. , data = checkStatus.data; //得到选中的数据
  383. if(data.length < 1){
  384. parent.layer.msg("请选择要关闭的项");
  385. }else{
  386. var ids = "";
  387. $.each(data, function (index, value) {
  388. ids += data[index].Id + ",";
  389. });
  390. ids = ids.substring(0, ids.length - 1);
  391. var index = layer.confirm('确定要关闭吗?', function (index) {
  392. $.ajax({
  393. type: "POST",
  394. url: "/Admin/ActiveReward/Close?r=" + Math.random(1),
  395. data: "Id=" + ids,
  396. dataType: "text",
  397. success: function (data) {
  398. layer.close(index);
  399. if (data == "success") {
  400. table.reload('LAY-list-manage');
  401. } else {
  402. layer.msg(data);
  403. }
  404. }
  405. });
  406. });
  407. }
  408. }
  409. };
  410. $('.layui-btn').on('click', function () {
  411. var type = $(this).data('type');
  412. active[type] ? active[type].call(this) : '';
  413. });
  414. });