app-module.vue 6.6 KB

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