tree.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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"></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. reactive,
  84. } from 'vue';
  85. const name = ref('荔枝')
  86. const showPicker = ref(false)
  87. const columns = reactive([
  88. ['荔枝', '香蕉', '苹果']
  89. ]);
  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]
  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. featchSessionStore()
  153. featchIsLookedGuide()
  154. featchLightTree()
  155. })
  156. const showMask = ref(false)
  157. const featchIsLookedGuide = () => {
  158. USER.isLookedGuide({
  159. type: 1
  160. }).then(({
  161. data
  162. }) => {
  163. if (data == false) {
  164. showMask.value = true
  165. }
  166. })
  167. }
  168. const handleClose = async () =>{
  169. const {code} = await USER.lookedGuide({type:1})
  170. if(code === 0){
  171. showMask.value = false
  172. }
  173. }
  174. const featchSessionStore = () => {
  175. USER.getSessionStore({
  176. key: 'successTree',
  177. miniUserId: userInfo.id
  178. }).then((({data}) => {
  179. if (data?.val == 0) {
  180. showGuardSuccess.value = true
  181. USER.setSessionStore({
  182. key: 'successTree',
  183. miniUserId: userInfo.id
  184. })
  185. }
  186. }))
  187. }
  188. const sampleId = ref('')
  189. //通过品类查询当前树
  190. const featchLightTree = () =>{
  191. TREE.getLightTree({farmId:766}).then((res =>{
  192. sampleId.value = res.data.id
  193. getBySampleId()
  194. }))
  195. }
  196. const treeData = ref({})
  197. const farmBuyId = ref('')
  198. const treeName = ref('')
  199. const userInfo = uni.getStorageSync('userInfo')
  200. const getBySampleId = () => {
  201. TREE.getBySampleId({
  202. sampleId: sampleId.value
  203. }).then(({
  204. data
  205. }) => {
  206. treeData.value = data || {}
  207. if (userInfo.tel) {
  208. treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length ? data.buyList[0]
  209. .nickname.slice(0, 3) + "荔" : data.buyList[0].owner.slice(0, 3) + "荔")
  210. } else {
  211. treeName.value = '飞鸟守护'
  212. }
  213. farmBuyId.value = data.buyList[0].id
  214. })
  215. }
  216. const showPoster = ref(false)
  217. const showAlbum = ref(false)
  218. const handleToolItem = ({
  219. path,
  220. clickName,
  221. params
  222. }) => {
  223. if (clickName === 'album') {
  224. showAlbum.value = !showAlbum.value
  225. } else if (clickName === 'poster') {
  226. showPoster.value = !showPoster.value
  227. } else {
  228. uni.navigateTo({
  229. url: `/pages/tabBar/tree/subPages/${path}?farmBuyId=${farmBuyId.value}`
  230. });
  231. }
  232. }
  233. const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
  234. const showBlessingsPopup = ref(false)
  235. const showSuccess = ref(false)
  236. const clockinType = ref('1')
  237. const handleItem = (index) => {
  238. if (index === 0) {
  239. clockinType.value = 1
  240. if (treeData.value.buyList[0].level.clockinMap['1']) {
  241. uni.showToast({
  242. title: '今日已守护',
  243. icon: 'none',
  244. duration: 2000
  245. });
  246. } else {
  247. showSuccess.value = !showSuccess.value
  248. }
  249. } else if (index === 1) {
  250. clockinType.value = 3
  251. if (treeData.value.buyList[0].level.clockinMap['3']) {
  252. uni.showToast({
  253. title: '今日已送过祝福',
  254. icon: 'none',
  255. duration: 2000
  256. });
  257. } else {
  258. showBlessingsPopup.value = !showBlessingsPopup.value
  259. }
  260. } else if (index === 2) {
  261. clockinType.value = 2
  262. if (!treeData.value.buyList[0].level.clockinMap['2']) {
  263. showSuccess.value = !showSuccess.value
  264. }
  265. } else {
  266. console.log('123')
  267. }
  268. }
  269. function requestSubscribe() {
  270. // #ifdef MP-WEIXIN
  271. //订阅模板
  272. TREE.getSubscribeTemplate({
  273. id: 1
  274. }).then(({
  275. data
  276. }) => {
  277. uni.requestSubscribeMessage({
  278. tmplIds: [data.templateId], // 模板ID
  279. success(res) {
  280. if (res[data.templateId] === 'accept') {
  281. TREE.addSubscribe({
  282. templateId: 1
  283. })
  284. } else if (res[data.templateId] === 'reject') {
  285. console.log('用户拒绝订阅模板');
  286. }
  287. },
  288. fail(err) {
  289. uni.openSetting({
  290. withSubscriptions: true, // 显示订阅消息开关
  291. });
  292. },
  293. });
  294. })
  295. // #endif
  296. }
  297. onShareAppMessage((res) => {
  298. if (res.from === 'button') {
  299. const params = {
  300. sampleId: treeData.value.buyList[0].sampleId,
  301. farmId: treeData.value.buyList[0].farmId,
  302. }
  303. return {
  304. title: '我分享了我的果树,快来查看吧~',
  305. path: `/pages/tabBar/tree/subPages/friendTree?params=${JSON.stringify(params)}`, // 分享的小程序页面路径
  306. 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()}`,
  307. }
  308. }
  309. })
  310. </script>
  311. <style lang="scss" scoped>
  312. @import "@/static/style/mixin.scss";
  313. .guide-bg{
  314. position: fixed;
  315. top: 0;
  316. width: 100%;
  317. height: 107vh;
  318. @include ossBg("treePage/guide-bg.png");
  319. z-index: 999;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. .guide-icon{
  324. width: 360rpx;
  325. height: 236rpx
  326. }
  327. }
  328. /* #ifdef H5 */
  329. .guide-bg{
  330. height: 102vh;
  331. }
  332. /* #endif */
  333. .base-container {
  334. @include ossBg("tree-bg.png");
  335. // background-position: top left;
  336. padding: 22rpx 0;
  337. .toogle {
  338. position: absolute;
  339. right: 0;
  340. top: calc(50% - 32rpx);
  341. font-size: 24rpx;
  342. color: #fff;
  343. border-radius: 50rpx 0 0 50rpx;
  344. background: rgba(0, 0, 0, 0.2);
  345. padding: 12rpx 20rpx;
  346. display: flex;
  347. .icon {
  348. margin-left: 10rpx;
  349. }
  350. }
  351. .tree-cont {
  352. width: 100%;
  353. margin-top: 10rpx;
  354. .tree-name {
  355. position: absolute;
  356. top: 60.45%;
  357. left: calc(50% - 32rpx);
  358. z-index: 2;
  359. font-size: 22rpx;
  360. font-family: 'SweiSpringCJKtc';
  361. text-align: center;
  362. width: 88rpx;
  363. .edit-icon {
  364. width: 44rpx;
  365. height: 44rpx;
  366. margin-top: 14rpx;
  367. }
  368. }
  369. .drone-icon {
  370. width: 376rpx;
  371. height: 384rpx;
  372. margin-left: 26rpx;
  373. }
  374. .tool-wrap {
  375. width: 100%;
  376. padding: 14rpx;
  377. box-sizing: border-box;
  378. position: absolute;
  379. bottom: calc(50% - 350rpx);
  380. display: flex;
  381. justify-content: space-between;
  382. .tool-left,
  383. .tool-right {
  384. .tool-item {
  385. color: #fff;
  386. font-size: 24rpx;
  387. font-weight: 500;
  388. text-align: center;
  389. width: 100rpx;
  390. margin-bottom: 16rpx;
  391. text-shadow:
  392. 0 0 3rpx #D7660A,
  393. 0 0 3rpx #D7660A,
  394. 0 0 3rpx #D7660A,
  395. 0 0 3rpx #D7660A;
  396. &.blue {
  397. text-shadow:
  398. 0 0 3rpx #2199F8,
  399. 0 0 3rpx #2199F8,
  400. 0 0 3rpx #2199F8,
  401. 0 0 3rpx #2199F8;
  402. }
  403. .icon {
  404. width: 100%;
  405. height: 82rpx;
  406. position: relative;
  407. }
  408. .name {
  409. margin-top: -24rpx;
  410. position: relative;
  411. z-index: 2;
  412. }
  413. &.gift {
  414. .icon {
  415. height: 114rpx;
  416. margin-top: -5rpx;
  417. }
  418. .name {
  419. margin-top: -44rpx;
  420. }
  421. }
  422. &.friend {
  423. .icon {
  424. height: 90rpx;
  425. }
  426. .name {
  427. margin-top: -35rpx;
  428. }
  429. }
  430. &.dynamic {
  431. .icon {
  432. height: 96rpx;
  433. }
  434. .name {
  435. margin-top: -32rpx;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. .tree-footer {
  443. position: absolute;
  444. left: 0;
  445. bottom: 76rpx;
  446. width: 100%;
  447. display: flex;
  448. justify-content: center;
  449. .footer-item {
  450. width: 18%;
  451. text-align: center;
  452. .share-btn {
  453. background: transparent;
  454. display: inline-flex;
  455. &::after {
  456. border: none;
  457. }
  458. }
  459. .icon {
  460. width: 96rpx;
  461. height: 96rpx;
  462. }
  463. .name {
  464. font-size: 24rpx;
  465. font-weight: 500;
  466. padding: 2rpx 16rpx;
  467. background-image: linear-gradient(0deg, #FFFFFF, #FFE079);
  468. border-radius: 50rpx;
  469. border: 2rpx solid #fff;
  470. }
  471. }
  472. .footer-item+.footer-item {
  473. margin-left: 30rpx;
  474. }
  475. }
  476. }
  477. </style>