fight-share-entry.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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 } 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. methods: {
  125. handleClick(type) {
  126. if (!this.hasLogin) {
  127. // 保存当前页面链接参数
  128. uni.setStorageSync(
  129. 'login_redirect_url',
  130. `/pages/fight-order/fight-share-entry?type=share&collageId=${this.collageId}&initiatorId=${
  131. this.initiatorId
  132. }`
  133. )
  134. this.$api.navigateTo('/pages/login/login')
  135. return
  136. }
  137. if (this.userId == this.initiatorId) {
  138. this.$util.msg('您不能参与自己发起的拼团')
  139. return
  140. }
  141. this.countVisible = true
  142. },
  143. // 拼团购买
  144. buyGroupNow() {
  145. console.log('拼团购买')
  146. let productStp = {
  147. allPrice: this.count * this.collageData.price,
  148. allCount: this.count,
  149. productId: this.collageData.productId,
  150. productCount: this.count,
  151. heUserId: this.userId,
  152. collageFlag: 1,
  153. collageId: this.collageId
  154. }
  155. uni.setStorageSync('commitProductInfo', productStp)
  156. this.$api.navigateTo('/pages/order/create-order?type=prodcut')
  157. this.countVisible = false
  158. },
  159. countDown() {
  160. const diffTime = new Date(this.collageData.endTime).getTime()
  161. const loadTime = new Date().getTime()
  162. this.$util.countDown(diffTime, loadTime, {}, item => {
  163. this.countDownTime = item.conttainer
  164. this.timer = item.t
  165. })
  166. },
  167. // 获取拼单详情
  168. fetchOrderDetails() {
  169. this.FightService.OrderCollageDetails({
  170. collageId: this.collageId,
  171. userId: this.userId
  172. }).then(res => {
  173. this.collageData = res.data
  174. // 拼团已完成
  175. if (this.collageData.orderId) {
  176. this.$util.msg('拼团已结束')
  177. setTimeout(() => {
  178. uni.switchTab({ url: '/pages/tabBar/index/index' })
  179. }, 2000)
  180. return
  181. }
  182. // 拼团未完成
  183. this.countDown()
  184. this.isRequest = false
  185. })
  186. },
  187. // 购买数量弹窗关闭
  188. drawerClose() {
  189. this.count = 1
  190. this.countVisible = false
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. /* scss中可以用mixin来扩展 */
  197. @mixin ellipsis($line: 1) {
  198. overflow: hidden;
  199. text-overflow: ellipsis;
  200. display: -webkit-box;
  201. -webkit-line-clamp: $line;
  202. -webkit-box-orient: vertical;
  203. }
  204. .flex-center-box {
  205. display: flex;
  206. justify-content: center;
  207. align-items: center;
  208. }
  209. .fight-share-entry {
  210. background: #f7f7f7;
  211. min-height: 100vh;
  212. .row {
  213. padding-top: 48rpx;
  214. background: #fff;
  215. overflow: hidden;
  216. }
  217. .service {
  218. display: flex;
  219. justify-content: space-around;
  220. align-items: center;
  221. color: #ff457b;
  222. width: 750rpx;
  223. height: 72rpx;
  224. padding: 0 24rpx;
  225. margin-top: 64rpx;
  226. background: #fff8fd;
  227. opacity: 1;
  228. box-sizing: border-box;
  229. .iconfont {
  230. font-size: 24rpx;
  231. line-height: 24rpx;
  232. text {
  233. color: #ff457b;
  234. margin-left: 4rpx;
  235. }
  236. }
  237. }
  238. .fight-tip {
  239. @extend .flex-center-box;
  240. margin-top: 48rpx;
  241. margin-bottom: 32rpx;
  242. font-size: 30rpx;
  243. font-weight: 400;
  244. color: #333333;
  245. text {
  246. color: #ff457b;
  247. }
  248. }
  249. .fight-control {
  250. display: flex;
  251. justify-content: center;
  252. align-items: center;
  253. flex-direction: column;
  254. margin-top: 40rpx;
  255. margin-bottom: 48rpx;
  256. .link {
  257. margin-top: 24rpx;
  258. font-size: 26rpx;
  259. line-height: 38rpx;
  260. color: #999999;
  261. }
  262. .btn {
  263. @extend .flex-center-box;
  264. width: 600rpx;
  265. height: 90rpx;
  266. border-radius: 45rpx;
  267. box-sizing: border-box;
  268. font-size: 30rpx;
  269. &.type1 {
  270. color: #ffffff;
  271. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  272. }
  273. &.type2 {
  274. margin-top: 24rpx;
  275. color: #ff457b;
  276. border: 1px solid #ff457b;
  277. }
  278. }
  279. }
  280. .grid {
  281. width: 750rpx;
  282. height: 20rpx;
  283. background: #f7f7f7;
  284. &.t48b48 {
  285. margin-top: 48rpx;
  286. margin-bottom: 48rpx;
  287. }
  288. &.t0b48 {
  289. margin-top: 0;
  290. margin-bottom: 48rpx;
  291. }
  292. }
  293. .line {
  294. width: 702px;
  295. height: 1px;
  296. margin: 32rpx auto 24rpx auto;
  297. background: #e1e1e1;
  298. }
  299. .goods-info {
  300. @extend .flex-center-box;
  301. padding: 0 24rpx 40rpx;
  302. .cover {
  303. width: 80rpx;
  304. height: 80rpx;
  305. background: eee;
  306. border: 1rpx solid #e1e1e1;
  307. border-radius: 8rpx;
  308. border: 50%;
  309. }
  310. .title {
  311. flex: 1;
  312. margin-left: 24rpx;
  313. word-break: break-word;
  314. font-size: 26rpx;
  315. line-height: 1.6;
  316. color: #333333;
  317. text-align: justify;
  318. @include ellipsis(2);
  319. }
  320. }
  321. }
  322. .count {
  323. padding: 60rpx 0;
  324. .top {
  325. display: flex;
  326. justify-content: flex-start;
  327. align-items: center;
  328. padding: 0 60rpx;
  329. .cover {
  330. width: 104rpx;
  331. height: 104rpx;
  332. }
  333. .right {
  334. margin-left: 24rpx;
  335. font-size: 24rpx;
  336. color: #333;
  337. .single-price {
  338. color: #ff457b;
  339. margin-top: 24rpx;
  340. }
  341. .number {
  342. display: flex;
  343. justify-content: flex-start;
  344. align-items: center;
  345. }
  346. }
  347. }
  348. .btn {
  349. width: 100%;
  350. height: 88rpx;
  351. margin-top: 32px;
  352. background: #ff457b;
  353. line-height: 88rpx;
  354. text-align: center;
  355. color: #ffffff;
  356. font-size: 28rpx;
  357. border-radius: 44rpx;
  358. }
  359. }
  360. </style>