my-tab.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. // console.log("tabItems:" , this.tabItems);
  46. this.tabCurrent = this.initActIndex;
  47. },
  48. methods: {
  49. getClassList(index) {
  50. // console.log("index:", index);
  51. let classList = "";
  52. if (this.tabCurrent == index) {
  53. classList = "tab-active";
  54. if (this.type == 1 && this.tabItems.length > 1) {
  55. if (index == 0) {
  56. classList += " boder-radius-left";
  57. } else if (index == (this.tabItems.length - 1)) {
  58. classList += " boder-radius-right";
  59. }
  60. } else {
  61. classList += " boder-radius-all";
  62. }
  63. } else {
  64. classList = "tab-unactive";
  65. if (this.type == 1) {
  66. if (index < (this.tabItems.length - 1)) {
  67. classList += " boder-solid-right";
  68. }
  69. }
  70. }
  71. // console.log("classList:", classList);
  72. return classList;
  73. },
  74. getTextStyle(index) {
  75. if (this.tabItemsMark == null || index > this.tabItemsMark.length - 1) {
  76. return;
  77. }
  78. let styleStr = "";
  79. const mark = this.tabItemsMark[index];
  80. if (mark.textColor.length > 0) {
  81. if (this.tabCurrent != index) {
  82. styleStr += "color: " + mark.textColor + ";";
  83. styleStr += "background: url('" + mark.icon + "') no-repeat;";
  84. } else {
  85. styleStr += "background: url('" + mark.icon + "') #2e85ec no-repeat;";
  86. }
  87. styleStr += "background-position-x: 90%;";
  88. styleStr += "background-position-y: 2%;";
  89. styleStr += "background-size: 14px;";
  90. }
  91. // console.log("getTextStyle: ", styleStr);
  92. return styleStr;
  93. },
  94. getSelectStyle() {
  95. let styleStr = "";
  96. // const len = this.tabItems.length;
  97. // if (len > 0) {
  98. // styleStr = "width: " + 100 / len + "%;";
  99. // }
  100. // console.log("getSelectStyle", styleStr);
  101. return styleStr;
  102. },
  103. onTabClick(index) {
  104. // console.log("onTabClick:", index);
  105. this.tabCurrent = index;
  106. this.$emit('onTabClick', index);
  107. },
  108. // 获取输入框中值
  109. getESelectText(data) {
  110. // console.log("getESelectText:", data);
  111. },
  112. // 获取选择选项值
  113. eSelectChange(data) {
  114. // console.log("eSelectChange:", data);
  115. this.$emit('onSelectChange', data);
  116. },
  117. }
  118. }
  119. </script>
  120. <style scoped>
  121. .tab {
  122. width: 90%;
  123. height: 60rpx;
  124. margin-top: 30rpx;
  125. background: #e7ecef;
  126. border-radius: 18px;
  127. justify-content: space-around;
  128. font-size: 16px;
  129. font-weight: 500;
  130. line-height: 60rpx;
  131. text-align: center;
  132. }
  133. .tab-active {
  134. width: 100%;
  135. height: 60rpx;
  136. background-color: #2e85ec;
  137. color: #ffffff;
  138. }
  139. .tab-unactive {
  140. width: 100%;
  141. height: 60rpx;
  142. color: #818181;
  143. }
  144. .tab-corner-mark {
  145. background-image: url('/static/common/award.png');
  146. background-repeat: no-repeat;
  147. background-position: center;
  148. background-size: cover;
  149. }
  150. .boder-radius-all {
  151. border-radius: 18px;
  152. }
  153. .boder-radius-left {
  154. border-radius: 18px 0 0 18px;
  155. }
  156. .boder-radius-right {
  157. border-radius: 0 18px 18px 0;
  158. }
  159. .boder-solid-left {
  160. border-left: #d7d7d7 1px solid;
  161. }
  162. .boder-solid-right {
  163. border-right: #d7d7d7 1px solid;
  164. }
  165. /deep/ .e-select {
  166. border: none !important;
  167. }
  168. /deep/ .e-select-input-text {
  169. color: inherit !important;
  170. }
  171. /deep/ .e-select-selector-item {
  172. color: #818181;
  173. }
  174. /deep/ .e-select-selector .e-select-selector-scroll .highlight {
  175. color: #409eff !important;
  176. }
  177. /deep/ .uni-icons {
  178. color: inherit !important;
  179. }
  180. /deep/ .e-select-input-placeholder {
  181. color: inherit !important;
  182. line-height: 60rpx !important;
  183. }
  184. /deep/ .e-select-input-text {
  185. width: 90% !important;
  186. }
  187. /deep/ .e-select-icon {
  188. /* width: 26px !important; */
  189. width: 10% !important;
  190. }
  191. </style>