TradeRecord_Admin.js 17 KB

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