fight-share-entry.vue 13 KB

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