tree.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. <image class="drone-icon" :src="`${config.BASIC_IMG}img/treePage/drone-icon.png`"></image>
  9. <view class="tool-wrap">
  10. <view class="tool-left">
  11. <view :class="['tool-item',item.className]" v-for="(item,index) in toolLeftList" :key="index"
  12. @click="handleToolItem(item)">
  13. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/l-tree-icon-${index+1}.png`"></image>
  14. <view class="name">{{item.name}}</view>
  15. </view>
  16. </view>
  17. <view class="tool-right">
  18. <view :class="['tool-item',item.className]" v-for="(item,index) in toolRightList" :key="index"
  19. @click="handleToolItem(item)">
  20. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/r-tree-icon-${index+1}.png`"></image>
  21. <view class="name">{{item.name}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="tree-footer">
  27. <view class="footer-item" v-for="(item,index) in footerList" :key="index" @click="handleItem(index)">
  28. <view @click="requestSubscribe">
  29. <button class="share-btn" open-type="share" v-if="index === 2">
  30. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`"></image>
  31. </button>
  32. <image v-else class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`"></image>
  33. <view class="name">{{item}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 切换 -->
  39. <up-picker :show="showPicker" :columns="columns" :defaultIndex="[0]" @cancel="handleCancel"
  40. @confirm="handleConfirm"></up-picker>
  41. <!-- 编辑树名称 -->
  42. <editNamePopup></editNamePopup>
  43. <!-- 海报弹窗 -->
  44. <posterPopup :showPoster="showPoster" :farmBuyId="farmBuyId" :treeName="treeName"></posterPopup>
  45. <!-- 果树成功弹窗 -->
  46. <guardSuccessPopup :show="showGuardSuccess"></guardSuccessPopup>
  47. <!-- 果树相册弹窗 -->
  48. <tree-album-popup :show="showAlbum"></tree-album-popup>
  49. <!-- 等级升级成功弹窗 -->
  50. <levelSuccessPopup></levelSuccessPopup>
  51. <!-- 祝福弹窗 -->
  52. <blessingsPopup :show="showBlessingsPopup" :showSuccess="showSuccess" :farmBuyId="farmBuyId" :clockinType="clockinType" @clockinCallback="getBySampleId"></blessingsPopup>
  53. </template>
  54. <script setup>
  55. import config from "@/api/config.js"
  56. import { onLoad ,onShareAppMessage} from '@dcloudio/uni-app'
  57. import memberLevel from "./components/memberLevel.vue"
  58. import treeAlbumPopup from "./components/treeAlbumPopup.vue"
  59. import blessingsPopup from "./components/blessingsPopup.vue"
  60. import TREE from '@/api/tree.js'
  61. import {
  62. ref,
  63. reactive,
  64. } from 'vue';
  65. const name = ref('荔枝')
  66. const showPicker = ref(false)
  67. const columns = reactive([
  68. ['荔枝', '香蕉', '苹果']
  69. ]);
  70. const handleShow = () => {
  71. showPicker.value = true
  72. }
  73. const handleCancel = () => {
  74. showPicker.value = false
  75. }
  76. const handleConfirm = (e) => {
  77. name.value = e.value[0]
  78. handleCancel()
  79. }
  80. const toolLeftList = [{
  81. name: "相册",
  82. clickName:'album'
  83. },
  84. {
  85. name: "日记",
  86. path: 'diary'
  87. },
  88. {
  89. name: "海报",
  90. className: 'blue',
  91. clickName:'poster'
  92. },
  93. {
  94. name: "礼物",
  95. className: 'gift',
  96. path: 'gift'
  97. }
  98. ]
  99. const toolRightList = [{
  100. name: "好友",
  101. className: 'friend',
  102. path: 'rank'
  103. },
  104. {
  105. name: "认养",
  106. },
  107. {
  108. name: "果园",
  109. },
  110. {
  111. name: "动态",
  112. className: 'dynamic',
  113. path: 'dynamic',
  114. params:'farmBuyId'
  115. }
  116. ]
  117. const showGuardSuccess = ref(false)
  118. onLoad(({successTree})=>{
  119. if(successTree){
  120. showGuardSuccess.value = true
  121. }
  122. getBySampleId()
  123. })
  124. const treeData = ref({})
  125. const farmBuyId = ref('')
  126. const treeName = ref('')
  127. const userInfo = uni.getStorageSync('userInfo')
  128. const getBySampleId = () =>{
  129. TREE.getBySampleId({sampleId:172055}).then(({data}) =>{
  130. treeData.value = data || {}
  131. if(userInfo.tel){
  132. treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length?data.buyList[0].nickname.slice(0, 3)+"荔": data.buyList[0].owner.slice(0, 3)+"荔")
  133. }else{
  134. treeName.value = '飞鸟守护'
  135. }
  136. farmBuyId.value = data.buyList[0].id
  137. })
  138. }
  139. const showPoster = ref(false)
  140. const showAlbum = ref(false)
  141. const handleToolItem = ({
  142. path,clickName,params
  143. }) => {
  144. if(clickName === 'album'){
  145. showAlbum.value = !showAlbum.value
  146. }else if(clickName === 'poster'){
  147. showPoster.value = !showPoster.value
  148. }else{
  149. uni.navigateTo({
  150. url: `/pages/tabBar/tree/subPages/${path}?farmBuyId=${farmBuyId.value}`
  151. });
  152. }
  153. }
  154. const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
  155. const showBlessingsPopup = ref(false)
  156. const showSuccess = ref(false)
  157. const clockinType = ref('1')
  158. const handleItem = (index) =>{
  159. if(index === 0){
  160. clockinType.value = 1
  161. if(treeData.value.buyList[0].level.clockinMap['1']){
  162. uni.showToast({
  163. title: '今日已守护',
  164. icon:'none',
  165. duration: 2000
  166. });
  167. }else{
  168. showSuccess.value = !showSuccess.value
  169. }
  170. }else if(index === 1){
  171. clockinType.value = 3
  172. if(treeData.value.buyList[0].level.clockinMap['3']){
  173. uni.showToast({
  174. title: '今日已送过祝福',
  175. icon:'none',
  176. duration: 2000
  177. });
  178. }else{
  179. showBlessingsPopup.value = !showBlessingsPopup.value
  180. }
  181. }else if(index === 2){
  182. clockinType.value = 2
  183. if(!treeData.value.buyList[0].level.clockinMap['2']){
  184. showSuccess.value = !showSuccess.value
  185. }
  186. }else{
  187. console.log('123')
  188. }
  189. }
  190. function requestSubscribe() {
  191. // #ifdef MP-WEIXIN
  192. //订阅模板
  193. TREE.getSubscribeTemplate({id:1}).then(({data}) =>{
  194. uni.requestSubscribeMessage({
  195. tmplIds: [data.templateId], // 模板ID
  196. success(res) {
  197. if (res[data.templateId] === 'accept') {
  198. TREE.addSubscribe({templateId:1})
  199. } else if (res[data.templateId] === 'reject') {
  200. console.log('用户拒绝订阅模板');
  201. }
  202. },
  203. fail(err) {
  204. uni.openSetting({
  205. withSubscriptions: true, // 显示订阅消息开关
  206. });
  207. },
  208. });
  209. })
  210. // #endif
  211. }
  212. onShareAppMessage((res) => {
  213. if (res.from === 'button') {
  214. const params = {
  215. sampleId:treeData.value.buyList[0].sampleId,
  216. farmId:treeData.value.buyList[0].farmId,
  217. }
  218. return {
  219. title: '我分享了我的果树,快来查看吧~',
  220. path: `/pages/tabBar/tree/subPages/friendTree?params=${JSON.stringify(params)}`, // 分享的小程序页面路径
  221. 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()}`,
  222. }
  223. }
  224. })
  225. </script>
  226. <style lang="scss" scoped>
  227. @import "@/static/style/mixin.scss";
  228. .base-container {
  229. @include ossBg("tree-bg.png");
  230. // background-position: top left;
  231. padding: 22rpx 0;
  232. .toogle {
  233. position: absolute;
  234. right: 0;
  235. top: calc(50% - 32rpx);
  236. font-size: 24rpx;
  237. color: #fff;
  238. border-radius: 50rpx 0 0 50rpx;
  239. background: rgba(0, 0, 0, 0.2);
  240. padding: 12rpx 20rpx;
  241. display: flex;
  242. .icon {
  243. margin-left: 10rpx;
  244. }
  245. }
  246. .tree-cont {
  247. width: 100%;
  248. margin-top: 10rpx;
  249. .drone-icon {
  250. width: 376rpx;
  251. height: 384rpx;
  252. margin-left: 26rpx;
  253. }
  254. .tool-wrap {
  255. width: 100%;
  256. padding: 14rpx;
  257. box-sizing: border-box;
  258. position: absolute;
  259. bottom: calc(50% - 350rpx);
  260. display: flex;
  261. justify-content: space-between;
  262. .tool-left,
  263. .tool-right {
  264. .tool-item {
  265. color: #fff;
  266. font-size: 24rpx;
  267. font-weight: 500;
  268. text-align: center;
  269. width: 100rpx;
  270. margin-bottom: 16rpx;
  271. text-shadow:
  272. 0 0 3rpx #D7660A,
  273. 0 0 3rpx #D7660A,
  274. 0 0 3rpx #D7660A,
  275. 0 0 3rpx #D7660A;
  276. &.blue {
  277. text-shadow:
  278. 0 0 3rpx #2199F8,
  279. 0 0 3rpx #2199F8,
  280. 0 0 3rpx #2199F8,
  281. 0 0 3rpx #2199F8;
  282. }
  283. .icon {
  284. width: 100%;
  285. height: 82rpx;
  286. position: relative;
  287. }
  288. .name {
  289. margin-top: -24rpx;
  290. position: relative;
  291. z-index: 2;
  292. }
  293. &.gift {
  294. .icon {
  295. height: 114rpx;
  296. margin-top: -5rpx;
  297. }
  298. .name {
  299. margin-top: -44rpx;
  300. }
  301. }
  302. &.friend {
  303. .icon {
  304. height: 90rpx;
  305. }
  306. .name {
  307. margin-top: -35rpx;
  308. }
  309. }
  310. &.dynamic {
  311. .icon {
  312. height: 96rpx;
  313. }
  314. .name {
  315. margin-top: -32rpx;
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. .tree-footer {
  323. position: absolute;
  324. left: 0;
  325. bottom: 76rpx;
  326. width: 100%;
  327. display: flex;
  328. justify-content: center;
  329. .footer-item {
  330. width: 18%;
  331. text-align: center;
  332. .share-btn{
  333. background: transparent;
  334. display: inline-flex;
  335. &::after{
  336. border: none;
  337. }
  338. }
  339. .icon {
  340. width: 96rpx;
  341. height: 96rpx;
  342. }
  343. .name {
  344. font-size: 24rpx;
  345. font-weight: 500;
  346. padding: 2rpx 16rpx;
  347. background-image: linear-gradient(0deg, #FFFFFF, #FFE079);
  348. border-radius: 50rpx;
  349. border: 2rpx solid #fff;
  350. }
  351. }
  352. .footer-item+.footer-item {
  353. margin-left: 30rpx;
  354. }
  355. }
  356. }
  357. </style>