OpenRewardDetail_Admin.js 19 KB

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