PosMachinesTwo_Admin.js 16 KB

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