adviser.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','upload'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,element = layui.element //元素操作
  7. ,form = layui.form
  8. ,upload = layui.upload;
  9. var tableIds = 'adviserlist'; //表格ID
  10. //第一个实例
  11. var indexTtable=table.render({
  12. elem: '#'+tableIds
  13. ,url: '/dictionaryb/adviserform' //数据接口
  14. ,where:{token:csrfToken}
  15. ,method:'post'
  16. ,page: true //开启分页
  17. ,text:'数据加载中'
  18. ,id:'tablerReload'
  19. ,cols: [[ //表头
  20. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  21. {type:'numbers'},
  22. {field: 'name', title: '姓名', width:200,align:'center'},
  23. {field: 'experience', title: '工作经验', align:'center'}
  24. ,{field: 'logo', title: '顾问头像', width:150,align:'center',templet:function(d){
  25. return '<img class="layui_magnify" src="'+d.photo+'">';
  26. }}
  27. ,{field: 'create_at', title: '添加时间', width:150,align:'center'}
  28. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  29. ]]
  30. });
  31. indexTtable.reload('tablerReload'); //重新加载
  32. //列表操作
  33. table.on('tool('+tableIds+')', function(obj){
  34. var layEvent = obj.event,
  35. data = obj.data;
  36. if(layEvent === 'edit'){
  37. layer.open({
  38. type: 2,
  39. title: '修改标签',
  40. closeBtn: 1, //不显示关闭按钮
  41. shade: [0],
  42. area: ['900px','550px'],
  43. anim: 2,
  44. content: ['/dictionaryb/adviseredit?id='+data.id, 'yes'], //iframe的url,no代表不显示滚动条
  45. });
  46. } else if(layEvent === 'del') {
  47. layer.confirm('您确定要删除吗?',{ btn: ['确定', '取消']},function () {
  48. $.post('/dictionaryb/adviserdel',{'id':data.id},function (data) {
  49. if(data.code == 200)
  50. {
  51. layer.msg(data.msg);
  52. table.reload(tableIds);
  53. } else if(data.code == 300 ) {
  54. layer.msg(data.msg);
  55. }
  56. })
  57. })
  58. }
  59. });
  60. // 区域列表logo点击放大图片
  61. $('.layui-table-main').on('click','.layui_magnify', function(){
  62. var _src = $(this).attr('src');
  63. layui.layer.open({
  64. type: 1,
  65. title: false, //是否显示标题
  66. area: ['60%', '80%'],
  67. shade: 0.6, //透明度
  68. closeBtn: 1, //按钮 1有,0无
  69. shadeClose: true,
  70. content: '<img style="width:100%;height:100%" src="'+_src+'">',
  71. });
  72. });
  73. var $ = layui.$, active = {
  74. addData: function(){ //获取选中数据
  75. layer.open({
  76. type: 2,
  77. title: '添加房产顾问',
  78. closeBtn: 1, //不显示关闭按钮
  79. shade: [0],
  80. area: ['900px','550px'],
  81. anim: 2,
  82. content: ['/dictionaryb/adviseradd', 'yes'], //iframe的url,no代表不显示滚动条
  83. });
  84. // var checkStatus = table.checkStatus('idTest')
  85. // ,data = checkStatus.data;
  86. // layer.alert(JSON.stringify(data));
  87. }
  88. };
  89. $('.demoTable .layui-btn').on('click', function(){
  90. var type = $(this).data('type');
  91. active[type] ? active[type].call(this) : '';
  92. });
  93. //修改
  94. form.on('submit(editadviser)', function(data){
  95. $.post('/dictionaryb/advisereditform',{'data':data.field,'token':csrfToken},function (data) {
  96. if(data.code == 200)
  97. {
  98. layer.msg(data.msg);
  99. parent.layui.table.reload(tableIds);
  100. TableClose();
  101. } else if(data.code == 300 ) {
  102. layer.msg(data.msg);
  103. }
  104. })
  105. return false;
  106. });
  107. //添加
  108. form.on('submit(addadviser)', function(data){
  109. $.post('/dictionaryb/adviseraddform',{'data':data.field,'token':csrfToken},function (data) {
  110. if(data.code == 200)
  111. {
  112. layer.msg(data.msg);
  113. // $('input').val(''); //清空input防止选择图片的时候删除上一张图片
  114. // $('textarea').val('');
  115. parent.layui.table.reload(tableIds);
  116. } else if(data.code == 300 ) {
  117. layer.msg(data.msg);
  118. }
  119. })
  120. return false;
  121. });
  122. //添加图片上传
  123. var uploadInst = upload.render({
  124. elem: '#test1'
  125. ,url: '/dictionaryb/adviserimg'
  126. ,data:{token:csrfToken,id:$('#editimgId').val()}
  127. ,field:'img'
  128. ,size:1000 //限制上传图片的大小,单位为KB
  129. ,exts: 'png|jpg|jpeg' //只允许上传压缩文件
  130. // ,auto:false
  131. // ,bindAction:'#addcity'
  132. ,before: function(obj){
  133. //预读本地文件示例,不支持ie8
  134. obj.preview(function(index, file, result){
  135. $('#demo1').attr('src', result); //图片链接(base64)
  136. });
  137. var _val = $("#imgname").val();
  138. unlinkImage(_val);
  139. }
  140. ,done: function(res){
  141. //如果上传失败
  142. if(res.code == 200){
  143. layer.msg(res.msg);
  144. $("#imgname").remove();
  145. $('form').append('<input type="hidden" name="photo" id="imgname" value="'+res.data+'">');
  146. parent.layui.table.reload(tableIds);
  147. } else if(res.code == 300) {
  148. return layer.msg('上传失败');
  149. }
  150. //上传成功
  151. }
  152. ,error: function(){
  153. //演示失败状态,并实现重传
  154. // var demoText = $('#demoText');
  155. // <a class="layui-btn layui-btn-mini demo-reload">重试</a>
  156. // demoText.html('<span style="color: #FF5722;">上传失败</span> ');
  157. // demoText.on('click', function(){
  158. // // alert(1);
  159. // // $.post('/categorycity/addcityform',{name:$("#imgname").val()},function (data) {
  160. // //
  161. // // })
  162. // // uploadInst.upload();
  163. // });
  164. }
  165. });
  166. function unlinkImage(name){
  167. if(name != 'undefined'){
  168. $.post('/dictionaryb/adviserunimg',{imgname:name},function (data) {
  169. })
  170. }
  171. }
  172. });