view.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <template>
  2. <view>
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <navbar :scroll="scrollNum" :iSimmersive="true" title="商品详情"></navbar>
  5. <!-- #endif -->
  6. <mescroll-body
  7. ref="mescrollRef"
  8. :up="upOption"
  9. @init="mescrollInit"
  10. @down="downCallback"
  11. >
  12. <view v-if="!isLoading">
  13. <view id="swiper-inner-box">
  14. <swiper class="swiper-box" :circular="true" :current="current" @change="onSwiperChange">
  15. <swiper-item
  16. class="have-none"
  17. v-if="images"
  18. v-for="(item, index) in images"
  19. :key="index"
  20. >
  21. <image :src="item" mode="scaleToFill"></image>
  22. </swiper-item>
  23. </swiper>
  24. <view class="custom-indicator" v-if="images">
  25. {{ current + 1 }} / {{ images.length }}
  26. </view>
  27. </view>
  28. <view class="goods-price">
  29. <view class="price">
  30. <view>¥<text>{{ products.sell_price || '' }}</text></view>
  31. <view>原价格<text>¥{{ products.market_price || '' }}</text></view>
  32. </view>
  33. </view>
  34. <view class="goods-info clear">
  35. <view class="title">
  36. <view class="goods-name">
  37. {{ products.title || '' }}
  38. </view>
  39. <view v-if="products.briefly.length" class="goods-name" style="font-size: 29rpx;" :style="{'color':products.briefly_color.length ? products.briefly_color : '#333'}">
  40. {{ products.briefly || '' }}
  41. </view>
  42. </view>
  43. <view class="goods-info-box">
  44. <text>库存: {{ products.store_nums || '' }}件</text>
  45. <text>销量: {{ products.sale || '0' }}件</text>
  46. </view>
  47. </view>
  48. <view class="goods-comments clear">
  49. <view class="title">
  50. <text>商品评价</text>
  51. <text v-if="comments.length > 0" @click="$utils.navigateTo('comments/view',{ id: goods_id, type: 'goods' })">更多 &gt;</text>
  52. </view>
  53. <view class="comments-empty" v-if="comments.length <= 0">该商品还没有评论哦!</view>
  54. <view
  55. class="goods-comments-list clear"
  56. v-if="comments.length > 0"
  57. >
  58. <view
  59. class="goods-comments-box clear"
  60. v-for="(item,index) in comments"
  61. :key="index"
  62. >
  63. <view class="t">
  64. <view class="u">
  65. <view><image :src="item.avatar"></view>
  66. <view>{{item.username}}</view>
  67. </view>
  68. <view class="time">{{item.time}}</view>
  69. </view>
  70. <view class="c">{{item.content}}</view>
  71. <view class="d" v-if="item.reply_content">
  72. <view class="d-1">商家回复</view>
  73. <view class="d-2">{{item.reply_content}}</view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="goods-content clear">
  79. <view class="title">图文详情</view>
  80. <view class="clear" v-html="products.content"></view>
  81. </view>
  82. </view>
  83. </mescroll-body>
  84. <sku-action
  85. v-model="isSkuStatus"
  86. :goods="products"
  87. :attribute="attribute"
  88. :item="item"
  89. :goods-info.sync="selectedGoodsInfo"
  90. :fields="fields"
  91. @sku="updateSku"
  92. ></sku-action>
  93. <view class="goods-action">
  94. <goods-action-icon icon="online" @click="$utils.navigateTo('message/view')" text="客服"></goods-action-icon>
  95. <goods-action-icon icon="cart" @click="$utils.switchTab('cart/index')" text="购物车" :count="cartCount"></goods-action-icon>
  96. <goods-action-icon icon="collect" @click="favorite" text="收藏" :active="collect"></goods-action-icon>
  97. <view class="goods-action-button button-cart" @click="onAddCartClicked">加入购物车</view>
  98. <view class="goods-action-button button-buy" @click="onBuyClicked">立即购买</view>
  99. </view>
  100. <loading v-if="isLoading" color="rgba(255,255,255,1)" :layer="true"></loading>
  101. <authorize v-model="isAuthShow"></authorize>
  102. </view>
  103. </template>
  104. <script>
  105. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  106. import SkuAction from '../../components/sku-action/sku-action';
  107. import GoodsAction from "../../components/goods-action/goods-action";
  108. import GoodsActionButton from "../../components/goods-action/goods-action-button";
  109. import GoodsActionIcon from "../../components/goods-action/goods-action-icon"
  110. import loading from '../../components/tool/loading'
  111. import navbar from "@/components/navbar/navbar";
  112. // #ifdef H5
  113. import { setShareData,shareConfig } from "../../common/wechat";
  114. // #endif
  115. import authorize from "@/components/authorize/authorize";
  116. export default {
  117. mixins: [MescrollMixin],
  118. components: {
  119. SkuAction,
  120. GoodsAction,
  121. GoodsActionButton,authorize,
  122. GoodsActionIcon,loading,navbar
  123. },
  124. data() {
  125. return {
  126. isAuthShow: false,
  127. isWechat: false,
  128. path: "",
  129. isShowPoster: false,
  130. isCreatePoster: false,
  131. scrollNum: 0,
  132. isLoading: true,
  133. isError: false,
  134. upOption: {
  135. use: false,
  136. auto: false
  137. },
  138. fields:["id"],
  139. isSkuStatus: false,
  140. isShareStatus: false,
  141. images: [],
  142. collect: false,
  143. cartCount: 0,
  144. current: 0,
  145. selectedGoodsInfo: {},
  146. products: {},
  147. attribute: [],
  148. comments: [],
  149. item:{},
  150. goods_id:0,
  151. url: "",
  152. painter: {
  153. width: '650rpx',
  154. height: '950rpx',
  155. views: []
  156. }
  157. };
  158. },
  159. onLoad(options) {
  160. this.goods_id = options.id;
  161. },
  162. onShow() {
  163. let users = this.$storage.getJson("users");
  164. this.cartCount = users != null ? users.shop_count : 0;
  165. },
  166. onPageScroll(obj){
  167. this.scrollNum = obj.scrollTop;
  168. },
  169. methods: {
  170. updateSku(data){
  171. this.attribute = data;
  172. },
  173. onSwiperChange(event){
  174. this.current = event.detail.current;
  175. },
  176. downCallback(){
  177. setTimeout(()=>{
  178. this.loadGoodsData();
  179. this.mescroll.endSuccess(10, false);
  180. },1200);
  181. },
  182. triggerDownScroll(){
  183. this.mescroll.triggerDownScroll();
  184. },
  185. loadGoodsData(){
  186. this.$http.getGoodsDetail({
  187. id: this.goods_id
  188. }).then((result)=>{
  189. if(result.status){
  190. this.collect = result.data.collect ? true : false;
  191. this.products = result.data.goods;
  192. this.attribute = result.data.attr;
  193. this.comments = result.data.comments;
  194. this.item = result.data.item;
  195. this.images = result.data.photo;
  196. this.isLoading = false;
  197. }else{
  198. this.$utils.redirectTo("public/404");
  199. }
  200. }).catch(err=>{alert(err)
  201. this.$utils.redirectTo("public/404");
  202. });
  203. },
  204. favorite(){
  205. this.$store.dispatch("usersStatus").then(()=>{
  206. this.$http.goodsDetailFavorite({
  207. id: this.goods_id
  208. }).then((result)=>{
  209. if(result.status){
  210. this.collect = result.data == 1 ? true : false;
  211. }else{
  212. this.$utils.msg(result.info);
  213. }
  214. });
  215. }).catch(()=>{
  216. this.isAuthShow = true;
  217. });
  218. },
  219. onChange(index) {
  220. this.current = index;
  221. },
  222. onBuyClicked(){
  223. if(this.isSkuStatus == false){
  224. this.isSkuStatus = true;
  225. return ;
  226. }
  227. if(!this.selectedGoodsInfo.isSubmit){
  228. this.$utils.msg("请选择规格!");
  229. return false;
  230. }
  231. this.$store.dispatch("usersStatus").then(()=>{
  232. this.$utils.navigateTo("cart/confirm",{
  233. id: this.selectedGoodsInfo.id,
  234. sku_id: this.selectedGoodsInfo.selectedSku.id,
  235. num: this.selectedGoodsInfo.num,
  236. type: "buy"
  237. });
  238. }).catch(()=>{
  239. this.isAuthShow = true;
  240. });
  241. },
  242. onAddCartClicked(){
  243. if(this.isSkuStatus == false){
  244. this.isSkuStatus = true;
  245. return ;
  246. }
  247. if(!this.selectedGoodsInfo.isSubmit){
  248. this.$utils.msg("请选择规格!");
  249. return false;
  250. }
  251. this.$store.dispatch("usersStatus").then(()=>{
  252. this.$http.goodsDetailAddCart({
  253. id: this.selectedGoodsInfo.id,
  254. sku_id: this.selectedGoodsInfo.selectedSku.id,
  255. num: this.selectedGoodsInfo.num
  256. }).then((result)=>{
  257. this.isShow = false;
  258. if(result.status){
  259. this.cartCount = result.data.count;
  260. this.$store.commit("UPDATECART",result.data.count);
  261. this.$utils.msg(result.info);
  262. if(result.data.count > 0){
  263. uni.setTabBarBadge({ index: 2, text: result.data.count.toString() });
  264. }else{
  265. uni.removeTabBarBadge({ index: 2 })
  266. }
  267. }else{
  268. this.$utils.msg(result.info);
  269. }
  270. }).catch((error)=>{
  271. this.$utils.msg("网络出错,请检查网络是否连接");
  272. });
  273. }).catch(()=>{
  274. // this.$storage.set("VUE_REFERER","/goods/view/id/" + this.selectedGoodsInfo.id);
  275. this.isAuthShow = true;
  276. });
  277. }
  278. },
  279. }
  280. </script>
  281. <style lang="scss" scoped>
  282. .poster-box {
  283. z-index: 100003;
  284. position: fixed;
  285. top: 40%;
  286. left: 50%;
  287. transform: translate(-50%,-40%);
  288. .savePoster{
  289. margin-top: 20rpx;
  290. background-color: #b91922;
  291. width: 100%;
  292. height: 100rpx;
  293. line-height: 100rpx;
  294. font-size: 35rpx;
  295. color: #fff;
  296. text-align: center;
  297. border-radius: 15rpx;
  298. }
  299. .poster-close {
  300. width: 100%; height: 100rpx;
  301. line-height: 100rpx; color: #fff;
  302. font-size: 45rpx; text-align: center;
  303. font-weight: normal;
  304. }
  305. }
  306. #swiper-inner-box {
  307. position: relative;
  308. .swiper-box{
  309. width: 100%;
  310. height: 800rpx;
  311. image {
  312. width: 100%;
  313. height: 800rpx;
  314. }
  315. }
  316. .custom-indicator {
  317. position: absolute;
  318. right: 40rpx;
  319. bottom: 40rpx;
  320. padding: 12rpx 30rpx;
  321. font-size: 28rpx;
  322. background: rgba(0, 0, 0, 0.3);
  323. color: #fff;
  324. border-radius: 12rpx;
  325. }
  326. }
  327. .goods-price{
  328. width: 100%;
  329. height: 140rpx;
  330. background-color: #1b43c4;
  331. .price {
  332. height: 140rpx;
  333. float: left;
  334. margin-left: 32rpx;
  335. view {
  336. display: block;
  337. color: #fff;
  338. &:first-child {
  339. font-size: 42rpx;
  340. padding-top: 24rpx;
  341. font-style: normal;
  342. }
  343. &:last-child {
  344. font-size: 24rpx;
  345. padding-top: 0px;
  346. text {
  347. font-style: normal;
  348. font-size: 26rpx;
  349. position: relative;
  350. top: 2rpx;
  351. text-decoration:line-through;
  352. padding-left: 4rpx;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. .goods-info{
  359. background-color: #fff;
  360. .title{
  361. display: block;
  362. padding: 24rpx 30rpx 6rpx 30rpx;
  363. color: #333;
  364. font-size: 32rpx;
  365. position: relative;
  366. min-height: 88rpx;
  367. .goods-name{
  368. padding-right: 77rpx;
  369. }
  370. .goods-share{
  371. position: absolute;
  372. top: 24rpx; right: 30rpx;
  373. view {
  374. text-align: center;
  375. border-left: 1px solid #ddd;
  376. padding-left: 10rpx;
  377. &:first-child{
  378. font-size: 45rpx;
  379. color: #1b43c4;
  380. padding-bottom: 10rpx;
  381. }
  382. &:last-child {
  383. font-size: 28rpx;
  384. color: #666;
  385. }
  386. }
  387. }
  388. }
  389. .goods-info-box{
  390. display: block;
  391. padding: 0 30rpx;
  392. display: flex;
  393. flex-direction: row;
  394. flex-wrap: nowrap;
  395. justify-content: center;
  396. text {
  397. width: 50%;
  398. height: 80rpx;
  399. line-height: 80rpx;
  400. text-align: left;
  401. font-size: 30rpx;
  402. color: #888;
  403. }
  404. }
  405. }
  406. .goods-comments{
  407. margin-top: 20rpx;
  408. background-color: #fff;
  409. height: auto;
  410. .title {
  411. height: 80rpx;
  412. line-height: 80rpx;
  413. font-size: 32rpx;
  414. width: 100%;
  415. border-bottom: 2rpx solid #e8e8e8;
  416. text:nth-child(1){
  417. float: left;
  418. color: #333;
  419. padding-left: 30rpx;
  420. }
  421. text:nth-child(2){
  422. float: right;
  423. color: #999;
  424. padding-right: 30rpx;
  425. }
  426. }
  427. .comments-empty { padding: 100rpx 30rpx; text-align: center; font-size: 32rpx; color: #666; }
  428. .goods-comments-list{
  429. .goods-comments-box{
  430. border-bottom: 2rpx solid #e8e8e8;
  431. min-height: 240rpx;
  432. background-color: #fff;
  433. padding-bottom: 40rpx;
  434. .t {
  435. padding: 0 30rpx;
  436. height: 170rpx;
  437. line-height: 160rpx;
  438. color: #666;
  439. .u{
  440. float: left;
  441. font-size: 30rpx;
  442. view { float: left; }
  443. view:first-child{
  444. width: 96rpx; height: 96rpx;
  445. overflow: hidden; border-radius: 50%;
  446. background-color: #eee; display: inline-block;
  447. position: relative; top: 30rpx;
  448. image {
  449. width: 96rpx; height: 96rpx;
  450. }
  451. }
  452. view:last-child { position: relative; left: 20rpx; }
  453. }
  454. .time{
  455. float: right;
  456. font-size: 28rpx;
  457. }
  458. }
  459. .c{
  460. padding: 0 30rpx 10rpx 30rpx;
  461. font-size: 30rpx; color: #333;
  462. }
  463. .d {
  464. background-color: #f7f7f7;
  465. margin: 0 30rpx;
  466. .d-1 {
  467. padding: 10rpx 30rpx 0 30rpx;
  468. font-size: 30rpx;
  469. }
  470. .d-2 {
  471. padding: 20rpx 30rpx 20rpx 30rpx;
  472. font-size: 28rpx;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. .goods-content{
  479. background-color: #fff;
  480. width: 100%;
  481. margin-top: 30rpx;
  482. margin-bottom: 100rpx;
  483. .title {
  484. font-size: 32rpx;
  485. color: #282828;
  486. height: 96rpx;
  487. width: 100%;
  488. background-color: #fff;
  489. text-align: center;
  490. line-height: 96rpx;
  491. }
  492. image {
  493. width: 100%;
  494. height: auto;
  495. float: left;
  496. }
  497. }
  498. .goods-action{
  499. position: fixed;
  500. right: 0;
  501. bottom: 0;
  502. left: 0;
  503. display: flex;
  504. align-items: center;
  505. box-sizing: content-box;
  506. height: 100rpx;
  507. border-top: 2rpx solid #d9d9d9;
  508. padding-bottom: constant(safe-area-inset-bottom);
  509. padding-bottom: env(safe-area-inset-bottom);
  510. background-color: #fff;
  511. z-index: 100000;
  512. overflow: hidden;
  513. .goods-action-button{
  514. position: relative;
  515. display: inline-block;
  516. box-sizing: border-box;
  517. margin: 0;
  518. padding: 0;
  519. text-align: center;
  520. cursor: pointer;
  521. transition: opacity .2s;
  522. -webkit-appearance: none;
  523. -webkit-box-flex: 1;
  524. -webkit-flex: 1;
  525. flex: 1;
  526. height: 100rpx;
  527. line-height: 100rpx;
  528. font-weight: 500;
  529. font-size: 28rpx;
  530. border: none;
  531. color: #fff;
  532. }
  533. .button-cart {
  534. background-color: #ffc03a;
  535. }
  536. .button-buy {
  537. background-color: #1b43c4;
  538. }
  539. }
  540. /* #ifdef H5 */
  541. .share-weixin {
  542. z-index: 211191; position: fixed;
  543. width: 100%; height: 100%; background: rgba(0,0,0,0.5); left: 0; top: 0;
  544. background-image: url(../../static/images/share_i.png);
  545. background-repeat: no-repeat;
  546. background-size: 90%;
  547. background-position-x: right;
  548. }
  549. /* #endif */
  550. </style>