lottery.vue 17 KB

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