TradeRecord_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. var ExcelData, ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/SpTradeRecord/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. //excel导入
  32. excel = layui.excel;
  33. $('#ExcelFile').change(function (e) {
  34. var files = e.target.files;
  35. excel.importExcel(files, {}, function (data) {
  36. ExcelData = data[0].sheet1;
  37. });
  38. });
  39. //监听单元格编辑
  40. table.on('edit(LAY-list-manage)', function (obj) {
  41. var value = obj.value //得到修改后的值
  42. , data = obj.data //得到所在行所有键值
  43. , field = obj.field; //得到字段
  44. if (field == "Sort") {
  45. $.ajax({
  46. type: "POST",
  47. url: "/Admin/SpTradeRecord/Sort?r=" + Math.random(1),
  48. data: "Id=" + data.Id + "&Sort=" + value,
  49. dataType: "text",
  50. success: function (data) {
  51. }
  52. });
  53. }
  54. });
  55. //列表数据
  56. table.render({
  57. elem: '#LAY-list-manage'
  58. , url: '/Admin/SpTradeRecord/IndexData' //模拟接口
  59. , cols: [[
  60. { type: 'checkbox', fixed: 'left' }
  61. // , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
  62. , { field: 'Status', width: 200, title: '状态', sort: true }
  63. , { field: 'TradeSerialNo', width: 200, title: '交易单号', sort: true }
  64. , { field: 'MerNo', width: 200, title: '商户编号', sort: true }
  65. , { field: 'TradeAmount', width: 200, title: '交易金额', sort: true }
  66. , { field: 'CreateDate', width: 200, title: '创建时间', sort: true }
  67. , { field: 'AgentNo', width: 200, title: '代理编号', sort: true }
  68. , { field: 'BankCardNo', width: 200, title: '交易卡号', sort: true }
  69. , { field: 'TradeSnNo', width: 200, title: '机具号', sort: true }
  70. , { field: 'TradeType', width: 200, title: '交易类型', sort: true }
  71. , { field: 'TradeStatus', width: 200, title: '交易状态', sort: true }
  72. // , { field: 'TradeDate', width: 200, title: '交易日期', sort: true }
  73. , { field: 'TradeTime', width: 200, title: '交易时间', sort: true }
  74. , { field: 'BankCardType', width: 200, title: '银行卡类型', sort: true }
  75. , { field: 'MerNo', width: 200, title: '商户编号', sort: true }
  76. // , { field: 'SettleFee', width: 200, title: '出款手续费', sort: true }
  77. // , { field: 'Remark', width: 200, title: '备注', sort: true }
  78. , { field: 'ProductType', width: 200, title: '产品类型', sort: true }
  79. // , { field: 'AgentNo', width: 200, title: '代理商编号', sort: true }
  80. , { field: 'ChannelSerial', width: 200, title: '渠道流水号', sort: true }
  81. , { field: 'TradeSerialNo', width: 200, title: '贸易序列号', sort: true }
  82. // , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  83. // , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  84. ]]
  85. , where: {
  86. }
  87. , page: true
  88. , limit: 30
  89. , height: 'full-220'
  90. , text: '对不起,加载出现异常!'
  91. , done: function (res, curr, count) {
  92. $(".layui-none").text("无数据");
  93. }
  94. });
  95. //监听工具条
  96. table.on('tool(LAY-list-manage)', function (obj) {
  97. var data = obj.data;
  98. if (obj.event === 'del') {
  99. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  100. $.ajax({
  101. type: "POST",
  102. url: "/Admin/SpTradeRecord/Delete?r=" + Math.random(1),
  103. data: "Id=" + data.Id,
  104. dataType: "text",
  105. success: function (data) {
  106. if (data == "success") {
  107. obj.del();
  108. layer.close(index);
  109. } else {
  110. parent.layer.msg(data);
  111. }
  112. }
  113. });
  114. });
  115. } else if (obj.event === 'edit') {
  116. var tr = $(obj.tr);
  117. var perContent = layer.open({
  118. type: 2
  119. , title: '交易记录-编辑'
  120. , content: 'Edit?Id=' + data.Id + ''
  121. , maxmin: true
  122. , area: ['500px', '450px']
  123. , btn: ['确定', '取消']
  124. , yes: function (index, layero) {
  125. var iframeWindow = window['layui-layer-iframe' + index]
  126. , submitID = 'LAY-list-front-submit'
  127. , submit = layero.find('iframe').contents().find('#' + submitID);
  128. setTimeout(function () {
  129. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  130. var errObj = $(this).find('.layui-form-danger');
  131. if (errObj.length > 0) {
  132. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  133. submit.click();
  134. }
  135. });
  136. }, 300);
  137. //监听提交
  138. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  139. var field = data.field; //获取提交的字段
  140. var userdata = "";
  141. for (var prop in field) {
  142. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  143. }
  144. //提交 Ajax 成功后,静态更新表格中的数据
  145. //$.ajax({});
  146. $.ajax({
  147. type: "POST",
  148. url: "/Admin/SpTradeRecord/Edit?r=" + Math.random(1),
  149. data: userdata,
  150. dataType: "text",
  151. success: function (data) {
  152. layer.close(index); //关闭弹层
  153. if (data == "success") {
  154. table.reload('LAY-list-manage'); //数据刷新
  155. } else {
  156. layer.msg(data);
  157. }
  158. }
  159. });
  160. });
  161. submit.trigger('click');
  162. }
  163. , success: function (layero, index) {
  164. }
  165. });
  166. layer.full(perContent);
  167. }
  168. });
  169. //监听搜索
  170. form.on('submit(LAY-list-front-search)', function (data) {
  171. var field = data.field;
  172. //执行重载
  173. table.reload('LAY-list-manage', {
  174. where: field,
  175. page: {
  176. curr: 1
  177. }
  178. });
  179. });
  180. form.on('submit(LAY-list-front-searchall)', function (data) {
  181. table.reload('LAY-list-manage', {
  182. where: null,
  183. page: {
  184. curr: 1
  185. }
  186. });
  187. });
  188. //事件
  189. var active = {
  190. batchdel: function () {
  191. var checkStatus = table.checkStatus('LAY-list-manage')
  192. , data = checkStatus.data; //得到选中的数据
  193. if (data.length < 1) {
  194. parent.layer.msg("请选择要删除的项");
  195. } else {
  196. var ids = "";
  197. $.each(data, function (index, value) {
  198. ids += data[index].Id + ",";
  199. });
  200. ids = ids.substring(0, ids.length - 1);
  201. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  202. $.ajax({
  203. type: "POST",
  204. url: "/Admin/SpTradeRecord/Delete?r=" + Math.random(1),
  205. data: "Id=" + ids,
  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. }
  218. }
  219. , add: function () {
  220. var perContent = layer.open({
  221. type: 2
  222. , title: '交易记录-添加'
  223. , content: 'Add'
  224. , maxmin: true
  225. , area: ['500px', '450px']
  226. , btn: ['确定', '取消']
  227. , yes: function (index, layero) {
  228. var iframeWindow = window['layui-layer-iframe' + index]
  229. , submitID = 'LAY-list-front-submit'
  230. , submit = layero.find('iframe').contents().find('#' + submitID);
  231. setTimeout(function () {
  232. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  233. var errObj = $(this).find('.layui-form-danger');
  234. if (errObj.length > 0) {
  235. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  236. submit.click();
  237. }
  238. });
  239. }, 300);
  240. //监听提交
  241. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  242. var field = data.field; //获取提交的字段
  243. var userdata = "";
  244. for (var prop in field) {
  245. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  246. }
  247. //提交 Ajax 成功后,静态更新表格中的数据
  248. //$.ajax({});
  249. $.ajax({
  250. type: "POST",
  251. url: "/Admin/SpTradeRecord/Add?r=" + Math.random(1),
  252. data: userdata,
  253. dataType: "text",
  254. success: function (data) {
  255. layer.close(index); //关闭弹层
  256. if (data == "success") {
  257. table.reload('LAY-list-manage'); //数据刷新
  258. } else {
  259. layer.msg(data);
  260. }
  261. }
  262. });
  263. });
  264. submit.trigger('click');
  265. }
  266. });
  267. layer.full(perContent);
  268. }
  269. , ImportData: function () {
  270. ExcelKind = 1;
  271. layer.open({
  272. type: 1,
  273. title: '导入',
  274. maxmin: false,
  275. area: ['460px', '280px'],
  276. content: $('#excelForm'),
  277. cancel: function () {
  278. }
  279. });
  280. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  281. }
  282. , ExportExcel: function () {
  283. var userdata = '';
  284. $(".layuiadmin-card-header-auto input").each(function (i) {
  285. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  286. });
  287. $(".layuiadmin-card-header-auto select").each(function (i) {
  288. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  289. });
  290. $.ajax({
  291. type: "GET",
  292. url: "/Admin/SpTradeRecord/ExportExcel?r=" + Math.random(1),
  293. data: userdata,
  294. dataType: "json",
  295. success: function (data) {
  296. data.Obj.unshift(data.Fields);
  297. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  298. }
  299. });
  300. }
  301. , Open: function () {
  302. var checkStatus = table.checkStatus('LAY-list-manage')
  303. , data = checkStatus.data; //得到选中的数据
  304. if (data.length < 1) {
  305. parent.layer.msg("请选择要开启的项");
  306. } else {
  307. var ids = "";
  308. $.each(data, function (index, value) {
  309. ids += data[index].Id + ",";
  310. });
  311. ids = ids.substring(0, ids.length - 1);
  312. var index = layer.confirm('确定要开启吗?', function (index) {
  313. $.ajax({
  314. type: "POST",
  315. url: "/Admin/SpTradeRecord/Open?r=" + Math.random(1),
  316. data: "Id=" + ids,
  317. dataType: "text",
  318. success: function (data) {
  319. layer.close(index);
  320. if (data == "success") {
  321. table.reload('LAY-list-manage');
  322. } else {
  323. layer.msg(data);
  324. }
  325. }
  326. });
  327. });
  328. }
  329. }
  330. , Close: function () {
  331. var checkStatus = table.checkStatus('LAY-list-manage')
  332. , data = checkStatus.data; //得到选中的数据
  333. if (data.length < 1) {
  334. parent.layer.msg("请选择要关闭的项");
  335. } else {
  336. var ids = "";
  337. $.each(data, function (index, value) {
  338. ids += data[index].Id + ",";
  339. });
  340. ids = ids.substring(0, ids.length - 1);
  341. var index = layer.confirm('确定要关闭吗?', function (index) {
  342. $.ajax({
  343. type: "POST",
  344. url: "/Admin/SpTradeRecord/Close?r=" + Math.random(1),
  345. data: "Id=" + ids,
  346. dataType: "text",
  347. success: function (data) {
  348. layer.close(index);
  349. if (data == "success") {
  350. table.reload('LAY-list-manage');
  351. } else {
  352. layer.msg(data);
  353. }
  354. }
  355. });
  356. });
  357. }
  358. }
  359. };
  360. $('.layui-btn').on('click', function () {
  361. var type = $(this).data('type');
  362. active[type] ? active[type].call(this) : '';
  363. });
  364. });