Detail.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!-- 商品详情 -->
  2. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  3. <home-base :show="false" ><view class="div product-detail-wrapper" v-if="productDetail">
  4. <!-- header -->
  5. <detail-header v-if="!isPreviewPicture"></detail-header>
  6. <!-- body -->
  7. <detail-body :isStock="productDetail.pgoods_storage"></detail-body>
  8. <!-- footer -->
  9. <detail-footer v-if="!isPreviewPicture"></detail-footer>
  10. <!-- 预览图片 -->
  11. <preview-picture
  12. ></preview-picture>
  13. </view></home-base>
  14. </template>
  15. <script>
  16. import {getFontSize} from '@/util/common'
  17. import HomeBase from '../HomeBase'
  18. import DetailHeader from './DetailHeader'
  19. import DetailBody from './DetailBody'
  20. import DetailFooter from './DetailFooter'
  21. import PreviewPicture from './child/PreviewPicture'
  22. import { getPointsgoodsInfo } from '../../../api/homePointsgoods'
  23. import { mapState, mapMutations, mapActions } from 'vuex'
  24. export default {
  25. data () {
  26. return {
  27. productId: '',
  28. productDetail: {},
  29. }
  30. },
  31. components:{
  32. HomeBase,
  33. DetailHeader,
  34. DetailBody,
  35. DetailFooter,
  36. PreviewPicture
  37. },
  38. onLoad: function (option) {
  39. this.productId=option.pgoods_id ? option.pgoods_id : ''
  40. this.getDetail()
  41. this.saveCartState(false)
  42. },
  43. computed: {
  44. fontSize(){
  45. return getFontSize()
  46. },
  47. ...mapState({
  48. isPreviewPicture: state => state.pointsgoods.isPreviewPicture,
  49. })
  50. },
  51. mounted () {
  52. this.$nextTick(() => {})
  53. },
  54. methods: {
  55. ...mapMutations({
  56. saveInfo: 'saveDetailInfo',
  57. saveCommendList: 'saveCommendList',
  58. saveCartState: 'saveCartState',
  59. setCurrentProductId: 'setCurrentProductId'
  60. }),
  61. /*
  62. getDetail: 获取商品详情, 并且存入状态管理
  63. */
  64. getDetail () {
  65. this.setCurrentProductId(this.productId)
  66. getPointsgoodsInfo(this.productId).then(res => {
  67. if (res) {
  68. this.productDetail = res.result.goods_info
  69. uni.setNavigationBarTitle({
  70. title: this.productDetail.goods_name
  71. })
  72. this.saveInfo(res.result.goods_info)
  73. this.saveCommendList(res.result.goods_commend_list)
  74. }
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .product-detail-wrapper {
  82. height: 100%;
  83. width: auto;
  84. }
  85. </style>