view.vue 15 KB

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