lottery.vue 17 KB

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