diary.vue 11 KB

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