uni-goods-nav.vue 4.5 KB

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