price.js 4.7 KB

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