price.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form'], function(){
  2. var laypage = layui.laypage //分页
  3. ,layer = layui.layer //弹层
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form;
  7. var tableIds = 'pricelist'; //表格ID
  8. var reloadId = 'tablerReload';
  9. //第一个实例
  10. var tableIns = table.render({
  11. elem: '#'+tableIds
  12. ,url: '/dictionarya/priceform' //数据接口
  13. ,where:{token:csrfToken}
  14. ,method:'post'
  15. ,page: true //开启分页
  16. ,height:600
  17. ,text:'数据加载中'
  18. ,id:reloadId
  19. ,cols: [[ //表头
  20. {type:'numbers'},
  21. {field: 'price', title: '价格',align:'center'},
  22. {field: 'state', title: '状态', width:200,align:'center'}
  23. ,{field: 'sort', title: '排序', width:200,align:'center',event:'sortData',edit: 'text',sort: true,templet:"#sortBox"}
  24. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  25. ]]
  26. });
  27. table.reload('tablerReload'); //重新加载
  28. //列表操作
  29. table.on('tool('+tableIds+')', function(obj){
  30. var layEvent = obj.event,
  31. data = obj.data;
  32. if(layEvent === 'edit'){
  33. layer.open({
  34. type: 2,
  35. title: '修改户型',
  36. area: ['600px', '500px'],
  37. content: '/dictionarya/priceedit?id='+data.id, //iframe的url,no代表不显示滚动条
  38. end:function () {
  39. table.reload('tablerReload'); //重新加载
  40. }
  41. });
  42. } else if(layEvent === 'del') {
  43. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  44. $.post('/dictionarya/pricedel',{'id':data.id},function (data) {
  45. if(data.code == 200)
  46. {
  47. layer.msg(data.msg);
  48. table.reload('tablerReload'); //重新加载
  49. } else if(data.code == 300 ) {
  50. layer.msg(data.msg);
  51. }
  52. })
  53. })
  54. }else if(layEvent === 'sortData'){ //修改排序
  55. /* 列表操作 edit 修改后执行 2018.7.24*/
  56. table.on('edit('+tableIds+')', function(obj){
  57. var data = obj.data;
  58. $.post('/dictionarya/pricesort',{id:data.id,type:'sort',sort:data.sort},function (data) {
  59. if(data.code == 200)
  60. {
  61. layer.msg(data.msg);
  62. } else if(data.code == 300 ) {
  63. layer.msg(data.msg);
  64. }
  65. })
  66. })
  67. // layer.prompt({
  68. // formType: 2
  69. // ,title: '价格排序'
  70. // ,value: data.sort
  71. // }, function(value, index){
  72. // $.post('/dictionarya/pricesort',{id:data.id,type:'sort',sort:value},function (data) {
  73. // layer.msg(data.msg);
  74. // table.reload('tablerReload');
  75. // })
  76. // });
  77. }
  78. });
  79. var $ = layui.$, active = {
  80. addData: function(){ //获取选中数据
  81. layer.open({
  82. type: 2,
  83. title: '添加区间价格',
  84. area: ['600px', '500px'],
  85. content: '/dictionarya/priceadd', //iframe的url,no代表不显示滚动条
  86. end:function () {
  87. table.reload('tablerReload'); //重新加载
  88. }
  89. });
  90. // var checkStatus = table.checkStatus('idTest')
  91. // ,data = checkStatus.data;
  92. // layer.alert(JSON.stringify(data));
  93. }
  94. };
  95. $('.demoTable .layui-btn').on('click', function(){
  96. var type = $(this).data('type');
  97. active[type] ? active[type].call(this) : '';
  98. });
  99. //修改
  100. form.on('submit(editprice)', function(data){
  101. $.post('/dictionarya/priceeditform',{'data':data.field,'token':csrfToken},function (data) {
  102. if(data.code == 200)
  103. {
  104. layer.msg(data.msg);
  105. } else if(data.code == 300 ) {
  106. layer.msg(data.msg);
  107. }
  108. })
  109. return false;
  110. });
  111. //添加
  112. form.on('submit(addprice)', function(data){
  113. $.post('/dictionarya/priceaddform',{'data':data.field,'token':csrfToken},function (data) {
  114. if(data.code == 200)
  115. {
  116. layer.msg(data.msg);
  117. } else if(data.code == 300 ) {
  118. layer.msg(data.msg);
  119. }
  120. })
  121. return false;
  122. });
  123. });