uni-goods-nav.vue 8.9 KB

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