haggle.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view class="haggle" v-if="!loadding">
  3. <view class="goto-home d-c-c" @click="gotoHome"><text class="iconfont icon-Homehomepagemenu"></text></view>
  4. <view class="haggle-content">
  5. <view class="rule red" @click="openRule">活动规则</view>
  6. <!--用户信息-->
  7. <view class="user d-c-c d-c">
  8. <image :src="task.user.avatarUrl" mode="widthFix"></image>
  9. <text class="gray6">{{ task.user.nickName }}</text>
  10. </view>
  11. <view class="tip p-20-0 d-c-c f30">“拿好物好朋友帮,快去邀请吧”</view>
  12. <!--商品信息-->
  13. <view class="product d-s-c p20">
  14. <view class="pic"><image :src="product.product.image[0].file_path" mode=""></image></view>
  15. <view class="info flex-1 ml30">
  16. <view class="text-ellipsis-2 f28">{{ task.product_name }}</view>
  17. <view>
  18. <text class="gray9">规格:</text>
  19. <text>{{ task.product_attr?task.product_attr:'无' }}</text>
  20. </view>
  21. <view class="">
  22. <text class="gray9">砍到底价:</text>
  23. <text class="red">¥{{ task.bargain_price }}</text>
  24. <text class="ml10 text-l-t gray9">¥{{ task.product_price }}</text>
  25. </view>
  26. <view class="">
  27. <text class="gray9">剩余:</text>
  28. <text>{{ product.stock }}</text>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="title-2 d-c-c p-30-0 f26" v-if="is_bargain">
  33. <text class="pr">
  34. {{is_creater?'先砍一刀试试运气':'帮好友砍一刀'}}</text>
  35. </view>
  36. <!--砍价进度-->
  37. <view class="progress pr">
  38. <view class="progress-box"><view class="progress-box-active" :style="'width:' + task.bargain_rate + '%;'"></view></view>
  39. <view class="progressState" :style="'left:' + task.bargain_rate + '%;'">已砍¥{{ task.cut_money }}</view>
  40. </view>
  41. <view class="d-b-c gray9">
  42. <text>¥{{ task.product_price }}</text>
  43. <text class="f30 red fb">¥{{ task.bargain_price }}</text>
  44. </view>
  45. <!--活动剩余时间-->
  46. <view class="ad-datetime p-30-0 d-c-c" v-if="task.status==0">
  47. <Countdown :config="countdownConfig"></Countdown>
  48. </view>
  49. <!--按钮-->
  50. <view class="btns mt30" v-if="task.status == 0||task.status == 1">
  51. <template v-if="is_bargain">
  52. <button type="primary" :disabled="submitting" @click="bargainFunc">
  53. {{is_creater?'我要砍价':'帮好友砍一刀'}}
  54. </button>
  55. </template>
  56. <template v-if="!is_bargain && task.is_floor != 1 && task.is_buy!=1">
  57. <button type="primary" open-type="share" @click="shareFunc">邀请好友帮忙砍价</button>
  58. </template>
  59. <template v-if="is_creater === true">
  60. <button type="primary" v-if="is_buy && active.conditions == 0" class="mt20" @click="buyNow">
  61. <template v-if="task.is_floor == 0">当前价购买</template>
  62. <template v-if="task.is_floor == 1">砍价成功 立即购买</template>
  63. </button>
  64. <button type="primary" v-if="is_buy && active.conditions == 1" class="mt20" @click="buyNow">砍价成功 立即购买</button>
  65. <view class="mt20 f34 red tc" v-if="task.is_buy==1">砍价成功,已购买</view>
  66. </template>
  67. <template v-if="is_creater == false">
  68. <button type="primary" class="buy-btn mt20" @click="involvedFunc">我要参与</button>
  69. </template>
  70. </view>
  71. <!--砍价历史-->
  72. <view class="help-list mt30">
  73. <view class="p-30-0 border-b fb f30">砍价记录</view>
  74. <view class="d-b-c p-20-0 border-b-e" v-for="(item, index) in help_list" :key="index">
  75. <view class="user d-s-c">
  76. <image :src="item.user.avatarUrl" mode="aspectFill"></image>
  77. <text class="ml20">{{ item.user.nickName }}</text>
  78. </view>
  79. <view class="red" :class="{ fb: item.is_creater == 0 }">-{{ item.cut_money }}</view>
  80. </view>
  81. </view>
  82. </view>
  83. <!--规则-->
  84. <Rule :isRule="isRule" :setting="setting" @close="closeRule"></Rule>
  85. <!--分享-->
  86. <share :isshare="isshare" @close="closeShare"></share>
  87. <!--app分享-->
  88. <AppShare :isAppShare="isAppShare" :appParams="appParams" @close="closeAppShare"></AppShare>
  89. <!--弹出框-->
  90. <Popup :show="isPopup" :width="400" :height="300" :padding="0" @hidePopup="hidePopupFunc">
  91. <view class="d-c-c d-c ww100 p-30-0">
  92. <text>本次砍掉</text>
  93. <view class="pt10">
  94. <text class="fb f34 red">{{ my_cut_money }}</text>
  95. </view>
  96. <view class="pt30"><button type="primary" class="btn-gray" @click="hidePopupFunc">关闭</button></view>
  97. </view>
  98. </Popup>
  99. </view>
  100. </template>
  101. <script>
  102. import Popup from '@/components/uni-popup.vue';
  103. import countdown from '@/components/countdown/countdown.vue';
  104. import Rule from './popup/Rule.vue';
  105. import share from './popup/share.vue';
  106. import AppShare from '@/components/app-share.vue';
  107. export default {
  108. components: {
  109. Popup,
  110. Rule,
  111. countdown,
  112. share,
  113. AppShare
  114. },
  115. data() {
  116. return {
  117. /*是否加载完成*/
  118. loadding: true,
  119. /*砍价任务ID*/
  120. bargain_task_id: 0,
  121. /*是否显示规则*/
  122. isRule: false,
  123. /*倒计时配置*/
  124. countdownConfig: {
  125. /*开始时间*/
  126. startstamp: 0,
  127. /*结束时间*/
  128. endstamp: 0,
  129. /*显示类别*/
  130. type: 'text',
  131. /*文字*/
  132. title: '剩余:'
  133. },
  134. /*任务对象*/
  135. task: {},
  136. /*商品对象*/
  137. product: {},
  138. /*活动*/
  139. active: {},
  140. /*活动设置*/
  141. setting: {},
  142. /*砍价历史*/
  143. help_list: [],
  144. /*是否分享*/
  145. isshare: false,
  146. /*是否是自己的*/
  147. is_creater: false,
  148. /*是否已经砍过*/
  149. is_cut: false,
  150. /*是否正在提交*/
  151. submitting: false,
  152. /*是否显示弹出框*/
  153. isPopup: false,
  154. /*我的砍价*/
  155. my_cut_money: 0,
  156. /*app分享*/
  157. isAppShare: false,
  158. appParams: {
  159. title: '',
  160. summary: '',
  161. path: ''
  162. },
  163. url: ''
  164. };
  165. },
  166. onLoad(e) {
  167. this.bargain_task_id = e.bargain_task_id;
  168. //#ifdef H5
  169. this.url = window.location.href;
  170. //#endif
  171. },
  172. mounted() {
  173. },
  174. onShow() {
  175. this.submitting=false;
  176. /*获取产品详情*/
  177. this.getData();
  178. },
  179. computed: {
  180. /*是否允许砍价*/
  181. is_bargain: function() {
  182. if (this.is_cut == false) {
  183. return true;
  184. } else {
  185. return false;
  186. }
  187. },
  188. /*是否允许购买、砍价过程中可购买或者砍到底价,并且砍价成功可购买*/
  189. is_buy: function() {
  190. if (this.active.conditions === 0 && this.task.is_buy!=1) {
  191. return true;
  192. }else if (this.active.conditions === 1 && this.task.is_floor == 1 && this.task.is_buy!=1) {
  193. return true;
  194. } else {
  195. return false;
  196. }
  197. }
  198. },
  199. methods: {
  200. /*获取数据*/
  201. getData() {
  202. let self = this;
  203. self.loading = true;
  204. uni.showLoading({
  205. title: '加载中'
  206. });
  207. self._get(
  208. 'plus.bargain.task/detail',
  209. {
  210. bargain_task_id: self.bargain_task_id,
  211. url: self.url
  212. },
  213. function(res) {
  214. self.countdownConfig.startstamp = res.data.active.start_time;
  215. self.countdownConfig.endstamp = res.data.task.end_time;
  216. self.is_creater = res.data.is_creater;
  217. self.is_cut = res.data.is_cut;
  218. self.task = res.data.task;
  219. self.active = res.data.active;
  220. self.product = res.data.product;
  221. self.setting = res.data.setting;
  222. self.help_list = res.data.help_list;
  223. // 配置微信分享参数
  224. //#ifdef H5
  225. if (self.url != '') {
  226. let params = {
  227. bargain_task_id: self.bargain_task_id
  228. };
  229. self.configWx(res.data.share.signPackage, res.data.share.shareParams, params);
  230. }
  231. //#endif
  232. self.loadding = false;
  233. uni.hideLoading();
  234. }
  235. );
  236. },
  237. /*我要砍价*/
  238. bargainFunc() {
  239. let self = this;
  240. self.submitting = true;
  241. self._post(
  242. 'plus.bargain.task/cut',
  243. {
  244. bargain_task_id: self.bargain_task_id
  245. },
  246. function(res) {
  247. self.my_cut_money = res.data.cut_money;
  248. self.isPopup = true;
  249. }
  250. );
  251. },
  252. /*关闭弹出框*/
  253. hidePopupFunc() {
  254. this.isPopup = false;
  255. this.getData();
  256. this.submitting = false;
  257. },
  258. /*确认提交*/
  259. buyNow() {
  260. this.createdOrder();
  261. },
  262. /*规则*/
  263. openRule() {
  264. this.isRule = true;
  265. },
  266. /*关闭规则*/
  267. closeRule() {
  268. this.isRule = false;
  269. },
  270. /*跳转首页*/
  271. gotoHome() {
  272. uni.switchTab({
  273. url: '/pages/index/index'
  274. });
  275. },
  276. /*创建订单*/
  277. createdOrder() {
  278. let self = this;
  279. let bargain_product_id = self.product.bargain_product_id;
  280. let product_sku_id = self.task.product_sku_id;
  281. let bargain_product_sku_id = self.task.bargain_product_sku_id;
  282. self.gotoPage('/pages/order/confirm-order?bargain_product_id=' +
  283. bargain_product_id +
  284. '&product_sku_id=' +
  285. product_sku_id +
  286. '&bargain_product_sku_id=' +
  287. bargain_product_sku_id +
  288. '&order_type=bargain' +
  289. '&bargain_task_id=' +
  290. self.bargain_task_id);
  291. },
  292. /*分享*/
  293. shareFunc() {
  294. let self = this;
  295. //#ifdef H5
  296. self.isshare = true;
  297. //#endif
  298. //#ifdef APP-PLUS
  299. self.appParams.title = '发现了一个好物,快来帮我砍一刀吧';
  300. self.appParams.summary = self.product.product.product_name;
  301. // 构建页面参数
  302. let params = self.getShareUrlParams({
  303. bargain_task_id: self.bargain_task_id
  304. });
  305. self.appParams.path = '/pages/plus/bargain/haggle/haggle?' + params;
  306. self.appParams.image = self.product.product.image[0].file_path;
  307. self.isAppShare = true;
  308. //#endif
  309. },
  310. /*关闭分享*/
  311. closeShare() {
  312. this.isshare = false;
  313. },
  314. //关闭分享
  315. closeAppShare(data) {
  316. this.isAppShare = false;
  317. },
  318. /*我要参与*/
  319. involvedFunc() {
  320. let url = 'pages/plus/bargain/detail/detail?bargain_product_id=' + this.product.bargain_product_id;
  321. this.gotoPage(url);
  322. },
  323. /*小程序分享*/
  324. onShareAppMessage() {
  325. let self = this;
  326. // 构建页面参数
  327. let params = self.getShareUrlParams({
  328. bargain_task_id: self.bargain_task_id
  329. });
  330. return {
  331. title: '发现了一个好物,快来帮我砍一刀吧',
  332. path: '/pages/plus/bargain/haggle/haggle?' + params
  333. };
  334. },
  335. }
  336. };
  337. </script>
  338. <style lang="scss">
  339. .haggle {
  340. min-height: 100vh;
  341. padding: 30rpx;
  342. box-sizing: border-box;
  343. background: $dominant-color;
  344. }
  345. .haggle .goto-home {
  346. position: fixed;
  347. top: 40rpx;
  348. left: 40rpx;
  349. width: 80rpx;
  350. height: 80rpx;
  351. line-height: 60rpx;
  352. border-radius: 50%;
  353. background: #ffffff;
  354. z-index: 20;
  355. }
  356. .haggle .goto-home .iconfont {
  357. color: $dominant-color;
  358. font-weight: bold;
  359. font-size: 40rpx;
  360. }
  361. .haggle-content {
  362. position: relative;
  363. padding: 30rpx;
  364. box-sizing: border-box;
  365. border-radius: 16rpx;
  366. background: #ffffff;
  367. }
  368. .haggle-content .rule {
  369. position: absolute;
  370. top: 30rpx;
  371. right: 30rpx;
  372. }
  373. .haggle-content .user image {
  374. width: 120rpx;
  375. height: 120rpx;
  376. border-radius: 50%;
  377. }
  378. .haggle-content .product {
  379. background: #eeeeee;
  380. }
  381. .haggle-content .product .pic,
  382. .haggle-content .product .pic image {
  383. width: 160rpx;
  384. height: 160rpx;
  385. }
  386. .haggle-content .title-2 text::before,
  387. .haggle-content .title-2 text::after {
  388. display: block;
  389. content: '';
  390. position: absolute;
  391. width: 100rpx;
  392. height: 2rpx;
  393. top: 50%;
  394. background: #cccccc;
  395. }
  396. .haggle-content .title-2 text::before {
  397. left: -120rpx;
  398. }
  399. .haggle-content .title-2 text::after {
  400. right: -120rpx;
  401. }
  402. .haggle-content .progress {
  403. padding-top: 60rpx;
  404. margin: 20rpx 80rpx 0;
  405. }
  406. .haggle-content .progress-box {
  407. height: 20rpx;
  408. background: #cccccc;
  409. border-radius: 10rpx;
  410. overflow: hidden;
  411. }
  412. .haggle-content .progress-box-active {
  413. height: 20rpx;
  414. border-radius: 16rpx;
  415. background: $dominant-color;
  416. }
  417. .haggle-content .progressState {
  418. top: 0;
  419. left: 0;
  420. position: absolute;
  421. width: 160rpx;
  422. height: 32rpx;
  423. transform: translateX(-80rpx);
  424. line-height: 32rpx;
  425. border-radius: 16rpx;
  426. font-size: 20rpx;
  427. text-align: center;
  428. background: $dominant-color;
  429. color: #ffffff;
  430. }
  431. .haggle-content .progressState::after {
  432. position: absolute;
  433. left: 50%;
  434. margin-left: -6rpx;
  435. display: block;
  436. content: '';
  437. border: 12rpx solid transparent;
  438. border-top-color: $dominant-color;
  439. }
  440. .haggle-content .ad-datetime .box {
  441. padding: 4rpx;
  442. border-radius: 4rpx;
  443. background: #000000;
  444. color: #ffffff;
  445. }
  446. .haggle-content .btns button {
  447. height: 88rpx;
  448. line-height: 88rpx;
  449. border-radius: 44rpx;
  450. background: $dominant-color;
  451. color: #ffffff;
  452. }
  453. .haggle-content .btns button.buy-btn {
  454. background: #ff8a00;
  455. }
  456. .haggle-content .help-list .user image {
  457. width: 60rpx;
  458. height: 60rpx;
  459. }
  460. </style>