tree.vue 12 KB

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