MachineApply_Admin.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. var ExcelData,ExcelKind;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/MachineApply/Import?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 {
  14. layer.msg(data);
  15. }
  16. }
  17. });
  18. }
  19. var excel;
  20. layui.config({
  21. base: '/layuiadmin/' //静态资源所在路径
  22. }).extend({
  23. myexcel: 'layui/lay/modules/excel',
  24. index: 'lib/index' //主入口模块
  25. }).use(['index', 'table', 'excel', 'laydate'], function () {
  26. var $ = layui.$
  27. , form = layui.form
  28. , table = layui.table;
  29. //- 筛选条件-日期
  30. var laydate = layui.laydate;
  31. var layCreateDate = laydate.render({
  32. elem: '#CreateDate',
  33. type: 'datetime',
  34. range: true,
  35. trigger: 'click',
  36. change: function (value, date, endDate) {
  37. var op = true;
  38. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  39. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  40. op = false;
  41. layCreateDate.hint('日期范围请不要超过1个月');
  42. setTimeout(function () {
  43. $(".laydate-btns-confirm").addClass("laydate-disabled");
  44. }, 1);
  45. }
  46. } else {
  47. op = false;
  48. layCreateDate.hint('日期范围请不要超过1个月');
  49. setTimeout(function () {
  50. $(".laydate-btns-confirm").addClass("laydate-disabled");
  51. }, 1);
  52. }
  53. if (op) {
  54. $('#CreateDate').val(value);
  55. }
  56. }
  57. });
  58. var layApplyTime = laydate.render({
  59. elem: '#ApplyTime',
  60. trigger: 'click',
  61. type: 'datetime',
  62. range: true,
  63. change: function (value, date, endDate) {
  64. var op = true;
  65. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  66. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  67. op = false;
  68. layApplyTime.hint('日期范围请不要超过1个月');
  69. setTimeout(function () {
  70. $(".laydate-btns-confirm").addClass("laydate-disabled");
  71. }, 1);
  72. }
  73. } else {
  74. op = false;
  75. layApplyTime.hint('日期范围请不要超过1个月');
  76. setTimeout(function () {
  77. $(".laydate-btns-confirm").addClass("laydate-disabled");
  78. }, 1);
  79. }
  80. if (op) {
  81. $('#ApplyTime').val(value);
  82. }
  83. }
  84. });
  85. var laySendDate = laydate.render({
  86. elem: '#SendDate',
  87. trigger: 'click',
  88. type: 'datetime',
  89. range: true,
  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. laySendDate.hint('日期范围请不要超过1个月');
  96. setTimeout(function () {
  97. $(".laydate-btns-confirm").addClass("laydate-disabled");
  98. }, 1);
  99. }
  100. } else {
  101. op = false;
  102. laySendDate.hint('日期范围请不要超过1个月');
  103. setTimeout(function () {
  104. $(".laydate-btns-confirm").addClass("laydate-disabled");
  105. }, 1);
  106. }
  107. if (op) {
  108. $('#SendDate').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/MachineApply/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/MachineApply/IndexData' //模拟接口
  140. , cols: [[
  141. { type: 'checkbox', fixed: 'left' }
  142. , {field:'Id', fixed: 'left', title:'ID', width:80, sort: true, unresize: true}
  143. ,{field:'ApplyNo', width: 200, title:'申请单号', sort: true}
  144. ,{field:'CreateDate', width: 200, title:'创建时间', sort: true}
  145. ,{field:'UserId', width: 200, title:'创客', sort: true}
  146. ,{field:'BrandId', width: 200, title:'品牌', sort: true}
  147. ,{field:'Areas', width: 200, title:'收货所在地区', sort: true}
  148. ,{field:'Address', width: 200, title:'收货详细地址', sort: true}
  149. ,{field:'RealName', width: 200, title:'收件人姓名', sort: true}
  150. ,{field:'Mobile', width: 200, title:'收件人手机号', sort: true}
  151. ,{field:'ApplyDeviceName', width: 200, title:'申请机具名称', sort: true}
  152. ,{field:'ApplyDeviceNum', width: 200, title:'申请机具数量', sort: true}
  153. ,{field:'ApplyTime', width: 200, title:'申请时间', sort: true}
  154. ,{field:'SendStatus', width: 200, title:'发货状态', sort: true}
  155. ,{field:'ExpressNo', width: 200, title:'快递单号', sort: true}
  156. ,{field:'ExpressName', width: 200, title:'快递名称', sort: true}
  157. ,{field:'DeliveryType', width: 200, title:'提货类型', sort: true}
  158. ,{field:'StoreId', width: 200, title:'发货仓库', sort: true}
  159. ,{field:'StoreName', width: 200, title:'发货仓库名称', sort: true}
  160. ,{field:'StoreManager', width: 200, title:'仓库联系人', sort: true}
  161. ,{field:'Remark', width: 200, title:'订单备注', sort: true}
  162. ,{field:'StoreUserId', width: 200, title:'仓库归属创客', sort: true}
  163. ,{field:'SendDate', width: 200, title:'发货时间', sort: true}
  164. ,{field:'SendSn', width: 200, title:'发货SN', sort: true}
  165. , {field:'Sort', fixed: 'right', title:'排序', width:80, edit: 'text'}
  166. , { title: '操作', align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  167. ]]
  168. , where: {
  169. }
  170. , page: true
  171. , limit: 30
  172. , height: 'full-220'
  173. , text: '对不起,加载出现异常!'
  174. , done: function (res, curr, count) {
  175. $(".layui-none").text("无数据");
  176. }
  177. });
  178. //监听工具条
  179. table.on('tool(LAY-list-manage)', function (obj) {
  180. var data = obj.data;
  181. if (obj.event === 'del') {
  182. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  183. $.ajax({
  184. type: "POST",
  185. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  186. data: "Id=" + data.Id,
  187. dataType: "text",
  188. success: function (data) {
  189. if (data == "success") {
  190. obj.del();
  191. layer.close(index);
  192. } else {
  193. parent.layer.msg(data);
  194. }
  195. }
  196. });
  197. });
  198. } else if (obj.event === 'edit') {
  199. var tr = $(obj.tr);
  200. var perContent = layer.open({
  201. type: 2
  202. , title: '机具申请订单-编辑'
  203. , content: 'Edit?Id=' + data.Id + ''
  204. , maxmin: true
  205. , area: ['500px', '450px']
  206. , btn: ['确定', '取消']
  207. , yes: function (index, layero) {
  208. var iframeWindow = window['layui-layer-iframe' + index]
  209. , submitID = 'LAY-list-front-submit'
  210. , submit = layero.find('iframe').contents().find('#' + submitID);
  211. setTimeout(function () {
  212. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  213. var errObj = $(this).find('.layui-form-danger');
  214. if (errObj.length > 0) {
  215. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  216. submit.click();
  217. }
  218. });
  219. }, 300);
  220. //监听提交
  221. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  222. var field = data.field; //获取提交的字段
  223. var userdata = "";
  224. for (var prop in field) {
  225. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  226. }
  227. //提交 Ajax 成功后,静态更新表格中的数据
  228. //$.ajax({});
  229. $.ajax({
  230. type: "POST",
  231. url: "/Admin/MachineApply/Edit?r=" + Math.random(1),
  232. data: userdata,
  233. dataType: "text",
  234. success: function (data) {
  235. layer.close(index); //关闭弹层
  236. if (data == "success") {
  237. table.reload('LAY-list-manage'); //数据刷新
  238. } else {
  239. layer.msg(data);
  240. }
  241. }
  242. });
  243. });
  244. submit.trigger('click');
  245. }
  246. , success: function (layero, index) {
  247. }
  248. });
  249. layer.full(perContent);
  250. }
  251. });
  252. //监听搜索
  253. form.on('submit(LAY-list-front-search)', function (data) {
  254. var field = data.field;
  255. //执行重载
  256. table.reload('LAY-list-manage', {
  257. where: field
  258. });
  259. });
  260. form.on('submit(LAY-list-front-searchall)', function (data) {
  261. table.reload('LAY-list-manage', {
  262. where: null
  263. });
  264. });
  265. //事件
  266. var active = {
  267. batchdel: function () {
  268. var checkStatus = table.checkStatus('LAY-list-manage')
  269. , data = checkStatus.data; //得到选中的数据
  270. if (data.length < 1) {
  271. parent.layer.msg("请选择要删除的项");
  272. } else {
  273. var ids = "";
  274. $.each(data, function (index, value) {
  275. ids += data[index].Id + ",";
  276. });
  277. ids = ids.substring(0, ids.length - 1);
  278. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  279. $.ajax({
  280. type: "POST",
  281. url: "/Admin/MachineApply/Delete?r=" + Math.random(1),
  282. data: "Id=" + ids,
  283. dataType: "text",
  284. success: function (data) {
  285. layer.close(index);
  286. if (data == "success") {
  287. table.reload('LAY-list-manage');
  288. } else {
  289. layer.msg(data);
  290. }
  291. }
  292. });
  293. });
  294. }
  295. }
  296. , add: function () {
  297. var perContent = layer.open({
  298. type: 2
  299. , title: '机具申请订单-添加'
  300. , content: 'Add'
  301. , maxmin: true
  302. , area: ['500px', '450px']
  303. , btn: ['确定', '取消']
  304. , yes: function (index, layero) {
  305. var iframeWindow = window['layui-layer-iframe' + index]
  306. , submitID = 'LAY-list-front-submit'
  307. , submit = layero.find('iframe').contents().find('#' + submitID);
  308. setTimeout(function () {
  309. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  310. var errObj = $(this).find('.layui-form-danger');
  311. if (errObj.length > 0) {
  312. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  313. submit.click();
  314. }
  315. });
  316. }, 300);
  317. //监听提交
  318. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  319. var field = data.field; //获取提交的字段
  320. var userdata = "";
  321. for (var prop in field) {
  322. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  323. }
  324. //提交 Ajax 成功后,静态更新表格中的数据
  325. //$.ajax({});
  326. $.ajax({
  327. type: "POST",
  328. url: "/Admin/MachineApply/Add?r=" + Math.random(1),
  329. data: userdata,
  330. dataType: "text",
  331. success: function (data) {
  332. layer.close(index); //关闭弹层
  333. if (data == "success") {
  334. table.reload('LAY-list-manage'); //数据刷新
  335. } else {
  336. layer.msg(data);
  337. }
  338. }
  339. });
  340. });
  341. submit.trigger('click');
  342. }
  343. });
  344. layer.full(perContent);
  345. }
  346. , ImportData: function () {
  347. ExcelKind = 1;
  348. layer.open({
  349. type: 1,
  350. title: '导入',
  351. maxmin: false,
  352. area: ['460px', '280px'],
  353. content: $('#excelForm'),
  354. cancel: function () {
  355. }
  356. });
  357. $("#excelTemp").html('<a href="/excelfile/模板文件.xlsx">点击下载模板文件</a>');
  358. }
  359. , ExportExcel: function () {
  360. var userdata = '';
  361. $(".layuiadmin-card-header-auto input").each(function (i) {
  362. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  363. });
  364. $(".layuiadmin-card-header-auto select").each(function (i) {
  365. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  366. });
  367. $.ajax({
  368. type: "GET",
  369. url: "/Admin/MachineApply/ExportExcel?r=" + Math.random(1),
  370. data: userdata,
  371. dataType: "json",
  372. success: function (data) {
  373. data.Obj.unshift(data.Fields);
  374. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  375. }
  376. });
  377. }
  378. , Open: function () {
  379. var checkStatus = table.checkStatus('LAY-list-manage')
  380. , data = checkStatus.data; //得到选中的数据
  381. if(data.length < 1){
  382. parent.layer.msg("请选择要开启的项");
  383. }else{
  384. var ids = "";
  385. $.each(data, function (index, value) {
  386. ids += data[index].Id + ",";
  387. });
  388. ids = ids.substring(0, ids.length - 1);
  389. var index = layer.confirm('确定要开启吗?', function (index) {
  390. $.ajax({
  391. type: "POST",
  392. url: "/Admin/MachineApply/Open?r=" + Math.random(1),
  393. data: "Id=" + ids,
  394. dataType: "text",
  395. success: function (data) {
  396. layer.close(index);
  397. if (data == "success") {
  398. table.reload('LAY-list-manage');
  399. } else {
  400. layer.msg(data);
  401. }
  402. }
  403. });
  404. });
  405. }
  406. }
  407. , Close: 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/MachineApply/Close?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. };
  437. $('.layui-btn').on('click', function () {
  438. var type = $(this).data('type');
  439. active[type] ? active[type].call(this) : '';
  440. });
  441. });