diary.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view class="sub-base-container">
  3. <view class="tree-info">
  4. <image class="image" mode="aspectFill" :src="getImageUrl(treeData.treeImages[0].filename)"></image>
  5. <view class="info-cont">
  6. <view class="tree-name">果树档案</view>
  7. <view class="text-wrap">
  8. <view class="row-text">
  9. <text class="label">树木名称</text>
  10. <text>{{treeName}}</text>
  11. </view>
  12. <view class="row-text">
  13. <text class="label">树木编号</text>
  14. <text>{{treeData.buyList[0].code}}</text>
  15. </view>
  16. <view class="row-text">
  17. <text class="label">来自农场</text>
  18. <text>{{treeData.countyName}}{{treeData.farmName}}</text>
  19. </view>
  20. <view class="row-text">
  21. <text class="label">品种树龄</text>
  22. <text>{{treeData.pz}}-{{treeData.age}}年</text>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="tree-diary">
  28. <view class="diary-head">
  29. <view class="date" @click="handleDate">
  30. <image class="img" :src="`${config.BASIC_IMG}img/subTreePage/date-icon.png`"></image>
  31. <text>{{formatDate(dateVal)}}</text>
  32. </view>
  33. <view class="arrow-group">
  34. <view class="arrow-icon" @click="changeDay(-1)">
  35. <up-icon name="arrow-left" size="17" bold color="#fff"></up-icon>
  36. </view>
  37. <view class="arrow-icon" @click="changeDay(+1)">
  38. <up-icon name="arrow-right" size="17" bold color="#fff"></up-icon>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="diary-cont">
  43. <template v-if="active === 0">
  44. <view class="text">{{diaryData.content}}</view>
  45. <view class="photo">
  46. <image class="img" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></image>
  47. </view>
  48. </template>
  49. <view class="template-1" v-else-if="active === 1">
  50. <view class="photo-group">
  51. <image class="img" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></image>
  52. <image class="img float" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></image>
  53. </view>
  54. <view class="text">{{diaryData.content}}</view>
  55. </view>
  56. <view class="template-2" v-else="active === 2">
  57. <view class="photo-group">
  58. <image class="img" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></image>
  59. <image class="img float" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></image>
  60. </view>
  61. <view class="text">{{diaryData.content}}</view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <up-datetime-picker
  67. :show="showDatetim"
  68. v-model="dateVal"
  69. mode="date"
  70. :maxDate="Date.now()"
  71. :formatter="formatter"
  72. @cancel="cancel"
  73. @confirm="confirm"
  74. ></up-datetime-picker>
  75. </template>
  76. <script setup>
  77. import config from "@/api/config.js"
  78. import {ref} from "vue"
  79. import TREE from '@/api/tree.js'
  80. import {
  81. onLoad
  82. } from '@dcloudio/uni-app'
  83. const resize = "?x-oss-process=image/resize,w_1000";
  84. const getImageUrl = (filename) =>{
  85. if (filename?.startsWith("https")) {
  86. return filename; // 直接使用完整 URL
  87. } else {
  88. return config.BASE_IMG_URL + filename + resize; // 拼接基础 URL
  89. }
  90. };
  91. const sampleId = ref('')
  92. onLoad((options)=>{
  93. sampleId.value = options.sampleId
  94. featchGetSampleDiary()
  95. getBySampleId()
  96. })
  97. const diaryData = ref({})
  98. const featchGetSampleDiary = () =>{
  99. const params = {
  100. sampleId:110950,
  101. createDateStart:'2025-04-13',
  102. createDateEnd:'2025-04-13',
  103. page:1,
  104. limit:1
  105. }
  106. TREE.getSampleDiary(params).then(res =>{
  107. if(res.data.length){
  108. diaryData.value = res.data[0]
  109. }
  110. })
  111. }
  112. const treeData = ref({})
  113. const treeName = ref('')
  114. const getBySampleId = () => {
  115. TREE.getBySampleId({
  116. sampleId: sampleId.value
  117. }).then(({
  118. data
  119. }) => {
  120. treeData.value = data || {}
  121. treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length ? data.buyList[0]
  122. .nickname.slice(0, 3) + "荔" : data.buyList[0].owner.slice(0, 3) + "荔")
  123. })
  124. }
  125. function formatDate(timestamp,type) {
  126. const date = new Date(timestamp);
  127. const year = date.getFullYear();
  128. const month = String(date.getMonth() + 1)
  129. const day = String(date.getDate()).padStart(2, '0'); // 日期补零
  130. return `${year}${type || '年'}${month}${type || '月'}${day}${type?'':'日'}`;
  131. }
  132. const currentDate = ref(new Date())
  133. function changeDay(type) {
  134. currentDate.value = new Date(currentDate.value);
  135. currentDate.value.setDate(currentDate.value.getDate() + type);
  136. if(currentDate.value > new Date()){
  137. currentDate.value.setDate(currentDate.value.getDate() - 1);
  138. return
  139. }
  140. dateVal.value = Date.parse(currentDate.value);
  141. //获取 0-2 的随机整数
  142. const randomInt = Math.floor(Math.random() * 3);
  143. active.value = randomInt
  144. }
  145. const showDatetim = ref(false)
  146. const dateVal = ref(Date.now())
  147. const handleDate = () =>{
  148. showDatetim.value = true
  149. }
  150. const cancel = () =>{
  151. showDatetim.value = false
  152. }
  153. const confirm = ()=>{
  154. const aaa = formatDate(date.value,'-')
  155. console.log(date.value,aaa)
  156. cancel()
  157. }
  158. const active = ref(2)
  159. const formatter = (type, value) => {
  160. if (type === 'year') {
  161. return `${value}年`;
  162. }
  163. if (type === 'month') {
  164. return `${value}月`;
  165. }
  166. if (type === 'day') {
  167. return `${value}日`;
  168. }
  169. return value;
  170. };
  171. </script>
  172. <style lang="scss" scoped>
  173. @import "@/static/style/mixin.scss";
  174. .sub-base-container {
  175. background-image: linear-gradient(0deg, #FFFFFF, rgba(33, 153, 248, 0.6));
  176. max-height: 484rpx;
  177. min-height: 484rpx;
  178. padding-top: 52rpx;
  179. .tree-info {
  180. display: flex;
  181. justify-content: space-between;
  182. .image {
  183. width: 220rpx;
  184. height: 220rpx;
  185. border: 2rpx solid #fff;
  186. border-radius: 16rpx;
  187. }
  188. .info-cont {
  189. width: calc(100% - 220rpx - 36rpx);
  190. border: 2rpx solid #fff;
  191. border-radius: 16rpx;
  192. background-image: linear-gradient(180deg, rgba(241, 249, 255, .6), rgba(255, 255, 255, .75));
  193. .tree-name {
  194. font-size: 28rpx;
  195. font-family: 'PangMenZhengDao';
  196. padding: 8rpx 0;
  197. border-radius: 16rpx 4rpx 16rpx 4rpx;
  198. background-image: linear-gradient(120deg, #9FD5FF, #2199F8);
  199. color: #fff;
  200. width: 164rpx;
  201. text-align: center;
  202. }
  203. .text-wrap {
  204. padding: 8rpx 0 0 20rpx;
  205. line-height: 36rpx;
  206. .row-text {
  207. font-size: 24rpx;
  208. .label {
  209. font-weight: 500;
  210. margin-right: 20rpx;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. .tree-diary {
  217. width: 100%;
  218. min-height: 960rpx;
  219. box-sizing: border-box;
  220. padding: 70rpx 0 56rpx 30rpx;
  221. @include ossBg("subTreePage/diary-bg.png");
  222. .diary-head{
  223. display: flex;
  224. justify-content: space-between;
  225. .date{
  226. font-family: 'PangMenZhengDao';
  227. font-size: 29rpx;
  228. color: #2199F8;
  229. display: flex;
  230. align-items: center;
  231. .img{
  232. width: 26rpx;
  233. height: 26rpx;
  234. margin-right: 10rpx;
  235. }
  236. }
  237. .arrow-group{
  238. display: flex;
  239. .arrow-icon{
  240. border-radius: 50%;
  241. background: rgba(33, 153, 248, 0.2);
  242. width: 56rpx;
  243. height: 56rpx;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. }
  248. .arrow-icon + .arrow-icon{
  249. margin-left: 20rpx;
  250. }
  251. }
  252. }
  253. .diary-cont{
  254. padding: 80rpx 60rpx 0 26rpx;
  255. .text{
  256. width: 72%;
  257. margin: 60rpx auto;
  258. font-weight: 500;
  259. position: relative;
  260. &::before{
  261. content: '“';
  262. position: absolute;
  263. top: -85rpx;
  264. left: -90rpx;
  265. font-size: 140rpx;
  266. color: rgba(33, 153, 248, 0.2);
  267. }
  268. &::after{
  269. content: '”';
  270. position: absolute;
  271. bottom: -130rpx;
  272. right: -110rpx;
  273. font-size: 140rpx;
  274. color: rgba(33, 153, 248, 0.2);
  275. }
  276. }
  277. .photo{
  278. width: 100%;
  279. height: 420rpx;
  280. margin-top: 90rpx;
  281. border: 10rpx solid #d0e6fb;
  282. box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.1);
  283. position: relative;
  284. &::before{
  285. content: '';
  286. position: absolute;
  287. z-index: 2;
  288. right: -34rpx;
  289. top: 0;
  290. background: rgba(33, 153, 248, 0.56);
  291. transform: rotate(38deg);
  292. width: 102rpx;
  293. height: 30rpx;
  294. }
  295. .img{
  296. width: 100%;
  297. height: 100%;
  298. object-fit: cover;
  299. }
  300. }
  301. .template-1{
  302. .photo-group{
  303. margin:0 -14rpx 240rpx 10rpx;
  304. .img{
  305. width: 354rpx;
  306. height: 240rpx;
  307. border: 10rpx solid rgba(255, 255, 255, 0.6);
  308. box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.1);
  309. }
  310. .float{
  311. width: 400rpx;
  312. height: 264rpx;
  313. float: right;
  314. margin-top: -130rpx;
  315. }
  316. }
  317. .text{
  318. width: 55%;
  319. margin: 0 auto;
  320. }
  321. }
  322. .template-2{
  323. .photo-group{
  324. margin:0 -10rpx 220rpx 10rpx;
  325. .img{
  326. position: relative;
  327. z-index: 2;
  328. width: 440rpx;
  329. height: 300rpx;
  330. border: 10rpx solid rgba(255, 255, 255, 0.3);
  331. box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.1);
  332. }
  333. .float{
  334. width: 332rpx;
  335. height: 222rpx;
  336. float: right;
  337. margin-top: -100rpx;
  338. transform: rotate(10deg);
  339. position: relative;
  340. z-index: 1;
  341. }
  342. }
  343. .text{
  344. width: 66%;
  345. margin: 0 auto;
  346. }
  347. }
  348. }
  349. }
  350. }
  351. </style>