index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <div class="container share-activity-page">
  3. <div class="poster-panel" :style="{'background-image':bgimg }"></div>
  4. <div class="info-panel">
  5. <div class="title">{{info.detail}}</div>
  6. <div class="info-text">
  7. TA 得9.9元秒杀券 <span class="red-text">{{info.title}}</span>
  8. </div>
  9. <div class="invite-btn">
  10. <div>
  11. <van-button v-if="isLogin&&isUserinfo" round block type="danger" size="small" open-type="share">分享给好友</van-button>
  12. <van-button v-if="!isLogin||!isUserinfo" round block type="danger" size="small" @click="setAuth()">分享给好友</van-button>
  13. </div>
  14. <div>
  15. <van-button v-if="isLogin&&isUserinfo" round block type="info" size="small" @click="creatShareImage()">分享到朋友圈</van-button>
  16. <van-button v-if="!isLogin||!isUserinfo" round block type="info" size="small" @click="setAuth()">分享到朋友圈</van-button>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="coupon-panel" v-if="coupons.length">
  21. <div class="art-title">我的奖励</div>
  22. <div class="coupon" v-for="coupon in coupons" :key="coupon.id" :class="{'nuse': coupon.status === '0' , 'paed': coupon.status === '2'}">
  23. <div class="coupen--status">
  24. {{coupon.tag}}
  25. </div>
  26. <div class="coupen_content">
  27. <div class="left">
  28. <div class="title">{{coupon.name}}</div>
  29. <div class="desc">有效期至{{coupon.expiryDate}}</div>
  30. </div>
  31. <div class="right" @click="couponClickHandle(coupon)">
  32. {{coupon.btnText}}
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="rule-panel">
  38. <div class="rule-info">
  39. <div class="art-title">活动规则说明</div>
  40. <div v-for="(remark, index) in info.remarks" :key="index" class="remark-row">
  41. {{remark}}
  42. </div>
  43. </div>
  44. </div>
  45. <van-dialog :show="authUser" confirm-button-open-type="getUserInfo" transition="none" confirmButtonText="确认授权" @getuserinfo="onGotUserInfo" message="为了方便领取9.9元秒杀券, 我们需要您得用户信息">
  46. <div></div>
  47. </van-dialog>
  48. <van-dialog :show="authPhone" confirm-button-open-type="getPhoneNumber" transition="none" confirmButtonText="确认授权" @getphonenumber="getPhoneNumber" message="为了方便领取9.9元秒杀券, 我们需要您得手机号码">
  49. <div></div>
  50. </van-dialog>
  51. </div>
  52. </template>
  53. <script>
  54. /**
  55. * getPhone
  56. */
  57. import { getUserInfo, zyycLogin, code2Session, checkLogin } from '@/api/login';
  58. import { getCouponPageData, get15CouponList } from '@/api/api';
  59. import { formatTime } from '@/utils/index';
  60. export default {
  61. name: 'washCar',
  62. data() {
  63. return {
  64. authUser: false,
  65. authPhone: false,
  66. isLogin: false,
  67. isUserinfo: false,
  68. userName: '丘比养车',
  69. userId: '',
  70. coupons: [],
  71. info: {}
  72. };
  73. },
  74. computed: {
  75. bgimg() {
  76. if (this.info.backgroundPic) {
  77. return `url(${this.info.backgroundPic})`;
  78. } else {
  79. return '';
  80. }
  81. }
  82. },
  83. methods: {
  84. setAuth(e) {
  85. if (!this.isLogin) {
  86. this.authPhone = true;
  87. } else {
  88. if (!this.isUserinfo) {
  89. this.authUser = true;
  90. }
  91. }
  92. },
  93. // 生成美图
  94. creatShareImage (){
  95. wx.navigateTo({
  96. url: `/pages/pagesA/creatShareImage/main`
  97. });
  98. },
  99. couponClickHandle(item) {
  100. if (item.status === '1') {
  101. wx.navigateTo({
  102. url: `/pages/placeOrder/main?id=${item.bundId}&couponId=${item.couponId}&customerCouponId=${item.id}`
  103. });
  104. } else if (item.status === '2' || item.status === '3') {
  105. wx.navigateTo({
  106. url: `/pages/orderDetail/main?id=${item.orderBundleId}`
  107. });
  108. }
  109. },
  110. getCouponList() {
  111. get15CouponList().then(res => {
  112. console.log(res,'奖励')
  113. if (res.status == '200') {
  114. const dict = {
  115. '1': ['未使用', '去使用'],
  116. '2': ['已使用', '去查看'],
  117. '3': ['已冻结', '去查看'],
  118. '0': ['已过期', '过期啦']
  119. };
  120. if (res.data) {
  121. let temp = []
  122. res.data.map(item => {
  123. let _date = formatTime(item.expiryDate);
  124. temp.push({
  125. id: item.id,
  126. name: item.coupon.name,
  127. desc: item.coupon.typeName,
  128. nuse: item.status === '1',
  129. bundId: item.bundleLimitList[0].bundId,
  130. tag: dict[item.status][0],
  131. btnText: dict[item.status][1],
  132. status: item.status,
  133. expiryDate: `${_date.year}年${_date.month}月${_date.day}日 ${_date.hour}:${_date.minute}`,
  134. orderBundleId: item.orderBundleId,
  135. couponId: item.couponId
  136. });
  137. });
  138. console.log(temp,'00000')
  139. this.coupons = temp
  140. }else{
  141. this.coupons = []
  142. }
  143. }
  144. });
  145. },
  146. onGotUserInfo(e) {
  147. this.authUser = false; // 打开微信授权页面后,关闭弹窗
  148. if (e.target.errMsg === 'getUserInfo:ok') {
  149. this.authUser = false;
  150. this.userName = e.target.userInfo.nickName;
  151. this.getCurrentUser(e.target);
  152. } else {
  153. wx.showToast({
  154. title: '您没有授权, 无法领取9.9元秒杀券',
  155. icon: 'none',
  156. duration: 2500
  157. });
  158. }
  159. },
  160. getPhoneNumber(e) {
  161. this.authPhone = false;// 打开微信授权页面后,关闭弹窗
  162. const _this = this;
  163. if (e.target.errMsg === 'getPhoneNumber:ok') {
  164. zyycLogin({
  165. openid: wx.getStorageSync('openid'),
  166. encryptedData: e.target.encryptedData,
  167. iv: e.target.iv
  168. }).then(res => {
  169. if (res.status === '200') {
  170. _this.isLogin = true;
  171. wx.setStorageSync('token', res.data.token);
  172. wx.setStorageSync('phone', res.data.phone);
  173. wx.setStorageSync('userId', res.data.userId);
  174. wx.removeStorageSync('openid');
  175. _this.getUserInfoStatus();
  176. _this.getCouponList();
  177. }
  178. });
  179. } else {
  180. wx.showToast({
  181. title: '您没有授权, 无法领取9.9元秒杀券',
  182. icon: 'none',
  183. duration: 1500,
  184. complete: function() {
  185. _this.getUserInfoStatus();
  186. }
  187. });
  188. }
  189. },
  190. getCurrentUser(info) {
  191. this.isUserinfo = true;
  192. if (this.isLogin) { // 登录情况下,更新用户微信信息
  193. getUserInfo(info).then(res => {
  194. if (res.status === '200') {
  195. this.userId = res.data;
  196. this.authUser = false;
  197. }
  198. });
  199. }
  200. },
  201. getUserInfoStatus() {
  202. const _this = this;
  203. wx.getSetting({
  204. success(res) {
  205. if (res.authSetting['scope.userInfo']) {
  206. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  207. wx.getUserInfo({
  208. success: function(res) {
  209. _this.userName = res.userInfo.nickName;
  210. _this.getCurrentUser(res);
  211. }
  212. });
  213. } else {
  214. _this.authUser = true;
  215. }
  216. }
  217. });
  218. }
  219. },
  220. onShareAppMessage() {
  221. if (!this.isLogin) {
  222. this.authPhone = true;
  223. } else {
  224. const { userName, userId } = this;
  225. if(!userId||userId==''){
  226. this.authUser = true;
  227. }else{
  228. let result = {
  229. title: `${userName}邀请您领取9.9元秒杀券`,
  230. path: '/pages/washCar/main?uid=' + userId,
  231. success: function(res) {
  232. wx.showToast({
  233. title: '分享成功了',
  234. icon: 'none',
  235. duration: 2500
  236. });
  237. }
  238. };
  239. if (this.info.backgroundPic) {
  240. result.imageUrl = this.info.backgroundPic;
  241. }
  242. return result;
  243. }
  244. }
  245. },
  246. onShow: function() {
  247. this.authUser = false;
  248. this.authPhone = false;
  249. this.isUserinfo = false;
  250. this.isLogin = false;
  251. const _this = this;
  252. checkLogin().then(res => {
  253. if (res.status === '200') {
  254. _this.getUserInfoStatus();
  255. _this.getCouponList();
  256. _this.isLogin = true;
  257. } else {
  258. _this.authPhone = true;
  259. wx.login({
  260. success(result) {
  261. if (result.code) {
  262. code2Session({
  263. code: result.code
  264. }).then(res => {
  265. wx.hideLoading();
  266. if (res.status === '200') {
  267. wx.setStorageSync('openid', res.data);
  268. };
  269. });
  270. }
  271. }
  272. });
  273. }
  274. });
  275. },
  276. onLoad: function(options) {
  277. wx.setNavigationBarTitle({
  278. title: options.title
  279. })
  280. wx.showLoading({
  281. mask: true,
  282. title: '加载中'
  283. });
  284. getCouponPageData().then(res => {
  285. wx.hideLoading();
  286. if (res.status === '200') {
  287. const result = res.data.filter(item => Math.round(item.couponId) === 900015);
  288. if (result && result.length > 0) {
  289. let info = result[0];
  290. info.remarks = info.remarks.split('$$');
  291. this.info = info;
  292. }
  293. }
  294. });
  295. }
  296. };
  297. </script>
  298. <style lang="stylus">
  299. .container {
  300. height: 100%;
  301. overflow: hidden;
  302. }
  303. .share-activity-page {
  304. .poster-panel {
  305. height: 72vw;
  306. background-repeat: no-repeat;
  307. background-size: 100% 100%;
  308. text-align: center;
  309. color: #fff;
  310. }
  311. .info-panel {
  312. text-align: center;
  313. border: 2rpx solid #dcdee2;
  314. margin: 1em;
  315. padding: 1em 0;
  316. .info-text {
  317. padding: 20rpx 0;
  318. font-size: 0.8em;
  319. }
  320. .red-text {
  321. color: #f44;
  322. }
  323. .invite-btn {
  324. text-align: 'center';
  325. padding: 0 15%;
  326. display: flex;
  327. > div{
  328. width:50%;
  329. padding: 0 2%;
  330. font-size: 1em;
  331. }
  332. }
  333. }
  334. .coupon-panel {
  335. border: 2rpx solid #dcdee2;
  336. margin: 1em;
  337. padding: 1.2em;
  338. color: #515a6e;
  339. .coupen_content {
  340. display: flex;
  341. align-items: stretch;
  342. width: 100%;
  343. }
  344. .left, .right {
  345. display: flex;
  346. justify-content: center;
  347. align-items: center;
  348. padding-top: 12px;
  349. padding-bottom: 12px;
  350. }
  351. .coupon {
  352. position: relative;
  353. overflow: hidden;
  354. border-radius: 0.5em;
  355. }
  356. .coupon + .coupon{
  357. margin-top: 10px;
  358. }
  359. .coupen--status {
  360. font-size: 0.6em;
  361. color: #fff;
  362. position: absolute;
  363. top: 0.75em;
  364. left: -1.5em;
  365. padding-bottom: 1rpx;
  366. transform: rotate(-45deg);
  367. background-color: #EF0006;
  368. width: 6em;
  369. text-align: center;
  370. }
  371. .left {
  372. flex: 1;
  373. flex-direction: column;
  374. background-color: #FBEBBA;
  375. .title {
  376. font-size: 1.1em;
  377. font-weight: bold;
  378. width: 70%;
  379. border-bottom: 1px solid #d3d3d3;
  380. text-align: center;
  381. padding-bottom: 3px;
  382. margin-bottom: 3px;
  383. }
  384. .desc {
  385. font-size: 0.7em;
  386. }
  387. }
  388. .right {
  389. color: #fff;
  390. padding-right: 20px;
  391. padding-left: 20px;
  392. box-sizing: border-box;
  393. background-color: #EF0006;
  394. }
  395. .nuse {
  396. .right, .coupen--status{
  397. background-color: #c5c8ce;
  398. }
  399. }
  400. .paed {
  401. .coupen--status{
  402. background-color: #c5c8ce;
  403. }
  404. }
  405. }
  406. .rule-panel {
  407. box-sizing: border-box;
  408. padding: 0 1em 1em;
  409. .rule-info {
  410. border: 2rpx solid #dcdee2;
  411. padding: 1.2em;
  412. color: #515a6e;
  413. .remark-row {
  414. font-size: 0.9em;
  415. &:before {
  416. content: '●';
  417. font-size: 0.8em;
  418. transform: scale(0.8);
  419. }
  420. }
  421. .remark-row + .remark-row {
  422. margin-top: 5rpx;
  423. }
  424. }
  425. }
  426. .art-title {
  427. color: #17233d;
  428. padding-bottom: 1.5em;
  429. font-size: 1em;
  430. text-align: center;
  431. display: flex;
  432. box-sizing: border-box;
  433. align-items: center;
  434. }
  435. .art-title:before {
  436. content: ' ';
  437. height: 0rpx;
  438. border-bottom: 1px solid #515a6e;
  439. flex: 1;
  440. margin-right: 20px;
  441. position: relative;
  442. top: 2rpx;
  443. }
  444. .art-title:after {
  445. content: ' ';
  446. height: 0rpx;
  447. border-bottom: 1px solid #515a6e;
  448. flex: 1;
  449. margin-left: 20px;
  450. position: relative;
  451. top: 2rpx;
  452. }
  453. .receive-title {
  454. padding: 0 10%;
  455. margin-bottom: 20rpx;
  456. }
  457. }
  458. </style>