lottery.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. };
  145. },
  146. onShow() {
  147. // 没有数据的话,或者请求中,不允许刷新
  148. if (this.isReqing) return;
  149. // 登录提示
  150. if (!this.$checkAccess.alterLogin()) return;
  151. // 如果存在产品ID的话
  152. if (this.requestParam.id > 0) {
  153. // 设置请求中
  154. this.isReqing = true;
  155. // 请求
  156. this.$http.request("api/lottery_order/get_detail", this.requestParam).then((re) => {
  157. // 设置非请求中
  158. this.isReqing = false;
  159. // 成功结果
  160. if (re.code == "success") {
  161. this.lotteryInfo = re.data;
  162. this.prizeList = re.data.reward_list;
  163. } else {
  164. if (re.code != "no_login") {
  165. uni.showModal({
  166. content: re.msg,
  167. showCancel: false,
  168. });
  169. }
  170. }
  171. });
  172. } else {
  173. uni.showModal({
  174. content: "未知的活动ID",
  175. showCancel: false,
  176. });
  177. }
  178. },
  179. methods: {
  180. onDone(index) {
  181. // 奖项
  182. let prize = this.prizeList[index];
  183. // 结果
  184. uni.showModal({
  185. title: prize.id == 0 ? "很遗憾" : "恭喜您",
  186. content: (prize.id != 0 ? `获得` : "") + prize.name + (prize.reward_type == 5 ? ",请在中奖记录中填写收货地址" : ""),
  187. showCancel: false,
  188. success: (re) => {
  189. if (re.confirm && prize.reward_type == 5) {
  190. // 显示中奖列表
  191. this.showRecord();
  192. }
  193. },
  194. });
  195. },
  196. onClick() {
  197. // 活动是否开始
  198. if (!this.lotteryInfo.id) {
  199. uni.showToast({
  200. title: "暂无可参与活动",
  201. icon: "none",
  202. });
  203. return;
  204. }
  205. // 活动是否开始
  206. if (this.lotteryInfo.start_time * 1000 > new Date().getTime()) {
  207. uni.showToast({
  208. title: "活动还没开始哦",
  209. icon: "none",
  210. });
  211. return;
  212. }
  213. // 活动是否结束
  214. if (this.lotteryInfo.end_time * 1000 <= new Date().getTime()) {
  215. uni.showToast({
  216. title: "活动已结束了哦",
  217. icon: "none",
  218. });
  219. return;
  220. }
  221. // 次数已用完了
  222. if (this.lotteryInfo.join_num <= 0) {
  223. uni.showToast({
  224. title: "次数已用完了",
  225. icon: "none",
  226. });
  227. return;
  228. }
  229. // 次数操作
  230. this.lotteryInfo.join_num = this.lotteryInfo.join_num - 1;
  231. // 请求列表
  232. this.$http.request("/api/lottery_order/get_reward", { lottery_id: this.lotteryInfo.id }).then((re) => {
  233. // 设置非请求中
  234. this.isReqing = false;
  235. // 成功结果
  236. if (re.code == "success") {
  237. // 奖品列表更新
  238. this.prizeList = re.data.reward_list;
  239. // 奖品的索引
  240. return this.$refs.dialer.run(re.data.reward_index);
  241. } else {
  242. uni.showToast({
  243. title: re.msg,
  244. icon: "none",
  245. });
  246. return;
  247. }
  248. });
  249. },
  250. showRule() {
  251. this.$refs.lotteryRule.open("center");
  252. },
  253. closeRule() {
  254. this.$refs.lotteryRule.close();
  255. },
  256. showRecord() {
  257. // 活动是否开始
  258. if (this.lotteryInfo.id) {
  259. // 请求列表
  260. this.$http.request("/api/lottery_order_record/get_list", { lottery_id: this.lotteryInfo.id }).then((re) => {
  261. // 设置非请求中
  262. this.isReqing = false;
  263. // 成功结果
  264. if (re.code == "success") {
  265. this.recordList = re.data;
  266. }
  267. });
  268. }
  269. this.$refs.lotteryRecord.open("bottom");
  270. },
  271. closeRecord() {
  272. this.$refs.lotteryRecord.close();
  273. },
  274. openAddr(index) {
  275. // 选择的下标
  276. this.recordIndex = index;
  277. // 地址列表
  278. this.getAddrList(true);
  279. },
  280. // 选择地址
  281. checkedAddrItem(item) {
  282. // 判断数据
  283. this.$http.request("api/lottery_order_record/set_addr", { id: this.recordList[this.recordIndex].id, addr_id: item.id }, "post").then((callback) => {
  284. // 获取成功
  285. if (callback.code == "success") {
  286. this.recordList[this.recordIndex].status = 1;
  287. this.recordList[this.recordIndex].state = "进行中";
  288. }
  289. this.$refs.addrPopup.close();
  290. });
  291. },
  292. getAddrList(showPopup = false) {
  293. // 判断数据
  294. this.$http.request("api/custom_addr/get_list").then((callback) => {
  295. // 获取成功
  296. if (callback.code == "success") {
  297. this.addrList = callback.data;
  298. // 如果有的话
  299. if (this.addrList.length) {
  300. // 获取默认的
  301. for (let i in this.addrList) {
  302. // 如果是默认的
  303. if (this.addrList[i].is_default) this.checkedAddr = this.addrList[i];
  304. }
  305. // 如果没有默认的话
  306. if (!this.checkedAddr.id) {
  307. this.checkedAddr = this.addrList[this.addrList.length - 1];
  308. }
  309. }
  310. // 弹出地址层
  311. if (showPopup) this.$refs.addrPopup.open("bottom");
  312. }
  313. });
  314. },
  315. },
  316. };
  317. </script>
  318. <style lang="less">
  319. .lottery_box {
  320. display: block;
  321. width: 750rpx;
  322. height: 1100rpx;
  323. margin: 0 auto;
  324. position: relative;
  325. background: linear-gradient(to bottom, #fc335f 0%, #fb7224 80%, #ffffff 100%);
  326. .lottery_time {
  327. top: 0rpx;
  328. left: 35rpx;
  329. z-index: 1;
  330. width: 700rpx;
  331. color: #ffffff;
  332. display: block;
  333. height: 40rpx;
  334. font-size: 24rpx;
  335. line-height: 40rpx;
  336. text-align: center;
  337. position: absolute;
  338. border-radius: 10rpx;
  339. background-color: rgba(0, 0, 0, 0.15);
  340. }
  341. .lottery_info {
  342. width: 750rpx;
  343. height: 240rpx;
  344. overflow: hidden;
  345. margin: 0rpx auto;
  346. position: relative;
  347. margin-bottom: 40rpx;
  348. .lottery_logo {
  349. float: left;
  350. width: 750rpx;
  351. height: 240rpx;
  352. display: block;
  353. }
  354. .lottery_rule_btn {
  355. top: 50%;
  356. right: 0rpx;
  357. width: 120rpx;
  358. height: 60rpx;
  359. color: #ffffff;
  360. overflow: hidden;
  361. font-size: 24rpx;
  362. text-align: center;
  363. line-height: 60rpx;
  364. position: absolute;
  365. padding: 0rpx 0rpx;
  366. border-top-left-radius: 30rpx;
  367. border-bottom-left-radius: 30rpx;
  368. border-top-right-radius: 0rpx;
  369. border-bottom-right-radius: 0rpx;
  370. background-color: rgba(0, 0, 0, 0.3);
  371. }
  372. .lottery_rule_btn::after {
  373. border: 0rpx solid transparent;
  374. }
  375. }
  376. .record_box {
  377. display: block;
  378. height: 120rpx;
  379. overflow: hidden;
  380. position: relative;
  381. margin-top: 40rpx;
  382. .score_info {
  383. display: block;
  384. overflow: auto;
  385. .custom_score {
  386. height: 60rpx;
  387. font-size: 28rpx;
  388. text-align: center;
  389. line-height: 60rpx;
  390. }
  391. .need_score {
  392. height: 60rpx;
  393. font-size: 32rpx;
  394. text-align: center;
  395. line-height: 60rpx;
  396. }
  397. }
  398. .lottery_record {
  399. top: 0rpx;
  400. right: 0rpx;
  401. width: 120rpx;
  402. height: 120rpx;
  403. overflow: hidden;
  404. text-align: center;
  405. position: absolute;
  406. padding: 0rpx 0rpx;
  407. background-color: transparent;
  408. .lottery_record_img {
  409. width: 60rpx;
  410. height: 60rpx;
  411. display: block;
  412. margin: 0rpx auto;
  413. }
  414. .lottery_record_text {
  415. color: #ffffff;
  416. display: block;
  417. height: 40rpx;
  418. width: 120rpx;
  419. font-size: 24rpx;
  420. line-height: 40rpx;
  421. }
  422. }
  423. .lottery_record::after {
  424. border: none;
  425. }
  426. }
  427. }
  428. .lottery_rule_box {
  429. width: 500rpx;
  430. display: block;
  431. overflow: hidden;
  432. background: #ffffff;
  433. font-size: 26rpx;
  434. margin: 0rpx auto;
  435. line-height: 50rpx;
  436. border-radius: 10rpx;
  437. padding: 0rpx 25rpx;
  438. padding-bottom: 20rpx;
  439. background-color: #fc335f;
  440. .lottery_rule_title {
  441. color: #ffffff;
  442. height: 60rpx;
  443. font-size: 32rpx;
  444. line-height: 60rpx;
  445. text-align: center;
  446. margin-bottom: 10rpx;
  447. .close_btn {
  448. float: right;
  449. width: 40rpx;
  450. height: 40rpx;
  451. font-size: 24rpx;
  452. margin-top: 9rpx;
  453. line-height: 40rpx;
  454. border-radius: 50%;
  455. border: 1rpx solid #ffffff;
  456. }
  457. }
  458. .lottery_rule_info {
  459. display: block;
  460. height: 500rpx;
  461. font-size: 24rpx;
  462. line-height: 40rpx;
  463. border-radius: 10rpx;
  464. padding: 20rpx 20rpx;
  465. box-sizing: border-box;
  466. background-color: #ffffff;
  467. .rich_text {
  468. white-space: break-spaces;
  469. }
  470. }
  471. }
  472. .lottery_record_box {
  473. display: block;
  474. color: #deb887;
  475. height: 700rpx;
  476. padding: 10rpx 25rpx;
  477. background-color: #faebd7;
  478. .lottery_record_title {
  479. color: #000000;
  480. height: 80rpx;
  481. font-weight: bold;
  482. font-size: 32rpx;
  483. line-height: 80rpx;
  484. text-align: center;
  485. margin-bottom: 20rpx;
  486. .close_btn {
  487. float: right;
  488. width: 40rpx;
  489. height: 40rpx;
  490. color: #deb887;
  491. font-size: 24rpx;
  492. margin-top: 9rpx;
  493. line-height: 40rpx;
  494. border-radius: 50%;
  495. border: 2rpx solid #deb887;
  496. }
  497. }
  498. .lottery_record_none {
  499. display: block;
  500. height: 200rpx;
  501. color: #deb887;
  502. font-size: 26rpx;
  503. text-align: center;
  504. line-height: 200rpx;
  505. }
  506. .lottery_record_list {
  507. display: block;
  508. height: 500rpx;
  509. .lottery_record_item {
  510. height: 80rpx;
  511. display: block;
  512. font-size: 26rpx;
  513. overflow: hidden;
  514. line-height: 80rpx;
  515. .reward_time {
  516. float: left;
  517. width: 300rpx;
  518. }
  519. .reward_name {
  520. float: left;
  521. width: 200rpx;
  522. }
  523. .reward_state {
  524. float: right;
  525. }
  526. }
  527. }
  528. }
  529. .popup {
  530. overflow: hidden;
  531. .popup_title {
  532. display: block;
  533. overflow: hidden;
  534. margin: 0rpx auto;
  535. font-size: 36rpx;
  536. height: 120rpx;
  537. line-height: 120rpx;
  538. padding: 0rpx 20rpx;
  539. border-bottom: 10rpx solid #f8f8f8;
  540. .to_addr_page {
  541. float: right;
  542. color: #f59a23;
  543. display: block;
  544. height: 120rpx;
  545. line-height: 120rpx;
  546. font-size: 26rpx;
  547. padding: 0rpx 10rpx;
  548. }
  549. }
  550. .addr_list {
  551. width: 730rpx;
  552. display: block;
  553. overflow: hidden;
  554. margin: 0rpx auto;
  555. min-height: 500rpx;
  556. .addr_item {
  557. display: block;
  558. font-size: 24rpx;
  559. overflow: hidden;
  560. line-height: 40rpx;
  561. padding: 15rpx 10rpx;
  562. border-radius: 15rpx;
  563. border-bottom: 2rpx solid #dddddd;
  564. .radio_label {
  565. width: 40rpx;
  566. float: left;
  567. height: 50rpx;
  568. padding-top: 30rpx;
  569. margin-right: 20rpx;
  570. .radio_icon {
  571. float: left;
  572. width: 40rpx;
  573. height: 40rpx;
  574. }
  575. }
  576. .contact_user {
  577. float: left;
  578. width: 640rpx;
  579. display: block;
  580. height: 50rpx;
  581. font-size: 24rpx;
  582. line-height: 50rpx;
  583. .contact_name {
  584. font-size: 26rpx;
  585. font-weight: bold;
  586. margin-right: 16rpx;
  587. }
  588. .contact_default {
  589. color: #f59a23;
  590. font-size: 20rpx;
  591. margin-left: 16rpx;
  592. border: 1rpx solid #f59a23;
  593. }
  594. .contact_shop {
  595. float: right;
  596. font-size: 26rpx;
  597. margin-right: 16rpx;
  598. }
  599. }
  600. .contact_addr {
  601. float: left;
  602. width: 640rpx;
  603. display: block;
  604. font-size: 24rpx;
  605. line-height: 30rpx;
  606. padding: 10rpx 5rpx;
  607. }
  608. }
  609. }
  610. .create_box {
  611. height: 140rpx;
  612. display: block;
  613. .create_addr {
  614. width: 700rpx;
  615. height: 80rpx;
  616. display: block;
  617. color: #ffffff;
  618. font-size: 30rpx;
  619. overflow: hidden;
  620. line-height: 80rpx;
  621. padding: 0rpx 0rpx;
  622. text-align: center;
  623. margin: 0rpx auto;
  624. margin-top: 20rpx;
  625. border-radius: 40rpx;
  626. background-color: #e03519;
  627. }
  628. }
  629. }
  630. </style>