小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

629 lines
20 KiB

  1. <template>
  2. <view class="bargain on">
  3. <!-- 在header上加 on 为请求支援 -->
  4. <!-- 当前登录的用户和url上携带的用户id不一致视为被邀请砍价 -->
  5. <view class="wrapper bargain-box on user" v-if="bargainUserInfo && bargainUid != userInfo.uid">
  6. <!-- <view class="people">
  7. {{ bargainShare.lookCount }}人查看 {{ bargainShare.shareCount }}人分享 {{ bargainShare.userCount }}人参与
  8. </view> -->
  9. <!-- 帮助砍价帮砍成功-->
  10. <view class="pictxt acea-row row-center-wrapper">
  11. <div class="bargain-header">
  12. <view class="pictrue"><image :src="bargainUserInfo.avatar" /></view>
  13. <view class="text">
  14. {{ bargainUserInfo.nickname }}
  15. <text>邀请您帮忙砍价</text>
  16. </view>
  17. </div>
  18. </view>
  19. </view>
  20. <view class="wrapper bargain-box time on">
  21. <div class="pictxt">
  22. <count-down :isDay="true" :tipText="'倒计时 '" :dayText="' 天 '" :hourText="' 时 '" :minuteText="' 分 '" :secondText="' 秒'" :datatime="goodsDetail.stopTime"></count-down>
  23. </div>
  24. </view>
  25. <view class="wrapper bargain-box bargain-product">
  26. <view class="pictxt acea-row row-between-wrapper" @click="openAlone">
  27. <view class="pictrue">
  28. <image :src="goodsDetail.image" />
  29. <view class="bargain_view">
  30. 查看商品
  31. <view class="iconfont icon-jiantou iconfonts"></view>
  32. </view>
  33. </view>
  34. <view class="text acea-row row-column-around">
  35. <view class="line2" v-text="goodsDetail.title"></view>
  36. <view class="money font-color-red">
  37. 已砍至:
  38. <text class="num" v-text="bargainHelpCount.remainingPrice"></text>
  39. </view>
  40. <view class="acea-row row-middle">
  41. <view class="successNum" v-text="`原价:${goodsDetail.price || 0}`"></view>
  42. <view class="successNum" v-text="`已有${bargainSumCount || 0}人砍价成功`"></view>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 砍价进度条 -->
  47. <view class="cu-progress acea-row row-middle round margin-top">
  48. <view class="acea-row row-middle bg-red" :style="{ width: bargainHelpCount.pricePercent + '%' }"></view>
  49. </view>
  50. <!-- 砍价进度条下的金额 -->
  51. <view class="balance acea-row row-between-wrapper">
  52. <view v-text="`已砍${bargainHelpCount.alreadyPrice || 0}元`"></view>
  53. <view v-if="bargainHelpCount.price === 0">砍价成功</view>
  54. <view v-else v-text="`还剩${bargainHelpCount.price || 0}元`"></view>
  55. </view>
  56. <!-- 砍价成功-->
  57. <!--
  58. surplusPrice 砍价剩余金额为0
  59. bargainUid 砍价人为发起砍价用户
  60. userBargainStatus 砍价状态为
  61. -->
  62. <view class="bargainSuccess" v-if="pay">
  63. <span class="iconfont icon-xiaolian"></span>
  64. 恭喜您砍价成功快去支付吧~
  65. </view>
  66. <!-- 参与砍价按钮 同一人-->
  67. <view v-if="participate" class="bargainBnt" @click="goParticipate">立即发起砍价</view>
  68. <!-- 邀请好友按钮 -->
  69. <view v-if="inviteFriends" class="bargainBnt" @click="goPoster">邀请好友帮砍价</view>
  70. <!-- 帮砍好友砍按钮 -->
  71. <view v-if="helpFriendsBargain" class="bargainBnt" @click="getBargainHelp">帮好友砍一刀</view>
  72. <!-- 发起砍价按钮 非同一人-->
  73. <view v-if="bargain" class="bargainBnt" @click="getBargainStart">我也要砍价</view>
  74. <!-- 支付按钮 -->
  75. <view class="bargainBnt" @click="goPay" v-if="pay">立即支付</view>
  76. <view class="bargainBnt on" @click="goList">抢更多商品</view>
  77. <view class="tip">
  78. 已有
  79. <span class="font-color-red" v-text="bargainHelpCount.count"></span>
  80. 位好友成功帮您砍价
  81. </view>
  82. <view class="lock"></view>
  83. </view>
  84. <view class="bargainGang bargain-box">
  85. <view class="title font-color-red acea-row row-center-wrapper">
  86. <view class="pictrue"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  87. <view class="titleCon">砍价帮</view>
  88. <view class="pictrue on"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  89. </view>
  90. <view class="list">
  91. <view class="item acea-row row-between-wrapper" v-for="(item, bargainHelpListIndex) in bargainHelpList" :key="bargainHelpListIndex">
  92. <view class="pictxt acea-row row-between-wrapper">
  93. <view class="pictrue"><image :src="item.avatar" /></view>
  94. <view class="text">
  95. <view class="name line1" v-text="item.nickname"></view>
  96. <view class="line1" v-text="item.add_time"></view>
  97. </view>
  98. </view>
  99. <view class="money font-color-red">
  100. <text class="iconfont icon-kanjia"></text>
  101. 砍掉{{ item.price }}
  102. </view>
  103. </view>
  104. </view>
  105. <view class="load font-color-red" v-if="!helpListStatus" @click="getBargainHelpList">点击加载更多</view>
  106. <view class="lock"></view>
  107. </view>
  108. <view class="goodsDetails bargain-box">
  109. <view class="title font-color-red acea-row row-center-wrapper">
  110. <view class="pictrue"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  111. <view class="titleCon">商品详情</view>
  112. <view class="pictrue on"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  113. </view>
  114. <view class="conter" v-html="goodsDetail.description"></view>
  115. <view class="lock"></view>
  116. </view>
  117. <view class="goodsDetails bargain-box">
  118. <view class="title font-color-red acea-row row-center-wrapper">
  119. <view class="pictrue"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  120. <view class="titleCon">活动规则</view>
  121. <view class="pictrue on"><image :src="`${$VUE_APP_RESOURCES_URL}/images/left.png`" /></view>
  122. </view>
  123. <view class="conter" v-html="goodsDetail.rule"></view>
  124. </view>
  125. <view class="bargainTip" :class="active === true ? 'on' : ''">
  126. <view class="cutOff" v-if="bargainUid === userInfo.uid">
  127. 您已砍掉
  128. <text class="font-color-red" v-text="bargainHelpPrice"></text>
  129. 听说分享次数越多砍价成功的机会越大哦
  130. </view>
  131. <view class="cutOff on" v-else>
  132. <view class="help font-color-red" v-text="'成功帮砍' + bargainHelpPrice + '元'"></view>
  133. 您也可以砍价低价拿哦快去挑选心仪的商品吧~
  134. </view>
  135. <view class="tipBnt" @click="goPoster" v-if="bargainUid === userInfo.uid">邀请好友帮砍价</view>
  136. <view class="tipBnt" @click="getBargainStart" v-else>我也要参与</view>
  137. </view>
  138. <view class="mask" @touchmove.prevent :hidden="active === false" @click="close"></view>
  139. </view>
  140. </template>
  141. <script>
  142. import CountDown from '@/components/CountDown'
  143. import { getBargainDetail, getBargainShare, getBargainStart, getBargainHelp, getBargainHelpPrice, getBargainHelpList, getBargainHelpCount, getBargainStartUser } from '@/api/activity'
  144. import { postCartAdd } from '@/api/store'
  145. import { mapGetters } from 'vuex'
  146. import {} from '@/libs/wechat'
  147. import { isWeixin, parseQuery, handleQrCode } from '@/utils/index'
  148. const NAME = 'DargainDetails'
  149. export default {
  150. name: 'DargainDetails',
  151. components: {
  152. CountDown,
  153. },
  154. props: {},
  155. data: function () {
  156. return {
  157. bargainId: 0, //砍价编号
  158. bargainSumCount: 0, //砍价成功人数
  159. activeMsg: '',
  160. active: false,
  161. bargainHelpPrice: 0, //砍掉金额
  162. bargainHelpList: [],
  163. helpListStatus: false, //砍价列表是否获取完成 false 未完成 true 完成
  164. page: 1, //页码
  165. limit: 2, //数量
  166. pricePercent: 0, //砍价进度条
  167. bargainShare: {}, // 砍价分享的消息
  168. bargainHelpCount: {}, // 砍价的信息数据
  169. goodsDetail: {}, // 商品的详情
  170. bargainUserInfo: [], // 开启砍价用户信息
  171. bargainUid: 0, // 参与砍价的用户
  172. pay: false, // 支付
  173. bargain: false, // 发起砍价
  174. participate: false, // 参与砍价
  175. inviteFriends: false, // 邀请好友
  176. helpFriendsBargain: false, // 帮好友砍
  177. bargainSuccess: false, // 帮好友砍价成功
  178. mainBargainSuccess: false, // 砍价成功
  179. }
  180. },
  181. computed: mapGetters(['userInfo', 'isLogin']),
  182. mounted: function () {
  183. this.mountedStart()
  184. },
  185. methods: {
  186. // 开始处理砍价逻辑
  187. mountedStart: function () {
  188. var that = this
  189. let url = handleQrCode()
  190. // bargainId 砍价商品id
  191. // bargainUid 发起砍价人
  192. if (url) {
  193. // 通过二维码进来
  194. that.bargainId = url.bargainId
  195. that.bargainUid = url.partake
  196. } else {
  197. // 正常途径进来
  198. that.bargainId = that.$yroute.query.id
  199. that.bargainUid = that.$yroute.query.partake
  200. }
  201. if (this.bargainUid == 0 || !this.bargainUid) {
  202. // url未携带用户uid,填上登录用户uid,跳转
  203. that.bargainUid = that.userInfo.uid
  204. }
  205. // 获取商品详情
  206. that.getBargainDetail()
  207. // 砍价数据统计
  208. that.getBargainShare(0)
  209. if (that.bargainUid !== that.userInfo.uid) {
  210. that.getBargainStartUser()
  211. }
  212. },
  213. // 发起砍价
  214. goParticipate() {
  215. //发起人和当前用户为同一人
  216. if (this.bargainUid === this.userInfo.uid) {
  217. // 变更为当前用户砍价页面
  218. this.getBargainStart()
  219. } else {
  220. // 发起人与当前用户非同一人,变更为发起人的砍价页面
  221. this.getBargainStartUser()
  222. }
  223. this.getBargainHelpCount()
  224. },
  225. // 查看商品
  226. openAlone: function () {
  227. this.$yrouter.push({
  228. path: '/pages/shop/GoodsCon/index',
  229. query: {
  230. id: this.goodsDetail.productId,
  231. },
  232. })
  233. },
  234. // 砍价完成,去支付
  235. goPay: function () {
  236. var data = {}
  237. var that = this
  238. data.productId = that.goodsDetail.productId
  239. data.cartNum = that.goodsDetail.num
  240. data.uniqueId = ''
  241. data.bargainId = that.bargainId
  242. data.new = 1
  243. postCartAdd(data)
  244. .then(res => {
  245. that.$yrouter.push({
  246. path: '/pages/order/OrderSubmission/index',
  247. query: {
  248. id: res.data.cartId,
  249. },
  250. })
  251. })
  252. .catch(err => {
  253. uni.showToast({
  254. title: err.msg || err.response.data.msg || err.response.data.message,
  255. icon: 'none',
  256. duration: 2000,
  257. })
  258. })
  259. },
  260. // 生成海报
  261. goPoster: function () {
  262. var that = this
  263. that.getBargainShare(that.bargainId)
  264. this.$yrouter.push({
  265. path: '/pages/activity/Poster/index',
  266. query: {
  267. id: that.bargainId,
  268. type: 2,
  269. },
  270. })
  271. },
  272. // 跳转砍价商品列表
  273. goList: function () {
  274. this.$yrouter.push({
  275. path: '/pages/activity/GoodsBargain/index',
  276. })
  277. },
  278. //砍价分享
  279. //bargainId 0 获取 查看人数 分享人数 参与人数
  280. //bargainId 砍价产品编号 添加分享次数 获取 查看人数 分享人数 参与人数
  281. getBargainShare: function (bargainId) {
  282. var that = this
  283. getBargainShare({
  284. bargainId: bargainId,
  285. }).then(res => {
  286. that.bargainShare = res.data
  287. })
  288. },
  289. // 获取产品详情
  290. getBargainDetail: function () {
  291. var that = this
  292. uni.showLoading({
  293. title: '加载中',
  294. mask: true,
  295. })
  296. getBargainDetail(that.bargainId)
  297. .then(res => {
  298. uni.hideLoading()
  299. that.goodsDetail = res.data.bargain
  300. console.log(that.goodsDetail)
  301. that.goodsDetail.description = that.goodsDetail.description.replace(/\<img/gi, '<img style="max-width:100%;height:auto;"')
  302. that.goodsDetail.rule = that.goodsDetail.rule.replace(/\<img/gi, '<img style="max-width:100%;height:auto;"')
  303. that.getBargainHelpCount()
  304. })
  305. .catch(res => {
  306. uni.hideLoading()
  307. uni.showToast({
  308. title: res.msg,
  309. icon: 'none',
  310. duration: 2000,
  311. })
  312. })
  313. },
  314. // 开启砍价-发起人与当前用户非同一人
  315. getBargainStart: function () {
  316. var that = this
  317. getBargainStart({
  318. bargainId: that.bargainId,
  319. })
  320. .then(() => {
  321. that.bargainUid = that.userInfo.uid
  322. that.getBargainHelp()
  323. that.getBargainHelpCount()
  324. })
  325. .catch(res => {
  326. uni.showToast({
  327. title: res.msg,
  328. icon: 'none',
  329. duration: 2000,
  330. })
  331. })
  332. },
  333. // 参与砍价
  334. getBargainHelp: function () {
  335. var that = this
  336. if (this.bargainHelpCount.price === 0 && that.bargainUid !== that.userInfo.uid) {
  337. return uni.showToast({
  338. title: '好友已经砍价成功',
  339. icon: 'success',
  340. duration: 2000,
  341. })
  342. }
  343. var data = {
  344. bargainId: that.bargainId,
  345. bargainUserUid: that.bargainUid,
  346. }
  347. getBargainHelp(data)
  348. .then(res => {
  349. that.activeMsg = res.data.status
  350. if (res.data.status === 'SUCCESSFUL' && that.bargainUid !== that.userInfo.uid) {
  351. uni.showToast({
  352. title: '您已经砍过了',
  353. icon: 'none',
  354. duration: 2000,
  355. })
  356. return
  357. }
  358. that.helpListStatus = false
  359. that.page = 1
  360. that.bargainHelpList = []
  361. that.getBargainHelpPrice()
  362. })
  363. .catch(res => {
  364. uni.showToast({
  365. title: res.msg,
  366. icon: 'none',
  367. duration: 2000,
  368. })
  369. })
  370. },
  371. //获取砍掉的金额
  372. getBargainHelpPrice: function () {
  373. var that = this
  374. getBargainHelpPrice({
  375. bargainId: that.bargainId,
  376. bargainUserUid: that.bargainUid,
  377. })
  378. .then(res => {
  379. that.bargainHelpPrice = res.data.price
  380. that.getBargainHelpCount()
  381. that.getBargainHelpList()
  382. switch (that.activeMsg) {
  383. case 'SUCCESSFUL':
  384. break
  385. case 'SUCCESS':
  386. that.active = true
  387. break
  388. }
  389. })
  390. .catch(res => {
  391. uni.showToast({
  392. title: res.msg,
  393. icon: 'none',
  394. duration: 2000,
  395. })
  396. })
  397. },
  398. // 砍价帮助列表
  399. getBargainHelpList: function () {
  400. var that = this
  401. if (that.helpListStatus === true) return
  402. getBargainHelpList({
  403. bargainId: that.bargainId,
  404. bargainUserUid: that.bargainUid,
  405. page: that.page,
  406. limit: that.limit,
  407. })
  408. .then(res => {
  409. that.helpListStatus = res.data.length < that.limit
  410. if (that.page == 1) {
  411. that.bargainHelpList = []
  412. }
  413. that.page++
  414. if (res.data) {
  415. that.bargainHelpList.push.apply(that.bargainHelpList, res.data)
  416. }
  417. })
  418. .catch(err => {
  419. if (!err.msg) {
  420. return
  421. }
  422. uni.showToast({
  423. title: err.msg || err.response.data.msg || err.response.data.message,
  424. icon: 'none',
  425. duration: 2000,
  426. })
  427. })
  428. },
  429. // 砍价 砍价帮总人数、剩余金额、进度条、已经砍掉的价格
  430. getBargainHelpCount: function () {
  431. getBargainHelpCount({
  432. bargainId: this.bargainId,
  433. bargainUserUid: this.bargainUid,
  434. })
  435. .then(res => {
  436. // 剩余砍价金额,显示已砍至¥** 使用 = 商品价格 - 已经砍掉的金额
  437. let remainingPrice = (this.goodsDetail.price - res.data.alreadyPrice).toFixed(2)
  438. this.bargainHelpCount = {
  439. ...res.data,
  440. remainingPrice,
  441. }
  442. this.handleButtonStatus()
  443. })
  444. .catch(err => {
  445. if (!err.msg) {
  446. return
  447. }
  448. uni.showToast({
  449. title: err.msg || err.response.data.msg || err.response.data.message,
  450. icon: 'none',
  451. duration: 2000,
  452. })
  453. })
  454. },
  455. // 判断是否可以支付
  456. handleButtonStatus() {
  457. // 砍价按钮分为
  458. // 1.参与砍价 ==> 发起人与当前用户为同一人 && 未参与
  459. if (this.bargainUid === this.userInfo.uid && this.bargainHelpCount.status == 0) {
  460. this.participate = true
  461. } else {
  462. this.participate = false
  463. }
  464. // 2.邀请好友 ==> 发起人与当前用户同一人 && 已参与未过期 && 剩余金额>0
  465. if (this.bargainUid === this.userInfo.uid && this.bargainHelpCount.status == 1 && this.bargainHelpCount.price > 0) {
  466. this.inviteFriends = true
  467. } else {
  468. this.inviteFriends = false
  469. }
  470. // 3.帮好友砍价 ==> 发起人与当前用户非一人 && 未参与未过期 && 剩余金额>0 && 为砍价
  471. if (
  472. this.bargainUid != this.userInfo.uid &&
  473. this.bargainHelpCount.status == 1 &&
  474. // this.bargainHelpCount.userBargainStatus &&
  475. this.bargainHelpCount.price > 0
  476. ) {
  477. this.helpFriendsBargain = true
  478. } else {
  479. this.helpFriendsBargain = false
  480. }
  481. // 4.支付 ==> 发起人与当前用户同一人 && 已参与未过期 && 剩余金额<=0
  482. if (this.bargainUid === this.userInfo.uid && this.bargainHelpCount.status == 1 && this.bargainHelpCount.price <= 0) {
  483. this.pay = true
  484. } else {
  485. this.pay = false
  486. }
  487. // 5.砍价人发起新的砍价 ==> 发起人与当前用户非一人 && 未参与
  488. if (this.bargainUid != this.userInfo.uid) {
  489. this.bargain = true
  490. } else {
  491. this.bargain = false
  492. }
  493. // 砍价弹窗
  494. // 1.发起人砍价成功 ==> 发起人与当前用户同一人 && 已参与未过期
  495. // 2.砍价人砍价成功 ==> 发起人与当前用户非一人 && 已参与未过期
  496. // 3.已砍价 ==> 已参与 && 砍价状态为 true
  497. },
  498. // 获取开启砍价用户信息
  499. // 参与砍价,为同一人发起砍价后
  500. getBargainStartUser: function () {
  501. var that = this
  502. getBargainStartUser({
  503. bargainId: that.bargainId,
  504. bargainUserUid: that.bargainUid,
  505. })
  506. .then(res => {
  507. that.bargainUserInfo = res.data
  508. that.getBargainHelpList()
  509. })
  510. .catch(res => {
  511. uni.showToast({
  512. title: res.msg,
  513. icon: 'none',
  514. duration: 2000,
  515. })
  516. })
  517. },
  518. // 关闭弹窗
  519. close: function () {
  520. this.active = false
  521. },
  522. // 设置微信分享
  523. onShareAppMessage: function () {
  524. return {
  525. title: this.storeInfo.title,
  526. imageUrl: this.storeInfo.image,
  527. path: 'pages/activity/DargainDetails/index?id=' + this.storeInfo.id + '&spread=' + uni.getStorageSync('uid'),
  528. success(res) {
  529. uni.showToast({
  530. title: '分享成功',
  531. })
  532. },
  533. fail(res) {
  534. uni.showToast({
  535. title: '分享失败',
  536. icon: 'none',
  537. })
  538. },
  539. }
  540. },
  541. },
  542. onShareAppMessage() {
  543. return {
  544. path: `/pages/activity/DargainDetails/index/?id=${this.$yroute.query.id}&partake=${this.userInfo.uid}`,
  545. }
  546. },
  547. }
  548. </script>
  549. <style lang="less">
  550. .bargain {
  551. &.on {
  552. .bargain-box {
  553. background: #fff;
  554. width: auto;
  555. margin: 0 20rpx;
  556. border: 0;
  557. }
  558. .header {
  559. height: auto;
  560. text-align: left;
  561. .time {
  562. text-align: left;
  563. font-size: 24rpx;
  564. margin: 0;
  565. padding: 0;
  566. padding: 20rpx;
  567. width: auto;
  568. height: auto;
  569. }
  570. }
  571. }
  572. }
  573. page {
  574. background-color: #f5f5f5 !important;
  575. }
  576. .bargainBnt_hui {
  577. font-size: 0.3 * 100rpx;
  578. font-weight: bold;
  579. color: #fff;
  580. width: 6 * 100rpx;
  581. height: 0.8 * 100rpx;
  582. border-radius: 0.4 * 100rpx;
  583. background: #bbb;
  584. text-align: center;
  585. line-height: 0.8 * 100rpx;
  586. margin-top: 0.32 * 100rpx;
  587. }
  588. .bargain_view {
  589. left: 0;
  590. right: 0;
  591. height: 0.48 * 100rpx;
  592. background: rgba(0, 0, 0, 0.5);
  593. opacity: 1;
  594. border-radius: 0 0 0.06 * 100rpx 0.06 * 100rpx;
  595. position: absolute;
  596. bottom: 0;
  597. font-size: 0.22 * 100rpx;
  598. color: #fff;
  599. text-align: center;
  600. line-height: 0.48 * 100rpx;
  601. }
  602. .iconfonts {
  603. font-size: 0.22 * 100rpx;
  604. }
  605. </style>