| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <template>
- <view class="tab uni-row" :style="'font-size: ' + fontSize + 'px;'">
- <template v-for="(item,index) in tabItems" :key="index">
- <text v-if="typeof item == 'string'" :class="getClassList(index)" :style="getTextStyle(index)" @click="onTabClick(index)">{{item}}</text>
- <e-select v-if="typeof item == 'object'" :style="getSelectStyle()" v-model="item.selectValue" maxHeight="300px"
- :options="item.data" :search="false" :inputClick="false" :clearable="false" :class="getClassList(index)"
- @click="onTabClick(index)" @getText="getESelectText" @change="eSelectChange"></e-select>
- </template>
- </view>
- </template>
- <script>
- export default {
- name: "my-tab",
- props: {
- initActIndex: {
- type: Number,
- default: 0
- },
- tabItems: {
- type: Array,
- default: null
- },
- tabItemsMark: {
- type: Array,
- default: null
- },
- type: {
- type: Number,
- default: 0
- },
- fontSize: {
- type: Number,
- default: 16
- },
- },
- emits: ['onTabClick', 'onSelectChange'],
- data() {
- return {
- tabCurrent: 0,
- selectedID: 0
- };
- },
- mounted() {
- // console.log("initActIndex:" , this.initActIndex);
- // console.log("tabItems:" , this.tabItems);
- this.tabCurrent = this.initActIndex;
- },
- methods: {
- getClassList(index) {
- // console.log("index:", index);
- let classList = "";
- if (this.tabCurrent == index) {
- classList = "tab-active";
- if (this.type == 1 && this.tabItems.length > 1) {
- if (index == 0) {
- classList += " boder-radius-left";
- } else if (index == (this.tabItems.length - 1)) {
- classList += " boder-radius-right";
- }
- } else {
- classList += " boder-radius-all";
- }
- } else {
- classList = "tab-unactive";
- if (this.type == 1) {
- if (index < (this.tabItems.length - 1)) {
- classList += " boder-solid-right";
- }
- }
- }
- // console.log("classList:", classList);
- return classList;
- },
- getTextStyle(index) {
- if (this.tabItemsMark == null || index > this.tabItemsMark.length - 1) {
- return;
- }
-
- let styleStr = "";
- const mark = this.tabItemsMark[index];
- if (mark.textColor.length > 0) {
- if (this.tabCurrent != index) {
- styleStr += "color: " + mark.textColor + ";";
- styleStr += "background: url('" + mark.icon + "') no-repeat;";
- } else {
- styleStr += "background: url('" + mark.icon + "') #2e85ec no-repeat;";
- }
- styleStr += "background-position-x: 90%;";
- styleStr += "background-position-y: 2%;";
- styleStr += "background-size: 14px;";
- }
- // console.log("getTextStyle: ", styleStr);
- return styleStr;
- },
- getSelectStyle() {
- let styleStr = "";
- // const len = this.tabItems.length;
- // if (len > 0) {
- // styleStr = "width: " + 100 / len + "%;";
- // }
- // console.log("getSelectStyle", styleStr);
- return styleStr;
- },
- onTabClick(index) {
- // console.log("onTabClick:", index);
- this.tabCurrent = index;
- this.$emit('onTabClick', index);
- },
- // 获取输入框中值
- getESelectText(data) {
- // console.log("getESelectText:", data);
- },
- // 获取选择选项值
- eSelectChange(data) {
- // console.log("eSelectChange:", data);
- this.$emit('onSelectChange', data);
- },
- }
- }
- </script>
- <style scoped>
- .tab {
- width: 90%;
- height: 60rpx;
- margin-top: 30rpx;
- background: #e7ecef;
- border-radius: 18px;
- justify-content: space-around;
-
- font-size: 16px;
- font-weight: 500;
- line-height: 60rpx;
- text-align: center;
- }
- .tab-active {
- width: 100%;
- height: 60rpx;
- background-color: #2e85ec;
- color: #ffffff;
- }
- .tab-unactive {
- width: 100%;
- height: 60rpx;
- color: #818181;
- }
-
- .tab-corner-mark {
- background-image: url('/static/common/award.png');
- background-repeat: no-repeat;
- background-position: center;
- background-size: cover;
- }
- .boder-radius-all {
- border-radius: 18px;
- }
- .boder-radius-left {
- border-radius: 18px 0 0 18px;
- }
- .boder-radius-right {
- border-radius: 0 18px 18px 0;
- }
- .boder-solid-left {
- border-left: #d7d7d7 1px solid;
- }
- .boder-solid-right {
- border-right: #d7d7d7 1px solid;
- }
- /deep/ .e-select {
- border: none !important;
- }
-
- /deep/ .e-select-input-text {
- color: inherit !important;
- }
-
- /deep/ .e-select-selector-item {
- color: #818181;
- }
-
- /deep/ .e-select-selector .e-select-selector-scroll .highlight {
- color: #409eff !important;
- }
-
- /deep/ .uni-icons {
- color: inherit !important;
- }
-
- /deep/ .e-select-input-placeholder {
- color: inherit !important;
- line-height: 60rpx !important;
- }
-
- /deep/ .e-select-input-text {
- width: 90% !important;
- }
-
- /deep/ .e-select-icon {
- /* width: 26px !important; */
- width: 10% !important;
- }
- </style>
|