app-module.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="app-module">
  3. <scroll-view :scroll-left="scrollLeft"
  4. v-if="list && list.length > 1"
  5. scroll-x
  6. :scroll-with-animation="true"
  7. :style="{backgroundColor: tabBackground}">
  8. <view class="dir-left-nowrap" style="height: 100%">
  9. <view v-for="(item, index) in list"
  10. :key="index"
  11. @click="changeTab(index)"
  12. class="scroll-item main-center cross-center"
  13. :style="[scrollStyle]">
  14. <view :style="[tabNameFill(index)]">
  15. <view class="tab-name" :style="[tabNameStyle(index)]">{{item.tabName}}</view>
  16. <view v-if="tabType === 'line'" class="line"
  17. :style="{background: current === index ? tabColor : 'none'}"
  18. ></view>
  19. </view>
  20. </view>
  21. </view>
  22. </scroll-view>
  23. <view v-if="false && list && list.length > 4" :style="{background: tabBackground}" class="scroll-right"></view>
  24. <app-diy-page
  25. :page-hide="pageHide"
  26. :home-pages="newHomePages(current)"
  27. :is_storage="is_storage"
  28. :theme="theme"
  29. :page_id="page_id"
  30. :is_module="false"
  31. :is_required="is_required"
  32. :coupon_req="coupon_req"
  33. d-type="module"
  34. :d-index="dIndex"
  35. @buyProduct="buyProduct"
  36. ></app-diy-page>
  37. </view>
  38. </template>
  39. <script>
  40. // #ifdef MP
  41. import appDiyPage from "@/components/page-component/index/app-diy-page.vue";
  42. // #endif
  43. export default {
  44. name: "app-module",
  45. // #ifdef MP
  46. components: {
  47. appDiyPage
  48. },
  49. // #endif
  50. data() {
  51. return {
  52. newPage: [],
  53. time: -1,
  54. current: 0,
  55. scrollLeft: 0,
  56. }
  57. },
  58. props: {
  59. homePages: {
  60. type: Object,
  61. default() {
  62. return {};
  63. }
  64. },
  65. scrollTop: {
  66. type: Number,
  67. default() {
  68. return 0;
  69. }
  70. },
  71. is_storage: Boolean,
  72. pageHide: Boolean,
  73. theme: Object,
  74. coupon_req: Boolean,
  75. is_required: Boolean,
  76. page_id: Number,
  77. /*********************************************/
  78. tabType: String,
  79. tabColor: String,
  80. textColor: String,
  81. tabBackground: String,
  82. list: Array,
  83. dIndex: Array,
  84. },
  85. computed: {
  86. scrollStyle() {
  87. let length = this.list.length;
  88. if (length < 5) {
  89. return {
  90. width: `${100 / length}%`
  91. }
  92. } else {
  93. length = 5;
  94. return {
  95. width: `${(100 / (length * 2 - 1)) * 2}%`,
  96. }
  97. }
  98. },
  99. tabNameFill() {
  100. return (index) => {
  101. if (this.tabType === 'filling') {
  102. if (this.current === index) {
  103. return {
  104. backgroundColor: this.tabColor,
  105. borderRadius: '32rpx',
  106. padding: '0 24rpx',
  107. }
  108. }
  109. }
  110. };
  111. },
  112. tabNameStyle() {
  113. return (index) => {
  114. let color = 'auto';
  115. if (this.tabType === 'line') {
  116. if (this.current === index) {
  117. color = this.tabColor;
  118. } else {
  119. color = this.textColor;
  120. }
  121. } else if (this.tabType === 'filling') {
  122. if (this.current === index) {
  123. color = this.tabBackground;
  124. } else {
  125. color = this.textColor;
  126. }
  127. }
  128. return {color};
  129. }
  130. },
  131. newHomePages() {
  132. return (index) => {
  133. let { id, title, navs } = this.homePages;
  134. return {
  135. 'id': id,
  136. 'is_home_page': 0,
  137. 'show_navs': 0,
  138. 'title': title,
  139. 'navs': [{
  140. 'id': '0',
  141. 'name': navs[0]['name'],
  142. 'page_id': this.page_id,
  143. 'template': this.list[index],
  144. 'template_id': navs[0]['template_id'],
  145. }],
  146. };
  147. }
  148. },
  149. },
  150. methods: {
  151. changeTab(index) {
  152. this.current = index;
  153. if (this.list.length > 4) {
  154. let num = parseFloat(this.scrollStyle['width']);
  155. this.scrollLeft = uni.getSystemInfoSync().windowWidth * (index * num - 50 + num / 2) / 100;
  156. }
  157. },
  158. buyProduct(data) {
  159. this.$emit('buyProduct', data);
  160. }
  161. },
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .app-module {
  166. position: relative;
  167. scroll-view {
  168. white-space: nowrap;
  169. height: #{90rpx};
  170. box-shadow: inset #{-12rpx} 0 #{10rpx} #{-10rpx} #555555;
  171. .scroll-item {
  172. width: 25%;
  173. flex: 0 0 auto;
  174. height: 100%;
  175. .scroll-z {
  176. height: #{56rpx};
  177. padding: 0 #{24rpx};
  178. border-radius: #{16rpx};
  179. }
  180. .tab-name {
  181. font-size: #{28rpx};
  182. line-height: 1;
  183. color: #666666;
  184. padding: #{12rpx} 0;
  185. }
  186. .line {
  187. height: #{4rpx};
  188. border-radius: #{16rpx};
  189. width: 100%;
  190. }
  191. }
  192. }
  193. .scroll-right {
  194. width: #{2rpx};
  195. position: absolute;
  196. height: #{90rpx};
  197. top: 0;
  198. right: 0;
  199. z-index: 22;
  200. background: #FFFFFF;
  201. box-shadow: #{-4rpx} #{0rpx} #{12rpx} #555555;
  202. }
  203. }
  204. </style>