lottery.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <template>
  2. <view>
  3. <view class="lottery_box" :style="height">
  4. <view class="lottery_time" v-if="lotteryInfo.id">活动时间:{{ lotteryInfo.start_date }} ~ {{ lotteryInfo.end_date }}</view>
  5. <view class="lottery_info">
  6. <image class="lottery_logo" v-if="lotteryInfo.logo" :src="lotteryInfo.logo" mode="widthFix"></image>
  7. <button class="lottery_rule_btn" @click="showRule">活动规则</button>
  8. </view>
  9. <l-dialer
  10. :customStyle="'width: 500rpx;height: 500rpx;margin: 0rpx auto;'"
  11. @click="onClick"
  12. dial-style="color: rgba(60,48,158,0.7); padding: 32rpx;background-image: url(https://mall.findit.ltd/uploads/images/default/lottery_bg.png)"
  13. :prizeList="prizeList"
  14. :turns="5"
  15. :duration="5"
  16. @done="onDone"
  17. ref="dialer"
  18. />
  19. <view class="record_box">
  20. <view class="score_info">
  21. <view class="custom_score">可用次数:{{ lotteryInfo.number }}</view>
  22. <view class="need_score" v-if="!lotteryInfo.id">暂无可参与的活动</view>
  23. </view>
  24. <button class="lottery_record" @click="showRecord" v-if="lotteryInfo.id">
  25. <image class="lottery_record_img" src="https://mall.findit.ltd/uploads/images/default/lottery_record.png" mode=""></image>
  26. <text class="lottery_record_text">中奖记录</text>
  27. </button>
  28. </view>
  29. <button open-type="share" class="share-btn">分享好友再答一次题</button>
  30. </view>
  31. <uni-popup ref="lotteryRule" type="center">
  32. <view class="lottery_rule_box">
  33. <view class="lottery_rule_title">
  34. <text>活动规则</text>
  35. <view class="close_btn" @click="closeRule"> X </view>
  36. </view>
  37. <scroll-view class="lottery_rule_info" scroll-y="true">
  38. <rich-text :nodes="lotteryInfo.rule" class="rich_text"></rich-text>
  39. </scroll-view>
  40. </view>
  41. </uni-popup>
  42. <uni-popup ref="lotteryRecord" type="bottom">
  43. <view class="lottery_record_box">
  44. <view class="lottery_record_title">
  45. <text>我的奖品</text>
  46. <view class="close_btn" @click="closeRecord"> X </view>
  47. </view>
  48. <view class="lottery_record_none" v-if="!recordList.length">这里还是空的哦~</view>
  49. <scroll-view class="lottery_record_list" scroll-y="true">
  50. <view class="lottery_record_item" v-for="(item, index) in recordList" :key="index">
  51. <view class="reward_time">{{ item.insert_time }}</view>
  52. <view class="reward_name">{{ item.reward_name }}</view>
  53. <view class="reward_state" v-if="item.status">{{ item.state }}</view>
  54. <view class="reward_state" v-if="!item.status" @click="openAddr(index)">{{ item.state }}</view>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. </uni-popup>
  59. <uni-popup ref="addrPopup" type="bottom" class="popup" background-color="#FFFFFF">
  60. <view class="popup_title">收货地址 <navigator url="/pages/addr/index?notify=addr" class="to_addr_page">管理</navigator> </view>
  61. <view class="addr_list">
  62. <view class="addr_item" v-for="(item, index) in addrList" :key="index" @click="checkedAddrItem(item)">
  63. <view class="radio_label">
  64. <image
  65. class="radio_icon"
  66. :src="item.id == checkedAddr.id ? 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/radioed.png' : 'https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/radio.png'"
  67. ></image>
  68. </view>
  69. <view class="contact_user">
  70. <text class="contact_name">{{ item.contact_name }}</text>
  71. <text class="contact_phone">{{ item.contact_phone }}</text>
  72. <text class="contact_default" v-if="item.is_default">默认</text>
  73. <text class="contact_shop">{{ item.contact_shop }}</text>
  74. </view>
  75. <view class="contact_addr"> {{ item.contact_province }} {{ item.contact_city }} {{ item.contact_area }} {{ item.contact_addr }} </view>
  76. </view>
  77. </view>
  78. <view class="create_box">
  79. <navigator url="/pages/addr/index?notify=addr&type=create" class="create_addr">新建收货地址</navigator>
  80. </view>
  81. </uni-popup>
  82. </view>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. height: "",
  89. // 奖项列表,
  90. prizeList: [],
  91. // 中奖记录
  92. recordList: [],
  93. // 地址列表
  94. addrList: [],
  95. // 抽奖信息
  96. lotteryInfo: {
  97. id: 0,
  98. name: "",
  99. logo: "",
  100. number: "0",
  101. start_date: "",
  102. end_date: "",
  103. start_time: "",
  104. end_time: "",
  105. rule: "",
  106. },
  107. recordId: 0,
  108. // 请求参数
  109. requestParam: {
  110. id: 0,
  111. activity_id: 0,
  112. },
  113. };
  114. },
  115. onLoad(param) {
  116. // 接收参数
  117. this.requestParam.id = param.id;
  118. this.requestParam.activity_id = param.activity_id;
  119. // 如果有scene参数的话,获取其中的ID
  120. if (param.scene) {
  121. // 转键值对参数
  122. let scene = this.$http.strToParam(param.scene);
  123. // 如果没有传入ID,但是传入了场景ID,获取场景ID
  124. if (!param.id && scene.id) this.requestParam.id = scene.id;
  125. }
  126. // 窗口信息
  127. var sysinfo = uni.getWindowInfo();
  128. // 获取屏幕可用高度
  129. this.height = "height:" + sysinfo.windowHeight + "px;";
  130. // 监听地址变动
  131. uni.$on("addr_list_change", (data) => {
  132. // 地址列表
  133. this.addrList = data.list;
  134. });
  135. // #ifdef MP-WEIXIN
  136. //分享按钮
  137. uni.showShareMenu({
  138. withShareTicket: true,
  139. menus: ["shareAppMessage", "shareTimeline"],
  140. });
  141. // #endif
  142. },
  143. onShareAppMessage(obj) {
  144. if (obj) {
  145. this.shareRequest();
  146. }
  147. return {
  148. title: "正月十五猜灯谜",
  149. path: "/pages/activity/index?id=" + this.requestParam.activity_id,
  150. };
  151. },
  152. onShow() {
  153. // 没有数据的话,或者请求中,不允许刷新
  154. if (this.isReqing) return;
  155. // 登录提示
  156. if (!this.$checkAccess.alterLogin()) return;
  157. // 如果存在产品ID的话
  158. if (this.requestParam.id > 0) {
  159. // 设置请求中
  160. this.isReqing = true;
  161. // 请求
  162. this.$http.request("api/lottery_riddle/get_detail", this.requestParam).then((re) => {
  163. // 设置非请求中
  164. this.isReqing = false;
  165. // 成功结果
  166. if (re.code == "success") {
  167. this.lotteryInfo = re.data;
  168. this.prizeList = re.data.reward_list;
  169. } else {
  170. if (re.code != "no_login") {
  171. uni.showModal({
  172. content: re.msg,
  173. showCancel: false,
  174. });
  175. }
  176. }
  177. });
  178. } else {
  179. uni.showModal({
  180. content: "未知的活动ID",
  181. showCancel: false,
  182. });
  183. }
  184. },
  185. methods: {
  186. shareRequest() {
  187. this.$http.request("api/riddle_active_share/add", { active_id: this.requestParam.activity_id }).then((response) => {});
  188. },
  189. onDone(index) {
  190. // 奖项
  191. let prize = this.prizeList[index];
  192. // 结果
  193. uni.showModal({
  194. title: prize.id == 0 ? "很遗憾" : "恭喜您",
  195. content: (prize.id != 0 ? `获得` : "") + prize.name + (prize.reward_type == 5 ? ",请在中奖记录中填写收货地址" : ""),
  196. showCancel: false,
  197. success: (re) => {
  198. if (re.confirm && prize.reward_type == 5) {
  199. // 显示中奖列表
  200. this.showRecord();
  201. }
  202. },
  203. });
  204. },
  205. onClick() {
  206. // 活动是否开始
  207. if (!this.lotteryInfo.id) {
  208. uni.showToast({
  209. title: "暂无可参与活动",
  210. icon: "none",
  211. });
  212. return;
  213. }
  214. // 活动是否开始
  215. if (this.lotteryInfo.start_time * 1000 > new Date().getTime()) {
  216. uni.showToast({
  217. title: "活动还没开始哦",
  218. icon: "none",
  219. });
  220. return;
  221. }
  222. // 活动是否结束
  223. if (this.lotteryInfo.end_time * 1000 <= new Date().getTime()) {
  224. uni.showToast({
  225. title: "活动已结束了哦",
  226. icon: "none",
  227. });
  228. return;
  229. }
  230. // 次数已用完了
  231. if (this.lotteryInfo.number <= 0) {
  232. uni.showToast({
  233. title: "次数已用完了",
  234. icon: "none",
  235. });
  236. return;
  237. }
  238. // 次数操作
  239. this.lotteryInfo.number = this.lotteryInfo.number - 1;
  240. // 请求列表
  241. this.$http.request("/api/lottery_riddle/get_reward", { lottery_id: this.lotteryInfo.id }).then((re) => {
  242. // 设置非请求中
  243. this.isReqing = false;
  244. // 成功结果
  245. if (re.code == "success") {
  246. // 奖品列表更新
  247. this.prizeList = re.data.reward_list;
  248. // 奖品的索引
  249. return this.$refs.dialer.run(re.data.reward_index);
  250. } else {
  251. uni.showToast({
  252. title: re.msg,
  253. icon: "none",
  254. });
  255. return;
  256. }
  257. });
  258. },
  259. showRule() {
  260. this.$refs.lotteryRule.open("center");
  261. },
  262. closeRule() {
  263. this.$refs.lotteryRule.close();
  264. },
  265. showRecord() {
  266. // 活动是否开始
  267. if (this.lotteryInfo.id) {
  268. // 请求列表
  269. this.$http.request("/api/lottery_riddle_record/get_list", { lottery_id: this.lotteryInfo.id }).then((re) => {
  270. // 设置非请求中
  271. this.isReqing = false;
  272. // 成功结果
  273. if (re.code == "success") {
  274. this.recordList = re.data;
  275. }
  276. });
  277. }
  278. this.$refs.lotteryRecord.open("bottom");
  279. },
  280. closeRecord() {
  281. this.$refs.lotteryRecord.close();
  282. },
  283. openAddr(index) {
  284. // 选择的下标
  285. this.recordIndex = index;
  286. // 地址列表
  287. this.getAddrList(true);
  288. },
  289. // 选择地址
  290. checkedAddrItem(item) {
  291. // 判断数据
  292. this.$http.request("api/lottery_riddle_record/set_addr", { id: this.recordList[this.recordIndex].id, addr_id: item.id }, "post").then((callback) => {
  293. // 获取成功
  294. if (callback.code == "success") {
  295. this.recordList[this.recordIndex].status = 1;
  296. this.recordList[this.recordIndex].state = "进行中";
  297. }
  298. this.$refs.addrPopup.close();
  299. });
  300. },
  301. getAddrList(showPopup = false) {
  302. // 判断数据
  303. this.$http.request("api/custom_addr/get_list").then((callback) => {
  304. // 获取成功
  305. if (callback.code == "success") {
  306. this.addrList = callback.data;
  307. // 如果有的话
  308. if (this.addrList.length) {
  309. // 获取默认的
  310. for (let i in this.addrList) {
  311. // 如果是默认的
  312. if (this.addrList[i].is_default) this.checkedAddr = this.addrList[i];
  313. }
  314. // 如果没有默认的话
  315. if (!this.checkedAddr.id) {
  316. this.checkedAddr = this.addrList[this.addrList.length - 1];
  317. }
  318. }
  319. // 弹出地址层
  320. if (showPopup) this.$refs.addrPopup.open("bottom");
  321. }
  322. });
  323. },
  324. },
  325. };
  326. </script>
  327. <style lang="less">
  328. .lottery_box {
  329. display: block;
  330. width: 750rpx;
  331. height: 1100rpx;
  332. margin: 0 auto;
  333. position: relative;
  334. background: linear-gradient(to bottom, #fc335f 0%, #fb7224 80%, #ffffff 100%);
  335. .share-btn {
  336. width: 80%;
  337. height: 80rpx;
  338. background-color: #f0370e;
  339. color: #fff;
  340. border-radius: 60rpx;
  341. display: flex;
  342. justify-content: center;
  343. align-items: center;
  344. padding: 16rpx;
  345. margin-top: 60rpx;
  346. box-sizing: border-box;
  347. }
  348. .lottery_time {
  349. top: 0rpx;
  350. left: 35rpx;
  351. z-index: 1;
  352. width: 700rpx;
  353. color: #ffffff;
  354. display: block;
  355. height: 40rpx;
  356. font-size: 24rpx;
  357. line-height: 40rpx;
  358. text-align: center;
  359. position: absolute;
  360. border-radius: 10rpx;
  361. background-color: rgba(0, 0, 0, 0.15);
  362. }
  363. .lottery_info {
  364. width: 750rpx;
  365. overflow: hidden;
  366. margin: 0rpx auto;
  367. position: relative;
  368. margin-bottom: 40rpx;
  369. .lottery_logo {
  370. float: left;
  371. width: 750rpx;
  372. height: 240rpx;
  373. display: block;
  374. }
  375. .lottery_rule_btn {
  376. top: 50%;
  377. right: 0rpx;
  378. width: 120rpx;
  379. height: 60rpx;
  380. color: #ffffff;
  381. overflow: hidden;
  382. font-size: 24rpx;
  383. text-align: center;
  384. line-height: 60rpx;
  385. position: absolute;
  386. padding: 0rpx 0rpx;
  387. border-top-left-radius: 30rpx;
  388. border-bottom-left-radius: 30rpx;
  389. border-top-right-radius: 0rpx;
  390. border-bottom-right-radius: 0rpx;
  391. background-color: rgba(0, 0, 0, 0.3);
  392. }
  393. .lottery_rule_btn::after {
  394. border: 0rpx solid transparent;
  395. }
  396. }
  397. .record_box {
  398. display: block;
  399. height: 120rpx;
  400. overflow: hidden;
  401. position: relative;
  402. margin-top: 40rpx;
  403. .score_info {
  404. display: block;
  405. overflow: auto;
  406. .custom_score {
  407. height: 60rpx;
  408. font-size: 28rpx;
  409. text-align: center;
  410. line-height: 60rpx;
  411. }
  412. .need_score {
  413. height: 60rpx;
  414. font-size: 32rpx;
  415. text-align: center;
  416. line-height: 60rpx;
  417. }
  418. }
  419. .lottery_record {
  420. top: 0rpx;
  421. right: 0rpx;
  422. width: 120rpx;
  423. height: 120rpx;
  424. overflow: hidden;
  425. text-align: center;
  426. position: absolute;
  427. padding: 0rpx 0rpx;
  428. background-color: transparent;
  429. .lottery_record_img {
  430. width: 60rpx;
  431. height: 60rpx;
  432. display: block;
  433. margin: 0rpx auto;
  434. }
  435. .lottery_record_text {
  436. color: #ffffff;
  437. display: block;
  438. height: 40rpx;
  439. width: 120rpx;
  440. font-size: 24rpx;
  441. line-height: 40rpx;
  442. }
  443. }
  444. .lottery_record::after {
  445. border: none;
  446. }
  447. }
  448. }
  449. .lottery_rule_box {
  450. width: 500rpx;
  451. display: block;
  452. overflow: hidden;
  453. background: #ffffff;
  454. font-size: 26rpx;
  455. margin: 0rpx auto;
  456. line-height: 50rpx;
  457. border-radius: 10rpx;
  458. padding: 0rpx 25rpx;
  459. padding-bottom: 20rpx;
  460. background-color: #fc335f;
  461. .lottery_rule_title {
  462. color: #ffffff;
  463. height: 60rpx;
  464. font-size: 32rpx;
  465. line-height: 60rpx;
  466. text-align: center;
  467. margin-bottom: 10rpx;
  468. .close_btn {
  469. float: right;
  470. width: 40rpx;
  471. height: 40rpx;
  472. font-size: 24rpx;
  473. margin-top: 9rpx;
  474. line-height: 40rpx;
  475. border-radius: 50%;
  476. border: 1rpx solid #ffffff;
  477. }
  478. }
  479. .lottery_rule_info {
  480. display: block;
  481. height: 500rpx;
  482. font-size: 24rpx;
  483. line-height: 40rpx;
  484. border-radius: 10rpx;
  485. padding: 20rpx 20rpx;
  486. box-sizing: border-box;
  487. background-color: #ffffff;
  488. .rich_text {
  489. white-space: break-spaces;
  490. }
  491. }
  492. }
  493. .lottery_record_box {
  494. display: block;
  495. color: #deb887;
  496. height: 700rpx;
  497. padding: 10rpx 25rpx;
  498. background-color: #faebd7;
  499. .lottery_record_title {
  500. color: #000000;
  501. height: 80rpx;
  502. font-weight: bold;
  503. font-size: 32rpx;
  504. line-height: 80rpx;
  505. text-align: center;
  506. margin-bottom: 20rpx;
  507. .close_btn {
  508. float: right;
  509. width: 40rpx;
  510. height: 40rpx;
  511. color: #deb887;
  512. font-size: 24rpx;
  513. margin-top: 9rpx;
  514. line-height: 40rpx;
  515. border-radius: 50%;
  516. border: 2rpx solid #deb887;
  517. }
  518. }
  519. .lottery_record_none {
  520. display: block;
  521. height: 200rpx;
  522. color: #deb887;
  523. font-size: 26rpx;
  524. text-align: center;
  525. line-height: 200rpx;
  526. }
  527. .lottery_record_list {
  528. display: block;
  529. height: 500rpx;
  530. .lottery_record_item {
  531. height: 80rpx;
  532. display: block;
  533. font-size: 26rpx;
  534. overflow: hidden;
  535. line-height: 80rpx;
  536. .reward_time {
  537. float: left;
  538. width: 300rpx;
  539. }
  540. .reward_name {
  541. float: left;
  542. width: 200rpx;
  543. }
  544. .reward_state {
  545. float: right;
  546. }
  547. }
  548. }
  549. }
  550. .popup {
  551. overflow: hidden;
  552. .popup_title {
  553. display: block;
  554. overflow: hidden;
  555. margin: 0rpx auto;
  556. font-size: 36rpx;
  557. height: 120rpx;
  558. line-height: 120rpx;
  559. padding: 0rpx 20rpx;
  560. border-bottom: 10rpx solid #f8f8f8;
  561. .to_addr_page {
  562. float: right;
  563. color: #f59a23;
  564. display: block;
  565. height: 120rpx;
  566. line-height: 120rpx;
  567. font-size: 26rpx;
  568. padding: 0rpx 10rpx;
  569. }
  570. }
  571. .addr_list {
  572. width: 730rpx;
  573. display: block;
  574. overflow: hidden;
  575. margin: 0rpx auto;
  576. min-height: 500rpx;
  577. .addr_item {
  578. display: block;
  579. font-size: 24rpx;
  580. overflow: hidden;
  581. line-height: 40rpx;
  582. padding: 15rpx 10rpx;
  583. border-radius: 15rpx;
  584. border-bottom: 2rpx solid #dddddd;
  585. .radio_label {
  586. width: 40rpx;
  587. float: left;
  588. height: 50rpx;
  589. padding-top: 30rpx;
  590. margin-right: 20rpx;
  591. .radio_icon {
  592. float: left;
  593. width: 40rpx;
  594. height: 40rpx;
  595. }
  596. }
  597. .contact_user {
  598. float: left;
  599. width: 640rpx;
  600. display: block;
  601. height: 50rpx;
  602. font-size: 24rpx;
  603. line-height: 50rpx;
  604. .contact_name {
  605. font-size: 26rpx;
  606. font-weight: bold;
  607. margin-right: 16rpx;
  608. }
  609. .contact_default {
  610. color: #f59a23;
  611. font-size: 20rpx;
  612. margin-left: 16rpx;
  613. border: 1rpx solid #f59a23;
  614. }
  615. .contact_shop {
  616. float: right;
  617. font-size: 26rpx;
  618. margin-right: 16rpx;
  619. }
  620. }
  621. .contact_addr {
  622. float: left;
  623. width: 640rpx;
  624. display: block;
  625. font-size: 24rpx;
  626. line-height: 30rpx;
  627. padding: 10rpx 5rpx;
  628. }
  629. }
  630. }
  631. .create_box {
  632. height: 140rpx;
  633. display: block;
  634. .create_addr {
  635. width: 700rpx;
  636. height: 80rpx;
  637. display: block;
  638. color: #ffffff;
  639. font-size: 30rpx;
  640. overflow: hidden;
  641. line-height: 80rpx;
  642. padding: 0rpx 0rpx;
  643. text-align: center;
  644. margin: 0rpx auto;
  645. margin-top: 20rpx;
  646. border-radius: 40rpx;
  647. background-color: #e03519;
  648. }
  649. }
  650. }
  651. </style>