kjDetail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <view>
  3. <!--activity/bargain/kjDetail/kjDetail.wxml-->
  4. <view class="banner">
  5. <image :src="picUrlss+'kjban.jpg'" mode="widthFix"></image>
  6. </view>
  7. <view class="con">
  8. <view class="info dflex" @tap="goPrcdetail">
  9. <view class="pinimgs">
  10. <image :src="acProduc.pic" mode="aspectFit" class="pinimg"></image>
  11. </view>
  12. <view class="pininfo flex">
  13. <view class="proname">{{acProduc.productName?acProduc.productName:''}}</view>
  14. <!-- <view class="guige">规格:15G</view> -->
  15. <view class="sta dflex">
  16. <view class="price"><text>¥</text>{{acProduc.money?acProduc.money:0}}<text class="del" v-if="acProduc.orPrice!=0&&acProduc.orPrice>acProduc.money">原价:¥{{acProduc.orPrice?acProduc.orPrice:'0'}}</text></view>
  17. <!-- <view class="nums">×1</view> -->
  18. </view>
  19. </view>
  20. </view>
  21. <view class="cantuan bgfff mt20 r10">
  22. <view class="faqir">
  23. <image :src="aprList.groupMainP.uavatar"></image>
  24. <view>{{aprList.groupMainP.unickName}}</view>
  25. <icon class="icon iconfont iconbaojiaquotation2"></icon><text>我想要这件好物,快来帮我砍一刀吧</text>
  26. <icon class="icon iconfont iconbaojiaquotation"></icon>
  27. </view>
  28. <view class="sheng dflex" v-if="!act.isJieshu || !acProduc.end">
  29. 剩余
  30. <view class="sheng-time dflex">
  31. <!-- <block wx:if="acProduc.end">
  32. <text>{{timer[0]}}</text>
  33. <text>{{timer[1]}}</text>:
  34. <text>{{timer[2]}}</text>:
  35. <text>{{timer[3]}}</text>
  36. </block> -->
  37. <!-- <block wx:else> -->
  38. <block v-if="timer.length==4">
  39. <block v-if="timer[0] !=0"><text>{{timer[0]}}</text>天</block>
  40. <text>{{timer[1]}}</text>:
  41. <text>{{timer[2]}}</text>:
  42. <text>{{timer[3]}}</text>
  43. </block>
  44. <block v-else>
  45. <text>{{timer[0]}}</text>:
  46. <text>{{timer[1]}}</text>:
  47. <text>{{timer[2]}}</text>
  48. </block>
  49. <!-- </block> -->
  50. </view>
  51. 结束
  52. </view>
  53. <view v-else class="sheng dflex">已过期</view>
  54. <view class="can-info">已邀{{participateCount}}人,共砍<text>¥{{bargainingMoney}},</text>仅差<text>¥{{surplusMoney<=0?'0':surplusMoney}}</text></view>
  55. <view class="process">
  56. <view class="ing" :style="'width:' + percent + ';'"></view>
  57. </view>
  58. <block v-if="!act.isJieshu">
  59. <block v-if="isSuccess">
  60. <view class="can-btn mbglinear" @tap="confirmBuy" v-if="whether == 2&&topay==null">立即购买</view>
  61. <view class="can-btn mbglinear" @tap="toOrder" v-if="whether == 2&&topay!=null">查看订单详情</view>
  62. <view class="kai-btn" v-if="whether == 1" @tap="goUrl">我也要发起砍价</view>
  63. </block>
  64. <block v-else>
  65. <block v-if="isKanjia!=1">
  66. <button @tap="initState" class="can-btn mbglinear" v-if="whether == 2 &&isKanjia!=1">立即砍价</button>
  67. <view class="can-btn mbglinear" v-if="whether == 1&&isKanjia!=1" @tap="initState">帮TA砍一刀</view>
  68. </block>
  69. <block v-else>
  70. <button open-type="share" class="can-btn mbglinear" v-if="whether == 1">邀请好友帮TA砍价</button>
  71. <view class="kai-btn" v-if="whether == 1" @tap="goUrl">我也要发起砍价</view>
  72. </block>
  73. <button open-type="share" class="can-btn mbglinear" v-if="whether == 2">邀请好友砍价</button>
  74. </block>
  75. </block>
  76. <view v-else class="can-btn end">已过期</view>
  77. </view>
  78. <view class="detail bgfff mt20 r10">
  79. <view class="tab dflex">
  80. <view :class="'li ' + (currentTab == 0? 'on' : '')" data-current="0" @tap="tab">商品详情</view>
  81. <view :class="'li ' + (currentTab == 1? 'on' : '')" data-current="1" @tap="tab">砍价亲友团</view>
  82. <view :class="'li ' + (currentTab == 2? 'on' : '')" data-current="2" @tap="tab">活动规则</view>
  83. </view>
  84. <view :class="currentTab == 0? 'show' : 'hide'">
  85. <mp-html :content="nodes" lazy-load="true"></mp-html>
  86. <block v-if="diyNodes || diyImgs.length > 0">
  87. <view class="details">
  88. <rich-text :nodes="diyNodes" @tap="richImg"></rich-text>
  89. </view>
  90. <view class="details">
  91. <block v-for="(item, index) in diyImgs" :key="index">
  92. <image class="img" :src="item" mode="widthFix" @tap="chooseImg1" :data-src="item"></image>
  93. </block>
  94. </view>
  95. </block>
  96. </view>
  97. <view :class="'friend ' + (currentTab == 1? 'show' : 'hide')">
  98. <block v-if="aprList.groupList.length > 0">
  99. <view v-for="(item, index) in aprList.groupList" :key="index" class="li dflex">
  100. <view class="timg">
  101. <image :src="item.uavatar" mode="aspectFit"></image>
  102. </view>
  103. <view class="name flex">{{item.unickName}}<text>{{item.careatDate}}</text></view>
  104. <view class="time">帮砍{{item.bargainingAmount}}元</view>
  105. </view>
  106. </block>
  107. <view class="nopeople" v-else>
  108. <image :src="picUrlss+'sqimg2.png'"></image>
  109. <text>还没有人帮你砍价,去邀请好友帮忙</text>
  110. </view>
  111. </view>
  112. <view :class="'guize ' + (currentTab == 2? 'show' : 'hide')">
  113. <rich-text :nodes="activityMain.rule"></rich-text>
  114. </view>
  115. </view>
  116. </view>
  117. <view class="mask" @tap="closeLayer" :hidden="isShow"></view>
  118. <view class="kjpop" :hidden="isShow">
  119. <image src="/static/pages/images/close3.png" class="kjclose" @tap="closeLayer"></image>
  120. <!-- <image :src="picUrlss+'sqimg2.png'" class="kjimg"></image>砍价了 -->
  121. <image src="/activity/static/activity/images/kanle1.png" class="kanle1" v-if="whether == 1"></image>
  122. <!--帮TA砍掉-->
  123. <image src="/activity/static/activity/images/kanle2.png" class="kanle2" v-if="whether == 2"></image>
  124. <!--您已砍了-->
  125. <!-- <image :src="picUrlss+'thsb.png'" class="kjimg"></image> -->
  126. <!--砍价失败了-->
  127. <!-- <view class="kjtip" wx:if="{{participate == 1}}">您已经砍过了</view> -->
  128. <!-- <view class="kjtip">砍价失败了</view> -->
  129. <view class="kandiao" v-if="whether == 2 && isSuccess">您已经砍到底价了</view>
  130. <!--砍到底价-->
  131. <view class="kandiao" v-if="whether == 1">帮TA砍掉<text>{{money}}元</text></view>
  132. <!--帮TA砍掉-->
  133. <view class="kandiao" v-if="whether == 2 && !isSuccess">您砍了<text>{{money}}元</text></view>
  134. <!--帮TA砍掉-->
  135. <view class="process">
  136. <view class="ing" :style="'width:' + percent + ';'"></view>
  137. </view>
  138. <view class="kjbtn dflex">
  139. <view class="back" @tap="closeLayer">返回</view>
  140. <block v-if="whether == 2">
  141. <view class="ljgm" @tap="confirmBuy" v-if="isSuccess&&topay==null">立即购买</view>
  142. <view class="ljgm" @tap="toOrder" v-if="isSuccess&&topay!=null">查看订单详情</view>
  143. <button open-type="share" class="fenx" v-if="!isSuccess">分享给好友</button>
  144. </block>
  145. <block v-else>
  146. <view class="ljgm" @tap="goUrl" v-if="whether == 1">我也要砍价</view>
  147. </block>
  148. </view>
  149. </view>
  150. <!-- #ifdef H5 -->
  151. <wx-share ref="wxshare" />
  152. <!-- #endif -->
  153. </view>
  154. </template>
  155. <script>
  156. // activity/bargain/kjDetail/kjDetail.js
  157. const app = getApp();
  158. const req = require("../../../utils/request.js");
  159. const utils = require("../../../utils/util.js");
  160. const route =require("../../../utils/route.js");
  161. import mpHtml from "../../../components/mp-html/components/mp-html/mp-html";
  162. export default {
  163. data() {
  164. return {
  165. picUrlss: req.public.picUrls,
  166. currentTab: 0,
  167. isShow: true,
  168. money: '',
  169. isSuccess: false,
  170. isKanjia: '',
  171. start: false,
  172. percent: "",
  173. timer: "",
  174. merchantId: "",
  175. topay: ""
  176. };
  177. },
  178. components: {mpHtml},
  179. props: {},
  180. async onLoad(options) {
  181. if(options.appId) req.setStorage('appId',options.appId);
  182. this.query = options;
  183. // console.log(options);
  184. if (options.money) {
  185. this.setData({
  186. isShow: false,
  187. money: options.money
  188. });
  189. }
  190. if (options.isShow) {
  191. this.setData({
  192. isShow: true
  193. });
  194. }
  195. },
  196. async onShow() {
  197. req.isLogin().then(success => {});
  198. this.getData();
  199. await this.loadProudct();
  200. this.gettoPay();
  201. },
  202. // onShareTimeline(){
  203. // let merchantId = '';
  204. // let path = '/activity/bargain/kjDetail/kjDetail?id=' + this.query.id + '&superiorId=' + this.aprList.groupMainP.userId + '&proid=' + this.query.proid ;
  205. // console.log(!req.getStorage('userInfo').id);
  206. // if (!req.getStorage('userInfo').id) {} else {
  207. // path += '&userId=' + req.getStorage('userInfo').id;
  208. // }
  209. // console.log(this.query.merchantId);
  210. // let shopId = '';
  211. // if (req.getStorage('MERCHANT') && req.getStorage('MERCHANT').id != null) {
  212. // path += '&merchantId=' + req.getStorage('MERCHANT').id;
  213. // merchantId = req.getStorage('MERCHANT').id;
  214. // if (req.getStorage('smallShop') && req.getStorage('MERCHANT').id != null) {
  215. // path += '&shopId=' + req.getStorage('smallShop').id;
  216. // shopId = req.getStorage('smallShop').id;
  217. // merchantId = req.getStorage('smallShop').merchantDTO.id;
  218. // }
  219. // }
  220. // console.log(path,"456")
  221. // route.share(1, req.getStorage('userInfo').id, path, merchantId, shopId, 9, this.query.proid + '_' + this.query.id);
  222. // return {
  223. // title: req.getStorage("userInfo").nickName + '邀请您帮忙砍价:' + this.acProduc.productName,
  224. // imageUrl: this.acProduc.pic,
  225. // path: path
  226. // };
  227. // },
  228. onShareAppMessage: function () {
  229. return this.onShareMessage();
  230. // return {
  231. // title: req.getStorage("userInfo").nickName + '邀请您帮忙砍价:' + this.acProduc.productName,
  232. // imageUrl: this.acProduc.pic,
  233. // path: '/activity/bargain/kjDetail/kjDetail?id=' + this.query.id + '&superiorId=' + this.aprList.groupMainP.userId + '&proid=' + this.query.proid + "&merchantId=" + this.query.merchantId
  234. // };
  235. },
  236. onReady() {
  237. // #ifdef H5
  238. var that = this;
  239. //初始化分享内容
  240. setTimeout(function() {
  241. var shareContent = that.onShareMessage();
  242. if (shareContent) {
  243. shareContent.path = window.location.origin + shareContent.path;
  244. }
  245. console.log('分享内容》》》》》', shareContent);
  246. that.$refs.wxshare.init(shareContent);
  247. }, 4 * 1000);
  248. // #endif
  249. },
  250. methods: {
  251. tab(event) {
  252. const tabIndex = event.currentTarget.dataset.current;
  253. if (this.currentTab === tabIndex) return false;
  254. this.setData({
  255. currentTab: tabIndex
  256. });
  257. },
  258. onShareMessage(){
  259. let merchantId = '';
  260. let path = '';
  261. let isSolution = '';
  262. // #ifndef H5
  263. isSolution = req.env[req.env.NODE_ENV].isSolution;
  264. // #endif
  265. // #ifdef H5
  266. isSolution = false;
  267. // #endif
  268. let userInfo = req.getStorage('userInfo');
  269. let shopId = '';
  270. if(isSolution){
  271. path = '/share/home/index?appId='+req.getStorage('appId')+'&userId='+userInfo.id;
  272. }else{
  273. path = '/activity/bargain/kjDetail/kjDetail?id=' + this.query.id + '&superiorId=' + this.aprList.groupMainP.userId + '&proid=' + this.query.proid+ '&appId=' + req.getStorage('appId');
  274. if (!userInfo.id) {} else {
  275. path += '&userId=' + userInfo.id;
  276. }
  277. // console.log(this.query.merchantId);
  278. if (req.getStorage('MERCHANT') && req.getStorage('MERCHANT').id != null) {
  279. path += '&merchantId=' + req.getStorage('MERCHANT').id;
  280. merchantId = req.getStorage('MERCHANT').id;
  281. if (req.getStorage('smallShop') && req.getStorage('MERCHANT').id != null) {
  282. path += '&shopId=' + req.getStorage('smallShop').id;
  283. shopId = req.getStorage('smallShop').id;
  284. merchantId = req.getStorage('smallShop').merchantDTO.id;
  285. }
  286. }
  287. }
  288. // console.log(path,"456")
  289. route.share(1, userInfo.id, path, merchantId, shopId, 9, this.query.proid + '_' + this.query.id);
  290. return {
  291. title: userInfo.nickName + '邀请您帮忙砍价:' + this.acProduc.productName,
  292. imageUrl: this.acProduc.pic,
  293. path: path
  294. };
  295. },
  296. closeLayer() {
  297. this.setData({
  298. isShow: true
  299. });
  300. },
  301. loadProudct() {
  302. let that = this;
  303. const query = that.query;
  304. // console.log(query.id);
  305. return new Promise((resolve, reject) => {
  306. req.getRequest('/api/activity/bargainPriceDetail', {
  307. id: query.id,
  308. merchantId: query.merchantId
  309. }, data => {
  310. if(data){
  311. data.bargainingMoney = parseFloat(data.bargainingMoney).toFixed(2);
  312. data.surplusMoney = parseFloat(data.surplusMoney).toFixed(2);
  313. this.setData(data);
  314. this.initStates();
  315. let percent = Math.round(data.bargainingMoney / (data.acProduc.orPrice - data.acProduc.money) * 100) + '%';
  316. if (data.bargainingMoney == (data.acProduc.orPrice * 10000 - data.acProduc.money * 10000) / 10000) {
  317. this.setData({
  318. isSuccess: true
  319. });
  320. }
  321. this.setData({
  322. percent: percent
  323. });
  324. this.initTimer(data.acProduc, data.aprList);
  325. }
  326. resolve(); // that.getCodeUrl();
  327. });
  328. });
  329. },
  330. getData() {
  331. let that = this;
  332. const query = this.query;
  333. return new Promise((resolve, reject) => {
  334. req.getRequest('/api/product/detail', { id: query.proid }, data => {
  335. // console.log("/api/product/detail")
  336. var nodes = data.detail;
  337. that.setData({ bannerUrls: data.images, pro: data, nodes: nodes });
  338. resolve();
  339. })
  340. })
  341. },
  342. initTimer(group, list) {
  343. //计时器
  344. let _ts = this;
  345. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  346. let startTime = new Date(group.createDate.replace(/-/g, '/')).getTime();
  347. let endTime = new Date(list.endDate.replace(/-/g, '/')).getTime();
  348. let times = parseInt((endTime - nowTime) / 1000);
  349. this.timer = setInterval(() => {
  350. times--;
  351. if (times === 0) {
  352. //重新加载列表
  353. _ts.setData({
  354. 'act.end': true
  355. });
  356. return false;
  357. }
  358. if (times < 0) {
  359. _ts.setData({
  360. 'act.isJieshu': true
  361. });
  362. }
  363. let n = utils.formatDayTimes(times);
  364. _ts.setData({
  365. timer: n.split(/:|天/g)
  366. });
  367. }, 1000);
  368. if (this.start) {
  369. clearInterval(this.timer);
  370. }
  371. },
  372. goUrl() {
  373. app.globalData.redirectTab('activity/bargain/index/index?merchantId=' + this.query.merchantId);
  374. },
  375. confirmBuy() {
  376. //直接购买
  377. if (this.start) return req.msg('活动已结束'); // let merchant = req.getStorage('defaultMerchant');
  378. if (this.query.merchantId) {
  379. this.setData({
  380. merchantId: this.query.merchantId
  381. });
  382. } // else{
  383. // if (req.getStorage('smallShop')) {
  384. // this.setData({ merchant: req.getStorage('smallShop').merchantDTO })
  385. // this.setData({ merchantId: req.getStorage('smallShop').merchantDTO.id })
  386. // } else if (req.getStorage('MERCHANT')) {
  387. // this.setData({ merchantId: req.getStorage('MERCHANT').id })
  388. // this.setData({ merchant: req.getStorage('MERCHANT') })
  389. // }
  390. // }
  391. // console.log(this.acProduc);
  392. const params = {
  393. skuId: this.acProduc.skuId,
  394. quantity: 1,
  395. productId: this.acProduc.productId,
  396. activityId: this.acProduc.id,
  397. aprId: this.query.id
  398. };
  399. if (this.query.merchantId) {
  400. params.merchantId = this.query.merchantId;
  401. } // if (this.data.merchant && this.data.merchant.type == 5) {
  402. // params.shopId = this.data.merchant.id
  403. // }
  404. // if (this.data.merchantId) params.merchantId = this.data.merchantId;
  405. req.postRequest('/api/purchase/direct/buy', params, res => {
  406. let redirect = '/product/subOrder/subOrder?ids=' + res;
  407. let orderType = 7; //砍价订单类型
  408. redirect += '&orderType=' + orderType;
  409. redirect += '&aprId=' + params.aprId;
  410. if (params.merchantId) {
  411. redirect += '&merchantId=' + this.merchantId;
  412. }
  413. if (params.shopId) {
  414. redirect += '&shopId=' + params.shopId;
  415. }
  416. uni.navigateTo({
  417. url: redirect
  418. });
  419. });
  420. },
  421. initState() {
  422. //判断是否发起砍价
  423. req.isLogin().then(success => {});
  424. let superid = this.query.id;
  425. let proid = this.acProduc.productId;
  426. if (this.isStates == 0) return req.msg('活动还未开始'); // if (this.data.isStates == 2) return req.msg('活动已结束');
  427. if (this.start) return req.msg('活动已结束');
  428. let param = {
  429. acpId: this.acProduc.id,
  430. actId: this.acProduc.actId,
  431. productId: this.acProduc.productId,
  432. type: 5,
  433. initOrPart: 2,
  434. superiorId: superid
  435. };
  436. req.getRequest('/api/activity/participationActivity', param, res => {
  437. //判断是否帮砍过
  438. // console.log("/api/activity/participationActivity");
  439. if (res.state == 1) {
  440. this.setData({
  441. isKanjia: res.state,
  442. isShow: false
  443. });
  444. return false;
  445. }
  446. let params = {
  447. acpId: this.acProduc.id,
  448. type: 5
  449. };
  450. if (superid) {
  451. params.superiorId = superid;
  452. }
  453. req.postRequest('/api/activity/carterActivityPurchaseRecords', params, res => {
  454. if (res) {
  455. let money = '';
  456. let id = '';
  457. if (superid) money = res, id = superid;else id = res;
  458. this.setData({
  459. isShow: false,
  460. money: money
  461. });
  462. this.loadProudct(); // wx.redirectTo({ url: '/activity/bargain/kjDetail/kjDetail?id=' + id + '&money=' + money + '&proid=' + proid })
  463. // app.openPage('activity/bargain/kjDetail/kjDetail?id=' + id + '&money=' + money + '&proid=' + proid)
  464. }
  465. });
  466. });
  467. },
  468. initStates() {
  469. //判断是否发起砍价
  470. req.isLogin().then(success => {});
  471. let params = {
  472. acpId: this.acProduc.id,
  473. actId: this.acProduc.actId,
  474. productId: this.acProduc.productId,
  475. type: 5,
  476. initOrPart: 2,
  477. superiorId: this.query.id
  478. };
  479. return new Promise((resolve, reject) => {
  480. req.getRequest('/api/activity/participationActivity', params, res => {
  481. // console.log("/api/activity/participationActivity");
  482. if (res.state != 1) {
  483. this.setData({
  484. isKanjia: res.state,
  485. isShow: true
  486. });
  487. } else {
  488. this.setData({
  489. isKanjia: res.state
  490. });
  491. }
  492. resolve();
  493. });
  494. });
  495. },
  496. gettoPay() {
  497. req.postRequest('/api/activity/toPay', {
  498. aprId: this.query.id,
  499. type: 5
  500. }, data => {
  501. this.setData({
  502. topay: data
  503. });
  504. });
  505. },
  506. toOrder() {
  507. uni.navigateTo({
  508. url: '/mine/orderDet/orderDet?id=' + this.topay
  509. });
  510. },
  511. // 活动商品详情
  512. goPrcdetail() {
  513. app.globalData.openPage('activity/bargain/detail/detail?acid=' + this.acProduc.id + '&id=' + this.acProduc.productId);
  514. }
  515. }
  516. };
  517. </script>
  518. <style>
  519. @import "./kjDetail.css";
  520. </style>