Blame view

pages-sub/daily/maintain-manage/index.vue 10.6 KB
834a3df1   刘淇   养护计划列表
1
  <template>
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
2
    <view class="page-container">
834a3df1   刘淇   养护计划列表
3
4
5
6
7
8
9
10
11
12
13
14
15
16
      <!-- 吸顶区域 -->
      <up-sticky>
        <view class="sticky-wrap">
          <!-- 第一行标签:养护类型 -->
          <up-tabs
              v-model="activeType"
              :list="typeTabs"
              line-width="40rpx"
              active-color="#1989fa"
              inactive-color="#666"
              :scrollable="true"
              class="first-tabs"
              @click="handleTypeChange"
          ></up-tabs>
c293da23   刘淇   新园林init
17
  
834a3df1   刘淇   养护计划列表
18
19
20
21
22
23
24
25
26
27
28
          <!-- 第二行标签:状态筛选 -->
          <up-tabs
              v-model="activeStatus"
              :list="statusTabs"
              line-width="40rpx"
              active-color="#1989fa"
              inactive-color="#666"
              :scrollable="true"
              class="second-tabs"
              @click="handleStatusChange"
          ></up-tabs>
c293da23   刘淇   新园林init
29
  
834a3df1   刘淇   养护计划列表
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
          <!-- 动态搜索框(道路名称/计划名称) -->
          <up-search
              v-model="searchValue"
              :placeholder="searchPlaceholder"
              bg-color="#f5f5f5"
              shape="round"
              :show-action="true"
              actionText="搜索"
              :animation="true"
              @search="handleSearch"
              @custom="handleSearch"
              :clearabled="false"
              maxlength="50"
              style="margin: 20rpx 20rpx 0"
          ></up-search>
        </view>
      </up-sticky>
  
      <!-- 内容区域 - 集成z-paging分页 -->
      <z-paging
          ref="pagingRef"
          v-model="currentList"
          @query="fetchData"
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
53
          :auto-show-system-loading="true"
834a3df1   刘淇   养护计划列表
54
55
56
57
58
59
      >
      <!-- 空数据提示 -->
      <template #empty>
        <empty-view/>
      </template>
  
834a3df1   刘淇   养护计划列表
60
        <!-- 道路类型卡片 -->
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
61
62
63
64
65
        <view v-if="activeType === '道路'" class="common-card-list" style="padding-top: 144px;">
  
          <up-card
              :border="false"
              :foot-border-top="false"
ec13a95c   刘淇   未完成明细 列表
66
              :head-border-bottom="false"
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
67
68
              v-for="(item,index) in currentList"
              :key="`${item.planNo}_${index}`"
ec13a95c   刘淇   未完成明细 列表
69
              :show-head="false"
834a3df1   刘淇   养护计划列表
70
          >
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
            <template #body>
              <view class="card-body">
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">道路名称:</view>
                  <view class="u-line-1 u-body-value">{{ item.roadName || '-' }}</view>
                </view>
  
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">所属街道:</view>
                  <view class="u-line-1 u-body-value">{{ item.streetName }}
                  </view>
                </view>
  
                <view class="u-body-item u-flex common-item-center common-justify-between">
                  <view class="u-body-item-title">养护级别: {{uni.$dict.getDictLabel('conserve_level', item.levelId) || '-'}}</view>
                  <view class="u-line-1">
                    <up-button
                        type="primary"
                        size="mini"
                        @click="goToDetail(item)"
                        class="submit-record-btn"
                    >
                      计划明细
                    </up-button>
                  </view>
                </view>
  
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">计划时间:</view>
                  <view class="u-line-1 u-body-value">{{ timeFormat(item.beginTime, 'yyyy-mm-dd') || '-' }} 至
                    {{ timeFormat(item.endTime, 'yyyy-mm-dd') || '-' }}
                  </view>
834a3df1   刘淇   养护计划列表
103
104
                </view>
              </view>
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
105
106
            </template>
          </up-card>
834a3df1   刘淇   养护计划列表
107
108
109
        </view>
  
        <!-- 其他养护类型卡片(补植/浇水等) -->
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
110
111
112
113
114
115
116
117
        <view v-else class="common-card-list" style="padding-top: 144px;">
  
          <up-card
              :border="false"
              :foot-border-top="false"
              v-for="(item,index) in currentList"
              :key="`${item.planNo}_${index}`"
  
834a3df1   刘淇   养护计划列表
118
          >
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
119
120
121
122
            <!-- 自定义标题区域 -->
            <template #head>
              <view class="card-header">
                <view class="common-card-title  u-line-1">{{ item.planName || '无计划名称' }}</view>
834a3df1   刘淇   养护计划列表
123
              </view>
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
            </template>
  
            <template #body>
              <view class="card-body">
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">计划编码:</view>
                  <view class="u-line-1 u-body-value">{{ item.planNo || '-' }}</view>
                </view>
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">养护周期:</view>
                  <view class="u-line-1 u-body-value">{{ item.rate || '-' }}
                    {{ uni.$dict.getDictLabel('cycle_id_type', item.cycleId) }}
                  </view>
                </view>
  
                <view class="u-body-item u-flex common-item-center common-justify-between">
                  <view class="u-body-item-title">计划完成次数: {{ item.planNum || 0 }}</view>
54955fb5   刘淇   巡查和养护 。 失效状态的判断
141
                  <view class="u-line-1" v-if="item.finishState!==3">
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
                    <up-button
                        type="primary"
                        size="mini"
                        @click="submitRecord(item)"
                        class="submit-record-btn"
                    >
                      提交记录
                    </up-button>
                  </view>
                </view>
  
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">已完成比例:</view>
                  <view class="u-line-1 u-body-value">{{ item.finishPercent || 0 }}%</view>
                </view>
  
                <view class="u-body-item u-flex">
                  <view class="u-body-item-title">计划有效期:</view>
                  <view class="u-line-1 u-body-value">{{ timeFormat(item.beginTime, 'yyyy-mm-dd') || '-' }} 至
                    {{ timeFormat(item.endTime, 'yyyy-mm-dd') || '-' }}
                  </view>
834a3df1   刘淇   养护计划列表
163
164
                </view>
              </view>
fb13622a   刘淇   养护计划列表 样式 差去一个卡片的头部
165
166
167
            </template>
          </up-card>
  
834a3df1   刘淇   养护计划列表
168
        </view>
834a3df1   刘淇   养护计划列表
169
170
      </z-paging>
    </view>
c293da23   刘淇   新园林init
171
172
  </template>
  
834a3df1   刘淇   养护计划列表
173
  <script setup>
ec13a95c   刘淇   未完成明细 列表
174
175
176
  import { ref, computed } from 'vue'
  import { onLoad, onShow } from '@dcloudio/uni-app'
  import { roadPage, planTypePage } from "@/api/maintain-manage/maintain-manage";
834a3df1   刘淇   养护计划列表
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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
297
298
299
300
301
302
303
304
  import { timeFormat } from '@/uni_modules/uview-plus';
  
  // 初始化响应式数据
  const typeTabs = ref([])
  const statusTabs = ref([
    { name: '待完成', id: '1' },
    { name: '已失效', id: '3' },
    { name: '已完成', id: '2' }
  ])
  
  // 核心响应式数据
  const activeType = ref('道路')
  const activeStatus = ref('1')
  const searchValue = ref('')
  const pagingRef = ref(null) // z-paging实例
  
  // 分页参数
  const pageSize = ref(10)
  const currentList = ref([]) // z-paging绑定的列表
  
  // 处理字典数据的方法
  const handleDictData = () => {
    // 获取养护类型字典
    const tabList = uni.$dict.getDictSimpleList('maintain_type')
    console.log('原始字典数据:', tabList)
  
    if (!tabList || tabList.length === 0) {
      console.warn('养护类型字典数据为空,请检查字典配置')
      typeTabs.value = [{ name: '道路', planTypeId: '', id: '道路' }]
      return
    }
  
    // 1. 过滤掉临时养护(包含"临时养护"的项)
    const filteredList = tabList.filter(item => !item.label.includes('临时养护'))
  
    // 2. 转换为 {name: 字典原生标签, planTypeId: 字典值, id: 标签名} 格式
    const convertedList = filteredList.map(item => ({
      name: item.label, // 直接使用字典原始名称
      planTypeId: item.value,
      id: item.label // 兼容up-tabs的id字段
    }))
  
    // 3. 补充道路类型(放在第一位)
    convertedList.unshift({
      name: '道路',
      planTypeId: '',
      id: '道路'
    })
  
    // 赋值给typeTabs
    typeTabs.value = convertedList
    console.log('处理后的字典数据:', typeTabs.value)
  }
  
  // 动态搜索框占位符
  const searchPlaceholder = computed(() => {
    return activeType.value === '道路' ? '请输入道路名称' : '请输入计划名称'
  })
  
  // 养护类型切换
  const handleTypeChange = (item) => {
    console.log('切换养护类型:', item)
    activeType.value = item.name
    searchValue.value = ''
    // 重置分页并刷新
    pagingRef.value?.reload()
  }
  
  // 状态筛选切换
  const handleStatusChange = (item) => {
    console.log('切换状态:', item)
    activeStatus.value = item.id
    // 重置分页并刷新
    pagingRef.value?.reload()
  }
  
  // 搜索处理
  const handleSearch = () => {
    console.log('搜索关键词:', searchValue.value)
    // 重置分页并刷新
    pagingRef.value?.reload()
  }
  
  // 核心数据请求方法(适配z-paging的query回调)
  const fetchData = async (pageNo, pageSize) => {
    try {
      let res = null
      // 道路类型请求
      if (activeType.value === '道路') {
        res = await roadPage({
          roadName: searchValue.value.trim(),
          pageNo,
          pageSize,
          finishState: activeStatus.value
        })
      } else {
        // 其他养护类型请求
        // 找到当前类型对应的planTypeId
        const currentType = typeTabs.value.find(item => item.name === activeType.value)
        res = await planTypePage({
          planTypeId: currentType?.planTypeId || '',
          planName: searchValue.value.trim(),
          pageNo,
          pageSize,
          finishState: activeStatus.value
        })
      }
  
      // 告诉z-paging数据加载完成
      // res.list为当前页数据,res.total为总条数(如果接口返回)
      pagingRef.value?.complete(res?.list || [], res?.total)
    } catch (error) {
      console.error('请求失败:', error)
      uni.showToast({ title: '网络异常,请重试', icon: 'none' })
      // 加载失败,告诉z-paging
      pagingRef.value?.complete(false)
    }
  }
  
  // 跳转到计划明细页面
  const goToDetail = (item) => {
    uni.navigateTo({
      url: `/pages-sub/daily/maintain-manage/road-detail-list?roadId=${item.roadId}&finish_state=${item.finishState || ''}`
    })
  }
  
  // 提交记录
  const submitRecord = (item) => {
834a3df1   刘淇   养护计划列表
305
    console.log('提交记录:', item)
cc42bec8   刘淇   快速工单和巡查计划样式优化
306
307
308
309
310
311
312
313
314
315
316
    if (item.finishPercent == 0) { // 去新增
      uni.navigateTo({
        url: `/pages-sub/daily/maintain-manage/add-record?finishState=${item.finishState}&planNo=${item.planNo}&finishPercent=${item.finishPercent}`
      })
    } else {
      uni.navigateTo({
        url: `/pages-sub/daily/maintain-manage/pending-plan-detail?finishState=${item.finishState}&planNo=${item.planNo}&finishPercent=${item.finishPercent}&planTypeId=${item.planTypeId}`
      })
    }
  
  
834a3df1   刘淇   养护计划列表
317
318
319
320
321
322
  }
  
  // 页面加载时初始化数据
  onLoad(() => {
    // 先处理字典数据
    handleDictData()
ec13a95c   刘淇   未完成明细 列表
323
324
  })
  onShow(()=>{
834a3df1   刘淇   养护计划列表
325
326
327
328
329
330
    // 初始化分页数据
    pagingRef.value?.reload()
  })
  </script>
  
  <style scoped lang="scss">
834a3df1   刘淇   养护计划列表
331
332
  // 吸顶区域样式
  .sticky-wrap {
54955fb5   刘淇   巡查和养护 。 失效状态的判断
333
    margin-top: -10rpx;
834a3df1   刘淇   养护计划列表
334
335
336
337
338
339
340
341
342
    background-color: #fff;
    padding-bottom: 10rpx;
    border-bottom: 1px solid #eee;
  
    .first-tabs, .second-tabs {
      margin: 10rpx 0;
    }
  }
  
c293da23   刘淇   新园林init
343
  
c293da23   刘淇   新园林init
344
  </style>