tree.vue 11 KB

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