PosMachinesTwo_Admin.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. var ExcelData, ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/PosMachinesTwo/ImportCreateData?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 if (data.indexOf("Warning") == 0) {
  14. var datalist = data.split('|');
  15. layer.alert(datalist[1], { time: 20000 }, function () {
  16. window.location.reload();
  17. });
  18. } else {
  19. layer.msg(data);
  20. }
  21. }
  22. });
  23. }
  24. function CheckImport(table, key, loadindex, index) {
  25. $.ajax({
  26. url: "/Admin/PosMachinesTwo/CheckImport?r=" + Math.random(1),
  27. data: "key=" + key,
  28. dataType: "text",
  29. success: function (data) {
  30. if (data.indexOf('success') == 0) {
  31. layer.msg("成功操作" + data.split('|')[1] + "台机具", { time: 2000 }, function () {
  32. layer.close(index); //关闭弹层
  33. layer.close(loadindex);
  34. table.reload('LAY-list-manage'); //数据刷新
  35. });
  36. } else {
  37. layer.msg(data, { time: 1000 }, function () {
  38. CheckImport(table, key, loadindex, index);
  39. });
  40. }
  41. }
  42. });
  43. }
  44. var excel;
  45. layui.config({
  46. base: '/layuiadmin/' //静态资源所在路径
  47. }).extend({
  48. myexcel: 'layui/lay/modules/excel',
  49. index: 'lib/index' //主入口模块
  50. }).use(['index', 'table', 'excel', 'laydate'], function () {
  51. var $ = layui.$
  52. , form = layui.form
  53. , table = layui.table;
  54. //- 筛选条件-日期
  55. var laydate = layui.laydate;
  56. var layCreateDate = laydate.render({
  57. elem: '#ActivationTime',
  58. type: 'date',
  59. range: true,
  60. trigger: 'click',
  61. change: function (value, date, endDate) {
  62. var op = true;
  63. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  64. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  65. op = false;
  66. layCreateDate.hint('日期范围请不要超过1个月');
  67. setTimeout(function () {
  68. $(".laydate-btns-confirm").addClass("laydate-disabled");
  69. }, 1);
  70. }
  71. } else {
  72. op = false;
  73. layCreateDate.hint('日期范围请不要超过1个月');
  74. setTimeout(function () {
  75. $(".laydate-btns-confirm").addClass("laydate-disabled");
  76. }, 1);
  77. }
  78. if (op) {
  79. $('#ActivationTime').val(value);
  80. }
  81. }
  82. });
  83. //- 筛选条件-日期
  84. var laydates = layui.laydate;
  85. var layCreateDate = laydates.render({
  86. elem: '#BindingTime',
  87. type: 'date',
  88. range: true,
  89. trigger: 'click',
  90. change: function (value, date, endDate) {
  91. var op = true;
  92. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  93. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  94. op = false;
  95. layCreateDate.hint('日期范围请不要超过1个月');
  96. setTimeout(function () {
  97. $(".laydate-btns-confirm").addClass("laydate-disabled");
  98. }, 1);
  99. }
  100. } else {
  101. op = false;
  102. layCreateDate.hint('日期范围请不要超过1个月');
  103. setTimeout(function () {
  104. $(".laydate-btns-confirm").addClass("laydate-disabled");
  105. }, 1);
  106. }
  107. if (op) {
  108. $('#BindingTime').val(value);
  109. }
  110. }
  111. });
  112. //excel导入
  113. excel = layui.excel;
  114. $('#ExcelFile').change(function (e) {
  115. var files = e.target.files;
  116. excel.importExcel(files, {}, function (data) {
  117. ExcelData = data[0].Sheet1;
  118. });
  119. });
  120. //监听单元格编辑
  121. table.on('edit(LAY-list-manage)', function (obj) {
  122. var value = obj.value //得到修改后的值
  123. , data = obj.data //得到所在行所有键值
  124. , field = obj.field; //得到字段
  125. if (field == "Sort") {
  126. $.ajax({
  127. type: "POST",
  128. url: "/Admin/PosMachinesTwo/Sort?r=" + Math.random(1),
  129. data: "Id=" + data.Id + "&Sort=" + value,
  130. dataType: "text",
  131. success: function (data) {
  132. }
  133. });
  134. }
  135. });
  136. //列表数据
  137. table.render({
  138. elem: '#LAY-list-manage'
  139. , url: '/Admin/PosMachinesTwo/IndexData' //模拟接口
  140. , cols: [[
  141. { type: 'checkbox', fixed: 'left' }
  142. , { field: 'PosSn', width: 200, title: 'SN编号', sort: true }
  143. , { field: 'BrandId', width: 200, title: '产品类型', sort: true }
  144. , { field: 'StoreIdCode', width: 200, title: '所在仓库编号', sort: true }
  145. , { field: 'StoreIdName', width: 200, title: '所在仓库名称', sort: true }
  146. , { field: 'UserIdMakerCode', width: 200, title: '创客编号', sort: true }
  147. , { field: 'UserIdRealName', width: 200, title: '创客姓名', sort: true }
  148. , { field: 'BindMerchantIdMerchantNo', width: 200, title: '绑定商户编号', sort: true }
  149. , { field: 'BindMerchantIdMerchantName', width: 200, title: '绑定商户姓名', sort: true }
  150. , { field: 'PosSnType', width: 200, title: '机具类型', sort: true }
  151. , { field: 'DeviceType', width: 200, title: '设备类型', sort: true }
  152. , { field: 'BindingState', width: 200, title: '绑定状态', sort: true }
  153. , { field: 'ActivationState', width: 200, title: '激活状态', sort: true }
  154. , { field: 'ActivationTime', width: 200, title: '激活时间', sort: true }
  155. , { field: 'BindingTime', width: 200, title: '绑定时间', sort: true }
  156. , { field: 'TransferTime', width: 200, title: '划拨时间', sort: true }
  157. , { field: 'CreateDate', width: 200, title: '入库时间', sort: true }
  158. , { field: 'RecycStartDate', width: 200, title: '循环开始时间', sort: true }
  159. , { field: 'SourcePosSn', width: 200, title: '来源机具', sort: true }
  160. , { field: 'RecycEndDate', width: 200, title: '循环截止时间', sort: true }
  161. , { field: 'UserInfo', width: 200, title: '大盟主券标记', sort: true }
  162. , { field: 'OpCode', width: 200, title: '所属运营中心', sort: true }
  163. , { field: 'IsFirst', width: 200, title: '是否第一台机具', sort: true }
  164. , { field: 'SeoKeyword', width: 200, title: '实际押金金额', sort: true }
  165. , { field: 'PrizeParams', width: 200, title: '设置押金金额', sort: true }
  166. , { title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  167. ]]
  168. , where: {
  169. }
  170. , page: true
  171. , limit: 30
  172. , height: 'full-' + String($('.layui-card-header').height() + 130)
  173. , text: '对不起,加载出现异常!'
  174. , done: function (res, curr, count) {
  175. $("#TotalCount").text(res.other.TotalCount);
  176. $("#KysCount99").text(res.other.KysCount99);
  177. $("#KssCount99").text(res.other.KssCount99);
  178. $("#KssCoun198").text(res.other.KssCoun198);
  179. $("#KssCount298").text(res.other.KssCount298);
  180. $(".layui-none").text("无数据");
  181. }
  182. });
  183. //监听工具条
  184. table.on('tool(LAY-list-manage)', function (obj) {
  185. var data = obj.data;
  186. if (obj.event === 'del') {
  187. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  188. $.ajax({
  189. type: "POST",
  190. url: "/Admin/PosMachinesTwo/Delete?r=" + Math.random(1),
  191. data: "Id=" + data.Id,
  192. dataType: "text",
  193. success: function (data) {
  194. if (data == "success") {
  195. obj.del();
  196. layer.close(index);
  197. } else {
  198. parent.layer.msg(data);
  199. }
  200. }
  201. });
  202. });
  203. } else if (obj.event === 'edit') {
  204. var tr = $(obj.tr);
  205. var perContent = layer.open({
  206. type: 2
  207. , title: '机具库-编辑'
  208. , content: 'Edit?Id=' + data.Id + ''
  209. , maxmin: true
  210. , area: ['500px', '450px']
  211. , btn: ['确定', '取消']
  212. , yes: function (index, layero) {
  213. var iframeWindow = window['layui-layer-iframe' + index]
  214. , submitID = 'LAY-list-front-submit'
  215. , submit = layero.find('iframe').contents().find('#' + submitID);
  216. setTimeout(function () {
  217. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  218. var errObj = $(this).find('.layui-form-danger');
  219. if (errObj.length > 0) {
  220. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  221. submit.click();
  222. }
  223. });
  224. }, 300);
  225. //监听提交
  226. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  227. var field = data.field; //获取提交的字段
  228. var userdata = "";
  229. for (var prop in field) {
  230. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  231. }
  232. //提交 Ajax 成功后,静态更新表格中的数据
  233. //$.ajax({});
  234. $.ajax({
  235. type: "POST",
  236. url: "/Admin/PosMachinesTwo/Edit?r=" + Math.random(1),
  237. data: userdata,
  238. dataType: "text",
  239. success: function (data) {
  240. layer.close(index); //关闭弹层
  241. if (data == "success") {
  242. table.reload('LAY-list-manage'); //数据刷新
  243. } else {
  244. layer.msg(data);
  245. }
  246. }
  247. });
  248. });
  249. submit.trigger('click');
  250. }
  251. , success: function (layero, index) {
  252. }
  253. });
  254. layer.full(perContent);
  255. }
  256. });
  257. //监听搜索
  258. form.on('submit(LAY-list-front-search)', function (data) {
  259. var field = data.field;
  260. field.ShowFlag = 1;
  261. if (field.UserIdMakerCode == "" && field.UserIdRealName == "" && field.StoreIdCode == "" && field.StoreIdName == "" && field.PosSn == "" && field.BindingStateSelect == "" && field.ActivationStateSelect == "" && field.ActivationDateData == "" && field.BindingDateData == "" && field.BrandId == "" && field.IsStoreSelect == "" && field.OpCode == "") {
  262. layer.alert('请输入查询条件');
  263. }
  264. else {
  265. //执行重载
  266. table.reload('LAY-list-manage', {
  267. where: field,
  268. page: {
  269. curr: 1
  270. }
  271. });
  272. }
  273. });
  274. form.on('submit(LAY-list-front-searchall)', function (data) {
  275. var field = data.field;
  276. field.ShowFlag = 1;
  277. field.UserIdMakerCode = "";
  278. field.UserIdRealName = "";
  279. field.StoreIdCode = "";
  280. field.StoreIdName = "";
  281. field.PosSn = "";
  282. field.BindingStateSelect = "";
  283. field.ActivationStateSelect = "";
  284. field.ActivationDateData = "";
  285. field.BindingDateData = "";
  286. field.BrandId = "";
  287. field.IsStoreSelect = "";
  288. field.OpCode = "";
  289. table.reload('LAY-list-manage', {
  290. where: field,
  291. page: {
  292. curr: 1
  293. }
  294. });
  295. });
  296. //事件
  297. var active = {
  298. batchdel: function () {
  299. var checkStatus = table.checkStatus('LAY-list-manage')
  300. , data = checkStatus.data; //得到选中的数据
  301. if (data.length < 1) {
  302. parent.layer.msg("请选择要删除的项");
  303. } else {
  304. var ids = "";
  305. $.each(data, function (index, value) {
  306. ids += data[index].Id + ",";
  307. });
  308. ids = ids.substring(0, ids.length - 1);
  309. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  310. $.ajax({
  311. type: "POST",
  312. url: "/Admin/PosMachinesTwo/Delete?r=" + Math.random(1),
  313. data: "Id=" + ids,
  314. dataType: "text",
  315. success: function (data) {
  316. layer.close(index);
  317. if (data == "success") {
  318. table.reload('LAY-list-manage');
  319. } else {
  320. layer.msg(data);
  321. }
  322. }
  323. });
  324. });
  325. }
  326. }
  327. , add: function () {
  328. var perContent = layer.open({
  329. type: 2
  330. , title: '机具库-添加'
  331. , content: 'Add'
  332. , maxmin: true
  333. , area: ['500px', '450px']
  334. , btn: ['确定', '取消']
  335. , yes: function (index, layero) {
  336. var iframeWindow = window['layui-layer-iframe' + index]
  337. , submitID = 'LAY-list-front-submit'
  338. , submit = layero.find('iframe').contents().find('#' + submitID);
  339. setTimeout(function () {
  340. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  341. var errObj = $(this).find('.layui-form-danger');
  342. if (errObj.length > 0) {
  343. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  344. submit.click();
  345. }
  346. });
  347. }, 300);
  348. //监听提交
  349. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  350. var field = data.field; //获取提交的字段
  351. var userdata = "";
  352. for (var prop in field) {
  353. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  354. }
  355. //提交 Ajax 成功后,静态更新表格中的数据
  356. //$.ajax({});
  357. $.ajax({
  358. type: "POST",
  359. url: "/Admin/PosMachinesTwo/Add?r=" + Math.random(1),
  360. data: userdata,
  361. dataType: "text",
  362. success: function (data) {
  363. layer.close(index); //关闭弹层
  364. if (data == "success") {
  365. table.reload('LAY-list-manage'); //数据刷新
  366. } else {
  367. layer.msg(data);
  368. }
  369. }
  370. });
  371. });
  372. submit.trigger('click');
  373. }
  374. });
  375. layer.full(perContent);
  376. }
  377. , ImportData: function () {
  378. var perContent = layer.open({
  379. type: 2
  380. , title: '金控入库时间导入'
  381. , content: 'Import'
  382. , maxmin: true
  383. , area: ['650px', '350px']
  384. , btn: ['确定', '取消']
  385. , yes: function (index, layero) {
  386. var iframeWindow = window['layui-layer-iframe' + index]
  387. , submitID = 'LAY-list-front-submit'
  388. , submit = layero.find('iframe').contents().find('#' + submitID);
  389. //监听提交
  390. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  391. var field = data.field; //获取提交的字段
  392. var userdata = "";
  393. for (var prop in field) {
  394. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  395. }
  396. //提交 Ajax 成功后,静态更新表格中的数据
  397. //$.ajax({});
  398. var loadindex = layer.load(1, {
  399. shade: [0.5, '#000']
  400. });
  401. $.ajax({
  402. type: "POST",
  403. url: "/Admin/PosMachinesTwo/ImportPost?r=" + Math.random(1),
  404. data: userdata,
  405. dataType: "text",
  406. success: function (data) {
  407. if (data.indexOf("success") == 0) {
  408. var datalist = data.split('|');
  409. var key = datalist[1];
  410. CheckImport(table, key, loadindex, index);
  411. } else {
  412. layer.msg(data);
  413. }
  414. }
  415. });
  416. });
  417. submit.trigger('click');
  418. }
  419. });
  420. },RejectStore: function () {
  421. ExcelKind = 1;
  422. layer.open({
  423. type: 1,
  424. title: '机具驳回仓库导入',
  425. maxmin: false,
  426. area: ['460px', '280px'],
  427. content: $('#excelForm'),
  428. cancel: function () {
  429. }
  430. });
  431. $("#excelTemp").html('<a href="/users/机具驳回仓库模版.xlsx">点击下载机具驳回仓库模版</a>');
  432. }
  433. , ImportCreateData: function () {
  434. layer.open({
  435. type: 1,
  436. title: '导入',
  437. maxmin: false,
  438. area: ['460px', '280px'],
  439. content: $('#excelForm'),
  440. cancel: function () {
  441. }
  442. });
  443. $("#excelTemp").html('<a href="/users/金控入库时间修改模板.xlsx">点击下载金控入库时间修改模板文件</a>');
  444. }
  445. , ExportExcel: function () {
  446. var userdata = '';
  447. $(".layuiadmin-card-header-auto input").each(function (i) {
  448. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  449. });
  450. $(".layuiadmin-card-header-auto select").each(function (i) {
  451. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  452. });
  453. var index = layer.load(1, {
  454. shade: [0.5, '#000']
  455. });
  456. $.ajax({
  457. type: "GET",
  458. url: "/Admin/PosMachinesTwo/ExportExcel?r=" + Math.random(1),
  459. data: userdata,
  460. dataType: "json",
  461. success: function (data) {
  462. data.Obj.unshift(data.Fields);
  463. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  464. layer.close(index);
  465. }
  466. });
  467. }
  468. , Open: function () {
  469. var checkStatus = table.checkStatus('LAY-list-manage')
  470. , data = checkStatus.data; //得到选中的数据
  471. if (data.length < 1) {
  472. parent.layer.msg("请选择要开启的项");
  473. } else {
  474. var ids = "";
  475. $.each(data, function (index, value) {
  476. ids += data[index].Id + ",";
  477. });
  478. ids = ids.substring(0, ids.length - 1);
  479. var index = layer.confirm('确定要开启吗?', function (index) {
  480. $.ajax({
  481. type: "POST",
  482. url: "/Admin/PosMachinesTwo/Open?r=" + Math.random(1),
  483. data: "Id=" + ids,
  484. dataType: "text",
  485. success: function (data) {
  486. layer.close(index);
  487. if (data == "success") {
  488. table.reload('LAY-list-manage');
  489. } else {
  490. layer.msg(data);
  491. }
  492. }
  493. });
  494. });
  495. }
  496. }
  497. , Close: function () {
  498. var checkStatus = table.checkStatus('LAY-list-manage')
  499. , data = checkStatus.data; //得到选中的数据
  500. if (data.length < 1) {
  501. parent.layer.msg("请选择要关闭的项");
  502. } else {
  503. var ids = "";
  504. $.each(data, function (index, value) {
  505. ids += data[index].Id + ",";
  506. });
  507. ids = ids.substring(0, ids.length - 1);
  508. var index = layer.confirm('确定要关闭吗?', function (index) {
  509. $.ajax({
  510. type: "POST",
  511. url: "/Admin/PosMachinesTwo/Close?r=" + Math.random(1),
  512. data: "Id=" + ids,
  513. dataType: "text",
  514. success: function (data) {
  515. layer.close(index);
  516. if (data == "success") {
  517. table.reload('LAY-list-manage');
  518. } else {
  519. layer.msg(data);
  520. }
  521. }
  522. });
  523. });
  524. }
  525. }
  526. };
  527. $('.layui-btn').on('click', function () {
  528. var type = $(this).data('type');
  529. active[type] ? active[type].call(this) : '';
  530. });
  531. });