UserTradeDaySummary_Admin.js 17 KB

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