lottery.vue 18 KB

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