金诚优选前端代码
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.

770 lines
21 KiB

  1. <template>
  2. <view class="">
  3. <view id="call">
  4. <view class="call-box" @tap="jumpDetail">
  5. <image mode="widthFix" :src="info.data.free.img" alt></image>
  6. <view class="name" v-if="info.data.free.label!=undefined">
  7. {{info.data.free.label}}
  8. </view>
  9. </view>
  10. <view class="time-box" :class="info.data.free.activity_status == 'OnGoing' ? 'active' : ''" v-if="info.free.activity_status == 'NoBegin'">
  11. <seckill :end="info.data.free.ends_at" :starts="info.data.free.starts_at" typename="集call" :server="info.data.free.server_time" mold="list" @starts="isStarts" @end="isEnd"></seckill>
  12. </view>
  13. <view class="call-user">
  14. <image v-if="info.data.task_user_avatar" :src="info.data.task_user_avatar"></image>
  15. <image v-else src="http://ovef29y3v.bkt.clouddn.com/%E5%A4%B4%E5%83%8F_%E7%94%BB%E6%9D%BF%201.png"></image>
  16. <view class="call-status">
  17. <view v-if="!info.meta.is_call && info.data.gap_task != 0">还差 <span>{{info.data.gap_task}}</span> 个Call就可以免费领取礼品了求助攻~</view>
  18. <view v-if="info.data.gap_task == 0 && !info.meta.is_call">我已集满</view>
  19. <view v-if="info.meta.is_call && Brand_name != 'UTO'">感谢你为我打Call~</view>
  20. <view v-if="info.meta.is_call && Brand_name == 'UTO'">听说给我点赞的朋友都变好看了~</view>
  21. <!--<view class="receive" wx:if="{{info.data.gap_task == 0}}">立即领取 </view>-->
  22. </view>
  23. </view>
  24. <view class="share-box" :style="'color: ' + config.mainColor" v-if="info.data.free.activity_status == 'OnGoing'">
  25. <button class="friends claa-btn" :style="'background: ' + config.mainColor" v-if="!info.meta.is_call && info.data.gap_task != 0 && !token" open-type="getUserInfo" @getuserinfo="bindUserInfo">帮TA打call</button>
  26. <view class="friends" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" v-if="!info.meta.is_call && info.data.gap_task != 0 && token" @tap="beforCall">帮TA打call</view>
  27. <button class="friend share-btn" :style="'color: ' + config.mainColor" v-if="info.meta.is_call && info.data.gap_task != 0" open-type="share">帮TA分享</button>
  28. <view class="friends" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" v-if="info.meta.is_call || info.data.gap_task == 0" @tap="jumpCall">我也要领取</view>
  29. </view>
  30. <view class="no-active" v-if="info.data.free.activity_status == 'NoBegin'">
  31. 活动未开始
  32. </view>
  33. <view class="call-num">
  34. <view class="text mx-1px-bottom">
  35. 已有 {{info.data.count_task}} 人为他打Call
  36. </view>
  37. <view class="item-box">
  38. <view class="call-num-item" :style="'height: ' + itemHeight + 'px;'" v-for="(item, index) in callList" :key="index">
  39. <view class="info">
  40. <image v-if="item.id && !item.meta.avatar" src="http://ovef29y3v.bkt.clouddn.com/%E5%A4%B4%E5%83%8F_%E7%94%BB%E6%9D%BF%201.png"></image>
  41. <image v-else :src="item.meta.avatar"></image>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="text-info mx-1px-top" @tap="infoF">
  46. 集Call说明
  47. </view>
  48. </view>
  49. <view class="home" @tap="jump">
  50. <i class="iconfont icon-home"></i>
  51. 首页
  52. </view>
  53. <view class="ibrand-author" v-if="author" @tap="jumpAuthor">
  54. <i class="iconfont icon-dibu"></i>
  55. </view>
  56. </view>
  57. <view class="call-goods" v-if="info.data.recommend_goods && info.data.recommend_goods.length">
  58. <view class="title mx-1px-bottom">
  59. 相关推荐
  60. </view>
  61. <view class="content">
  62. <view class="like_list">
  63. <view class="like_box" v-for="(item, index) in info.data.recommend_goods" :key="index" :data-id="item.id" @tap="jumpStore">
  64. <view>
  65. <view class="like_image">
  66. <image class="responsive" :src="item.img" alt></image>
  67. </view>
  68. <view class="like_name">
  69. {{item.name}}
  70. </view>
  71. <view class="like_money">
  72. {{item.sell_price}}
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view id="coupon-box" v-if="!coupon.has_get && coupon.discount">
  80. <view class="mask">
  81. </view>
  82. <view class="coupon-body">
  83. <view class="title">
  84. 优惠券
  85. </view>
  86. <view class="tips">
  87. <view>
  88. Hi亲爱的会员
  89. </view>
  90. <view>
  91. 这是我送给你的优惠券快去领取吧
  92. </view>
  93. </view>
  94. <view class="coupon" v-for="(item, index) in coupon.discount" :key="index">
  95. <view class="left">
  96. <view class="icon">
  97. <i class="iconfont icon-xingzhuang"></i>
  98. </view>
  99. <view class="text-box">
  100. <view class="title nowarp">
  101. {{item.title}}
  102. </view>
  103. <view class="info">
  104. 仅支持商城使用
  105. </view>
  106. </view>
  107. </view>
  108. <view class="right">
  109. <text class="money" v-if="item.action_type.type == 'cash'"></text>
  110. <sapn>{{ item.action_type.value }}</sapn>
  111. <text class="money" v-if="item.action_type.type == 'discount'"></text>
  112. </view>
  113. </view>
  114. <view class="close iconfont icon-yiquxiao" @tap="closeCoupon">
  115. </view>
  116. <view class="btn" v-if="token" @tap="getCoupon">
  117. 立即领取
  118. </view>
  119. <button class="btn" v-else open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  120. 立即领取
  121. </button>
  122. </view>
  123. </view>
  124. </view>
  125. </template>
  126. <script>
  127. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  128. import seckill from "@/components/seckill/seckill";
  129. export default {
  130. data() {
  131. return {
  132. itemHeight: '',
  133. callList: '',
  134. info: '',
  135. init: false,
  136. task_id: '',
  137. token: "",
  138. userInfo: '',
  139. shop_id: '',
  140. unionInFo: '',
  141. openInFo: '',
  142. author: config.PACKAGES.author,
  143. list: [{
  144. id: 1,
  145. value: 1
  146. }, {
  147. id: 2,
  148. value: 2
  149. }],
  150. Brand_name: '',
  151. config: '',
  152. coupon: '',
  153. code: ''
  154. };
  155. },
  156. components:{
  157. seckill
  158. },
  159. onShareAppMessage(res) {
  160. return {
  161. title: '快来帮我免费领取|' + this.info.data.free.label,
  162. imageUrl: this.info.data.free.img,
  163. path: '/pages/store/shareCall/shareCall?task_id=' + this.info.data.id
  164. };
  165. },
  166. onShow() {
  167. var token = this.$cookieStorage.get('user_token');
  168. this.token=token;
  169. // 用来区分是哪个项目
  170. /*if(config.BRAND.name == 'nu') {
  171. this.userAuthorize();
  172. }*/
  173. this.queryTaskInfo(this.task_id);
  174. if (!this.token) {
  175. this.getOpenid();
  176. }
  177. },
  178. onLoad(e) {
  179. // 第三方平台配置颜色
  180. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  181. var init = this.$cookieStorage.get('init');
  182. this.setData({
  183. config: gbConfig,
  184. author: init ? init.other_technical_support : ''
  185. });
  186. if (!gbConfig) {
  187. let extConfig = {};
  188. if (extConfig) {
  189. this.setData({
  190. config: extConfig
  191. });
  192. }
  193. }
  194. wx.getSystemInfo({
  195. success: res => {
  196. // this.setData({
  197. // itemHeight: (res.screenWidth - 14) / 12.5
  198. // });
  199. this.itemHeight=(res.screenWidth-14)/12.5;
  200. }
  201. });
  202. if (e.scene) {
  203. this.setData({
  204. task_id: decodeURIComponent(e.scene)
  205. });
  206. }
  207. if (e.task_id) {
  208. this.setData({
  209. task_id: e.task_id
  210. });
  211. }
  212. },
  213. components: {
  214. seckill
  215. },
  216. props: {},
  217. methods: {
  218. jumpAuthor() {
  219. wx.navigateTo({
  220. url: '/pages/index/author/author'
  221. });
  222. },
  223. infoF() {
  224. wx.showModal({
  225. title: '集Call说明',
  226. content: this.info.data.free.content,
  227. showCancel: false
  228. });
  229. },
  230. jump() {
  231. wx.switchTab({
  232. url: '/pages/index/index/index'
  233. });
  234. },
  235. jumpDetail() {
  236. wx.navigateTo({
  237. url: '/pages/store/detail/detail?id=' + this.info.data.free.freeable_id
  238. });
  239. },
  240. jumpEnd() {
  241. wx.redirectTo({
  242. url: '/pages/store/detail/detail?id=' + this.info.free.freeable_id
  243. });
  244. },
  245. jumpCall() {
  246. if (this.token) {
  247. wx.redirectTo({
  248. url: '/pages/store/call/call?id=' + this.info.data.free_id
  249. });
  250. } else {
  251. wx.showModal({
  252. content: '请先登录',
  253. success: res => {
  254. if (res.confirm || !res.cancel && !res.confirm) {
  255. pageLogin(getUrl());
  256. }
  257. }
  258. });
  259. }
  260. },
  261. jumpStore(e) {
  262. var id = e.currentTarget.dataset.id;
  263. wx.redirectTo({
  264. url: '/pages/store/detail/detail?id=' + id
  265. });
  266. },
  267. // 查询信息
  268. queryTaskInfo(id) {
  269. var token = this.$cookieStorage.get('user_token') || '';
  270. wx.showLoading({
  271. title: "加载中",
  272. mask: true
  273. });
  274. this.$http.get({
  275. api: 'api/free_event/task/getTaskForUser/' + id,
  276. data: {
  277. open_id: this.$cookieStorage.get('user_open_id') || ''
  278. },
  279. header: {
  280. Authorization: token
  281. }
  282. }).then(res => {
  283. if (res.statusCode == 200) {
  284. res = res.data;
  285. if (res.status) {
  286. if (res.meta.is_self) {
  287. wx.redirectTo({
  288. url: '/pages/store/call/call?id=' + res.data.free_id
  289. });
  290. return;
  291. }
  292. var list = Array(res.data.free.per_count - res.data.count_task).fill({
  293. meta: {
  294. avatar: ''
  295. }
  296. });
  297. var newList = res.data.items.concat(list);
  298. this.setData({
  299. info: res,
  300. callList: newList // init: true
  301. });
  302. /*
  303. NoBegin 未开始
  304. OnGoing 进行中
  305. End 结束
  306. */
  307. // 如果活动未开始,不显示转发按钮
  308. if (res.data.free.activity_status == 'NoBegin') {
  309. wx.hideShareMenu();
  310. }
  311. } else {
  312. wx.showModal({
  313. content: res.message || '请求失败',
  314. showCancel: false,
  315. success: res => {
  316. if (res.confirm || !res.cancel && !res.confirm) {
  317. wx.redirectTo({
  318. url: '/pages/store/callList/callList'
  319. });
  320. }
  321. }
  322. });
  323. }
  324. } else {
  325. wx.showModal({
  326. content: res.message || '请求失败',
  327. showCancel: false,
  328. success: res => {
  329. if (res.confirm || !res.cancel && !res.confirm) {
  330. wx.redirectTo({
  331. url: '/pages/store/callList/callList'
  332. });
  333. }
  334. }
  335. });
  336. }
  337. wx.hideLoading();
  338. }).catch(rej => {
  339. wx.hideLoading();
  340. wx.showModal({
  341. content: '内部错误',
  342. showCancel: false,
  343. success: res => {
  344. if (res.confirm || !res.cancel && !res.confirm) {
  345. wx.redirectTo({
  346. url: '/pages/store/callList/callList'
  347. });
  348. }
  349. }
  350. });
  351. });
  352. },
  353. beforCall() {
  354. if (this.token) {
  355. this.call();
  356. }
  357. },
  358. // 关闭优惠券弹出
  359. closeCoupon() {
  360. this.setData({
  361. 'coupon.has_get': true
  362. });
  363. },
  364. // 获取手机号
  365. getPhoneNumber(e) {
  366. if (e.detail.encryptedData) {
  367. wx.login({
  368. success: res => {
  369. if (res.code) {
  370. this.setData({
  371. code: res.code
  372. }, res => {
  373. this.phone(e);
  374. });
  375. } else {
  376. wx.showModal({
  377. content: " 获取code失败",
  378. showCancel: false
  379. });
  380. }
  381. }
  382. });
  383. }
  384. },
  385. // 利用手机号登录
  386. phone(e) {
  387. wx.showLoading({
  388. title: '正在登录',
  389. mask: true
  390. });
  391. this.$http.post({
  392. api: 'api/oauth/MiniProgramMobileLogin',
  393. data: {
  394. open_type: 'miniprogram',
  395. code: this.code,
  396. encryptedData: e.detail.encryptedData,
  397. iv: e.detail.iv,
  398. open_id: this.$cookieStorage.get('user_open_id') || ''
  399. }
  400. }).then(res => {
  401. if (res.statusCode == 200) {
  402. res = res.data;
  403. if (res.access_token) {
  404. var access_token = res.token_type + ' ' + res.access_token;
  405. var expires_in = res.expires_in || 315360000;
  406. this.$cookieStorage.set("user_token", access_token, expires_in); // 领取优惠券
  407. this.getCoupon();
  408. } else {
  409. wx.showModal({
  410. content: res.message || '请求失败,请重试',
  411. showCancel: false
  412. });
  413. }
  414. } else {
  415. wx.showModal({
  416. content: '请求失败,请重试',
  417. showCancel: false
  418. });
  419. }
  420. wx.hideLoading();
  421. }).catch(rej => {
  422. wx.hideLoading();
  423. wx.showModal({
  424. content: '请求失败,请重试',
  425. showCancel: false
  426. });
  427. });
  428. },
  429. // 获取优惠券信息
  430. getCouponInfo() {
  431. var token = this.$cookieStorage.get('user_token') || '';
  432. this.$http.get({
  433. api: 'api/free_event/getCouponList',
  434. header: {
  435. Authorization: token
  436. }
  437. }).then(res => {
  438. if (res.statusCode == 200) {
  439. res = res.data;
  440. if (res.status) {
  441. this.setData({
  442. coupon: res.data
  443. });
  444. console.log(res);
  445. } else {
  446. wx.showModal({
  447. content: res.message || '请求失败',
  448. showCancel: false
  449. });
  450. }
  451. } else {
  452. wx.showModal({
  453. content: '请求失败',
  454. showCancel: false
  455. });
  456. }
  457. }).catch(err => {
  458. wx.showModal({
  459. content: '内部错误',
  460. showCancel: false
  461. });
  462. });
  463. },
  464. // 领取优惠券
  465. getCoupon() {
  466. wx.showLoading({
  467. title: '领取中',
  468. mask: true
  469. });
  470. var discount_ids = [];
  471. this.coupon.discount.forEach(item => {
  472. discount_ids.push(item.id);
  473. });
  474. var token = this.$cookieStorage.get('user_token') || '';
  475. this.$http.post({
  476. api: 'api/coupon/getCouponConvertBatch',
  477. data: {
  478. discount_ids: discount_ids
  479. },
  480. header: {
  481. Authorization: token
  482. }
  483. }).then(res => {
  484. if (res.statusCode == 200) {
  485. res = res.data;
  486. if (res.status) {
  487. wx.showModal({
  488. content: '领取成功',
  489. showCancel: false
  490. });
  491. this.closeCoupon();
  492. } else {
  493. wx.showModal({
  494. content: res.message || '请求失败',
  495. showCancel: false
  496. });
  497. }
  498. } else {
  499. wx.showModal({
  500. content: '请求失败',
  501. showCancel: false
  502. });
  503. }
  504. wx.hideLoading();
  505. }).catch(err => {
  506. wx.hideLoading();
  507. wx.showModal({
  508. content: '内部错误',
  509. showCancel: false
  510. });
  511. });
  512. },
  513. // 绑定用户信息
  514. bindUserInfo(e) {
  515. if (e.detail.encryptedData) {
  516. this.call(this.open_id, e.detail.userInfo);
  517. }
  518. },
  519. // 打Call
  520. call(open_id, user_info) {
  521. var token = this.$cookieStorage.get('user_token');
  522. wx.showLoading({
  523. title: "正在打Call",
  524. mask: true
  525. });
  526. this.$http.post({
  527. api: 'api/free_event/task/call',
  528. data: {
  529. task_id: this.task_id,
  530. open_id: open_id || this.$cookieStorage.get('user_open_id') || '',
  531. userInfo: user_info
  532. },
  533. header: {
  534. Authorization: token
  535. }
  536. }).then(res => {
  537. if (res.statusCode = 200) {
  538. res = res.data;
  539. if (res.status) {
  540. this.queryTaskInfo(this.task_id);
  541. this.getCouponInfo();
  542. } else {
  543. wx.showModal({
  544. content: res.message || '请求失败',
  545. showCancel: false
  546. });
  547. }
  548. } else {
  549. wx.showModal({
  550. content: res.message || '请求失败',
  551. showCancel: false
  552. });
  553. }
  554. wx.hideLoading();
  555. }).catch(rej => {
  556. wx.hideLoading();
  557. wx.showModal({
  558. content: '内部错误',
  559. showCancel: false
  560. });
  561. });
  562. },
  563. // 获取open_id
  564. getOpenid() {
  565. wx.showLoading({
  566. title: "正在登录",
  567. mask: true
  568. });
  569. wx.login({
  570. success: res => {
  571. if (res.code) {
  572. this.autoLogin(res.code);
  573. } else {
  574. wx.hideLoading();
  575. wx.showToast({
  576. title: '获取code失败',
  577. image: '../../../static/error.png'
  578. });
  579. }
  580. }
  581. });
  582. },
  583. // 自动登录
  584. autoLogin(code) {
  585. this.$http.post({
  586. api: 'api/mini/program/login',
  587. data: {
  588. code: code
  589. }
  590. }).then(res => {
  591. if (res.statusCode == 200) {
  592. res = res.data;
  593. if (res.access_token) {
  594. var access_token = res.token_type + ' ' + res.access_token;
  595. var expires_in = res.expires_in || 315360000;
  596. this.$cookieStorage.set("user_token", access_token, expires_in); // this.call();
  597. } else if (res.data && res.data.open_id) {
  598. this.$cookieStorage.set('user_open_id', res.data.open_id); // this.getUserAuthorize(res.data.open_id)
  599. // this.call(res.data.open_id)
  600. } else {
  601. wx.showModal({
  602. content: res.message || '获取数据失败',
  603. showCancel: false
  604. });
  605. }
  606. } else {
  607. wx.showModal({
  608. content: res.message || '获取数据失败',
  609. showCancel: false
  610. });
  611. }
  612. wx.hideLoading();
  613. }).catch(rej => {
  614. wx.hideLoading();
  615. wx.showModal({
  616. content: '获取数据失败',
  617. showCancel: false
  618. });
  619. });
  620. },
  621. // 获取用户授权
  622. getUserAuthorize(open_id) {
  623. wx.getSetting({
  624. success: res => {
  625. if (!res.authSetting['scope.userInfo']) {
  626. wx.authorize({
  627. scope: 'scope.userInfo',
  628. success: res => {
  629. wx.getUserInfo({
  630. lang: 'zh_CN',
  631. success: res => {
  632. this.$cookieStorage.set('Wechat_user_info', res);
  633. this.call(open_id, res.userInfo);
  634. }
  635. });
  636. },
  637. fail: ret => {
  638. wx.showModal({
  639. content: '需要授权才能完成打Call',
  640. showCancel: false,
  641. success: res => {
  642. if (res.confirm || !res.cancel && !res.confirm) {
  643. wx.openSetting({
  644. success: res => {
  645. if (res.authSetting['scope.userInfo']) {
  646. wx.getUserInfo({
  647. lang: 'zh_CN',
  648. success: ret => {
  649. this.$cookieStorage.set('Wechat_user_info', ret);
  650. this.call(open_id, ret.userInfo);
  651. }
  652. });
  653. }
  654. }
  655. });
  656. }
  657. }
  658. });
  659. }
  660. });
  661. } else {
  662. wx.getUserInfo({
  663. lang: 'zh_CN',
  664. success: res => {
  665. this.$cookieStorage.set('Wechat_user_info', res);
  666. this.call(open_id, res.userInfo);
  667. }
  668. });
  669. }
  670. }
  671. });
  672. },
  673. // 开始
  674. isStarts(e) {
  675. if (this.info.free.activity_status == 'NoBegin') {
  676. this.queryTaskInfo(this.id);
  677. }
  678. },
  679. // 结束
  680. isEnd(e) {
  681. if (this.info.free.activity_status == 'OnGoing') {
  682. this.jumpEnd();
  683. }
  684. },
  685. setData: function (obj) {
  686. let that = this;
  687. let keys = [];
  688. let val, data;
  689. Object.keys(obj).forEach(function (key) {
  690. keys = key.split('.');
  691. val = obj[key];
  692. data = that.$data;
  693. keys.forEach(function (key2, index) {
  694. if (index + 1 == keys.length) {
  695. that.$set(data, key2, val);
  696. } else {
  697. if (!data[key2]) {
  698. that.$set(data, key2, {});
  699. }
  700. }
  701. data = data[key2];
  702. });
  703. });
  704. }
  705. },
  706. computed: {},
  707. watch: {}
  708. };
  709. </script>
  710. <style rel="stylesheet/less" lang="less">
  711. @import "shareCall";
  712. </style>