tree.vue 12 KB

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