tree.vue 12 KB

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