diary.vue 11 KB

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