tree.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. <template>
  2. <view class="page-container">
  3. <view class="base-container">
  4. <member-level :treeData="treeData">
  5. <view class="toogle" @click="handleShow">切换 {{name}}<up-icon class="icon" name="arrow-down" color="#fff"
  6. size="12"></up-icon></view>
  7. </member-level>
  8. <view class="tree-cont">
  9. <!-- 弹幕组件 -->
  10. <view class="danmaku-wrapper">
  11. <danmakuManager
  12. :danmakuList="danmakuList"
  13. :height="100"
  14. :infinite="true"
  15. :speed="80"
  16. @danmakuComplete="onDanmakuComplete"
  17. ></danmakuManager>
  18. </view>
  19. <view class="dialogue-tips">
  20. <view class="tips-name">
  21. <image class="tip-img" :src="`${config.BASIC_IMG}img/treePage/sun-icon.png`"></image>
  22. <text>亲爱的主人!</text>
  23. </view>
  24. <view class="tips-cont">今天是我开花的日子,我很开心!</view>
  25. </view>
  26. <view class="tree-name">
  27. <view>{{treeName}}</view>
  28. <image @click="handleEditName" class="edit-icon" :src="`${config.BASIC_IMG}img/edit-icon.png`">
  29. </image>
  30. </view>
  31. <image class="drone-icon" :src="`${config.BASIC_IMG}img/treePage/drone-icon.png`"></image>
  32. <view class="tool-wrap">
  33. <view class="tool-left">
  34. <view :class="['tool-item',item.className]" v-for="(item,index) in toolLeftList" :key="index"
  35. @click="handleToolItem(item)">
  36. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/l-tree-icon-${index+1}.png`">
  37. </image>
  38. <view class="name">{{item.name}}</view>
  39. </view>
  40. </view>
  41. <view class="tool-right">
  42. <view :class="['tool-item',item.className]" v-for="(item,index) in toolRightList" :key="index"
  43. @click="handleToolItem(item)">
  44. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/r-tree-icon-${index+1}.png`">
  45. </image>
  46. <view class="name">{{item.name}}</view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="tree-footer">
  52. <template v-if="userInfo.tel">
  53. <view class="footer-item" v-for="(item,index) in footerList" :key="index" @click="handleItem(index)">
  54. <view @click="requestSubscribe">
  55. <button class="share-btn" open-type="share" v-if="index === 2">
  56. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`">
  57. </image>
  58. </button>
  59. <image v-else class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`">
  60. </image>
  61. <view class="name">{{item}}</view>
  62. </view>
  63. </view>
  64. </template>
  65. <view v-else class="button" @click="handlePage">开启我的守护</view>
  66. </view>
  67. </view>
  68. <!-- 引导弹窗 -->
  69. <view class="guide-bg" v-if="showMask" @click="handleClose">
  70. <image class="guide-icon" :src="`${config.BASIC_IMG}img/treePage/guide-1.png`"></image>
  71. </view>
  72. <!-- 切换 -->
  73. <up-picker :show="showPicker" :columns="columns" :defaultIndex="[0]" @cancel="handleCancel"
  74. @confirm="handleConfirm" keyName="name" valueName="speciesId"></up-picker>
  75. <!-- 签到打卡 -->
  76. <checkinPopup @closedCheckPopup="closedCheckPopup"></checkinPopup>
  77. <!-- 编辑树名称 -->
  78. <editNamePopup ref="editNameRef" @editEnd="getBySampleId"></editNamePopup>
  79. <!-- 海报弹窗 -->
  80. <posterPopup :showPoster="showPoster" :farmBuyId="farmBuyId" :treeName="treeName"></posterPopup>
  81. <!-- 果树成功弹窗 -->
  82. <guardSuccessPopup :show="showGuardSuccess" :treeData="treeData"></guardSuccessPopup>
  83. <!-- 果树相册弹窗 -->
  84. <tree-album-popup :show="showAlbum" :farmBuyId="farmBuyId" :sampleId="sampleId"></tree-album-popup>
  85. <!-- 等级升级成功弹窗 -->
  86. <levelSuccessPopup></levelSuccessPopup>
  87. <!-- 祝福弹窗 -->
  88. <blessingsPopup :show="showBlessingsPopup" :showSuccess="showSuccess" :farmBuyId="farmBuyId"
  89. :clockinType="clockinType" @clockinCallback="getBySampleId"></blessingsPopup>
  90. </view>
  91. </template>
  92. <script setup>
  93. import config from "@/api/config.js"
  94. import {
  95. onLoad,
  96. onShareAppMessage,
  97. onShow
  98. } from '@dcloudio/uni-app'
  99. import memberLevel from "./components/memberLevel.vue"
  100. import treeAlbumPopup from "./components/treeAlbumPopup.vue"
  101. import blessingsPopup from "./components/blessingsPopup.vue"
  102. import danmakuManager from "@/components/danmakuManager/danmakuManager.vue"
  103. import TREE from '@/api/tree.js'
  104. import USER from '@/api/user.js'
  105. import {
  106. ref
  107. } from 'vue';
  108. const name = ref('荔枝')
  109. const showPicker = ref(false)
  110. const columns = ref([]);
  111. const handleShow = () => {
  112. showPicker.value = true
  113. }
  114. const handleCancel = () => {
  115. showPicker.value = false
  116. }
  117. const handleConfirm = (e) => {
  118. name.value = e.value[0].name
  119. handleCancel()
  120. }
  121. const toolLeftList = [{
  122. name: "相册",
  123. clickName: 'album'
  124. },
  125. {
  126. name: "日记",
  127. path: 'diary'
  128. },
  129. {
  130. name: "海报",
  131. className: 'blue',
  132. clickName: 'poster'
  133. },
  134. {
  135. name: "礼物",
  136. className: 'gift',
  137. path: 'gift'
  138. }
  139. ]
  140. const toolRightList = [{
  141. name: "好友",
  142. className: 'friend',
  143. path: 'rank'
  144. },
  145. {
  146. name: "认养",
  147. },
  148. {
  149. name: "果园",
  150. },
  151. {
  152. name: "动态",
  153. className: 'dynamic',
  154. path: 'dynamic',
  155. params: 'farmBuyId'
  156. }
  157. ]
  158. const showGuardSuccess = ref(false)
  159. const editNameRef = ref(null)
  160. const formatDate = (dateStr) => {
  161. return dateStr.split(" ")[0].replace(/-/g, ".");
  162. };
  163. const handleEditName = () => {
  164. editNameRef.value.showPopup({
  165. id: farmBuyId.value,
  166. treeName: treeName.value,
  167. nickname: treeData.value.buyList[0].nickname,
  168. showName: treeData.value.buyList[0].showName,
  169. createDate: formatDate(treeData.value.buyList[0].createDate),
  170. })
  171. }
  172. onLoad(() => {
  173. featchIsLookedGuide()
  174. featchCategoryList()
  175. })
  176. onShow(()=>{
  177. featchLightTree()
  178. })
  179. //品类查询所有
  180. const featchCategoryList = () =>{
  181. TREE.categoryList().then(({
  182. data
  183. }) => {
  184. columns.value[0] = data || []
  185. })
  186. }
  187. const showMask = ref(false)
  188. const featchIsLookedGuide = () => {
  189. USER.isLookedGuide({
  190. type: 1
  191. }).then(({
  192. data
  193. }) => {
  194. if (data == false) {
  195. showMask.value = true
  196. }
  197. })
  198. }
  199. const handleClose = async () =>{
  200. const {code} = await USER.lookedGuide({type:1})
  201. if(code === 0){
  202. showMask.value = false
  203. }
  204. }
  205. const featchSessionStore = () => {
  206. USER.getSessionStore({
  207. key: 'successTree',
  208. miniUserId: userInfo.id
  209. }).then((({data}) => {
  210. if (data?.val == 0) {
  211. showGuardSuccess.value = !showGuardSuccess.value
  212. USER.setSessionStore({
  213. key: 'successTree',
  214. miniUserId: userInfo.id,
  215. val:1
  216. })
  217. }
  218. }))
  219. }
  220. const closedCheckPopup = () =>{
  221. showPoster.value = !showPoster.value
  222. }
  223. const sampleId = ref('')
  224. //通过品类查询当前树
  225. const featchLightTree = () =>{
  226. TREE.getLightTree({farmId:766}).then((res =>{
  227. sampleId.value = res.data.id
  228. getBySampleId()
  229. }))
  230. }
  231. const treeData = ref({})
  232. const farmBuyId = ref('')
  233. const treeName = ref('')
  234. const userInfo = uni.getStorageSync('userInfo')
  235. const getBySampleId = () => {
  236. TREE.getBySampleId({
  237. sampleId: sampleId.value
  238. }).then(({
  239. data
  240. }) => {
  241. treeData.value = data || {}
  242. if (userInfo.tel) {
  243. treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length ? data.buyList[0]
  244. .nickname.slice(0, 3) + "荔" : data.buyList[0].owner.slice(0, 3) + "荔")
  245. } else {
  246. treeName.value = '飞鸟守护'
  247. }
  248. farmBuyId.value = data.buyList[0].id
  249. featchSessionStore()
  250. })
  251. }
  252. const handlePage = () =>{
  253. uni.navigateTo({
  254. url: `/pages/login/index`
  255. });
  256. }
  257. const showPoster = ref(false)
  258. const showAlbum = ref(false)
  259. const handleToolItem = ({
  260. path,
  261. clickName,
  262. params
  263. }) => {
  264. if (clickName === 'album') {
  265. showAlbum.value = !showAlbum.value
  266. } else if (clickName === 'poster') {
  267. showPoster.value = !showPoster.value
  268. } else {
  269. uni.navigateTo({
  270. url: `/pages/tabBar/tree/subPages/${path}?farmBuyId=${farmBuyId.value}&sampleId=${sampleId.value}`
  271. });
  272. }
  273. }
  274. const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
  275. const showBlessingsPopup = ref(false)
  276. const showSuccess = ref(false)
  277. const clockinType = ref('1')
  278. // 弹幕相关数据
  279. const danmakuList = ref([
  280. {
  281. text: "晨曦微露,阳光洒满大地",
  282. avatar: `${userInfo.icon}`
  283. },
  284. {
  285. text: "守护果树,收获美好",
  286. avatar: `${userInfo.icon}`
  287. },
  288. {
  289. text: "今天也要给果树浇水哦",
  290. avatar: `${userInfo.icon}`
  291. },
  292. {
  293. text: "果树长得好快啊",
  294. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  295. },
  296. {
  297. text: "期待果实成熟的那一天",
  298. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  299. },
  300. {
  301. text: "和好友一起守护果树",
  302. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  303. },
  304. {
  305. text: "每日签到,果树茁壮成长",
  306. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  307. },
  308. {
  309. text: "分享给更多朋友",
  310. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  311. }
  312. ])
  313. // 弹幕完成回调
  314. const onDanmakuComplete = (id) => {
  315. console.log('弹幕播放完成:', id)
  316. }
  317. const handleItem = (index) => {
  318. if (index === 0) {
  319. clockinType.value = 1
  320. if (treeData.value.buyList[0].level.clockinMap['1']) {
  321. uni.showToast({
  322. title: '今日已守护',
  323. icon: 'none',
  324. duration: 2000
  325. });
  326. } else {
  327. showSuccess.value = !showSuccess.value
  328. }
  329. } else if (index === 1) {
  330. clockinType.value = 3
  331. if (treeData.value.buyList[0].level.clockinMap['3']) {
  332. uni.showToast({
  333. title: '今日已送过祝福',
  334. icon: 'none',
  335. duration: 2000
  336. });
  337. } else {
  338. showBlessingsPopup.value = !showBlessingsPopup.value
  339. }
  340. } else if (index === 2) {
  341. clockinType.value = 2
  342. if (!treeData.value.buyList[0].level.clockinMap['2']) {
  343. showSuccess.value = !showSuccess.value
  344. }
  345. } else {
  346. console.log('123')
  347. }
  348. }
  349. function requestSubscribe() {
  350. // #ifdef MP-WEIXIN
  351. //订阅模板
  352. TREE.getSubscribeTemplate({
  353. id: 1
  354. }).then(({
  355. data
  356. }) => {
  357. uni.requestSubscribeMessage({
  358. tmplIds: [data.templateId], // 模板ID
  359. success(res) {
  360. if (res[data.templateId] === 'accept') {
  361. TREE.addSubscribe({
  362. templateId: 1
  363. })
  364. } else if (res[data.templateId] === 'reject') {
  365. console.log('用户拒绝订阅模板');
  366. }
  367. },
  368. fail(err) {
  369. uni.openSetting({
  370. withSubscriptions: true, // 显示订阅消息开关
  371. });
  372. },
  373. });
  374. })
  375. // #endif
  376. }
  377. onShareAppMessage((res) => {
  378. if (res.from === 'button') {
  379. const params = {
  380. sampleId: treeData.value.buyList[0].sampleId,
  381. farmId: treeData.value.buyList[0].farmId,
  382. }
  383. return {
  384. title: '我分享了我的果树,快来查看吧~',
  385. path: `/pages/tabBar/tree/subPages/friendTree?params=${JSON.stringify(params)}`, // 分享的小程序页面路径
  386. imageUrl: `http://birdseye-api.feiniaotech.sysuimars.cn/mini/z_farm_buy/genImage/${farmBuyId.value}?key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9&x1=25&y1=220&fontSize1=40&x2=55&y2=250&fontSize2=16&timestamp=${Date.now()}`,
  387. }
  388. }
  389. })
  390. </script>
  391. <style lang="scss" scoped>
  392. @import "@/static/style/mixin.scss";
  393. .guide-bg{
  394. position: fixed;
  395. top: 0;
  396. width: 100%;
  397. height: 107vh;
  398. @include ossBg("treePage/guide-bg.png");
  399. z-index: 999;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. .guide-icon{
  404. width: 360rpx;
  405. height: 236rpx
  406. }
  407. }
  408. /* #ifdef H5 */
  409. .guide-bg{
  410. height: 102vh;
  411. }
  412. /* #endif */
  413. .base-container {
  414. @include ossBg("tree-bg.png");
  415. // background-position: top left;
  416. padding: 22rpx 0;
  417. position: relative;
  418. .danmaku-wrapper {
  419. position: absolute;
  420. top: 21%;
  421. left: 0;
  422. right: 0;
  423. z-index: 100;
  424. pointer-events: none;
  425. }
  426. .toogle {
  427. position: absolute;
  428. right: 0;
  429. top: calc(50% - 32rpx);
  430. font-size: 24rpx;
  431. color: #fff;
  432. border-radius: 50rpx 0 0 50rpx;
  433. background: rgba(0, 0, 0, 0.2);
  434. padding: 12rpx 20rpx;
  435. display: flex;
  436. .icon {
  437. margin-left: 10rpx;
  438. }
  439. }
  440. .tree-cont {
  441. width: 100%;
  442. margin-top: 10rpx;
  443. .dialogue-tips{
  444. position: absolute;
  445. top: 31.5%;
  446. right: 80rpx;
  447. font-size: 24rpx;
  448. @include ossBg("treePage/tips-bg.png");
  449. padding: 10rpx 10rpx 30rpx 20rpx;
  450. .tips-name{
  451. font-size: 28rpx;
  452. font-weight: 500;
  453. margin-bottom: 6rpx;
  454. display: flex;
  455. align-items: center;
  456. .tip-img{
  457. width: 40rpx;
  458. height: 40rpx;
  459. margin-right: 4rpx;
  460. }
  461. }
  462. }
  463. .tree-name {
  464. position: absolute;
  465. top: 60.45%;
  466. left: calc(50% - 32rpx);
  467. z-index: 2;
  468. font-size: 22rpx;
  469. font-family: 'SweiSpringCJKtc';
  470. text-align: center;
  471. width: 88rpx;
  472. .edit-icon {
  473. width: 44rpx;
  474. height: 44rpx;
  475. margin-top: 14rpx;
  476. }
  477. }
  478. .drone-icon {
  479. width: 376rpx;
  480. height: 384rpx;
  481. margin-left: 26rpx;
  482. }
  483. .tool-wrap {
  484. width: 100%;
  485. padding: 14rpx;
  486. box-sizing: border-box;
  487. position: absolute;
  488. bottom: calc(50% - 350rpx);
  489. display: flex;
  490. justify-content: space-between;
  491. .tool-left,
  492. .tool-right {
  493. .tool-item {
  494. color: #fff;
  495. font-size: 24rpx;
  496. font-weight: 500;
  497. text-align: center;
  498. width: 100rpx;
  499. margin-bottom: 16rpx;
  500. text-shadow:
  501. 0 0 3rpx #D7660A,
  502. 0 0 3rpx #D7660A,
  503. 0 0 3rpx #D7660A,
  504. 0 0 3rpx #D7660A;
  505. &.blue {
  506. text-shadow:
  507. 0 0 3rpx #2199F8,
  508. 0 0 3rpx #2199F8,
  509. 0 0 3rpx #2199F8,
  510. 0 0 3rpx #2199F8;
  511. }
  512. .icon {
  513. width: 100%;
  514. height: 82rpx;
  515. position: relative;
  516. }
  517. .name {
  518. margin-top: -24rpx;
  519. position: relative;
  520. z-index: 2;
  521. }
  522. &.gift {
  523. .icon {
  524. height: 114rpx;
  525. margin-top: -5rpx;
  526. }
  527. .name {
  528. margin-top: -44rpx;
  529. }
  530. }
  531. &.friend {
  532. .icon {
  533. height: 90rpx;
  534. }
  535. .name {
  536. margin-top: -35rpx;
  537. }
  538. }
  539. &.dynamic {
  540. .icon {
  541. height: 96rpx;
  542. }
  543. .name {
  544. margin-top: -32rpx;
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. .tree-footer {
  552. position: absolute;
  553. left: 0;
  554. bottom: 76rpx;
  555. width: 100%;
  556. display: flex;
  557. justify-content: center;
  558. .button {
  559. padding: 26rpx 80rpx;
  560. border-radius: 50rpx;
  561. border: 2rpx solid #fff;
  562. background-image: linear-gradient(120deg, #FFD887, #ED9E1E);
  563. margin-top: 20rpx;
  564. color: #fff;
  565. }
  566. .footer-item {
  567. width: 18%;
  568. text-align: center;
  569. .share-btn {
  570. background: transparent;
  571. display: inline-flex;
  572. &::after {
  573. border: none;
  574. }
  575. }
  576. .icon {
  577. width: 96rpx;
  578. height: 96rpx;
  579. }
  580. .name {
  581. font-size: 24rpx;
  582. font-weight: 500;
  583. padding: 2rpx 16rpx;
  584. background-image: linear-gradient(0deg, #FFFFFF, #FFE079);
  585. border-radius: 50rpx;
  586. border: 2rpx solid #fff;
  587. }
  588. }
  589. .footer-item+.footer-item {
  590. margin-left: 30rpx;
  591. }
  592. }
  593. }
  594. </style>