<script setup>
import { getElevatorLargeScreenListApi } from '@/api/elevator'
import { usePaging } from '@/composables/use-paging'

const webView = '/pages/views/web-view/index'
const toDetail = (item) => {
  console.log('toDetail =>', item)
  const { name, areaCode, address } = item
  const domain = address.replace(
    'http://111.172.230.93:7001',
    'https://h5.hbrja.com'
  )

  let codeList = []
  try {
    codeList = JSON.parse(areaCode)
  } catch (error) {
    console.log('获取区域码失败', error)
  }
  const code = codeList[codeList.length - 1]
  const link = `${domain}?areaCode=${code}&name=${name}`
  const url = `${webView}?url=${encodeURIComponent(link)}&hasBack=1`

  uni.navigateTo({
    url
  })
}

const query = ref({})
const { paging, dataList, queryHandler } = usePaging({
  apiFn: getElevatorLargeScreenListApi,
  query
})

const options = ref({})
onLoad(async (e) => {
  dataList.value = []
  options.value = e
})
</script>

<template>
  <view class="passenger-feedback" w-full h-100vh flex-col f-s-c bg="#F8F8F8">
    <view w-full flex-auto overflow-hidden mt-8 bg-white>
      <z-paging
        ref="paging"
        v-model="dataList"
        :fixed="false"
        @query="queryHandler"
      >
        <up-card
          v-for="(item, index) in dataList"
          :key="index"
          :title="item.name"
          @click="toDetail(item)"
        >
          <template #body>
            <view>
              <up-cell title="名称" :value="item.address" />
              <up-cell title="备注" :value="item.remark" />
            </view>
          </template>
        </up-card>
      </z-paging>
    </view>
  </view>
</template>
