blessingsPopup.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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" :style="{width:clockinType == 4?'90%':'81%'}"
  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. emit("closeBlessings")
  91. emit('clockinCallback')
  92. };
  93. const getRandomPick = () => {
  94. TREE.randomPick({
  95. count: 6
  96. }).then(({
  97. data
  98. }) => {
  99. list.value = data || [];
  100. if (activeIndex.value != null) {
  101. message.value = data[activeIndex.value].clockinText;
  102. }
  103. });
  104. };
  105. const handleMsg = (index, item) => {
  106. activeIndex.value = index;
  107. message.value = item.clockinText;
  108. };
  109. const sucessPopup = ref(false);
  110. const emit = defineEmits(['clockinCallback', "closeBlessings"])
  111. const handleSend = () => {
  112. const params = {
  113. farmBuyId: props.farmBuyId,
  114. clockinType: props.clockinType,
  115. msg: message.value,
  116. };
  117. if(props.clockinType!=4){
  118. TREE.clockin(params).then((res) => {
  119. if (res.code === 0) {
  120. handleCancel();
  121. sucessPopup.value = true;
  122. }
  123. });
  124. }else{
  125. sucessPopup.value = true;
  126. }
  127. };
  128. onMounted(() => {
  129. getRandomPick();
  130. });
  131. watch(
  132. () => props.show,
  133. () => {
  134. showPopup.value = true;
  135. }
  136. );
  137. watch(
  138. () => props.showSuccess,
  139. () => {
  140. handleSend()
  141. }
  142. );
  143. </script>
  144. <style scoped lang="scss">
  145. @import "@/static/style/mixin.scss";
  146. .blessings-popup {
  147. width: 90vw;
  148. padding: 40rpx 30rpx;
  149. box-sizing: border-box;
  150. position: relative;
  151. &::before {
  152. content: '';
  153. position: absolute;
  154. bottom: 190rpx;
  155. right: 0;
  156. z-index: 2;
  157. @include ossBg("subTreePage/blessing-bg.png");
  158. width: 336rpx;
  159. height: 336rpx;
  160. }
  161. .blessings-title {
  162. font-size: 48rpx;
  163. text-align: center;
  164. font-family: "PangMenZhengDao";
  165. }
  166. .blessings-cont {
  167. margin: 40rpx 0 48rpx;
  168. .head {
  169. display: flex;
  170. align-items: center;
  171. justify-content: space-between;
  172. .common-title {
  173. display: flex;
  174. align-items: center;
  175. font-weight: 500;
  176. .line {
  177. width: 8rpx;
  178. height: 32rpx;
  179. border-radius: 10rpx;
  180. background: #F3C11D;
  181. margin-right: 14rpx;
  182. }
  183. }
  184. .button {
  185. font-size: 24rpx;
  186. color: #f3c11d;
  187. padding: 8rpx 24rpx;
  188. border-radius: 40rpx;
  189. background: rgba(243, 193, 29, 0.1);
  190. border: 1px solid #f3c11d;
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. .text {
  195. margin-left: 10rpx;
  196. }
  197. }
  198. }
  199. .blessings-list {
  200. display: flex;
  201. align-items: flex-start;
  202. flex-direction: column;
  203. padding-bottom: 24rpx;
  204. margin-bottom: 24rpx;
  205. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  206. .blessings-item {
  207. font-size: 24rpx;
  208. padding: 8rpx 20rpx;
  209. border-radius: 40rpx;
  210. background: #f4f6f8;
  211. margin-top: 20rpx;
  212. &.active {
  213. background: #fff2c4;
  214. }
  215. }
  216. }
  217. }
  218. .blessings-footer {
  219. display: flex;
  220. .btn {
  221. text-align: center;
  222. flex: 1;
  223. color: #666666;
  224. font-size: 32rpx;
  225. padding: 16rpx;
  226. border: 1px solid #999999;
  227. border-radius: 50rpx;
  228. }
  229. .send {
  230. margin-left: 26rpx;
  231. color: #fff;
  232. background-image: linear-gradient(120deg, #ffd887, #ed9e1e);
  233. border: none;
  234. }
  235. }
  236. }
  237. .sucess-popup {
  238. width: 100vw;
  239. min-height: 100vh;
  240. .image {
  241. width: 570rpx;
  242. height: 480rpx;
  243. }
  244. .sucess-bg {
  245. width: 100%;
  246. height: 830rpx;
  247. @include ossBg("subTreePage/light-effect-bg.png");
  248. display: flex;
  249. align-items: flex-end;
  250. justify-content: center;
  251. .img {
  252. width: 81%;
  253. height: 410rpx;
  254. }
  255. }
  256. .button-group {
  257. margin: 46rpx auto;
  258. width: 312rpx;
  259. .btn {
  260. font-size: 44rpx;
  261. padding: 20rpx 0;
  262. border-radius: 50rpx;
  263. font-family: "PangMenZhengDao";
  264. color: #954600;
  265. background: linear-gradient(120deg, #FFE6B2, #FFC339);
  266. text-align: center;
  267. }
  268. .close {
  269. margin-top: 80rpx;
  270. display: flex;
  271. justify-content: center;
  272. }
  273. }
  274. }
  275. </style>