PosMachinesTwoTimeOut_Admin.js 21 KB

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