detail.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="page">
  3. <!-- 商品图片 -->
  4. <ImgSwiper :list="[goodsDetail.cover]"></ImgSwiper>
  5. <!-- 商品信息 -->
  6. <GoodsInfo :data="goodsDetail" :goodsType="goodsType" :selectedSku="selectedSku"></GoodsInfo>
  7. <!-- 选择项 -->
  8. <GoodsSelect :selectedSku="selectedSku" :expressInfo="expressInfo" :selectedAddress="selectedAddress" @openSku="openSkuPopup"></GoodsSelect>
  9. <!-- 商品详情 -->
  10. <TitleOperate title="商品详情" :backgroundColor="bgColor" titleSize="32rpx" align="center"></TitleOperate>
  11. <!-- <view class="details-html" v-html="goodsDetail.html"></view> -->
  12. <view class="detailsBox">
  13. <view class="p">
  14. <text>书名:{{goodsDetail.title||''}}</text>
  15. </view>
  16. <view class="p">
  17. <text>定价:{{goodsDetail.price_market||''}}</text>
  18. </view>
  19. <view class="p">
  20. <text>作者:{{goodsDetail.author||''}}</text>
  21. </view>
  22. <view class="p">
  23. <text>出版社:{{goodsDetail.publish||''}}</text>
  24. </view>
  25. <view class="p">
  26. <text>出版日期:{{goodsDetail.pub_date||''}}{{goodsDetail.pub_time?'-'+goodsDetail.pub_time:''}}</text>
  27. </view>
  28. <view class="p">
  29. <text>ISBN:{{goodsDetail.isbn||''}}</text>
  30. </view>
  31. </view>
  32. <!-- 底部操作按钮 -->
  33. <submitBar :data="goodsDetail" @addShoppingCart="addShoppingCart" @buyNow="buyNow"></submitBar>
  34. <!-- 选择sku -->
  35. <GoodsSelectSku ref="GoodsSelectSkuRef" :expressInfo="expressInfo" @addShoppingCart="addShoppingCart" @buyNow="buyNow" @change="changeSku"></GoodsSelectSku>
  36. <!-- <u-skeleton :loading="pageLoading" :animation="true" bgColor="#FFF"></u-skeleton> -->
  37. </view>
  38. </template>
  39. <script>
  40. import TitleOperate from '@/components/title-operate.vue';
  41. import ImgSwiper from '@/components/img-swiper.vue';
  42. import GoodsInfo from '@/pages-mall/components/goods/goods-info.vue';
  43. import GoodsSelect from '@/pages-mall/components/goods/goods-select.vue';
  44. import submitBar from '@/pages-mall/components/goods/submitBar.vue';
  45. import GoodsSelectSku from '@/pages-mall/components/goods/goods-select-sku.vue';
  46. import CardGoods from '@/pages/mall/components/card.vue';
  47. var _self;
  48. export default {
  49. components: {
  50. TitleOperate,
  51. ImgSwiper,
  52. GoodsInfo,
  53. GoodsSelect,
  54. submitBar,
  55. GoodsSelectSku,
  56. CardGoods
  57. },
  58. data() {
  59. return {
  60. pageLoading:false,
  61. // 背景色
  62. bgColor: this.$appTheme.appThemeBgColor,
  63. // 商品类型,normal、points
  64. goodsType: 'normal',
  65. goodsId:null,
  66. goodsDetail:{},
  67. // 相关商品
  68. goodsData: [],
  69. // 已选择sku
  70. selectedSku: { difference: '', id: 0 },
  71. // 已选择地址
  72. selectedAddress: {},
  73. // 浏览历史
  74. browseHistory:[],
  75. };
  76. },
  77. onLoad(ops) {
  78. _self = this;
  79. const token = uni.getStorageSync('token');
  80. if(!token){
  81. uni.navigateTo({
  82. url:'/pages/login/index'
  83. })
  84. return false;
  85. }
  86. if (ops.goodsId){
  87. this.goodsId = ops.goodsId;
  88. this.getGoodsDetail();
  89. if(!this.$store.state.pub.baseConfig.express_type){
  90. this.getExpressInfo();
  91. }
  92. }else{
  93. uni.navigateBack();
  94. }
  95. },
  96. onShow() {
  97. uni.$once('addressInfo',function(data){
  98. console.log(data);
  99. _self.selectedAddress = data;
  100. })
  101. },
  102. computed: {
  103. // 运费模板
  104. expressInfo() {
  105. return this.$store.state.pub.baseConfig;
  106. },
  107. },
  108. methods: {
  109. // 足迹
  110. addBrowHistory(){
  111. const hist = uni.getStorageSync('browseHistory');
  112. console.log('browseHistory>>>',hist)
  113. if(hist){
  114. let index = hist.findIndex(e=>e.id===this.goodsDetail.id);
  115. console.log('查到了index>>',index);
  116. if(index>-1){
  117. // 之前在缓存中存在了,先删除,在追加到第一位
  118. hist.splice(index, 1);
  119. }
  120. //将 e 重新追加到数组第一位
  121. this.browseHistory = [].concat(hist);
  122. }
  123. /*
  124. author: "刘浪"
  125. cate_id: "61"
  126. code: "wk-755732"
  127. cover: "https://bookyun.oss-cn-qingdao.aliyuncs.com/bookpic/xyg9787569205107.jpg"
  128. express_template_id: 0
  129. expresstemplate: null
  130. id: 2
  131. is_collection: 1
  132. isbn: "9787569205107"
  133. price_selling: "0.01"
  134. pub_date: "2017-05"
  135. pub_time: "1"
  136. publish: "吉林大学出版社"
  137. sku: [{id: 28, admin_id: 1, goods_id: 2, stock_total: 100, price_selling: "0.01", need_score: null,…},…]
  138. spu: [{id: 10, spu_id: 1, goods_id: 2, name: "品相", item: "良品,一般,次品", createtime: 1711707864,…}]
  139. stock_sales: 11221
  140. stock_total: "278"
  141. tags_type: "hot"
  142. title: "医药数理统计"
  143. */
  144. let json = {
  145. id:this.goodsDetail.id,
  146. cover:this.goodsDetail.cover,
  147. title:this.goodsDetail.title,
  148. publish:this.goodsDetail.publish,
  149. };
  150. // 追加到第一位
  151. this.browseHistory.unshift(json);
  152. //只保存前100
  153. this.browseHistory.slice(0, 100);
  154. uni.setStorageSync('browseHistory', this.browseHistory);
  155. },
  156. // 获取运费模板信息
  157. getExpressInfo(){
  158. this.$u.api.getBaseInfoAjax().then(({data})=>{
  159. console.log(data);
  160. this.$store.commit('pub/commitBaseConfig',data);
  161. }).catch(()=>{
  162. })
  163. },
  164. // 查询商品详情
  165. getGoodsDetail() {
  166. this.pageLoading = true;
  167. this.$u.api.getGoodsDetailAjax(this.goodsId).then(({code,data})=>{
  168. this.pageLoading = false;
  169. this.goodsDetail = data;
  170. // this.selectedSku = this.goodsDetail.sku[1]||this.goodsDetail.sku[0];
  171. this.$refs.GoodsSelectSkuRef.initSkuFun(this.goodsDetail);
  172. // 进入足迹
  173. this.addBrowHistory();
  174. });
  175. },
  176. // 打开选择sku的弹窗
  177. openSkuPopup() {
  178. console.log(222);
  179. this.$refs.GoodsSelectSkuRef.open(this.goodsDetail);
  180. },
  181. // 切换sku
  182. changeSku(e) {
  183. this.selectedSku = e;
  184. },
  185. // 加入购物车
  186. addShoppingCart() {
  187. this.openSkuPopup();
  188. },
  189. // 立即购买
  190. buyNow() {
  191. console.log(111);
  192. this.openSkuPopup();
  193. }
  194. }
  195. };
  196. </script>
  197. <style lang="scss" scoped>
  198. // .page{
  199. // padding-bottom: 130rpx;
  200. // }
  201. .details-html {
  202. background-color: $app-theme-bg-color;
  203. padding: 0 30rpx 30rpx 30rpx;
  204. margin-bottom: 100rpx;
  205. }
  206. .detailsBox{
  207. padding: 30rpx;
  208. background-color: #fff;
  209. .p{
  210. line-height: 1.5;
  211. }
  212. }
  213. </style>