Blame view

pages-sub/data/tree-archive/editTree.vue 8.3 KB
12e66ec8   刘淇   新增树
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <template>
    <view class="container">
      <!-- ✅ 顶部固定吸顶Tabs区域 - 核心新增 -->
      <up-sticky bg-color="#ffffff">
        <view class="header-wrap">
          <up-tabs
              v-model="activeTab"
              :list="tabList"
              active-color="#1989fa"
              inactive-color="#666"
              font-size="30rpx"
              @click="handleTabChange"
              :scrollable="false"
          />
        </view>
      </up-sticky>
8ddc6f6e   刘淇   登录 修改样式
17
  
12e66ec8   刘淇   新增树
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
      <!-- ✅ Tab0 基本信息页面 (树木的详情编辑页,保留你原编辑页核心结构,这里给你做了标准基础版,可直接加表单) -->
      <view v-show="activeTab === 0" class="base-info-wrap">
        <up-card :border="false" :show-head="false" class="base-card">
          <view class="card-body-inner">
            <view class="record-list-left" :style="`background-image: url(${treeInfo.treephoto});`"></view>
            <view class="record-list-right">
              <view class="record-list-right-title">
                <view class="u-line-1 treetypeName">{{ treeInfo.treetype }}</view>
              </view>
              <view class="fs-mt8 fs-align__center">
                <img src="../../../static/imgs/tree/tree-high.png" style="width: 14px;height: 14px;margin-right: 6px;" alt=""> 高度:{{ treeInfo.treeheight }} 米
              </view>
              <view class="fs-mt8 fs-align__center">
                <img src="../../../static/imgs/tree/treearound.png" style="width: 14px;height: 14px;margin-right: 6px;" alt="">胸径:{{ treeInfo.dbh }} 厘米
              </view>
              <view class="fs-mt8 fs-align__center">
                <text>树木编号:{{ treeInfo.treenumber }}</text>
              </view>
            </view>
          </view>
          <!-- 这里可以继续加你的 编辑表单/其他基本信息 -->
        </up-card>
      </view>
8ddc6f6e   刘淇   登录 修改样式
41
  
12e66ec8   刘淇   新增树
42
43
44
45
46
47
48
49
50
51
52
      <!-- ✅ Tab1 变更日志页面 - 和列表页布局完全一致 + 无新增按钮 + 点击卡片跳转详情 -->
      <view v-show="activeTab === 1" class="log-wrap">
        <up-empty v-if="logRows.length === 0" text="暂无变更日志"></up-empty>
        <view class="record-wrap" v-else>
          <up-card
              v-for="item in logRows"
              :key="item.id"
              :border="false"
              :show-head="false"
              class="tree-card"
              :foot-border-top="false"
c5fdc60a   刘淇   树详情
53
              @click="toLogDetailPage(item)"
12e66ec8   刘淇   新增树
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
          >
            <template #body>
              <view class="card-body-inner">
                <!-- ✅ 保留你要求的背景图写法 -->
                <view class="record-list-left" :style="`background-image: url(${item.treephotoone});`"></view>
                <view class="record-list-right">
                  <view class="record-list-right-title">
                    <view class="u-line-1 treetypeName">{{ item.treetype }}</view>
                    <view style="text-align: right">{{ timeFormat(item.updatetime) }}</view>
                  </view>
                  <view class=" fs-align__center" style="margin: 5px 0">
                    <img src="../../../static/imgs/tree/tree-high.png" style="width: 14px;height: 14px;margin-right: 6px;" alt=""> 高度:{{ item.treeheight }} 米
                  </view>
                  <view class=" fs-align__center">
                    <img src="../../../static/imgs/tree/treearound.png" style="width: 14px;height: 14px;margin-right: 6px;" alt="">胸径:{{ item.dbh }} 厘米
                  </view>
                </view>
              </view>
              <view class="treenumber-no">
                树木编号:{{ item.treenumber }}
              </view>
            </template>
          </up-card>
        </view>
      </view>
  
      <!-- ✅ 新增按钮 只在【基本信息Tab】显示,变更日志Tab自动隐藏,无需手动处理 -->
      <view class="fixed-bottom-btn-wrap">
        <up-button
            type="primary"
            @click="toAddTreePage"
            v-show="count > 0 && count > rows.length && activeTab === 0"
        >
          新增树木录入
        </up-button>
      </view>
8ddc6f6e   刘淇   登录 修改样式
90
  
12e66ec8   刘淇   新增树
91
    </view>
8ddc6f6e   刘淇   登录 修改样式
92
93
  </template>
  
12e66ec8   刘淇   新增树
94
95
  <script setup>
  import { ref, reactive } from 'vue'
c5fdc60a   刘淇   树详情
96
97
98
99
100
101
102
  import { onReady, onLoad, onShow, onUnload } from '@dcloudio/uni-app';
  onUnload(() => {
    // 关闭所有页面,直接打开【行道树档案】主页面 【微信小程序完美兼容,无任何报错】
    uni.reLaunch({
      url: '/pages-sub/data/tree-archive/index'
    })
  })
12e66ec8   刘淇   新增树
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  import { treeRoadReq,treeLogReq } from "@/api/tree-archive/tree-archive.js";
  import { timeFormat } from '@/uni_modules/uview-plus';
  
  // ========== 基础变量 ==========
  const rows = ref([])
  const roadId = ref('')
  const count = ref(0)
  const treeId = ref('')
  
  // ========== Tab切换核心变量 ==========
  const activeTab = ref(0); // 0=基本信息 1=变更日志
  const tabList = ref([
    { name: '基本信息' },
    { name: '变更日志' }
  ]);
  
  // ========== 数据变量 ==========
  const treeInfo = reactive({ // 基本信息-单棵树详情
    treephoto: '',
    treetype: '',
    treeheight: '',
    dbh: '',
    treenumber: '',
    updatetime: ''
  })
  const logRows = ref([]) // 变更日志列表数据
  
  // ========== 生命周期 ==========
  onLoad((options) => {
    console.log('编辑页入参', options)
    roadId.value = options.roadId || ''
    count.value = options.count || 0
    treeId.value = options.id || '' // 树木主键ID
  })
  
  onShow(() => {
    treeRoadQuery()
    if(activeTab.value === 0){
      // getTreeDetail() // 进入页面默认加载基本信息
    }
  })
  
c5fdc60a   刘淇   树详情
145
  
12e66ec8   刘淇   新增树
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  // ========== Tab切换事件 ==========
  const handleTabChange = (item) => {
    activeTab.value = item.index
    // 切换到哪个tab,加载对应的数据
    if(activeTab.value === 0){
      getTreeDetail() // 加载基本信息
    }else if(activeTab.value === 1){
      getTreeLogList() // 加载变更日志列表
    }
  }
  
  // ========== 接口请求 ==========
  // 树木列表查询
  const treeRoadQuery = async () => {
    const res = await treeRoadReq( {road: roadId.value})
    rows.value = res.list
  }
  
  // // 获取单棵树的基本信息
  // const getTreeDetail = async () => {
  //   const res = await treeDetailReq({ id: treeId.value })
  //   Object.assign(treeInfo, res)
  // }
  
  // 获取树木的变更日志列表
  const getTreeLogList = async () => {
    const res = await treeLogReq({ treeid: treeId.value })
    logRows.value = res.list
  }
  
  // ========== 页面跳转 ==========
  // 前往修改页面(原有)
  const toEditPage = (id) => {
    uni.navigateTo({
      url: `/pages-sub/data/tree-archive/editTree?id=${id}&roadId=${roadId.value}`
    })
  }
  
  // 前往新增页面(原有)
  const toAddTreePage = () => {
    uni.navigateTo({
      url: `/pages-sub/data/tree-archive/addTree?roadId=${roadId.value}`
    })
  }
  
  // ✅ 新增:点击变更日志卡片 前往日志详情页面
c5fdc60a   刘淇   树详情
192
  const toLogDetailPage = (i) => {
12e66ec8   刘淇   新增树
193
    uni.navigateTo({
c5fdc60a   刘淇   树详情
194
195
196
197
198
199
200
201
202
203
204
205
      // url: `/pages-sub/data/tree-archive/logDetail?id=${logId}&treeId=${treeId.value}`
      url: `/pages-sub/data/tree-archive/logDetail`,
      events: {
        sendBackData: (data) => {
          console.log('B页面回传的数据:', data);
        }
      },
      // 2. 向B页面传递数据
      success: (res) => {
        // 通过 eventChannel 发送数据,key
        res.eventChannel.emit('logData', i);
      }
12e66ec8   刘淇   新增树
206
207
208
209
    })
  }
  </script>
  
8ddc6f6e   刘淇   登录 修改样式
210
  <style scoped lang="scss">
12e66ec8   刘淇   新增树
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
  .container {
    min-height: 100vh;
  }
  
  // ✅ 顶部tabs吸顶样式
  .header-wrap {
    background-color: #fff;
    padding: 10rpx 0;
    box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.03);
  }
  
  // 基本信息样式
  .base-info-wrap {
    padding: 20rpx 10rpx;
  }
  .base-card {
    background: #fff;
    border-radius: 6px;
    padding: 10px;
  }
  
  // 变更日志样式 和列表页完全一致
  .log-wrap {
    min-height: calc(100vh - 120rpx);
  }
  .record-wrap {
    padding-bottom: 20px;
  }
  
  .treetypeName {
    flex: 1;
    font-size: 16px;
    font-weight: bold;
  }
  
  .record-list-left {
    height: 70px;
    width: 70px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
  }
  
  .record-list-right {
    margin-left: 20px;
    flex: 1;
    overflow: hidden;
  }
  
  .record-list-right-title {
    display: flex;
    justify-content: space-between;
  }
  
  .treenumber-no {
    padding: 3px 10px;
    background: #bdefd0;
    font-size: 12px;
    margin-top: 8px;
  }
  
  // up-card样式适配
  .tree-card {
    //margin: 15px 10px 0;
    //padding: 10px;
    //border-radius: 6px;
    //font-size: 14px;
    //box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
    //background-color: #ffffff;
  }
  .card-body-inner{
    display: flex;
  }
  
  
  .addTree {
    width: 100%;
    position: fixed;
    bottom: 0;
  }
  
  
  .fs-align__center {
    display: flex;
    align-items: center;
  }
8ddc6f6e   刘淇   登录 修改样式
297
298
  
  </style>