ProductNorm_Admin.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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', title: '名称', sort: true }
  63. , { field: 'Price', title: '价格', sort: true }
  64. , { field: 'Integral', title: '抵扣积分', sort: true }
  65. , { field: 'UserPrice', title: '会员价', sort: true }
  66. , { field: 'UserIntegral', title: '会员抵扣积分', sort: true }
  67. , { field: 'Stock', title: '库存', sort: true }
  68. , { field: 'BuyCount', title: '已购买数', sort: true }
  69. , { field: 'Code', title: '编码', sort: true }
  70. , { field: 'LimitCount', 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-220'
  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. });
  158. });
  159. form.on('submit(LAY-list-front-searchall)', function (data) {
  160. table.reload('LAY-list-manage', {
  161. where: null
  162. });
  163. });
  164. //事件
  165. var active = {
  166. batchdel: function () {
  167. var checkStatus = table.checkStatus('LAY-list-manage')
  168. , data = checkStatus.data; //得到选中的数据
  169. if (data.length < 1) {
  170. parent.layer.msg("请选择要删除的项");
  171. } else {
  172. var ids = "";
  173. $.each(data, function (index, value) {
  174. ids += data[index].Id + ",";
  175. });
  176. ids = ids.substring(0, ids.length - 1);
  177. var index = layer.confirm('确定要删除吗?删除后不能恢复!', function (index) {
  178. $.ajax({
  179. type: "POST",
  180. url: "/Admin/ProductNorm/Delete?r=" + Math.random(1),
  181. data: "Id=" + ids,
  182. dataType: "text",
  183. success: function (data) {
  184. layer.close(index);
  185. if (data == "success") {
  186. table.reload('LAY-list-manage');
  187. } else {
  188. layer.msg(data);
  189. }
  190. }
  191. });
  192. });
  193. }
  194. }
  195. , add: function () {
  196. var perContent = layer.open({
  197. type: 2
  198. , title: '商品规格-添加'
  199. , content: 'Add'
  200. , maxmin: true
  201. , area: ['500px', '450px']
  202. , btn: ['确定', '取消']
  203. , yes: function (index, layero) {
  204. var iframeWindow = window['layui-layer-iframe' + index]
  205. , submitID = 'LAY-list-front-submit'
  206. , submit = layero.find('iframe').contents().find('#' + submitID);
  207. //监听提交
  208. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  209. if (clickFlag) {
  210. clickFlag = false;
  211. var field = data.field; //获取提交的字段
  212. var userdata = "";
  213. for (var prop in field) {
  214. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  215. }
  216. //提交 Ajax 成功后,静态更新表格中的数据
  217. //$.ajax({});
  218. $.ajax({
  219. type: "POST",
  220. url: "/Admin/ProductNorm/Add?r=" + Math.random(1),
  221. data: userdata,
  222. dataType: "text",
  223. success: function (data) {
  224. clickFlag = true;
  225. layer.close(index); //关闭弹层
  226. if (data == "success") {
  227. table.reload('LAY-list-manage'); //数据刷新
  228. } else {
  229. layer.msg(data);
  230. }
  231. }
  232. });
  233. }
  234. });
  235. submit.trigger('click');
  236. }
  237. });
  238. layer.full(perContent);
  239. }
  240. , ImportData: function () {
  241. layer.open({
  242. type: 2,
  243. title: '导入',
  244. maxmin: false,
  245. area: ['460px', '180px'],
  246. content: $('#excelForm'),
  247. cancel: function () {
  248. }
  249. });
  250. }
  251. , ExportExcel: function () {
  252. var userdata = '';
  253. $(".layuiadmin-card-header-auto input").each(function (i) {
  254. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  255. });
  256. $(".layuiadmin-card-header-auto select").each(function (i) {
  257. userdata += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
  258. });
  259. $.ajax({
  260. type: "GET",
  261. url: "/Admin/ProductNorm/ExportExcel?r=" + Math.random(1),
  262. data: userdata,
  263. dataType: "json",
  264. success: function (data) {
  265. data.Obj.unshift(data.Fields);
  266. excel.exportExcel(data.Obj, data.Info, 'xlsx');
  267. }
  268. });
  269. }
  270. , Open: function () {
  271. var checkStatus = table.checkStatus('LAY-list-manage')
  272. , data = checkStatus.data; //得到选中的数据
  273. if (data.length < 1) {
  274. parent.layer.msg("请选择要开启的项");
  275. } else {
  276. var ids = "";
  277. $.each(data, function (index, value) {
  278. ids += data[index].Id + ",";
  279. });
  280. ids = ids.substring(0, ids.length - 1);
  281. var index = layer.confirm('确定要开启吗?', function (index) {
  282. $.ajax({
  283. type: "POST",
  284. url: "/Admin/ProductNorm/Open?r=" + Math.random(1),
  285. data: "Id=" + ids,
  286. dataType: "text",
  287. success: function (data) {
  288. layer.close(index);
  289. if (data == "success") {
  290. table.reload('LAY-list-manage');
  291. } else {
  292. layer.msg(data);
  293. }
  294. }
  295. });
  296. });
  297. }
  298. }
  299. , Close: function () {
  300. var checkStatus = table.checkStatus('LAY-list-manage')
  301. , data = checkStatus.data; //得到选中的数据
  302. if (data.length < 1) {
  303. parent.layer.msg("请选择要关闭的项");
  304. } else {
  305. var ids = "";
  306. $.each(data, function (index, value) {
  307. ids += data[index].Id + ",";
  308. });
  309. ids = ids.substring(0, ids.length - 1);
  310. var index = layer.confirm('确定要关闭吗?', function (index) {
  311. $.ajax({
  312. type: "POST",
  313. url: "/Admin/ProductNorm/Close?r=" + Math.random(1),
  314. data: "Id=" + ids,
  315. dataType: "text",
  316. success: function (data) {
  317. layer.close(index);
  318. if (data == "success") {
  319. table.reload('LAY-list-manage');
  320. } else {
  321. layer.msg(data);
  322. }
  323. }
  324. });
  325. });
  326. }
  327. }
  328. };
  329. $('.layui-btn').on('click', function () {
  330. var type = $(this).data('type');
  331. active[type] ? active[type].call(this) : '';
  332. });
  333. });