PosMachinesTwo_Admin.js 24 KB

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