ProductNorm_Admin.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. var clickFlag = true;
  2. var ExcelData;
  3. function ConfirmImport() {
  4. $.ajax({
  5. type: "POST",
  6. url: "/Admin/ProductNorm/Import?r=" + Math.random(1),
  7. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  8. dataType: "text",
  9. success: function (data) {
  10. if (data == "success") {
  11. layer.msg("导入成功", { time: 2000 }, function () {
  12. window.location.reload();
  13. });
  14. } else {
  15. layer.msg(data);
  16. }
  17. }
  18. });
  19. }
  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. //excel导入
  32. var excel = layui.excel;
  33. $('#ExcelFile').change(function (e) {
  34. var files = e.target.files;
  35. excel.importExcel(files, {}, function (data) {
  36. ExcelData = data[0].Sheet1;
  37. });
  38. });
  39. //监听单元格编辑
  40. table.on('edit(LAY-list-manage)', function (obj) {
  41. var value = obj.value //得到修改后的值
  42. , data = obj.data //得到所在行所有键值
  43. , field = obj.field; //得到字段
  44. if (field == "Sort") {
  45. $.ajax({
  46. type: "POST",
  47. url: "/Admin/ProductNorm/Sort?r=" + Math.random(1),
  48. data: "Id=" + data.Id + "&Sort=" + value,
  49. dataType: "text",
  50. success: function (data) {
  51. }
  52. });
  53. }
  54. });
  55. //列表数据
  56. table.render({
  57. elem: '#LAY-list-manage'
  58. , url: '/Admin/ProductNorm/IndexData' //模拟接口
  59. , cols: [[
  60. { type: 'checkbox', fixed: 'left' }
  61. , { field: 'Id', fixed: 'left', title: 'ID', width: 80, sort: true, unresize: true }
  62. , { field: 'ColName', width: 200, title: '名称', sort: true }
  63. , { field: 'Price', width: 200, title: '价格', sort: true }
  64. , { field: 'Integral', width: 200, title: '抵扣积分', sort: true }
  65. , { field: 'UserPrice', width: 200, title: '创客价', sort: true }
  66. , { field: 'UserIntegral', width: 200, title: '创客抵扣积分', sort: true }
  67. , { field: 'Stock', width: 200, title: '库存', sort: true }
  68. , { field: 'BuyCount', width: 200, title: '已购买数', sort: true }
  69. , { field: 'Code', width: 200, title: '编码', sort: true }
  70. , { field: 'LimitCount', width: 200, title: '限购数量', sort: true }
  71. , { field: 'Sort', fixed: 'right', title: '排序', width: 80, edit: 'text' }
  72. , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-list-tools' }
  73. ]]
  74. , page: true
  75. , limit: 30
  76. , height: 'full-' + String($('.layui-card-header').height() + 130)
  77. , text: '对不起,加载出现异常!'
  78. , done: function (res, curr, count) {
  79. $(".layui-none").text("无数据");
  80. }
  81. });
  82. //监听工具条
  83. table.on('tool(LAY-list-manage)', function (obj) {
  84. var data = obj.data;
  85. if (obj.event === 'del') {
  86. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  87. $.ajax({
  88. type: "POST",
  89. url: "/Admin/ProductNorm/Delete?r=" + Math.random(1),
  90. data: "Id=" + data.Id,
  91. dataType: "text",
  92. success: function (data) {
  93. if (data == "success") {
  94. obj.del();
  95. layer.close(index);
  96. } else {
  97. parent.layer.msg(data);
  98. }
  99. }
  100. });
  101. });
  102. } else if (obj.event === 'edit') {
  103. var tr = $(obj.tr);
  104. var perContent = layer.open({
  105. type: 2
  106. , title: '商品规格-编辑'
  107. , content: 'Edit?Id=' + data.Id
  108. , maxmin: true
  109. , area: ['500px', '450px']
  110. , btn: ['确定', '取消']
  111. , yes: function (index, layero) {
  112. var iframeWindow = window['layui-layer-iframe' + index]
  113. , submitID = 'LAY-list-front-submit'
  114. , submit = layero.find('iframe').contents().find('#' + submitID);
  115. //监听提交
  116. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  117. if (clickFlag) {
  118. clickFlag = false;
  119. var field = data.field; //获取提交的字段
  120. var userdata = "";
  121. for (var prop in field) {
  122. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  123. }
  124. //提交 Ajax 成功后,静态更新表格中的数据
  125. //$.ajax({});
  126. $.ajax({
  127. type: "POST",
  128. url: "/Admin/ProductNorm/Edit?r=" + Math.random(1),
  129. data: userdata,
  130. dataType: "text",
  131. success: function (data) {
  132. clickFlag = true;
  133. layer.close(index); //关闭弹层
  134. if (data == "success") {
  135. table.reload('LAY-list-manage'); //数据刷新
  136. } else {
  137. layer.msg(data);
  138. }
  139. }
  140. });
  141. }
  142. });
  143. submit.trigger('click');
  144. }
  145. , success: function (layero, index) {
  146. }
  147. });
  148. layer.full(perContent);
  149. }
  150. });
  151. //监听搜索
  152. form.on('submit(LAY-list-front-search)', function (data) {
  153. var field = data.field;
  154. //执行重载
  155. table.reload('LAY-list-manage', {
  156. where: field,
  157. page: {
  158. curr: 1
  159. }
  160. });
  161. });
  162. form.on('submit(LAY-list-front-searchall)', function (data) {
  163. table.reload('LAY-list-manage', {
  164. where: null,
  165. page: {
  166. curr: 1
  167. }
  168. });
  169. });
  170. //事件
  171. var active = {
  172. batchdel: function () {
  173. var checkStatus = table.checkStatus('LAY-list-manage')
  174. , data = checkStatus.data; //得到选中的数据
  175. if (data.length < 1) {
  176. parent.layer.msg("请选择要删除的项");
  177. } else {
  178. var ids = "";
  179. $.each(data, function (index, value) {
  180. ids += data[index].Id + ",";
  181. });
  182. ids = ids.substring(0, ids.length - 1);
  183. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  184. $.ajax({
  185. type: "POST",
  186. url: "/Admin/ProductNorm/Delete?r=" + Math.random(1),
  187. data: "Id=" + ids,
  188. dataType: "text",
  189. success: function (data) {
  190. layer.close(index);
  191. if (data == "success") {
  192. table.reload('LAY-list-manage');
  193. } else {
  194. layer.msg(data);
  195. }
  196. }
  197. });
  198. });
  199. }
  200. }
  201. , add: function () {
  202. var perContent = layer.open({
  203. type: 2
  204. , title: '商品规格-添加'
  205. , content: 'Add'
  206. , maxmin: true
  207. , area: ['500px', '450px']
  208. , btn: ['确定', '取消']
  209. , yes: function (index, layero) {
  210. var iframeWindow = window['layui-layer-iframe' + index]
  211. , submitID = 'LAY-list-front-submit'
  212. , submit = layero.find('iframe').contents().find('#' + submitID);
  213. //监听提交
  214. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  215. if (clickFlag) {
  216. clickFlag = false;
  217. var field = data.field; //获取提交的字段
  218. var userdata = "";
  219. for (var prop in field) {
  220. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  221. }
  222. //提交 Ajax 成功后,静态更新表格中的数据
  223. //$.ajax({});
  224. $.ajax({
  225. type: "POST",
  226. url: "/Admin/ProductNorm/Add?r=" + Math.random(1),
  227. data: userdata,
  228. dataType: "text",
  229. success: function (data) {
  230. clickFlag = true;
  231. layer.close(index); //关闭弹层
  232. if (data == "success") {
  233. table.reload('LAY-list-manage'); //数据刷新
  234. } else {
  235. layer.msg(data);
  236. }
  237. }
  238. });
  239. }
  240. });
  241. submit.trigger('click');
  242. }
  243. });
  244. layer.full(perContent);
  245. }
  246. , ImportData: function () {
  247. layer.open({
  248. type: 2,
  249. title: '导入',
  250. maxmin: false,
  251. area: ['460px', '180px'],
  252. content: $('#excelForm'),
  253. cancel: function () {
  254. }
  255. });
  256. }
  257. , ExportExcel: function () {
  258. var userdata = '';
  259. $(".layuiadmin-card-header-auto input").each(function (i) {
  260. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  261. });
  262. $(".layuiadmin-card-header-auto select").each(function (i) {
  263. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  264. });
  265. $.ajax({
  266. type: "GET",
  267. url: "/Admin/ProductNorm/ExportExcel?r=" + Math.random(1),
  268. data: userdata,
  269. dataType: "json",
  270. success: function (data) {
  271. data.Obj.unshift(data.Fields);
  272. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  273. }
  274. });
  275. }
  276. , Open: function () {
  277. var checkStatus = table.checkStatus('LAY-list-manage')
  278. , data = checkStatus.data; //得到选中的数据
  279. if (data.length < 1) {
  280. parent.layer.msg("请选择要开启的项");
  281. } else {
  282. var ids = "";
  283. $.each(data, function (index, value) {
  284. ids += data[index].Id + ",";
  285. });
  286. ids = ids.substring(0, ids.length - 1);
  287. var index = layer.confirm('确定要开启吗?', function (index) {
  288. $.ajax({
  289. type: "POST",
  290. url: "/Admin/ProductNorm/Open?r=" + Math.random(1),
  291. data: "Id=" + ids,
  292. dataType: "text",
  293. success: function (data) {
  294. layer.close(index);
  295. if (data == "success") {
  296. table.reload('LAY-list-manage');
  297. } else {
  298. layer.msg(data);
  299. }
  300. }
  301. });
  302. });
  303. }
  304. }
  305. , Close: function () {
  306. var checkStatus = table.checkStatus('LAY-list-manage')
  307. , data = checkStatus.data; //得到选中的数据
  308. if (data.length < 1) {
  309. parent.layer.msg("请选择要关闭的项");
  310. } else {
  311. var ids = "";
  312. $.each(data, function (index, value) {
  313. ids += data[index].Id + ",";
  314. });
  315. ids = ids.substring(0, ids.length - 1);
  316. var index = layer.confirm('确定要关闭吗?', function (index) {
  317. $.ajax({
  318. type: "POST",
  319. url: "/Admin/ProductNorm/Close?r=" + Math.random(1),
  320. data: "Id=" + ids,
  321. dataType: "text",
  322. success: function (data) {
  323. layer.close(index);
  324. if (data == "success") {
  325. table.reload('LAY-list-manage');
  326. } else {
  327. layer.msg(data);
  328. }
  329. }
  330. });
  331. });
  332. }
  333. }
  334. };
  335. $('.layui-btn').on('click', function () {
  336. var type = $(this).data('type');
  337. active[type] ? active[type].call(this) : '';
  338. });
  339. });