farm.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="farm-page">
  3. <custom-header name="我的农场"></custom-header>
  4. <div class="farm-list">
  5. <div class="list-item" v-for="item in farmList" :key="item.id" @click="handleItemClick(item)">
  6. <div class="item-info">
  7. <div class="item-top">
  8. <img class="left-img" src="@/assets/img/home/farm.png" alt="" />
  9. <div class="left-content">
  10. <div class="content-title">
  11. <div class="title-left">
  12. <span class="title-text van-ellipsis">{{ item.name }}</span>
  13. <div class="content-tag" v-if="item.defaultOption">默认</div>
  14. <div class="content-text" v-else @click.stop="handleSetDefault(item)">设为默认</div>
  15. </div>
  16. <div class="item-btn">查看详情</div>
  17. </div>
  18. <div class="content-desc">
  19. <div>服务作物:{{ item.speciesName }}</div>
  20. <div>农场位置:{{ item.address }}</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script setup>
  30. import customHeader from "@/components/customHeader.vue";
  31. import { ref, onMounted } from "vue";
  32. import { ElMessageBox } from "element-plus";
  33. import { useRouter } from "vue-router";
  34. const router = useRouter();
  35. const farmList = ref([]);
  36. onMounted(() => {
  37. getFarmList();
  38. });
  39. const handleSetDefault = async ({id}) => {
  40. ElMessageBox.confirm('确定将该农场设为默认农场吗?', '提示', {
  41. confirmButtonText: '确定',
  42. cancelButtonText: '取消',
  43. type: 'warning',
  44. }).then(async () => {
  45. const { code } = await VE_API.farm.updateFarm({
  46. farmId: id,
  47. defaultFarm: 1,
  48. });
  49. if(code === 0){
  50. getFarmList();
  51. }
  52. }).catch(() => {});
  53. };
  54. const getFarmList = async () => {
  55. const { data } = await VE_API.farm.userFarmSelectOption();
  56. farmList.value = data || [];
  57. };
  58. const handleItemClick = (item) => {
  59. router.push({
  60. path: '/monitor',
  61. query: {
  62. farmId: item.id,
  63. defaultFarm: item.defaultOption,
  64. isHeaderShow: true,
  65. },
  66. });
  67. };
  68. </script>
  69. <style scoped lang="scss">
  70. .farm-page {
  71. width: 100%;
  72. height: 100vh;
  73. .farm-list {
  74. width: 100%;
  75. height: calc(100% - 40px);
  76. background-color: #f7f7f7;
  77. padding: 12px;
  78. box-sizing: border-box;
  79. overflow: auto;
  80. .list-item {
  81. background-color: #fff;
  82. border-radius: 10px;
  83. padding: 10px;
  84. display: flex;
  85. width: 100%;
  86. box-sizing: border-box;
  87. .item-info {
  88. width: 100%;
  89. .item-top {
  90. width: 100%;
  91. display: flex;
  92. align-items: center;
  93. gap: 12px;
  94. .left-img {
  95. width: 68px;
  96. height: 68px;
  97. border-radius: 8px;
  98. }
  99. .left-content {
  100. width: calc(100% - 68px - 12px);
  101. .content-title {
  102. display: flex;
  103. align-items: center;
  104. justify-content: space-between;
  105. margin-bottom: 4px;
  106. font-size: 16px;
  107. font-weight: 500;
  108. .title-left{
  109. display: flex;
  110. align-items: center;
  111. gap: 10px;
  112. width: calc(100% - 62px);
  113. .title-text{
  114. max-width: calc(100% - 60px);
  115. }
  116. .content-tag {
  117. background-color: #2199f8;
  118. color: #fff;
  119. padding: 2px 8px;
  120. border-radius: 15px;
  121. font-size: 12px;
  122. font-weight: 400;
  123. }
  124. .content-text {
  125. font-size: 12px;
  126. color: #2199f8;
  127. font-weight: 400;
  128. }
  129. }
  130. }
  131. .item-btn {
  132. color: #a8a8a8;
  133. font-size: 14px;
  134. font-weight: 400;
  135. }
  136. .content-desc {
  137. font-size: 12px;
  138. color: #999999;
  139. line-height: 18px;
  140. }
  141. }
  142. }
  143. }
  144. }
  145. .list-item + .list-item {
  146. margin-top: 12px;
  147. }
  148. }
  149. }
  150. </style>