uni-goods-nav.vue 7.9 KB

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