fight-share-entry.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="fight-share-entry">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <view class="row">
  5. <!-- 商品信息 -->
  6. <cm-order-prodcut
  7. :countVisible="false"
  8. :goodsData="collageData"
  9. :normal="true"
  10. :tagsList="tagsList"
  11. ></cm-order-prodcut>
  12. <view class="service">
  13. <view class="iconfont icon-wuyoushouhou"><text>无忧退货</text></view>
  14. <view class="iconfont icon-wuyoushouhou"><text>快速退款</text></view>
  15. <view class="iconfont icon-wuyoushouhou"><text>正品保证</text></view>
  16. </view>
  17. <view class="grid t0b48"></view>
  18. <view class="fight-tip">还差<text>1</text>人,赶快邀请好友来拼单吧!</view>
  19. <!-- 倒计时 -->
  20. <countdown-box :countDownTime="countDownTime"></countdown-box>
  21. <!-- 操作 -->
  22. <view class="fight-control"> <button class="btn type1" @click="handleClick">立即参团</button> </view>
  23. <view class="grid t48b48"></view>
  24. <!-- 拼单用户列表 -->
  25. <user-list></user-list>
  26. <view class="line"></view>
  27. <view class="goods-info">
  28. <image :src="collageData.productImage" class="cover"></image>
  29. <view class="title" v-text="collageData.productName"></view>
  30. </view>
  31. </view>
  32. <!-- 购买数量弹窗 -->
  33. <cm-drawer :visible="countVisible" @close="drawerClose" position="bottom">
  34. <view class="count">
  35. <view class="top">
  36. <image :src="collageData.productImage" class="cover"></image>
  37. <view class="right">
  38. <view class="number">
  39. <text>数量:</text>
  40. <cm-number-box v-model="count" :min="1" :max="2"></cm-number-box>
  41. </view>
  42. <view class="single-price">
  43. <text>单价:¥</text> <text class="price">{{ collageData.price | formatPrice }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="btn" @click="buyGroupNow">确认</view>
  48. </view>
  49. </cm-drawer>
  50. </view>
  51. </template>
  52. <script>
  53. import UserList from './components/user-list.vue'
  54. import CountdownBox from './components/countdown-box.vue'
  55. import CmOrderProdcut from '@/components/cm-module/cm-order-prodcut/cm-order-prodcut.vue'
  56. import CmNumberBox from '@/components/cm-module/cm-number-box/cm-number-box.vue'
  57. import CmDrawer from '@/components/cm-module/cm-drawer/cm-drawer.vue'
  58. import { mapGetters, mapActions } from 'vuex'
  59. export default {
  60. components: {
  61. UserList,
  62. CountdownBox,
  63. CmOrderProdcut,
  64. CmDrawer,
  65. CmNumberBox
  66. },
  67. computed: {
  68. ...mapGetters(['userId', 'hasLogin'])
  69. },
  70. data() {
  71. return {
  72. isRequest: true,
  73. collageId: '',
  74. initiatorId: '',
  75. collageData: {},
  76. // 自定义标签
  77. tagsList: ['2人拼团价'],
  78. // 倒计时
  79. countDownTime: {},
  80. timer: null,
  81. // 商品数量
  82. count: 1,
  83. countVisible: false
  84. }
  85. },
  86. beforeDestroy() {
  87. clearTimeout(this.timer)
  88. },
  89. onShareTimeline(e) {
  90. // 加密参数
  91. const shareData = {
  92. type: 4,
  93. inviteUserId: this.userId
  94. }
  95. // 加密
  96. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  97. return {
  98. title: '哈喽,赶快来参团吧!这件商品拼团买更便宜~~',
  99. path: `pages/tabBar/index/index?state_str=${state_str}`,
  100. imageUrl: 'https://picsum.photos/400/400?random=3'
  101. }
  102. },
  103. onShareAppMessage(e) {
  104. // 加密参数
  105. const shareData = {
  106. type: 4,
  107. inviteUserId: this.userId
  108. }
  109. // 加密
  110. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  111. return {
  112. title: '哈喽,赶快来参团吧!这件商品拼团买更便宜~~',
  113. path: `pages/tabBar/index/index?state_str=${state_str}`,
  114. imageUrl: 'https://picsum.photos/400/400?random=3'
  115. }
  116. },
  117. onLoad(options) {
  118. this.collageId = options.collageId
  119. this.initiatorId = options.initiatorId
  120. setTimeout(()=>{
  121. this.fetchOrderDetails()
  122. }, 2000)
  123. },
  124. onShow() {
  125. !this.isRequest && this.countDown()
  126. },
  127. methods: {
  128. handleClick(type) {
  129. if (!this.hasLogin) {
  130. // 保存当前页面链接参数
  131. uni.setStorageSync(
  132. 'login_redirect_url',
  133. `/pages/fight-order/fight-share-entry?type=share&collageId=${this.collageId}&initiatorId=${
  134. this.initiatorId
  135. }`
  136. )
  137. this.$api.navigateTo('/pages/login/login')
  138. return
  139. }
  140. if (this.userId == this.initiatorId) {
  141. this.$util.msg('您不能参与自己发起的拼团')
  142. return
  143. }
  144. this.countVisible = true
  145. },
  146. // 拼团购买
  147. buyGroupNow() {
  148. console.log('拼团购买')
  149. let productStp = {
  150. allPrice: this.count * this.collageData.price,
  151. allCount: this.count,
  152. productId: this.collageData.productId,
  153. productCount: this.count,
  154. heUserId: this.userId,
  155. collageFlag: 1,
  156. collageId: this.collageId
  157. }
  158. uni.setStorageSync('commitProductInfo', productStp)
  159. this.$api.navigateTo('/pages/order/create-order?type=prodcut')
  160. this.countVisible = false
  161. },
  162. countDown() {
  163. const diffTime = new Date(this.collageData.endTime).getTime()
  164. const loadTime = new Date().getTime()
  165. this.timer && clearTimeout(this.timer)
  166. this.$util.countDown(diffTime, loadTime, {}, item => {
  167. this.countDownTime = item.conttainer
  168. this.timer = item.t
  169. })
  170. },
  171. // 获取拼单详情
  172. fetchOrderDetails() {
  173. this.FightService.OrderCollageDetails({
  174. collageId: this.collageId,
  175. userId: this.userId
  176. }).then(res => {
  177. this.collageData = res.data
  178. // 拼团已完成
  179. if (this.collageData.orderId) {
  180. this.$util.msg('拼团已结束')
  181. setTimeout(() => {
  182. uni.switchTab({ url: '/pages/tabBar/index/index' })
  183. }, 2000)
  184. return
  185. }
  186. // 拼团未完成
  187. this.countDown()
  188. this.isRequest = false
  189. })
  190. },
  191. // 购买数量弹窗关闭
  192. drawerClose() {
  193. this.count = 1
  194. this.countVisible = false
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. /* scss中可以用mixin来扩展 */
  201. @mixin ellipsis($line: 1) {
  202. overflow: hidden;
  203. text-overflow: ellipsis;
  204. display: -webkit-box;
  205. -webkit-line-clamp: $line;
  206. -webkit-box-orient: vertical;
  207. }
  208. .flex-center-box {
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. }
  213. .fight-share-entry {
  214. background: #f7f7f7;
  215. min-height: 100vh;
  216. .row {
  217. padding-top: 48rpx;
  218. background: #fff;
  219. overflow: hidden;
  220. }
  221. .service {
  222. display: flex;
  223. justify-content: space-around;
  224. align-items: center;
  225. color: #ff457b;
  226. width: 750rpx;
  227. height: 72rpx;
  228. padding: 0 24rpx;
  229. margin-top: 64rpx;
  230. background: #fff8fd;
  231. opacity: 1;
  232. box-sizing: border-box;
  233. .iconfont {
  234. font-size: 24rpx;
  235. line-height: 24rpx;
  236. text {
  237. color: #ff457b;
  238. margin-left: 4rpx;
  239. }
  240. }
  241. }
  242. .fight-tip {
  243. @extend .flex-center-box;
  244. margin-top: 48rpx;
  245. margin-bottom: 32rpx;
  246. font-size: 30rpx;
  247. font-weight: 400;
  248. color: #333333;
  249. text {
  250. color: #ff457b;
  251. }
  252. }
  253. .fight-control {
  254. display: flex;
  255. justify-content: center;
  256. align-items: center;
  257. flex-direction: column;
  258. margin-top: 40rpx;
  259. margin-bottom: 48rpx;
  260. .link {
  261. margin-top: 24rpx;
  262. font-size: 26rpx;
  263. line-height: 38rpx;
  264. color: #999999;
  265. }
  266. .btn {
  267. @extend .flex-center-box;
  268. width: 600rpx;
  269. height: 90rpx;
  270. border-radius: 45rpx;
  271. box-sizing: border-box;
  272. font-size: 30rpx;
  273. &.type1 {
  274. color: #ffffff;
  275. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  276. }
  277. &.type2 {
  278. margin-top: 24rpx;
  279. color: #ff457b;
  280. border: 1px solid #ff457b;
  281. }
  282. }
  283. }
  284. .grid {
  285. width: 750rpx;
  286. height: 20rpx;
  287. background: #f7f7f7;
  288. &.t48b48 {
  289. margin-top: 48rpx;
  290. margin-bottom: 48rpx;
  291. }
  292. &.t0b48 {
  293. margin-top: 0;
  294. margin-bottom: 48rpx;
  295. }
  296. }
  297. .line {
  298. width: 702px;
  299. height: 1px;
  300. margin: 32rpx auto 24rpx auto;
  301. background: #e1e1e1;
  302. }
  303. .goods-info {
  304. @extend .flex-center-box;
  305. padding: 0 24rpx 40rpx;
  306. .cover {
  307. width: 80rpx;
  308. height: 80rpx;
  309. background: eee;
  310. border: 1rpx solid #e1e1e1;
  311. border-radius: 8rpx;
  312. border: 50%;
  313. }
  314. .title {
  315. flex: 1;
  316. margin-left: 24rpx;
  317. word-break: break-word;
  318. font-size: 26rpx;
  319. line-height: 1.6;
  320. color: #333333;
  321. text-align: justify;
  322. @include ellipsis(2);
  323. }
  324. }
  325. }
  326. .count {
  327. padding: 60rpx 0;
  328. .top {
  329. display: flex;
  330. justify-content: flex-start;
  331. align-items: center;
  332. padding: 0 60rpx;
  333. .cover {
  334. width: 104rpx;
  335. height: 104rpx;
  336. }
  337. .right {
  338. margin-left: 24rpx;
  339. font-size: 24rpx;
  340. color: #333;
  341. .single-price {
  342. color: #ff457b;
  343. margin-top: 24rpx;
  344. }
  345. .number {
  346. display: flex;
  347. justify-content: flex-start;
  348. align-items: center;
  349. }
  350. }
  351. }
  352. .btn {
  353. width: 100%;
  354. height: 88rpx;
  355. margin-top: 32px;
  356. background: #ff457b;
  357. line-height: 88rpx;
  358. text-align: center;
  359. color: #ffffff;
  360. font-size: 28rpx;
  361. border-radius: 44rpx;
  362. }
  363. }
  364. </style>