diary.vue 11 KB

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