index.vue 11.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 90 91 92 93 94 95 96 97 98 99 100 101 102 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 145 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 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
<template>
  <view class="page-container">
    <!-- 吸顶区域 -->
    <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>

        <!-- 第二行标签:状态筛选 -->
        <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>

        <!-- 动态搜索框(道路名称/计划名称) -->
        <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"
        :auto-show-system-loading="true"
    >
    <!-- 空数据提示 -->
    <template #empty>
      <empty-view/>
    </template>

      <!-- 道路类型卡片 -->
      <view v-if="activeType === '道路'" class="common-card-list" style="padding-top: 144px;">

        <up-card
            :border="false"
            :foot-border-top="false"
            :head-border-bottom="false"
            v-for="(item,index) in currentList"
            :key="`${item.planNo}_${index}`"
            :show-header="false"
        >
          <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>
              </view>
            </view>
          </template>
        </up-card>
      </view>

      <!-- 其他养护类型卡片(补植/浇水等) -->
      <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}`"

        >
          <!-- 自定义标题区域 -->
          <template #head>
            <view class="card-header">
              <view class="common-card-title  u-line-1">{{ item.planName || '无计划名称' }}</view>
            </view>
          </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>
                <view class="u-line-1">
                  <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>
              </view>
            </view>
          </template>
        </up-card>

      </view>
    </z-paging>
  </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { roadPage, getRoadDetails, planTypePage } from "@/api/maintain-manage/maintain-manage";
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) => {
  uni.navigateTo({
    url: `/pages/submitRecord/submitRecord?planId=${item.id || ''}&planName=${encodeURIComponent(item.planName || '')}`
  })
  console.log('提交记录:', item)
}

// 页面加载时初始化数据
onLoad(() => {
  // 先处理字典数据
  handleDictData()
  // 初始化分页数据
  pagingRef.value?.reload()
})
</script>

<style scoped lang="scss">
.main-container {
  min-height: 100vh;
  background-color: #f8f8f8;
}

// 吸顶区域样式
.sticky-wrap {
  background-color: #fff;
  padding-bottom: 10rpx;
  border-bottom: 1px solid #eee;

  .first-tabs, .second-tabs {
    margin: 10rpx 0;
  }
}

// 内容区域样式
.content-wrap {
  padding:200rpx 20rpx 20rpx;
  box-sizing: border-box;
}

// 卡片列表样式
.card-list {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

// 卡片项样式
.card-item {
  background-color: #fff;
  border-radius: 12rpx;
  padding: 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);

  .card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12rpx;

    .card-text {
      font-size: 28rpx;
      color: #333;
      line-height: 1.4;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between; // 让文本和按钮两端对齐

      &.font-bold {
        font-weight: 600;
        font-size: 30rpx;
      }

      .field-name {
        color: #999;
        display: inline-block;
        margin-right: 15rpx;
        flex-shrink: 0;
      }
    }
  }
}

// 行内操作按钮样式
.inline-action {
  font-size: 26rpx;
  color: #1989fa;
  padding: 4rpx 12rpx;
  border-radius: 4rpx;
  background-color: #f0f8ff;
  white-space: nowrap;
  float: right;
  &.submit-btn {
    background-color: #1989fa;
    color: #fff;
  }
}


</style>