my-tab.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="tab uni-row" :style="'font-size: ' + fontSize + 'px;'">
  3. <template v-for="(item,index) in tabItems" :key="index">
  4. <text v-if="typeof item == 'string'" :class="getClassList(index)" :style="getTextStyle(index)" @click="onTabClick(index)">{{item}}</text>
  5. <e-select v-if="typeof item == 'object'" :style="getSelectStyle()" v-model="item.selectValue"
  6. :options="item.data" :search="false" :inputClick="false" :clearable="false" :class="getClassList(index)"
  7. @click="onTabClick(index)" @getText="getESelectText" @change="eSelectChange"></e-select>
  8. </template>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "my-tab",
  14. props: {
  15. initActIndex: {
  16. type: Number,
  17. default: 0
  18. },
  19. tabItems: {
  20. type: Array,
  21. default: null
  22. },
  23. tabItemsMark: {
  24. type: Array,
  25. default: null
  26. },
  27. type: {
  28. type: Number,
  29. default: 0
  30. },
  31. fontSize: {
  32. type: Number,
  33. default: 16
  34. },
  35. },
  36. emits: ['onTabClick', 'onSelectChange'],
  37. data() {
  38. return {
  39. tabCurrent: 0,
  40. selectedID: 0
  41. };
  42. },
  43. mounted() {
  44. // console.log("initActIndex:" , this.initActIndex);
  45. this.tabCurrent = this.initActIndex;
  46. },
  47. methods: {
  48. getClassList(index) {
  49. // console.log("index:", index);
  50. let classList = "";
  51. if (this.tabCurrent == index) {
  52. classList = "tab-active";
  53. if (this.type == 1 && this.tabItems.length > 1) {
  54. if (index == 0) {
  55. classList += " boder-radius-left";
  56. } else if (index == (this.tabItems.length - 1)) {
  57. classList += " boder-radius-right";
  58. }
  59. } else {
  60. classList += " boder-radius-all";
  61. }
  62. } else {
  63. classList = "tab-unactive";
  64. if (this.type == 1) {
  65. if (index < (this.tabItems.length - 1)) {
  66. classList += " boder-solid-right";
  67. }
  68. }
  69. }
  70. // console.log("classList:", classList);
  71. return classList;
  72. },
  73. getTextStyle(index) {
  74. if (this.tabItemsMark == null || index > this.tabItemsMark.length - 1) {
  75. return;
  76. }
  77. let styleStr = "";
  78. const mark = this.tabItemsMark[index];
  79. if (mark.textColor.length > 0) {
  80. if (this.tabCurrent != index) {
  81. styleStr += "color: " + mark.textColor + ";";
  82. }
  83. styleStr += "background: url('" + mark.icon + "') no-repeat;";
  84. styleStr += "background-position-x: 90%;";
  85. styleStr += "background-position-y: 2%;";
  86. styleStr += "background-size: 14px;";
  87. }
  88. console.log("getTextStyle: ", styleStr);
  89. return styleStr;
  90. },
  91. getSelectStyle() {
  92. let styleStr = "";
  93. // const len = this.tabItems.length;
  94. // if (len > 0) {
  95. // styleStr = "width: " + 100 / len + "%;";
  96. // }
  97. // console.log("getSelectStyle", styleStr);
  98. return styleStr;
  99. },
  100. onTabClick(index) {
  101. // console.log("onTabClick:", index);
  102. this.tabCurrent = index;
  103. this.$emit('onTabClick', index);
  104. },
  105. // 获取输入框中值
  106. getESelectText(data) {
  107. // console.log("getESelectText:", data);
  108. },
  109. // 获取选择选项值
  110. eSelectChange(data) {
  111. // console.log("eSelectChange:", data);
  112. this.$emit('onSelectChange', data);
  113. },
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .tab {
  119. width: 90%;
  120. height: 60rpx;
  121. margin-top: 30rpx;
  122. background: #e7ecef;
  123. border-radius: 18px;
  124. justify-content: space-around;
  125. font-size: 16px;
  126. font-weight: 500;
  127. line-height: 60rpx;
  128. text-align: center;
  129. }
  130. .tab-active {
  131. width: 100%;
  132. height: 60rpx;
  133. background: #2e85ec;
  134. color: #ffffff;
  135. }
  136. .tab-unactive {
  137. width: 100%;
  138. height: 60rpx;
  139. color: #818181;
  140. }
  141. .tab-corner-mark {
  142. background-image: url('/static/common/award.png');
  143. background-repeat: no-repeat;
  144. background-position: center;
  145. background-size: cover;
  146. }
  147. .boder-radius-all {
  148. border-radius: 18px;
  149. }
  150. .boder-radius-left {
  151. border-radius: 18px 0 0 18px;
  152. }
  153. .boder-radius-right {
  154. border-radius: 0 18px 18px 0;
  155. }
  156. .boder-solid-left {
  157. border-left: #d7d7d7 1px solid;
  158. }
  159. .boder-solid-right {
  160. border-right: #d7d7d7 1px solid;
  161. }
  162. /deep/ .e-select {
  163. border: none !important;
  164. }
  165. /deep/ .e-select-input-text {
  166. color: inherit !important;
  167. }
  168. /deep/ .e-select-selector-item {
  169. color: #818181;
  170. }
  171. /deep/ .e-select-selector .e-select-selector-scroll .highlight {
  172. color: #409eff !important;
  173. }
  174. /deep/ .uni-icons {
  175. color: inherit !important;
  176. }
  177. /deep/ .e-select-input-placeholder {
  178. color: inherit !important;
  179. line-height: 60rpx !important;
  180. }
  181. /deep/ .e-select-input-text {
  182. width: 90% !important;
  183. }
  184. /deep/ .e-select-icon {
  185. /* width: 26px !important; */
  186. width: 10% !important;
  187. }
  188. </style>