goods.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <app-layout>
  3. <view v-if="!goods" class="u-goods-detail"></view>
  4. <view class="app-goods" v-if="goods">
  5. <view class="banner">
  6. <app-banner :videoUrl="goods.video_url" :share="goods.share" :picList="goods.pic_url" :goods_id="goods_id" sign="flash_sale"></app-banner>
  7. </view>
  8. <!-- 时间 -->
  9. <view class="f-timing">
  10. <view class="f-image" :style="{'background-color': getTheme.background}"></view>
  11. <view class="f-activity" :style="{'color': getTheme.color}">
  12. {{goods.discount_type === 1 ? goods.min_discount + '折' : '减' + goods.min_discount + '元' }}
  13. </view>
  14. <view class="f-content dir-top-nowrap">
  15. <view class="app-text" v-if="activity_status === 0">距离开始仅剩</view>
  16. <view class="app-text" v-else-if="activity_status === 1">距离结束仅剩</view>
  17. <view class="app-text over-text" v-else-if="activity_status === 2">活动已结束</view>
  18. <view class="app-time cross-center main-around" v-if="activity_status !== 2">
  19. <text class="app-num app-right" >{{time_str.day}}</text>
  20. <text>天</text>
  21. <text class="app-num app-right">{{time_str.hou}}</text>
  22. <text>时</text>
  23. <text class="app-num app-right">{{time_str.min}}</text>
  24. <text>分</text>
  25. <text class="app-num app-right">{{time_str.sec}}</text>
  26. <text>秒</text>
  27. </view>
  28. </view>
  29. </view>
  30. <bd-info
  31. :theme="getTheme"
  32. :name="goods.name"
  33. :is-negotiable="goods.is_negotiable"
  34. :subtitle="goods.subtitle"
  35. :level-show="goods.level_show"
  36. :price="goods.price"
  37. :original-price="goods.original_price"
  38. :price-max="goods.price_max"
  39. :price-min="goods.price_min"
  40. :price-member-max="goods.price_member_max"
  41. :price-member-min="goods.price_member_min"
  42. :discount='discount'
  43. :is-vip-card-user="is_vip_card_user"
  44. :sales="goods.sales"
  45. :unit="goods.unit"
  46. :is-sales="goods.is_sales"
  47. :is-vip="is_vip"
  48. :goods-id="goods.id"
  49. :extra-quick-share="goods.extra_quick_share"
  50. :app-share-pic="goods.app_share_pic"
  51. :app-share-title="goods.app_share_title"
  52. :poster-config="poster_config + `&goods_id=` + goods.id"
  53. :poster-generate="poster_generate + `&goods_id=` + goods.id"
  54. :has-poster-nav="true"
  55. @quickShare="quickShare"
  56. v-bind:goods="goods"
  57. @share="hShareAppMessage"
  58. :min-number="goods.min_number"
  59. :limit-buy="goods.limit_buy"
  60. ></bd-info>
  61. <bd-coupon @change="setCoupon" :theme="getTheme" :coupons="goods.goods_coupon_center"></bd-coupon>
  62. <bd-xbc
  63. :coAttr="is_open"
  64. :attr-list="selectAttr.attr_list"
  65. :type="goods.type"
  66. :guarantee-title="goods.guarantee_title"
  67. :guarantee-pic="goods.guarantee_pic"
  68. :param_content="goods.param_content"
  69. :param_name="goods.param_name"
  70. :services="goods.services"
  71. :attr-groups="goods.attr_groups"
  72. :goods-stock="goods.goods_stock"
  73. :co-attr="activity_status"
  74. @openAttr="joinCart"
  75. ></bd-xbc>
  76. <bd-hc
  77. :integral="goods.goods_marketing_award.integral"
  78. :coupon="goods.goods_marketing_award.coupon"
  79. :card="goods.goods_marketing_award.card"
  80. :balance="goods.goods_marketing_award.balance"
  81. :theme="getTheme"
  82. ></bd-hc>
  83. <bd-kb
  84. :limit="goods.goods_marketing.limit"
  85. :express="goods.express"
  86. :shipping="goods.goods_marketing.shipping"
  87. :pickup="goods.goods_marketing.pickup"
  88. ></bd-kb>
  89. <bd-comments :goods-id="goods.id"></bd-comments>
  90. <bd-detail :detail="goods.detail"></bd-detail>
  91. <!-- 相关推荐 -->
  92. <template v-if="list.length > 0">
  93. <app-related-suggestion-product :theme="getTheme" :list="list"></app-related-suggestion-product>
  94. </template>
  95. <!--空格区域-->
  96. <view class="safe-area-inset-bottom">
  97. <view class="u-bottom-height" :class="full_reduce ? 'u-bottom-height-1' : 'u-bottom-height-0'"></view>
  98. </view>
  99. <!-- 底部按钮 -->
  100. <view v-if="is_open == 1" class="safe-area-inset-bottom u-bottom-fixed">
  101. <view v-if="full_reduce">
  102. <app-goods-full-reduce
  103. :theme="getTheme"
  104. sign="flash_sale"
  105. :full_reduce="full_reduce"
  106. >
  107. </app-goods-full-reduce>
  108. </view>
  109. <view class="bd-bottom dir-left-nowrap cross-center">
  110. <view class="bd-back dir-top-nowrap main-center cross-center box-grow-0" @click="back">
  111. <image class="bd-icon" src="../../../static/image/icon/index.png"></image>
  112. <text class="bd-text">首页</text>
  113. </view>
  114. <bd-service :name="goods.name" :url="webUrl"></bd-service>
  115. <view v-if="goods.goods_stock == 0" class="bd-button box-grow-1 bd-oversell-btn" >
  116. 已售罄
  117. </view>
  118. <template v-else >
  119. <template v-if="activity_status === 1">
  120. <view class="dir-left-nowrap box-grow-1">
  121. <view @click="joinCart" class="bd-btn-half bd-button bd-btn-left"
  122. :style="{'background': !goods || goods.buy_goods_auth ? getTheme.background_s_gradient_btn : '#999999','color': !goods || goods.buy_goods_auth ? getTheme.secondary_text : ''}">
  123. 加入购物车
  124. </view>
  125. <view @click="joinCart" class="bd-btn-half bd-button bd-btn-right"
  126. :style="{'background': goods.buy_goods_auth ? getTheme.background_gradient_btn : '#999999','color': goods.buy_goods_auth ? getTheme.main_text : ''}">
  127. 立即购买
  128. </view>
  129. </view>
  130. </template>
  131. <view class="dir-left-nowrap box-grow-1" v-if="activity_status === 0">
  132. <view class="bd-btn-half bd-button bd-btn-left" @click="joinCart" :style="{'background': !goods || goods.buy_goods_auth ? getTheme.background_s_gradient_btn : '#999999','color' : !goods || goods.buy_goods_auth ? getTheme.secondary_text : ''}">
  133. 加入购物车
  134. </view>
  135. <view style="background: #999999;line-height: 1" class="dir-top-nowrap bd-button bd-btn-right bd-btn-half main-center cross-center">
  136. <view style="font-size: 28rpx">{{activity.start_at | getStart}}</view>
  137. <view style="font-size: 20rpx">{{activity.start_at | getStartT}}</view>
  138. </view>
  139. </view>
  140. <view v-if="activity_status === 2" class="bd-button bd-oversell-btn box-grow-1" >
  141. 活动已结束
  142. </view>
  143. </template>
  144. </view>
  145. </view>
  146. <u-attr
  147. v-model="show"
  148. :goods="goods"
  149. :theme="getTheme"
  150. :checked="selectAttr"
  151. @check="onAttr"
  152. :rightFunc="true"
  153. :leftFunc="true"
  154. @leftFunc="leftFunc"
  155. @rightFunc="rightFunc"
  156. :is_show_right="activity_status === 1"
  157. >
  158. </u-attr>
  159. </view>
  160. <app-close v-if="showClose" :modal="false" @update="getMall"></app-close>
  161. </app-layout>
  162. </template>
  163. <script>
  164. import {mapGetters, mapState} from 'vuex';
  165. import appBanner from '../../../components/page-component/goods/app-goods-banner.vue';
  166. import appRelatedSuggestionProduct from '../../../components/page-component/app-related-suggestion-product/app-related-suggestion-product.vue';
  167. import appGoodsFullReduce from '../../../components/page-component/goods/app-goods-full-reduce.vue';
  168. import uAttr from '../../../components/page-component/goods/u-attr.vue';
  169. import bdInfo from '@/components/page-component/goods/bd-info';
  170. import bdCoupon from '@/components/page-component/goods/bd-coupon.vue';
  171. import bdXbc from '@/components/page-component/goods/bd-xbc.vue';
  172. import bdKb from '@/components/page-component/goods/bd-kb.vue';
  173. import bdHc from '@/components/page-component/goods/bd-hc.vue';
  174. import bdDetail from '@/components/page-component/goods/bd-detail.vue';
  175. import bdComments from '@/components/page-component/goods/bd-comments.vue';
  176. import appClose from '@/components/basic-component/app-close/app-close.vue';
  177. import bdService from '@/components/page-component/goods/bd-service.vue';
  178. export default {
  179. name: 'goods',
  180. data() {
  181. return {
  182. showClose: false,
  183. is_open: 0,
  184. goods_id: -1,
  185. full_reduce: null,
  186. activity: {},
  187. activity_status: 0,
  188. time_str: {
  189. day: 0,
  190. hou: 0,
  191. min: 0,
  192. sec: 0
  193. },
  194. timing: null,
  195. discount: null,
  196. is_vip: false,
  197. is_vip_card_user: 0,
  198. shareData: null,
  199. poster_config: this.$api.flash_sale.poster_config,
  200. poster_generate: this.$api.flash_sale.poster_generate,
  201. selectAttr: {},
  202. url: '',
  203. webUrl: '',
  204. show: false,
  205. list: [],
  206. miaosha_buy_count: 0,
  207. is_activity: 0,
  208. loading: false,
  209. is_show_buy: true,
  210. share: false,
  211. goods: null,
  212. disable: 'disable'
  213. }
  214. },
  215. onLoad(options) { this.$commonLoad.onload(options);
  216. this.goods_id = options.id;
  217. this.webUrl = '/plugins/flash_sale/goods/goods?id=' + options.id;
  218. this.share = options.share;
  219. // #ifdef MP-WEIXIN
  220. wx.showShareMenu({
  221. menus: ['shareAppMessage', 'shareTimeline']
  222. })
  223. // #endif
  224. },
  225. onHide() {
  226. clearInterval(this.timing);
  227. },
  228. onUnload() {
  229. clearInterval(this.timing);
  230. },
  231. onShow() {
  232. this.showClose = false;
  233. setTimeout(()=>{
  234. this.showClose = true;
  235. })
  236. },
  237. computed: {
  238. ...mapGetters('mallConfig', {
  239. getTheme: 'getTheme'
  240. }),
  241. },
  242. // #ifdef MP-WEIXIN
  243. onShareTimeline() {
  244. let { app_share_title, name, id } = this.goods;
  245. return this.$shareTimeline({
  246. title: app_share_title ? app_share_title : name,
  247. query: {
  248. id,
  249. share: true
  250. }
  251. });
  252. },
  253. // #endif
  254. // #ifdef MP
  255. onShareAppMessage() {
  256. return this.hShareAppMessage();
  257. },
  258. // #endif
  259. methods: {
  260. hShareAppMessage(s = false){
  261. let { app_share_title, name, app_share_pic, id, pic_url, subtitle} = this.goods;
  262. return this.$shareAppMessage({
  263. path: '/plugins/flash_sale/goods/goods',
  264. title: app_share_title ? app_share_title : name,
  265. imageUrl: app_share_pic ? app_share_pic : pic_url[0].pic_url,
  266. desc: subtitle,
  267. params: {
  268. id,
  269. share: true
  270. }
  271. },s);
  272. },
  273. getMall(e) {
  274. this.is_open = e.is_open;
  275. },
  276. async getDetail() {
  277. this.loading = false;
  278. const e = await this.$request({
  279. url: this.$api.flash_sale.detail,
  280. data: {
  281. id: this.goods_id
  282. }
  283. });
  284. if (e.code === 0) {
  285. this.loading = true;
  286. let { detail, activity, activity_status } = e.data;
  287. this.goods = detail;
  288. this.activity = activity;
  289. if (detail.goods_activity) {
  290. this.full_reduce = detail.goods_activity.full_reduce;
  291. }
  292. this.activity_status = activity_status;
  293. if(detail.vip_card_appoint.discount) {
  294. this.is_vip = true;
  295. this.discount = detail.vip_card_appoint.discount;
  296. }
  297. this.is_vip_card_user = detail.vip_card_appoint.is_vip_card_user;
  298. if (activity_status === 1) {
  299. this.set_time(activity.end_at);
  300. } else if (activity_status === 0) {
  301. this.set_time(activity.start_at);
  302. this.is_show_buy = false;
  303. }
  304. // #ifdef H5
  305. this.hShareAppMessage();
  306. // #endif
  307. } else {
  308. uni.showToast({
  309. title: e.msg,
  310. icon: 'none'
  311. });
  312. if (!this.share) {
  313. uni.navigateBack();
  314. } else {
  315. uni.navigateTo({
  316. url: `/plugins/flash_sale/index/index`
  317. })
  318. }
  319. }
  320. },
  321. set_time(time_at) {
  322. clearInterval(this.timing);
  323. let time_str = new Date(time_at.replace(/-/g, '/'));
  324. this.now_time(time_str);
  325. this.timing = setInterval(() => {
  326. this.now_time(time_str);
  327. }, 1000);
  328. },
  329. now_time(time_str) {
  330. let time = time_str.getTime() - new Date().getTime();
  331. if (time < 0) {
  332. clearInterval(this.timing);
  333. }
  334. let day = parseInt(time/1000/60/60/24);
  335. let hou = parseInt((time/1000/60/60)%24);
  336. let min = parseInt((time/1000/60)%60);
  337. let sec = parseInt((time/1000)%60);
  338. this.time_str.day = day < 10 ? '0' + day : day;
  339. this.time_str.hou = hou < 10 ? '0' + hou : hou;
  340. this.time_str.min = min < 10 ? '0' + min : min;
  341. this.time_str.sec = sec < 10 ? '0' + sec : sec;
  342. },
  343. quickShare(info) {
  344. this.shareData = info;
  345. },
  346. async request({ url, data }) {
  347. const response = await this.$request({
  348. url: url,
  349. data: data,
  350. });
  351. if (response.code === 0) {
  352. return response.data;
  353. }
  354. },
  355. onAttr({item}) {
  356. this.selectAttr = item;
  357. },
  358. joinCart() {
  359. if (!this.goods.buy_goods_auth) {
  360. this.$tips.showToast({
  361. title: '您暂无权限购买该商品',
  362. icon: 'none'
  363. });
  364. return;
  365. }
  366. this.show = true;
  367. },
  368. leftFunc: function (number) {
  369. this.$request({
  370. url: this.$api.flash_sale.add_cart,
  371. data: {
  372. flash_goods_id: this.selectAttr.goods_id,
  373. attr_id: this.selectAttr.id,
  374. num: number
  375. },
  376. method: 'post'
  377. }).then(e => {
  378. uni.showToast({
  379. title: e.msg,
  380. type: 'success'
  381. });
  382. });
  383. },
  384. rightFunc(data) {
  385. uni.navigateTo({
  386. url: `/pages/order-submit/order-submit?mch_list=${JSON.stringify([data])}`
  387. })
  388. },
  389. setCoupon(index) {
  390. this.$set(this.goods.goods_coupon_center[index], 'is_receive', 1);
  391. },
  392. back() {
  393. uni.redirectTo({
  394. url: '/pages/index/index'
  395. });
  396. }
  397. },
  398. watch: {
  399. goods_id: {
  400. handler() {
  401. this.getDetail();
  402. }
  403. }
  404. },
  405. filters: {
  406. getStart(data) {
  407. if (!data) return;
  408. let time_str = new Date(data.replace(/-/g, '/'));
  409. return `${time_str.getHours() < 10 ? '0'
  410. + time_str.getHours() : time_str.getHours()}:${time_str.getMinutes() < 10 ? '0' +
  411. time_str.getMinutes() : time_str.getMinutes()} 开抢 `;
  412. },
  413. getStartT(data) {
  414. if (!data) return;
  415. let time_str = new Date(data.replace(/-/g, '/'));
  416. return `${time_str.getFullYear()}.${time_str.getMonth() + 1}.${time_str.getDate()}`
  417. }
  418. },
  419. components: {
  420. 'app-banner': appBanner,
  421. 'app-related-suggestion-product': appRelatedSuggestionProduct,
  422. appGoodsFullReduce,
  423. uAttr,
  424. bdInfo,
  425. bdCoupon,
  426. bdXbc,
  427. bdKb,
  428. bdHc,
  429. bdDetail,
  430. bdComments,
  431. appClose,
  432. bdService
  433. }
  434. }
  435. </script>
  436. <style scoped lang="scss">
  437. @import './goods.scss';
  438. .u-coupon {
  439. margin-top: 20upx;
  440. }
  441. .u-bottom-fixed {
  442. position: fixed;
  443. bottom: 0;
  444. left: 0;
  445. width: 100%;
  446. z-index: 1500;
  447. background-color: #ffffff;
  448. }
  449. .u-bottom-height {
  450. height: 110upx;
  451. }
  452. .u-bottom-height-0 {
  453. height: 110upx;
  454. }
  455. .u-bottom-height-1 {
  456. height: 190upx;
  457. }
  458. .bd-bottom {
  459. height: 110upx;
  460. width: 750upx;
  461. padding: 20upx 24upx;
  462. }
  463. .bd-back {
  464. width: 66upx;
  465. height: 100%;
  466. margin-right: 20upx;
  467. font-size: 20upx;
  468. color: #888888;
  469. }
  470. .bd-btn-half {
  471. width: 50%;
  472. }
  473. .bd-icon {
  474. width: 30upx;
  475. height: 30upx;
  476. margin-bottom: 8upx;
  477. }
  478. .bd-button {
  479. text-align: center;
  480. line-height: 70upx;
  481. font-size: 28upx;
  482. border-radius: 35upx;
  483. }
  484. .bd-btn-left {
  485. border-top-right-radius: 0;
  486. border-bottom-right-radius: 0;
  487. }
  488. .bd-btn-right {
  489. border-top-left-radius: 0;
  490. border-bottom-left-radius: 0;
  491. color: #ffffff;
  492. }
  493. .bd-oversell-btn {
  494. background-color: #CDCDCD;
  495. color: #ffffff;
  496. }
  497. </style>