tree.vue 12 KB

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