navtabs.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div id="navtab">
  3. <i class="el-icon-arrow-left" @click="tapFirst"></i>
  4. <div class="list" ref="listNav">
  5. <div
  6. class="lis"
  7. @mouseenter="mouseIn($event, item.id)"
  8. @mouseleave="mouseLeave()"
  9. @click="tourl(item)"
  10. :class="{ showlis: info.supplier_list[tapInd - 1].id == item.id }"
  11. v-for="(item, index) in listShow(info.supplier_list)"
  12. :key="index"
  13. >
  14. <div>{{ item.store_name == 'null'?item.username.slice(0,5):item.store_name.slice(0,5) }}</div>
  15. <div>{{ item.store_name == 'null'?item.username.slice(5,7):item.store_name.slice(5,7) }}</div>
  16. </div>
  17. </div>
  18. <i class="el-icon-arrow-right" @click="tapNext"></i>
  19. </div>
  20. </template>
  21. <script>
  22. import { mapState } from "vuex";
  23. export default {
  24. props: {
  25. info: {
  26. type: Object,
  27. default: {},
  28. },
  29. timeSet: {
  30. type: Number,
  31. default: 3000,
  32. },
  33. },
  34. computed: {
  35. ...mapState(["basicSet", "basic_info"]),
  36. },
  37. data() {
  38. return {
  39. showListInd: 0,
  40. tapInd: 1,
  41. // arr: ["1", "2", "3", "4", "5", "6", "7", "8"],
  42. // 后端设置的秒数
  43. settimeOut: null,
  44. ceilNum: 0,
  45. };
  46. },
  47. mounted() {
  48. this.$emit("postChildInd", this.tapInd - 1);
  49. if (this.timeSet != 0) {
  50. this.settimeOut = setInterval(() => {
  51. if (this.tapInd < this.info.supplier_list.length) {
  52. this.tapInd = this.tapInd + 1;
  53. } else {
  54. this.tapInd = 1;
  55. }
  56. if (this.tapInd <= 9) {
  57. this.showListInd = 9;
  58. } else if (
  59. this.tapInd > this.showListInd &&
  60. this.showListInd < this.info.supplier_list.length
  61. ) {
  62. this.showListInd = this.showListInd + 9;
  63. }
  64. this.$emit("postChildInd", this.tapInd - 1);
  65. }, this.timeSet);
  66. }
  67. },
  68. methods: {
  69. tourl(item) {
  70. let supplier_Id = item.id;
  71. if (this.$baseURL) {
  72. // 静态部署环境下
  73. this.$router.push(
  74. this.fun.getUrl("supplierGoodList", { id: supplier_Id }, {})
  75. );
  76. } else {
  77. this.$router.push(
  78. this.fun.getUrl("supplierGoodList-id", { id: supplier_Id }, {})
  79. );
  80. }
  81. },
  82. mouseLeave() {
  83. if (this.timeSet != 0) {
  84. if (!this.settimeOut) {
  85. this.settimeOut = setInterval(() => {
  86. if (this.tapInd < this.info.supplier_list.length) {
  87. this.tapInd = this.tapInd + 1;
  88. } else {
  89. this.tapInd = 1;
  90. }
  91. this.$emit("postChildInd", this.tapInd - 1);
  92. }, this.timeSet);
  93. }
  94. }
  95. },
  96. mouseIn(e, id) {
  97. for (let i = 0; i < this.info.supplier_list.length; i++) {
  98. if (this.info.supplier_list[i].id == id) {
  99. this.tapInd = Number(i + 1);
  100. }
  101. }
  102. // this.tapInd = Number(ind + 1);
  103. if (this.timeSet != 0) {
  104. if (this.settimeOut) {
  105. clearInterval(this.settimeOut);
  106. this.settimeOut = null;
  107. }
  108. }
  109. this.$emit("postChildInd", this.tapInd - 1);
  110. },
  111. tapFirst() {
  112. if (this.showListInd == 9) return;
  113. if (this.showListInd - 9 <= 9) return (this.showListInd = 9);
  114. this.showListInd = this.showListInd - 9;
  115. },
  116. tapNext() {
  117. let len = this.info.supplier_list.length;
  118. if (len <= 9) return;
  119. if (this.showListInd == len) return;
  120. if (this.showListInd + 9 > len) {
  121. this.showListInd = len;
  122. } else {
  123. this.showListInd = this.showListInd + 9;
  124. }
  125. },
  126. listShow(arr) {
  127. if (this.showListInd == 0) {
  128. this.showListInd = 9;
  129. let arrinfo = arr.slice(0, this.showListInd);
  130. return arrinfo;
  131. } else {
  132. let arrinfo = arr.slice(this.showListInd - 9, this.showListInd);
  133. return arrinfo;
  134. }
  135. },
  136. },
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. .el-icon-arrow-left,
  141. .el-icon-arrow-right {
  142. font-size: 20px;
  143. color: #7e7e7e;
  144. cursor: pointer;
  145. }
  146. #navtab {
  147. width: 100%;
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. padding: 0 32px;
  152. overflow: hidden;
  153. }
  154. ::-webkit-scrollbar {
  155. display: none;
  156. }
  157. .list {
  158. padding: 20px 0;
  159. width: 100%;
  160. display: flex;
  161. justify-content: flex-start;
  162. overflow: hidden;
  163. .showlis {
  164. color: #2973fd;
  165. font-size: 14px;
  166. }
  167. .lis {
  168. cursor: pointer;
  169. flex-shrink: 0;
  170. margin: 0 0 0 42px;
  171. width: 77px;
  172. font-size: 14px;
  173. font-weight: bold;
  174. display: -webkit-box;
  175. -webkit-box-orient: vertical;
  176. -webkit-line-clamp: 2;
  177. overflow: hidden;
  178. text-align: center;
  179. }
  180. }
  181. </style>