uni-goods-nav.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. display: flex;
  128. flex-direction: row;
  129. }
  130. .uni-tab__cart-sub-right {
  131. flex: 1;
  132. }
  133. .uni-tab__right {
  134. margin: 5px 0;
  135. margin-right: 10px;
  136. border-radius: 100px;
  137. overflow: hidden;
  138. }
  139. .uni-tab__cart-button-left {
  140. /* #ifndef APP-NVUE */
  141. display: flex;
  142. /* #endif */
  143. // flex: 1;
  144. position: relative;
  145. justify-content: center;
  146. align-items: center;
  147. flex-direction: column;
  148. margin: 0 10px;
  149. /* #ifdef H5 */
  150. cursor: pointer;
  151. /* #endif */
  152. }
  153. .uni-tab__icon {
  154. width: 18px;
  155. height: 18px;
  156. }
  157. .image {
  158. width: 18px;
  159. height: 18px;
  160. }
  161. .uni-tab__text {
  162. margin-top: 3px;
  163. font-size: 12px;
  164. color: #646566;
  165. }
  166. .uni-tab__cart-button-right {
  167. /* #ifndef APP-NVUE */
  168. display: flex;
  169. flex-direction: column;
  170. /* #endif */
  171. flex: 1;
  172. justify-content: center;
  173. align-items: center;
  174. /* #ifdef H5 */
  175. cursor: pointer;
  176. /* #endif */
  177. }
  178. .uni-tab__cart-button-right-text {
  179. font-size: 14px;
  180. color: #fff;
  181. }
  182. .uni-tab__cart-button-right:active {
  183. opacity: 0.7;
  184. }
  185. .uni-tab__dot-box {
  186. /* #ifndef APP-NVUE */
  187. display: flex;
  188. flex-direction: column;
  189. /* #endif */
  190. position: absolute;
  191. right: -2px;
  192. top: 2px;
  193. justify-content: center;
  194. align-items: center;
  195. // width: 0;
  196. // height: 0;
  197. }
  198. .uni-tab__dot {
  199. // width: 30rpx;
  200. // height: 30rpx;
  201. padding: 0 4px;
  202. line-height: 15px;
  203. color: #ffffff;
  204. text-align: center;
  205. font-size: 12px;
  206. background-color: #ff0000;
  207. border-radius: 15px;
  208. }
  209. .uni-tab__dots {
  210. padding: 0 4px;
  211. // width: auto;
  212. border-radius: 15px;
  213. }
  214. </style>