ActivateRecord_Admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. var ExcelData, ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/ActivateRecord/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/ActivateRecord/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/ActivateRecord/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: 'SeoTitle', width: 200, title: '押金', sort: true }
  64. , { field: 'MerNo', width: 200, title: '商户编号', sort: true }
  65. , { field: 'MerName', width: 200, title: '商户名称', sort: true }
  66. , { field: 'ProductType', width: 200, title: '产品类型', sort: true }
  67. // , { field: 'MerMobile', width: 200, title: '商户手机号', sort: true }
  68. , { field: 'SnNo', width: 200, title: '终端机身号', sort: true }
  69. // , { field: 'MerRegDate', width: 200, title: '注册日期', sort: true }
  70. // , { field: 'AssessMonth', width: 200, title: '考核月', sort: true }
  71. // , { field: 'AssessMonthCount', width: 200, title: '考核第几月', sort: true }
  72. // , { field: 'ActivateStatus', width: 200, title: '激活状态', sort: true }
  73. , { field: 'ActivateDate', width: 200, title: '激活日期', sort: true }
  74. // , { field: 'MerRealName', width: 200, title: '商户真实姓名', sort: true }
  75. // , { field: 'MerIdcardNo', width: 200, title: '商户身份证号', sort: true }
  76. // , { field: 'Remark', width: 200, title: '备注', sort: true }
  77. , { field: 'AgentNo', width: 200, title: '代理商编号', sort: true }
  78. , { field: 'ChannelSerial', width: 200, title: '渠道流水号', sort: true }
  79. , { field: 'BizEnterName', width: 200, title: '业务企业名称', sort: true }
  80. , { field: 'BizEnterNo', width: 200, title: '业务企业编号', sort: true }
  81. // , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  82. // , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  83. ]]
  84. , where: {
  85. }
  86. , page: true
  87. , limit: 30
  88. , height: 'full-220'
  89. , text: '对不起,加载出现异常!'
  90. , done: function (res, curr, count) {
  91. $(".layui-none").text("无数据");
  92. }
  93. });
  94. //监听工具条
  95. table.on('tool(LAY-list-manage)', function (obj) {
  96. var data = obj.data;
  97. if (obj.event === 'del') {
  98. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  99. $.ajax({
  100. type: "POST",
  101. url: "/Admin/ActivateRecord/Delete?r=" + Math.random(1),
  102. data: "Id=" + data.Id,
  103. dataType: "text",
  104. success: function (data) {
  105. if (data == "success") {
  106. obj.del();
  107. layer.close(index);
  108. } else {
  109. parent.layer.msg(data);
  110. }
  111. }
  112. });
  113. });
  114. } else if (obj.event === 'edit') {
  115. var tr = $(obj.tr);
  116. var perContent = layer.open({
  117. type: 2
  118. , title: '激活记录-编辑'
  119. , content: 'Edit?Id=' + data.Id + ''
  120. , maxmin: true
  121. , area: ['500px', '450px']
  122. , btn: ['确定', '取消']
  123. , yes: function (index, layero) {
  124. var iframeWindow = window['layui-layer-iframe' + index]
  125. , submitID = 'LAY-list-front-submit'
  126. , submit = layero.find('iframe').contents().find('#' + submitID);
  127. setTimeout(function () {
  128. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  129. var errObj = $(this).find('.layui-form-danger');
  130. if (errObj.length > 0) {
  131. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  132. submit.click();
  133. }
  134. });
  135. }, 300);
  136. //监听提交
  137. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  138. var field = data.field; //获取提交的字段
  139. var userdata = "";
  140. for (var prop in field) {
  141. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  142. }
  143. //提交 Ajax 成功后,静态更新表格中的数据
  144. //$.ajax({});
  145. $.ajax({
  146. type: "POST",
  147. url: "/Admin/ActivateRecord/Edit?r=" + Math.random(1),
  148. data: userdata,
  149. dataType: "text",
  150. success: function (data) {
  151. layer.close(index); //关闭弹层
  152. if (data == "success") {
  153. table.reload('LAY-list-manage'); //数据刷新
  154. } else {
  155. layer.msg(data);
  156. }
  157. }
  158. });
  159. });
  160. submit.trigger('click');
  161. }
  162. , success: function (layero, index) {
  163. }
  164. });
  165. layer.full(perContent);
  166. }
  167. });
  168. //监听搜索
  169. form.on('submit(LAY-list-front-search)', function (data) {
  170. var field = data.field;
  171. //执行重载
  172. table.reload('LAY-list-manage', {
  173. where: field,
  174. page: {
  175. curr: 1
  176. }
  177. });
  178. });
  179. form.on('submit(LAY-list-front-searchall)', function (data) {
  180. table.reload('LAY-list-manage', {
  181. where: null,
  182. page: {
  183. curr: 1
  184. }
  185. });
  186. });
  187. //事件
  188. var active = {
  189. batchdel: function () {
  190. var checkStatus = table.checkStatus('LAY-list-manage')
  191. , data = checkStatus.data; //得到选中的数据
  192. if (data.length < 1) {
  193. parent.layer.msg("请选择要删除的项");
  194. } else {
  195. var ids = "";
  196. $.each(data, function (index, value) {
  197. ids += data[index].Id + ",";
  198. });
  199. ids = ids.substring(0, ids.length - 1);
  200. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  201. $.ajax({
  202. type: "POST",
  203. url: "/Admin/ActivateRecord/Delete?r=" + Math.random(1),
  204. data: "Id=" + ids,
  205. dataType: "text",
  206. success: function (data) {
  207. layer.close(index);
  208. if (data == "success") {
  209. table.reload('LAY-list-manage');
  210. } else {
  211. layer.msg(data);
  212. }
  213. }
  214. });
  215. });
  216. }
  217. }
  218. , add: function () {
  219. var perContent = layer.open({
  220. type: 2
  221. , title: '激活记录-添加'
  222. , content: 'Add'
  223. , maxmin: true
  224. , area: ['500px', '450px']
  225. , btn: ['确定', '取消']
  226. , yes: function (index, layero) {
  227. var iframeWindow = window['layui-layer-iframe' + index]
  228. , submitID = 'LAY-list-front-submit'
  229. , submit = layero.find('iframe').contents().find('#' + submitID);
  230. setTimeout(function () {
  231. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  232. var errObj = $(this).find('.layui-form-danger');
  233. if (errObj.length > 0) {
  234. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  235. submit.click();
  236. }
  237. });
  238. }, 300);
  239. //监听提交
  240. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  241. var field = data.field; //获取提交的字段
  242. var userdata = "";
  243. for (var prop in field) {
  244. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  245. }
  246. //提交 Ajax 成功后,静态更新表格中的数据
  247. //$.ajax({});
  248. $.ajax({
  249. type: "POST",
  250. url: "/Admin/ActivateRecord/Add?r=" + Math.random(1),
  251. data: userdata,
  252. dataType: "text",
  253. success: function (data) {
  254. layer.close(index); //关闭弹层
  255. if (data == "success") {
  256. table.reload('LAY-list-manage'); //数据刷新
  257. } else {
  258. layer.msg(data);
  259. }
  260. }
  261. });
  262. });
  263. submit.trigger('click');
  264. }
  265. });
  266. layer.full(perContent);
  267. }
  268. , ImportData: function () {
  269. ExcelKind = 1;
  270. layer.open({
  271. type: 1,
  272. title: '导入',
  273. maxmin: false,
  274. area: ['460px', '280px'],
  275. content: $('#excelForm'),
  276. cancel: function () {
  277. }
  278. });
  279. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  280. }
  281. , ExportExcel: function () {
  282. var userdata = '';
  283. $(".layuiadmin-card-header-auto input").each(function (i) {
  284. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  285. });
  286. $(".layuiadmin-card-header-auto select").each(function (i) {
  287. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  288. });
  289. $.ajax({
  290. type: "GET",
  291. url: "/Admin/ActivateRecord/ExportExcel?r=" + Math.random(1),
  292. data: userdata,
  293. dataType: "json",
  294. success: function (data) {
  295. data.Obj.unshift(data.Fields);
  296. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  297. }
  298. });
  299. }
  300. , Open: function () {
  301. var checkStatus = table.checkStatus('LAY-list-manage')
  302. , data = checkStatus.data; //得到选中的数据
  303. if (data.length < 1) {
  304. parent.layer.msg("请选择要开启的项");
  305. } else {
  306. var ids = "";
  307. $.each(data, function (index, value) {
  308. ids += data[index].Id + ",";
  309. });
  310. ids = ids.substring(0, ids.length - 1);
  311. var index = layer.confirm('确定要开启吗?', function (index) {
  312. $.ajax({
  313. type: "POST",
  314. url: "/Admin/ActivateRecord/Open?r=" + Math.random(1),
  315. data: "Id=" + ids,
  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. }
  328. }
  329. , Close: function () {
  330. var checkStatus = table.checkStatus('LAY-list-manage')
  331. , data = checkStatus.data; //得到选中的数据
  332. if (data.length < 1) {
  333. parent.layer.msg("请选择要关闭的项");
  334. } else {
  335. var ids = "";
  336. $.each(data, function (index, value) {
  337. ids += data[index].Id + ",";
  338. });
  339. ids = ids.substring(0, ids.length - 1);
  340. var index = layer.confirm('确定要关闭吗?', function (index) {
  341. $.ajax({
  342. type: "POST",
  343. url: "/Admin/ActivateRecord/Close?r=" + Math.random(1),
  344. data: "Id=" + ids,
  345. dataType: "text",
  346. success: function (data) {
  347. layer.close(index);
  348. if (data == "success") {
  349. table.reload('LAY-list-manage');
  350. } else {
  351. layer.msg(data);
  352. }
  353. }
  354. });
  355. });
  356. }
  357. }
  358. };
  359. $('.layui-btn').on('click', function () {
  360. var type = $(this).data('type');
  361. active[type] ? active[type].call(this) : '';
  362. });
  363. });