PosMachines_Admin.js 15 KB

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