blessingsPopup.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <up-popup :show="showPopup" round="8" mode="center" closeable @close="handleCancel">
  3. <view class="blessings-popup">
  4. <view class="blessings-title">每日祝福</view>
  5. <view class="blessings-cont">
  6. <view class="head">
  7. <view class="common-title">
  8. <view class="line"></view>
  9. <text>随机祝福</text>
  10. </view>
  11. <view class="button" @click="getRandomPick">
  12. <icon name="exchange" />
  13. <text class="text">换一换</text>
  14. </view>
  15. </view>
  16. <view class="blessings-list">
  17. <view v-for="(item, index) in list" :key="index" class="blessings-item"
  18. :class="{ active: activeIndex === index }" @click="handleMsg(index, item)">
  19. {{ item.clockinText }}
  20. </view>
  21. </view>
  22. <up-textarea class="message-field" v-model="message" placeholder="给 TA 一份暖心的祝福吧~"
  23. autoHeight></up-textarea>
  24. </view>
  25. <view class="blessings-footer">
  26. <view class="btn" @click="handleCancel">取消</view>
  27. <view class="send btn" @click="handleSend">发送</view>
  28. </view>
  29. </view>
  30. </up-popup>
  31. <!-- 祝福成功弹窗 -->
  32. <up-popup :show="sucessPopup" mode="center" @close="handleCancelSucess" bgColor="transparent" overlayOpacity="0.8">
  33. <view class="sucess-popup" @click="handleCancelSucess">
  34. <view class="sucess-bg">
  35. <image v-if="isFriend" class="img" :src="`${config.BASIC_IMG}img/subTreePage/blessing-sucess.png`">
  36. </image>
  37. <image v-else class="img"
  38. :src="`${config.BASIC_IMG}img/subTreePage/blessing-sucess-${clockinType}.png`"></image>
  39. </view>
  40. <view class="button-group">
  41. <view class="btn">开心收下</view>
  42. <view class="close">
  43. <up-icon name="close-circle-fill" size="30" color="rgba(255, 255, 255, 0.7)"></up-icon>
  44. </view>
  45. </view>
  46. </view>
  47. </up-popup>
  48. </template>
  49. <script setup>
  50. import config from "@/api/config.js"
  51. import {
  52. onMounted,
  53. ref,
  54. watch
  55. } from "vue";
  56. import TREE from '@/api/tree.js'
  57. const props = defineProps({
  58. show: {
  59. type: Boolean,
  60. defalut: false,
  61. },
  62. showSuccess: {
  63. type: Boolean,
  64. defalut: false,
  65. },
  66. farmBuyId: {
  67. type: [Number, String],
  68. defalut: '',
  69. },
  70. isFriend: {
  71. type: Boolean,
  72. defalut: false,
  73. },
  74. clockinType: {
  75. type: [Number, String],
  76. defalut: "1",
  77. },
  78. });
  79. const showPopup = ref(false);
  80. const message = ref("");
  81. const activeIndex = ref(null);
  82. const list = ref([]);
  83. const handleCancel = () => {
  84. activeIndex.value = null;
  85. message.value = "";
  86. showPopup.value = false;
  87. };
  88. const handleCancelSucess = () => {
  89. sucessPopup.value = false;
  90. };
  91. const getRandomPick = () => {
  92. TREE.randomPick({
  93. count: 6
  94. }).then(({
  95. data
  96. }) => {
  97. list.value = data || [];
  98. if (activeIndex.value != null) {
  99. message.value = data[activeIndex.value].clockinText;
  100. }
  101. });
  102. };
  103. const handleMsg = (index, item) => {
  104. activeIndex.value = index;
  105. message.value = item.clockinText;
  106. };
  107. const sucessPopup = ref(false);
  108. const emit = defineEmits(['clockinCallback'])
  109. const handleSend = () => {
  110. const params = {
  111. farmBuyId: props.farmBuyId,
  112. clockinType: props.clockinType,
  113. msg: message.value,
  114. };
  115. TREE.clockin(params).then((res) => {
  116. if (res.code === 0) {
  117. handleCancel();
  118. sucessPopup.value = true;
  119. emit('clockinCallback')
  120. }
  121. });
  122. };
  123. onMounted(() => {
  124. getRandomPick();
  125. });
  126. watch(
  127. () => props.show,
  128. () => {
  129. showPopup.value = true;
  130. }
  131. );
  132. watch(
  133. () => props.showSuccess,
  134. () => {
  135. handleSend()
  136. }
  137. );
  138. </script>
  139. <style scoped lang="scss">
  140. @import "@/static/style/mixin.scss";
  141. .blessings-popup {
  142. width: 90vw;
  143. padding: 40rpx 30rpx;
  144. box-sizing: border-box;
  145. position: relative;
  146. &::before {
  147. content: '';
  148. position: absolute;
  149. bottom: 190rpx;
  150. right: 0;
  151. z-index: 2;
  152. @include ossBg("subTreePage/blessing-bg.png");
  153. width: 336rpx;
  154. height: 336rpx;
  155. }
  156. .blessings-title {
  157. font-size: 48rpx;
  158. text-align: center;
  159. font-family: "PangMenZhengDao";
  160. }
  161. .blessings-cont {
  162. margin: 40rpx 0 48rpx;
  163. .head {
  164. display: flex;
  165. align-items: center;
  166. justify-content: space-between;
  167. .common-title {
  168. display: flex;
  169. align-items: center;
  170. font-weight: 500;
  171. .line {
  172. width: 8rpx;
  173. height: 32rpx;
  174. border-radius: 10rpx;
  175. background: #F3C11D;
  176. margin-right: 14rpx;
  177. }
  178. }
  179. .button {
  180. font-size: 24rpx;
  181. color: #f3c11d;
  182. padding: 8rpx 24rpx;
  183. border-radius: 40rpx;
  184. background: rgba(243, 193, 29, 0.1);
  185. border: 1px solid #f3c11d;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. .text {
  190. margin-left: 10rpx;
  191. }
  192. }
  193. }
  194. .blessings-list {
  195. display: flex;
  196. align-items: flex-start;
  197. flex-direction: column;
  198. padding-bottom: 24rpx;
  199. margin-bottom: 24rpx;
  200. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  201. .blessings-item {
  202. font-size: 24rpx;
  203. padding: 8rpx 20rpx;
  204. border-radius: 40rpx;
  205. background: #f4f6f8;
  206. margin-top: 20rpx;
  207. &.active {
  208. background: #fff2c4;
  209. }
  210. }
  211. }
  212. }
  213. .blessings-footer {
  214. display: flex;
  215. .btn {
  216. text-align: center;
  217. flex: 1;
  218. color: #666666;
  219. font-size: 32rpx;
  220. padding: 16rpx;
  221. border: 1px solid #999999;
  222. border-radius: 50rpx;
  223. }
  224. .send {
  225. margin-left: 26rpx;
  226. color: #fff;
  227. background-image: linear-gradient(120deg, #ffd887, #ed9e1e);
  228. border: none;
  229. }
  230. }
  231. }
  232. .sucess-popup {
  233. width: 100vw;
  234. min-height: 100vh;
  235. .image {
  236. width: 570rpx;
  237. height: 480rpx;
  238. }
  239. .sucess-bg {
  240. width: 100%;
  241. height: 830rpx;
  242. @include ossBg("subTreePage/light-effect-bg.png");
  243. display: flex;
  244. align-items: flex-end;
  245. justify-content: center;
  246. .img {
  247. width: 81%;
  248. height: 410rpx;
  249. }
  250. }
  251. .button-group {
  252. margin: 46rpx auto;
  253. width: 312rpx;
  254. .btn {
  255. font-size: 44rpx;
  256. padding: 20rpx 0;
  257. border-radius: 50rpx;
  258. font-family: "PangMenZhengDao";
  259. color: #954600;
  260. background: linear-gradient(120deg, #FFE6B2, #FFC339);
  261. text-align: center;
  262. }
  263. .close {
  264. margin-top: 80rpx;
  265. display: flex;
  266. justify-content: center;
  267. }
  268. }
  269. }
  270. </style>