app-recommended-product-list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <view class="app-recommended-product-list dir-left-nowrap">
  3. <scroll-view scroll-y class="app-classification" :style="{height: `${height - 110}rpx`,backgroundColor: catBgColor}">
  4. <text class="app-class-item"
  5. v-for="(item, index) in catList" :key="index"
  6. :style="{'color': activeIndex === index ? theme.color : '#353535', 'border-color': activeIndex === index ? theme.border : '' }"
  7. @click="goClass(index)"
  8. v-bind:style="activeIndex === index ? `background-color: ${tagColor};color: ${catSelectedColor}`: `color: ${catUnselectedColor}`"
  9. >{{item.menuName}}</text>
  10. </scroll-view>
  11. <view class="app-product">
  12. <scroll-view class="app-product-scroll" :scroll-into-view="`scroll-${activeIndex}`" :style="{height: `${height - 110}rpx`}" scroll-y>
  13. <block v-for="(page, number) in catList" :key="number">
  14. <view class="app-product-class-item">
  15. <text class="app-class-name" :id="`scroll-${number}`">{{page.menuName}}</text>
  16. <view class="app-product-item"
  17. v-for="(item, index) in page.goodsList"
  18. :key="index"
  19. :class="{'app-product-border': index !== getLength(page.goodsList), 'app-margin-top': index !== 0,'have-bg': goodsStyle < 3}"
  20. >
  21. <view class="app-product-border-all"
  22. :class="{'app-product-border-all-item': goodsStyle === 2}"
  23. >
  24. <view @click="jump_router(item)" >
  25. <view class="out-dialog" v-if="item.goods_stock == 0 && appSetting.is_show_stock == '1'">
  26. <image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
  27. </view>
  28. <view class="dir-left-nowrap main-between cross-top">
  29. <image lazy-load="true" class="app-tag-icon" :src="goodsTagPicUrl" v-if="showGoodsTag"></image>
  30. <view style="border-radius: 16rpx;">
  31. <app-image borderRadius="16rpx" :img-src="item.cover_pic" width="160rpx" height="160rpx"
  32. :mode="fill === 1 ? 'aspectFill' : 'aspectFit'"></app-image>
  33. </view>
  34. <view class="app-product-content dir-top-nowrap main-between"
  35. :class="{'dir-top-nowrap': !showGoodsName, 'main-right': !showGoodsName}"
  36. >
  37. <text class="app-product-name" v-if="showGoodsName">{{item.name}}</text>
  38. <view class="app-price-buttons main-between cross-bottom" :class="{'dir-right-nowrap': !showGoodsPrice , 'dir-left-nowrap': showGoodsPrice}">
  39. <view class="price">
  40. <view v-if="item.is_level == 1 && item.is_negotiable != 1" style="height: 32rpx;margin-bottom: 8rpx;">
  41. <app-member-price :theme="theme" :price="item.level_price"></app-member-price>
  42. </view>
  43. <app-sup-vip v-if="item.vip_card_appoint && item.vip_card_appoint.discount" :discount="item.vip_card_appoint.discount" :is_vip_card_user="item.vip_card_appoint.is_vip_card_user"></app-sup-vip>
  44. <text class="app-price" v-if="showGoodsPrice" :style="{'color': theme.color}">{{item.price_content}}</text>
  45. <text v-if="isShowOriginalPrice(goods)" class="bd-original-price">¥{{item.original_price}}</text>
  46. </view>
  47. <template v-if="showBuyBtn && item.price_content !== '面议'">
  48. <button class="app-product-button"
  49. @click.stop="buyProduct(item)"
  50. v-if="buyBtn === 'text'" :style="item.buy_goods_auth ? btnStyle : disableBtnStyle"
  51. :class="{
  52. 'app-button-filling': buyBtnStyle === 1,
  53. 'app-button-line' : buyBtnStyle === 2 ,
  54. 'app-button-fillet' : buyBtnStyle === 3,
  55. 'app-button-rounded-lines': buyBtnStyle === 4,
  56. }"
  57. >{{buyBtnText}}</button>
  58. <icon @click.stop="buyProduct(item)"
  59. class="app-button-icon app-product-button-cart"
  60. :style="{'background-color': item.buy_goods_auth ? theme.background : '#999999'}"
  61. v-if="buyBtn === 'cart' && item.goods_stock != 0"
  62. type></icon>
  63. <icon @click.stop="buyProduct(item)"
  64. class="app-button-icon app-product-button-add"
  65. :style="{'background-color': item.buy_goods_auth ? theme.background : '#999999'}"
  66. v-if="buyBtn === 'add' && item.goods_stock != 0"
  67. type></icon>
  68. </template>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </block>
  77. </scroll-view>
  78. </view>
  79. <view>
  80. <app-attr
  81. :goods="goods"
  82. :attrGroupList="goods.attr_groups"
  83. :show="show"
  84. :selectAttr="selectAttr"
  85. @attr="attr"
  86. :theme="theme"
  87. ></app-attr>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import { mapState, mapGetters } from "vuex";
  93. import appAttr from '../../../components/page-component/app-attr/app-attr.vue';
  94. export default {
  95. name: 'app-recommended-product-list',
  96. data() {
  97. return {
  98. scrollIndex: 0,
  99. height: 0,
  100. activeIndex: 0,
  101. cartIndex: -1,
  102. show: false,
  103. selectAttr: {},
  104. goods: {},
  105. disableColor: '#999999',
  106. disable: 'disable',
  107. // 规格商品
  108. attrGoods: {
  109. goods: {},
  110. attrShow: 0
  111. },
  112. }
  113. },
  114. props: {
  115. catList: {
  116. type: Array,
  117. default: function() {
  118. return []
  119. }
  120. },
  121. fill: {
  122. type: Number,
  123. default: function() {
  124. return 1;
  125. }
  126. },
  127. buyBtnText: {
  128. type: String,
  129. default: function() {
  130. return '';
  131. }
  132. },
  133. buyBtnStyle: {
  134. type: Number,
  135. default: function() {
  136. return 4;
  137. }
  138. },
  139. showBuyBtn: {
  140. type: Boolean,
  141. default: function() {
  142. return true;
  143. }
  144. },
  145. showGoodsPrice: {
  146. type: Boolean,
  147. default: function() {
  148. return true;
  149. }
  150. },
  151. buyBtn: {
  152. type: String,
  153. default: function() {
  154. return 'cart';
  155. }
  156. },
  157. goodsStyle: {
  158. type: Number,
  159. default: function() {
  160. return 1;
  161. }
  162. },
  163. goodsTagPicUrl: {
  164. type: String,
  165. default: function() {
  166. return '';
  167. }
  168. },
  169. showGoodsTag: {
  170. type: Boolean,
  171. default: function() {
  172. return true;
  173. }
  174. },
  175. showGoodsName: {
  176. type: Boolean,
  177. default: function() {
  178. return true;
  179. }
  180. },
  181. buttonColor: {
  182. type: String,
  183. default() {
  184. return '';
  185. }
  186. },
  187. theme: Object,
  188. isUnderLinePrice: {
  189. type: Boolean,
  190. default: function() {
  191. return false;
  192. }
  193. },
  194. isBuy: {
  195. type: Boolean,
  196. default: true
  197. },
  198. // 是否显示规格
  199. isShowAttr: {
  200. type: Boolean,
  201. default: false
  202. },
  203. //标签颜色
  204. tagColor: {
  205. type: String
  206. },
  207. //选中颜色
  208. catSelectedColor: {
  209. type: String
  210. },
  211. //未选中颜色
  212. catUnselectedColor: {
  213. type: String
  214. },
  215. //背景色
  216. catBgColor: {
  217. type: String
  218. }
  219. },
  220. computed: {
  221. ...mapState({
  222. appImg: state => state.mallConfig.__wxapp_img.mall,
  223. appSetting: state => state.mallConfig.mall.setting,
  224. platform: function(state) {
  225. return state.gConfig.systemInfo.platform;
  226. }
  227. }),
  228. ...mapGetters('mallConfig',{
  229. getVideo: 'getVideo'
  230. }),
  231. btnStyle() {
  232. let btnStyle = ``;
  233. if (this.buyBtnStyle === 1 || this.buyBtnStyle === 3) {
  234. btnStyle += `background-color: ${this.buttonColor};color: #ffffff;`;
  235. } else {
  236. btnStyle += `border-color: ${this.buttonColor};color: ${this.buttonColor};`;
  237. }
  238. return btnStyle;
  239. },
  240. disableBtnStyle() {
  241. let btnStyle = ``;
  242. if (this.buyBtnStyle === 1 || this.buyBtnStyle === 3) {
  243. btnStyle += `background-color: ${this.disableColor};color: #ffffff;`;
  244. } else {
  245. btnStyle += `border-color: ${this.disableColor};color: ${this.disableColor};`;
  246. }
  247. return btnStyle;
  248. },
  249. },
  250. created() {
  251. let _this = this;
  252. wx.getSystemInfo({
  253. success: function(res) {
  254. _this.height = (750/res.windowWidth) * res.windowHeight;
  255. }
  256. })
  257. },
  258. methods: {
  259. getLength(data) {
  260. return data.length -1;
  261. },
  262. // 购买按钮点击事件
  263. buyProduct(goods) {
  264. if(this.isBuy) {
  265. if (this.isShowAttr) {
  266. this.attrGoods.goods = goods;
  267. this.attrGoods.attrShow = Math.random();
  268. } else {
  269. uni.showLoading({
  270. text: '',
  271. mask: true
  272. });
  273. this.$request({
  274. url: this.$api.goods.attr,
  275. data: {
  276. id: goods.id,
  277. mch_id: goods.mch_id
  278. }
  279. }).then(e => {
  280. uni.hideLoading();
  281. if (e.code === 0) {
  282. let data = Object.assign(goods, e.data);
  283. this.$emit('buyProduct', {
  284. goods: data,
  285. attrShow: Math.random()
  286. });
  287. } else {
  288. uni.showToast({
  289. title: e.msg,
  290. icon: 'none'
  291. })
  292. }
  293. })
  294. }
  295. }else {
  296. this.jump_router(goods);
  297. }
  298. },
  299. goClass(index) {
  300. this.activeIndex = index;
  301. },
  302. attr(data) {},
  303. jump_router(data) {
  304. // #ifndef MP-BAIDU
  305. if (data.video_url && this.getVideo == 1) {
  306. // #ifdef MP
  307. uni.navigateTo({
  308. url: `/pages/goods/video?goods_id=${data.id}&sign=${data.sign}`
  309. });
  310. // #endif
  311. // #ifdef H5
  312. uni.navigateTo({
  313. url: data.page_url
  314. });
  315. // #endif
  316. } else {
  317. uni.navigateTo({
  318. url: data.page_url
  319. });
  320. }
  321. // #endif
  322. // #ifdef MP-BAIDU
  323. uni.navigateTo({
  324. url: data.page_url
  325. });
  326. // #endif
  327. },
  328. // 是否显示原价
  329. isShowOriginalPrice(goods) {
  330. return this.isUnderLinePrice && goods.is_negotiable !== 1 ? 1 : 0;
  331. },
  332. },
  333. components: {
  334. 'app-attr': appAttr
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. .app-class-item {
  340. display: inline-block;
  341. width: #{158rpx};
  342. line-height: #{104rpx};
  343. font-size: #{26rpx};
  344. text-align: center;
  345. border-left: #{2rpx} solid transparent;
  346. }
  347. .app-recommended-product-list {
  348. width: #{750rpx};
  349. height: #{100%};
  350. .app-classification {
  351. width: #{160rpx};
  352. height: #{100%};
  353. }
  354. .app-product {
  355. height: #{100%};
  356. padding-left: #{24rpx};
  357. padding-top: #{4rpx};
  358. .app-product-class-item {
  359. width: #{750-160-24rpx};
  360. .app-class-name {
  361. display: inline-block;
  362. width: #{750-160-24rpx};
  363. padding-top: #{40rpx};
  364. padding-bottom: #{36rpx};
  365. font-size: #{24rpx};
  366. color: #666666;
  367. }
  368. .app-product-item {
  369. width: #{750-160-24-12rpx};
  370. border-radius: #{16rpx};
  371. &.have-bg {
  372. background-color: #fff;
  373. }
  374. position: relative;
  375. .app-tag-icon {
  376. position: absolute;
  377. top: 0;
  378. left: 0;
  379. width: #{55rpx};
  380. height: #{55rpx};
  381. z-index: 1000;
  382. }
  383. .out-dialog {
  384. width: #{160rpx};
  385. height: #{160rpx};
  386. position: absolute;
  387. z-index: 10;
  388. background-color: rgba(0,0,0,.5);
  389. image {
  390. width: #{160rpx};
  391. height: #{160rpx};
  392. border-radius: #{16rpx};
  393. }
  394. }
  395. .app-product-image {
  396. /* #ifndef MP-ALIPAY */
  397. width: #{150rpx};
  398. /* #endif */
  399. /* #ifdef MP-ALIPAY */
  400. width: #{136rpx};
  401. /* #endif */
  402. /* #ifndef MP-ALIPAY */
  403. height: #{150rpx};
  404. /* #endif */
  405. /* #ifdef MP-ALIPAY */
  406. height: #{136rpx};
  407. /* #endif */
  408. }
  409. .app-product-content {
  410. width: #{750-160-24-152-20rpx};
  411. min-height: #{160upx};
  412. padding: 0 #{21rpx} #{23rpx};
  413. .app-product-name {
  414. font-size: #{28rpx};
  415. color: #353535;
  416. padding-top: #{15rpx};
  417. display: -webkit-box;
  418. -webkit-box-orient: vertical;
  419. -webkit-line-clamp: 2;
  420. overflow: hidden;
  421. width: #{750-160-24-152-20-24rpx};
  422. margin-bottom: #{10rpx};
  423. }
  424. .app-price-buttons {
  425. width: #{750-160-24-152-20-24-24rpx};
  426. .app-price {
  427. font-size: #{28rpx};
  428. }
  429. .app-product-button {
  430. display: inline-block;
  431. padding: 0 #{20rpx};
  432. height: #{48rpx};
  433. font-size: #{28rpx};
  434. color: #ffffff;
  435. line-height: #{48rpx};
  436. border-radius: 0;
  437. margin: 0;
  438. }
  439. .app-button-filling {
  440. }
  441. .app-button-fillet {
  442. border-radius: #{20rpx} !important;
  443. }
  444. .app-button-line {
  445. }
  446. .app-button-rounded-lines {
  447. border-radius: #{20rpx} !important;
  448. }
  449. .app-product-button-cart {
  450. background-image: url("../../../static/image/icon/goods-cart.png");
  451. }
  452. .app-product-button-add {
  453. background-image: url("../../../static/image/icon/add-to.png");
  454. }
  455. }
  456. }
  457. .app-product-border-all {
  458. width: #{750-160-24-12rpx};
  459. border-radius: #{10rpx};
  460. }
  461. .app-product-border-all-item {
  462. border: #{1rpx} solid #e2e2e2;
  463. }
  464. .app-button-icon {
  465. background-repeat: no-repeat;
  466. background-size: 100% 100%;
  467. width: #{36rpx};
  468. height: #{36rpx};
  469. }
  470. }
  471. .app-product-border {
  472. border-bottom-color: #e2e2e2;
  473. }
  474. .app-margin-top {
  475. margin-top: #{24rpx};
  476. }
  477. }
  478. }
  479. }
  480. .app-volume {
  481. margin: #{8rpx 0};
  482. font-size: #{22rpx};
  483. color: #666666;
  484. }
  485. .bd-original-price {
  486. color: #999999;
  487. font-size: 22upx;
  488. text-decoration: line-through;
  489. margin-left: 10upx;
  490. }
  491. </style>