PosMachines_Admin.js 15 KB

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