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