table-panel.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. (function(){
  2. Vue.component('table-panel',{
  3. template: '<div class="table-panel">\
  4. <div class="flex table-tab-pane" v-if="!hastopbar">\
  5. <div class="f_s_0 c-t-center pt20" style="width:40px;"><img v-show="reqlength&&reqlength>1" @click="back" src="../../../images/fanhui_icon.png" width="18" height="18"></div>\
  6. <div class="f_g_1 table-tab-item" v-for="(item,index) in tabList" :key="index" @click="tabClick(index)" v-if="item.isShow">\
  7. <div class="plr20" :class="{\'active\':tabActive==index}"><span>{{item.name}}</span></div>\
  8. </div>\
  9. </div>\
  10. <div class="ptb20 plr25">\
  11. <table class="table-content table-bordered table-striped mb20" id="listTable">\
  12. <thead><tr>\
  13. <th class="c-t-center" v-if="firstTh">{{firstTh}}</th>\
  14. <th v-for="(th,i) in headers" :key="i" :class="i>=2?\'c-t-right\':\'\'">{{th.thead}}\
  15. <el-tooltip class="item" effect="dark" :content="th.tip" placement="top" v-if="th.tip">\
  16. <img class="c-position-a tip" src="../../../images/icon_wenhao2.png" alt="" style="top: 13px;left:70px;">\
  17. </el-tooltip>\
  18. </th>\
  19. </tr></thead>\
  20. <tbody>\
  21. <tr v-if="tabledata.length>0" v-for="(row,index) in tabledata" :key="index" class="data-row">\
  22. <td class="c-t-center" v-if="firstTh">{{row.rank}}</td>\
  23. <td v-for="(th,i) in headers" :key="i" :class="{\'c-t-right\':i>=1,\'tdPointor\':!cantclick}" @click="getLowLevelData(row,th)">\
  24. {{row[th.param]}}\
  25. </td>\
  26. </tr>\
  27. <tr v-if="tabledata.length==0">\
  28. <td v-if="firstTh" :colspan="headers.length+1" class="c-t-center">无数据</td>\
  29. <td v-else :colspan="headers.length" class="c-t-center">无数据</td>\
  30. </tr>\
  31. </tbody>\
  32. </table>\
  33. </div>\
  34. </div>',
  35. props:["index","tabledata","cantclick","hastopbar","reqlength"],
  36. data: function(){
  37. return {
  38. tabList:[{name:"各区",level:"4",lowlevel:"",isShow:true},{name:"社区",level:"3",lowlevel:"2",isShow:true},{name:"团队",level:"2",lowlevel:"1",isShow:true}],
  39. tabActive:0,
  40. headers:[{thead:"排名",param:"name"},{thead:"名称",param:"name",tip:""},{thead:"",param:"address",tip:""}],
  41. firstTh:"排名",
  42. }
  43. },
  44. mounted: function(){
  45. var vm=this
  46. EventBus.$on("render-table-data", function(arg){
  47. vm.firstTh=arg.firstTh||"排名"
  48. })
  49. },
  50. methods: {
  51. initTable:function(arg){
  52. var vm = this;
  53. if(arg.tabList&&arg.tabList.length>0){
  54. vm.tabList=arg.tabList
  55. }
  56. if(arg.headers&&arg.headers.length>0){
  57. vm.headers=arg.headers
  58. }
  59. var showIndex=vm.tabList.length-arg.tabnumber||0 //小于这个值的tab隐藏
  60. _.each(vm.tabList,function(item,index){
  61. if(index<showIndex){
  62. item.isShow=false
  63. }else{
  64. item.isShow=true
  65. }
  66. })
  67. vm.tabActive=showIndex
  68. if(!vm.hastopbar){
  69. vm.headers[0].thead=vm.tabList[vm.tabActive].name
  70. }
  71. },
  72. tabClick:function(index){
  73. var vm = this;
  74. if(vm.tabActive != index){
  75. vm.tabActive = index
  76. //触发组件监听事件,去父页面请求新的数据
  77. this.$emit("getnewdata", {
  78. lowLevel: vm.tabList[index].lowlevel
  79. });
  80. }
  81. },
  82. getLowLevelData: function(row,th){
  83. var vm=this
  84. if(th.canclick){ //点击名称有效
  85. if(vm.tabActive == vm.tabList.length-1){
  86. if(vm.tabList[vm.tabActive].name=="团队"){ //tab在最后一级,显示团队信息
  87. var title="团队信息"
  88. var size="md"
  89. var component='team-info'
  90. if(vm.index==27){
  91. title="团队信息和代预约记录"
  92. size="lg"
  93. component='team-info-dyy'
  94. }
  95. //弹框显示团队信息
  96. Vuedals.Bus.$emit('new', {
  97. title: title,
  98. component: component,
  99. props: {
  100. teamId: row.code,
  101. year: vm.year
  102. },
  103. size:size
  104. });
  105. }
  106. }else{
  107. vm.changeTab()
  108. //触发组件监听事件,去父页面请求新的数据
  109. this.$emit("getnewdata", {
  110. level: vm.tabList[vm.tabActive].level,
  111. area: row.code,
  112. areaTitle: row.name,
  113. });
  114. }
  115. }
  116. },
  117. changeTab:function(arg){
  118. var vm=this
  119. var showIndex=0
  120. if(arg){ //回退
  121. vm.tabActive--
  122. showIndex = _.findIndex(vm.tabList,{level:arg.level.toString()})
  123. }else{ //下转
  124. vm.tabActive++
  125. showIndex = vm.tabActive
  126. }
  127. _.each(vm.tabList,function(item,index){
  128. if(index<showIndex){
  129. item.isShow=false
  130. }else{
  131. item.isShow=true
  132. }
  133. })
  134. if(!vm.hastopbar){
  135. vm.headers[0].thead=vm.tabList[vm.tabActive].name
  136. }
  137. },
  138. back:function(){
  139. //触发组件监听事件,去父页面请求新的数据
  140. this.$emit("backtobefore");
  141. },
  142. }
  143. });
  144. })()