uni-goods-nav.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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}" 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>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import uniIcons from '../uni-icons/uni-icons.vue'
  28. /**
  29. * GoodsNav 商品导航
  30. * @description 商品加入购物车、立即购买等
  31. * @tutorial https://ext.dcloud.net.cn/plugin?id=865
  32. * @property {Array} options 组件参数
  33. * @property {Array} buttonGroup 组件按钮组参数
  34. * @property {Boolean} fill = [true | false] 组件按钮组参数
  35. * @event {Function} click 左侧点击事件
  36. * @event {Function} buttonClick 右侧按钮组点击事件
  37. * @example <uni-goods-nav :fill="true" options="" buttonGroup="buttonGroup" @click="" @buttonClick="" />
  38. */
  39. export default {
  40. name: 'UniGoodsNav',
  41. components: {
  42. uniIcons
  43. },
  44. props: {
  45. options: {
  46. type: Array,
  47. default () {
  48. return [{
  49. icon: 'shop',
  50. text: '店铺',
  51. }, {
  52. icon: 'cart',
  53. text: '购物车'
  54. }]
  55. }
  56. },
  57. buttonGroup: {
  58. type: Array,
  59. default () {
  60. return [{
  61. text: '加入购物车',
  62. backgroundColor: '#ffa200',
  63. color: '#fff'
  64. },
  65. {
  66. text: '立即购买',
  67. backgroundColor: '#ff0000',
  68. color: '#fff'
  69. }
  70. ]
  71. }
  72. },
  73. fill: {
  74. type: Boolean,
  75. default: false
  76. }
  77. },
  78. methods: {
  79. onClick(index, item) {
  80. this.$emit('click', {
  81. index,
  82. content: item,
  83. })
  84. },
  85. buttonClick(index, item) {
  86. if (uni.report) {
  87. uni.report(item.text, item.text)
  88. }
  89. this.$emit('buttonClick', {
  90. index,
  91. content: item
  92. })
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. .flex {
  99. /* #ifndef APP-NVUE */
  100. display: flex;
  101. /* #endif */
  102. flex-direction: row;
  103. }
  104. .uni-goods-nav {
  105. /* #ifndef APP-NVUE */
  106. display: flex;
  107. /* #endif */
  108. flex: 1;
  109. flex-direction: row;
  110. }
  111. .uni-tab__cart-box {
  112. flex: 1;
  113. height: 50px;
  114. background-color: #fff;
  115. z-index: 900;
  116. }
  117. .uni-tab__cart-sub-left {
  118. padding: 0 5px;
  119. }
  120. .uni-tab__cart-sub-right {
  121. flex: 1;
  122. }
  123. .uni-tab__right {
  124. margin: 5px 0;
  125. margin-right: 10px;
  126. border-radius: 100px;
  127. overflow: hidden;
  128. }
  129. .uni-tab__cart-button-left {
  130. /* #ifndef APP-NVUE */
  131. display: flex;
  132. /* #endif */
  133. /* flex: 1;
  134. */
  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: 12px;
  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: 14px;
  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. */
  182. /* height: 0;
  183. */
  184. }
  185. .uni-tab__dot {
  186. /* width: 30rpx;
  187. */
  188. /* height: 30rpx;
  189. */
  190. padding: 0 4px;
  191. line-height: 15px;
  192. color: #ffffff;
  193. text-align: center;
  194. font-size: 12px;
  195. background-color: #ff0000;
  196. border-radius: 15px;
  197. }
  198. .uni-tab__dots {
  199. padding: 0 4px;
  200. /* width: auto;
  201. */
  202. border-radius: 15px;
  203. }
  204. .uni-tab__color-y {
  205. background-color: #ffa200;
  206. }
  207. .uni-tab__color-r {
  208. background-color: #ff0000;
  209. }
  210. </style>