PosMachinesTwo_Admin.js 24 KB

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