uni-goods-nav.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="uni-goods-nav">
  3. <!-- 底部占位 -->
  4. <view class="uni-tab__seat" />
  5. <view class="uni-tab__cart-box flex">
  6. <view class="flex uni-tab__cart-sub-left">
  7. <view v-for="(item,index) in options" :key="index" class="flex uni-tab__cart-button-left uni-tab__shop-cart" @click="onClick(index,item)">
  8. <view class="uni-tab__icon">
  9. <uni-icons :type="item.icon" size="20" color="#646566"></uni-icons>
  10. <!-- <image class="image" :src="item.icon" mode="widthFix" /> -->
  11. </view>
  12. <text class="uni-tab__text">{{ item.text }}</text>
  13. <view class="flex uni-tab__dot-box">
  14. <text v-if="item.info" :class="{ 'uni-tab__dots': item.info > 9 }" class="uni-tab__dot " :style="{'backgroundColor':item.infoBackgroundColor?item.infoBackgroundColor:'#ff0000',
  15. color:item.infoColor?item.infoColor:'#fff'
  16. }">{{ item.info }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <view :class="{'uni-tab__right':fill}" class="flex uni-tab__cart-sub-right ">
  21. <view v-for="(item,index) in buttonGroup" :key="index" :style="{backgroundColor:item.backgroundColor,color:item.color}"
  22. class="flex uni-tab__cart-button-right" @click="buttonClick(index,item)"><text :style="{color:item.color}" class="uni-tab__cart-button-right-text">{{ item.text }}</text></view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import uniIcons from '../uni-icons/uni-icons.vue'
  29. /**
  30. * GoodsNav 商品导航
  31. * @description 商品加入购物车、立即购买等
  32. * @tutorial https://ext.dcloud.net.cn/plugin?id=865
  33. * @property {Array} options 组件参数
  34. * @property {Array} buttonGroup 组件按钮组参数
  35. * @property {Boolean} fill = [true | false] 组件按钮组参数
  36. * @event {Function} click 左侧点击事件
  37. * @event {Function} buttonClick 右侧按钮组点击事件
  38. * @example <uni-goods-nav :fill="true" options="" buttonGroup="buttonGroup" @click="" @buttonClick="" />
  39. */
  40. export default {
  41. name: 'UniGoodsNav',
  42. components: {
  43. uniIcons
  44. },
  45. props: {
  46. options: {
  47. type: Array,
  48. default () {
  49. return [{
  50. icon: 'shop',
  51. text: '店铺',
  52. }, {
  53. icon: 'cart',
  54. text: '购物车'
  55. }]
  56. }
  57. },
  58. buttonGroup: {
  59. type: Array,
  60. default () {
  61. return [{
  62. text: '加入购物车',
  63. backgroundColor: '#ffa200',
  64. color: '#fff'
  65. },
  66. {
  67. text: '立即购买',
  68. backgroundColor: '#ff0000',
  69. color: '#fff'
  70. }
  71. ]
  72. }
  73. },
  74. fill: {
  75. type: Boolean,
  76. default: false
  77. }
  78. },
  79. methods: {
  80. onClick(index, item) {
  81. this.$emit('click', {
  82. index,
  83. content: item,
  84. })
  85. },
  86. buttonClick(index, item) {
  87. if (uni.report) {
  88. uni.report(item.text, item.text)
  89. }
  90. this.$emit('buttonClick', {
  91. index,
  92. content: item
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .flex {
  100. /* #ifndef APP-NVUE */
  101. display: flex;
  102. /* #endif */
  103. flex-direction: row;
  104. }
  105. .uni-goods-nav {
  106. /* #ifndef APP-NVUE */
  107. display: flex;
  108. /* #endif */
  109. flex: 1;
  110. flex-direction: row;
  111. }
  112. .uni-tab__cart-box {
  113. flex: 1;
  114. height: 50px;
  115. background-color: #fff;
  116. z-index: 900;
  117. }
  118. .uni-tab__cart-sub-left {
  119. padding: 0 5px;
  120. }
  121. .uni-tab__cart-sub-right {
  122. flex: 1;
  123. }
  124. .uni-tab__right {
  125. margin: 5px 0;
  126. margin-right: 10px;
  127. border-radius: 100px;
  128. overflow: hidden;
  129. }
  130. .uni-tab__cart-button-left {
  131. /* #ifndef APP-NVUE */
  132. display: flex;
  133. /* #endif */
  134. // flex: 1;
  135. position: relative;
  136. justify-content: center;
  137. align-items: center;
  138. flex-direction: column;
  139. margin: 0 10px;
  140. }
  141. .uni-tab__icon {
  142. width: 18px;
  143. height: 18px;
  144. }
  145. .image {
  146. width: 18px;
  147. height: 18px;
  148. }
  149. .uni-tab__text {
  150. margin-top: 3px;
  151. font-size: $uni-font-size-sm;
  152. color: #646566;
  153. }
  154. .uni-tab__cart-button-right {
  155. /* #ifndef APP-NVUE */
  156. display: flex;
  157. flex-direction: column;
  158. /* #endif */
  159. flex: 1;
  160. justify-content: center;
  161. align-items: center;
  162. }
  163. .uni-tab__cart-button-right-text {
  164. font-size: $uni-font-size-base;
  165. color: #fff;
  166. }
  167. .uni-tab__cart-button-right:active {
  168. opacity: 0.7;
  169. }
  170. .uni-tab__dot-box {
  171. /* #ifndef APP-NVUE */
  172. display: flex;
  173. flex-direction: column;
  174. /* #endif */
  175. position: absolute;
  176. right: -2px;
  177. top: 2px;
  178. justify-content: center;
  179. align-items: center;
  180. // width: 0;
  181. // height: 0;
  182. }
  183. .uni-tab__dot {
  184. // width: 30rpx;
  185. // height: 30rpx;
  186. padding: 0 4px;
  187. line-height: 15px;
  188. color: #ffffff;
  189. text-align: center;
  190. font-size: 12px;
  191. background-color: #ff0000;
  192. border-radius: 15px;
  193. }
  194. .uni-tab__dots {
  195. padding: 0 4px;
  196. // width: auto;
  197. border-radius: 15px;
  198. }
  199. .uni-tab__color-y {
  200. background-color: #ffa200;
  201. }
  202. .uni-tab__color-r {
  203. background-color: #ff0000;
  204. }
  205. </style>