table-panel.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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" :style="headers[0].tablestyle">\
  12. <thead><tr>\
  13. <th class="c-t-center" v-if="firstTh" style="width:50px;">{{firstTh}}</th>\
  14. <th v-for="(th,i) in headers" :key="i" :style="th.style">{{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-center\':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. if(!vm.hastopbar){
  81. vm.headers[0].thead=vm.tabList[vm.tabActive].name
  82. }
  83. }
  84. },
  85. getLowLevelData: function(row,th){
  86. var vm=this
  87. if(!vm.cantclick||th.canclick){ //点击名称有效
  88. if(vm.tabActive == vm.tabList.length-1){
  89. if(vm.tabList[vm.tabActive].name=="团队"){ //tab在最后一级,显示团队信息
  90. var title="团队信息"
  91. var size="md"
  92. var component='team-info'
  93. if(vm.index==27){
  94. title="团队信息和代预约记录"
  95. size="lg"
  96. component='team-info-dyy'
  97. }
  98. //弹框显示团队信息
  99. Vuedals.Bus.$emit('new', {
  100. title: title,
  101. component: component,
  102. props: {
  103. teamId: row.code,
  104. year: vm.year
  105. },
  106. size:size
  107. });
  108. }
  109. }else{
  110. vm.changeTab()
  111. //触发组件监听事件,去父页面请求新的数据
  112. this.$emit("getnewdata", {
  113. level: vm.tabList[vm.tabActive].level,
  114. area: row.code,
  115. areaTitle: row.name,
  116. });
  117. }
  118. }
  119. },
  120. changeTab:function(arg){
  121. var vm=this
  122. var showIndex=0
  123. if(arg){ //回退
  124. vm.tabActive--
  125. showIndex = _.findIndex(vm.tabList,{level:arg.level.toString()})
  126. }else{ //下转
  127. vm.tabActive++
  128. showIndex = vm.tabActive
  129. }
  130. _.each(vm.tabList,function(item,index){
  131. if(index<showIndex){
  132. item.isShow=false
  133. }else{
  134. item.isShow=true
  135. }
  136. })
  137. if(!vm.hastopbar){
  138. vm.headers[0].thead=vm.tabList[vm.tabActive].name
  139. }
  140. },
  141. back:function(){
  142. //触发组件监听事件,去父页面请求新的数据
  143. this.$emit("backtobefore");
  144. },
  145. }
  146. });
  147. })()