PosMachinesTwo_Admin.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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: 'PosIsFirst', width: 200, title: '是否首台(机具奖励发放)', sort: true }
  165. , { field: 'SeoKeyword', width: 200, title: '实际押金金额', sort: true }
  166. , { field: 'PrizeParams', width: 200, title: '设置押金金额', sort: true }
  167. , { title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  168. ]]
  169. , where: {
  170. }
  171. , page: true
  172. , limit: 30
  173. , height: 'full-' + String($('.layui-card-header').height() + 130)
  174. , text: '对不起,加载出现异常!'
  175. , done: function (res, curr, count) {
  176. $("#TotalCount").text(res.other.TotalCount);
  177. $("#KysCount99").text(res.other.KysCount99);
  178. $("#KssCount99").text(res.other.KssCount99);
  179. $("#KssCoun198").text(res.other.KssCoun198);
  180. $("#KssCount298").text(res.other.KssCount298);
  181. $(".layui-none").text("无数据");
  182. }
  183. });
  184. //监听工具条
  185. table.on('tool(LAY-list-manage)', function (obj) {
  186. var data = obj.data;
  187. if (obj.event === 'del') {
  188. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  189. $.ajax({
  190. type: "POST",
  191. url: "/Admin/PosMachinesTwo/Delete?r=" + Math.random(1),
  192. data: "Id=" + data.Id,
  193. dataType: "text",
  194. success: function (data) {
  195. if (data == "success") {
  196. obj.del();
  197. layer.close(index);
  198. } else {
  199. parent.layer.msg(data);
  200. }
  201. }
  202. });
  203. });
  204. } else if (obj.event === 'edit') {
  205. var tr = $(obj.tr);
  206. var perContent = layer.open({
  207. type: 2
  208. , title: '机具库-编辑'
  209. , content: 'Edit?Id=' + data.Id + ''
  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/PosMachinesTwo/Edit?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. , success: function (layero, index) {
  253. }
  254. });
  255. layer.full(perContent);
  256. }
  257. });
  258. //监听搜索
  259. form.on('submit(LAY-list-front-search)', function (data) {
  260. var field = data.field;
  261. field.ShowFlag = 1;
  262. 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 == "") {
  263. layer.alert('请输入查询条件');
  264. }
  265. else {
  266. //执行重载
  267. table.reload('LAY-list-manage', {
  268. where: field,
  269. page: {
  270. curr: 1
  271. }
  272. });
  273. }
  274. });
  275. form.on('submit(LAY-list-front-searchall)', function (data) {
  276. var field = data.field;
  277. field.ShowFlag = 1;
  278. field.UserIdMakerCode = "";
  279. field.UserIdRealName = "";
  280. field.StoreIdCode = "";
  281. field.StoreIdName = "";
  282. field.PosSn = "";
  283. field.BindingStateSelect = "";
  284. field.ActivationStateSelect = "";
  285. field.ActivationDateData = "";
  286. field.BindingDateData = "";
  287. field.BrandId = "";
  288. field.IsStoreSelect = "";
  289. field.OpCode = "";
  290. table.reload('LAY-list-manage', {
  291. where: field,
  292. page: {
  293. curr: 1
  294. }
  295. });
  296. });
  297. //事件
  298. var active = {
  299. batchdel: function () {
  300. var checkStatus = table.checkStatus('LAY-list-manage')
  301. , data = checkStatus.data; //得到选中的数据
  302. if (data.length < 1) {
  303. parent.layer.msg("请选择要删除的项");
  304. } else {
  305. var ids = "";
  306. $.each(data, function (index, value) {
  307. ids += data[index].Id + ",";
  308. });
  309. ids = ids.substring(0, ids.length - 1);
  310. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  311. $.ajax({
  312. type: "POST",
  313. url: "/Admin/PosMachinesTwo/Delete?r=" + Math.random(1),
  314. data: "Id=" + ids,
  315. dataType: "text",
  316. success: function (data) {
  317. layer.close(index);
  318. if (data == "success") {
  319. table.reload('LAY-list-manage');
  320. } else {
  321. layer.msg(data);
  322. }
  323. }
  324. });
  325. });
  326. }
  327. }
  328. , add: function () {
  329. var perContent = layer.open({
  330. type: 2
  331. , title: '机具库-添加'
  332. , content: 'Add'
  333. , maxmin: true
  334. , area: ['500px', '450px']
  335. , btn: ['确定', '取消']
  336. , yes: function (index, layero) {
  337. var iframeWindow = window['layui-layer-iframe' + index]
  338. , submitID = 'LAY-list-front-submit'
  339. , submit = layero.find('iframe').contents().find('#' + submitID);
  340. setTimeout(function () {
  341. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  342. var errObj = $(this).find('.layui-form-danger');
  343. if (errObj.length > 0) {
  344. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  345. submit.click();
  346. }
  347. });
  348. }, 300);
  349. //监听提交
  350. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  351. var field = data.field; //获取提交的字段
  352. var userdata = "";
  353. for (var prop in field) {
  354. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  355. }
  356. //提交 Ajax 成功后,静态更新表格中的数据
  357. //$.ajax({});
  358. $.ajax({
  359. type: "POST",
  360. url: "/Admin/PosMachinesTwo/Add?r=" + Math.random(1),
  361. data: userdata,
  362. dataType: "text",
  363. success: function (data) {
  364. layer.close(index); //关闭弹层
  365. if (data == "success") {
  366. table.reload('LAY-list-manage'); //数据刷新
  367. } else {
  368. layer.msg(data);
  369. }
  370. }
  371. });
  372. });
  373. submit.trigger('click');
  374. }
  375. });
  376. layer.full(perContent);
  377. }
  378. , ImportData: function () {
  379. var perContent = layer.open({
  380. type: 2
  381. , title: '金控入库时间导入'
  382. , content: 'Import'
  383. , maxmin: true
  384. , area: ['650px', '350px']
  385. , btn: ['确定', '取消']
  386. , yes: function (index, layero) {
  387. var iframeWindow = window['layui-layer-iframe' + index]
  388. , submitID = 'LAY-list-front-submit'
  389. , submit = layero.find('iframe').contents().find('#' + submitID);
  390. //监听提交
  391. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  392. var field = data.field; //获取提交的字段
  393. var userdata = "";
  394. for (var prop in field) {
  395. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  396. }
  397. //提交 Ajax 成功后,静态更新表格中的数据
  398. //$.ajax({});
  399. var loadindex = layer.load(1, {
  400. shade: [0.5, '#000']
  401. });
  402. $.ajax({
  403. type: "POST",
  404. url: "/Admin/PosMachinesTwo/ImportPost?r=" + Math.random(1),
  405. data: userdata,
  406. dataType: "text",
  407. success: function (data) {
  408. if (data.indexOf("success") == 0) {
  409. var datalist = data.split('|');
  410. var key = datalist[1];
  411. CheckImport(table, key, loadindex, index);
  412. } else {
  413. layer.msg(data);
  414. }
  415. }
  416. });
  417. });
  418. submit.trigger('click');
  419. }
  420. });
  421. },RejectStore: function () {
  422. ExcelKind = 1;
  423. layer.open({
  424. type: 1,
  425. title: '机具驳回仓库导入',
  426. maxmin: false,
  427. area: ['460px', '280px'],
  428. content: $('#excelForm'),
  429. cancel: function () {
  430. }
  431. });
  432. $("#excelTemp").html('<a href="/users/机具驳回仓库模版.xlsx">点击下载机具驳回仓库模版</a>');
  433. }
  434. , ImportCreateData: function () {
  435. layer.open({
  436. type: 1,
  437. title: '导入',
  438. maxmin: false,
  439. area: ['460px', '280px'],
  440. content: $('#excelForm'),
  441. cancel: function () {
  442. }
  443. });
  444. $("#excelTemp").html('<a href="/users/金控入库时间修改模板.xlsx">点击下载金控入库时间修改模板文件</a>');
  445. }
  446. , ExportExcel: function () {
  447. var userdata = '';
  448. $(".layuiadmin-card-header-auto input").each(function (i) {
  449. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  450. });
  451. $(".layuiadmin-card-header-auto select").each(function (i) {
  452. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  453. });
  454. var index = layer.load(1, {
  455. shade: [0.5, '#000']
  456. });
  457. $.ajax({
  458. type: "GET",
  459. url: "/Admin/PosMachinesTwo/ExportExcel?r=" + Math.random(1),
  460. data: userdata,
  461. dataType: "json",
  462. success: function (data) {
  463. data.Obj.unshift(data.Fields);
  464. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  465. layer.close(index);
  466. }
  467. });
  468. }
  469. , Open: function () {
  470. var checkStatus = table.checkStatus('LAY-list-manage')
  471. , data = checkStatus.data; //得到选中的数据
  472. if (data.length < 1) {
  473. parent.layer.msg("请选择要开启的项");
  474. } else {
  475. var ids = "";
  476. $.each(data, function (index, value) {
  477. ids += data[index].Id + ",";
  478. });
  479. ids = ids.substring(0, ids.length - 1);
  480. var index = layer.confirm('确定要开启吗?', function (index) {
  481. $.ajax({
  482. type: "POST",
  483. url: "/Admin/PosMachinesTwo/Open?r=" + Math.random(1),
  484. data: "Id=" + ids,
  485. dataType: "text",
  486. success: function (data) {
  487. layer.close(index);
  488. if (data == "success") {
  489. table.reload('LAY-list-manage');
  490. } else {
  491. layer.msg(data);
  492. }
  493. }
  494. });
  495. });
  496. }
  497. }
  498. , Close: function () {
  499. var checkStatus = table.checkStatus('LAY-list-manage')
  500. , data = checkStatus.data; //得到选中的数据
  501. if (data.length < 1) {
  502. parent.layer.msg("请选择要关闭的项");
  503. } else {
  504. var ids = "";
  505. $.each(data, function (index, value) {
  506. ids += data[index].Id + ",";
  507. });
  508. ids = ids.substring(0, ids.length - 1);
  509. var index = layer.confirm('确定要关闭吗?', function (index) {
  510. $.ajax({
  511. type: "POST",
  512. url: "/Admin/PosMachinesTwo/Close?r=" + Math.random(1),
  513. data: "Id=" + ids,
  514. dataType: "text",
  515. success: function (data) {
  516. layer.close(index);
  517. if (data == "success") {
  518. table.reload('LAY-list-manage');
  519. } else {
  520. layer.msg(data);
  521. }
  522. }
  523. });
  524. });
  525. }
  526. }
  527. };
  528. $('.layui-btn').on('click', function () {
  529. var type = $(this).data('type');
  530. active[type] ? active[type].call(this) : '';
  531. });
  532. });