<template>
  <div class='app-container'>
    <el-form v-if="isCookie" label-position="top">
      <el-form-item label="申请查询">
        <el-input v-model="data.form.mobile" placeholder="请输入需要查询的手机号" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList">查询</el-button>
      </el-form-item>
    </el-form>
    <div v-else class="list" v-for="item in data.tableData" :key="item.id">
      <div class="header between">
        <span>快递单号：{{ item.logisticsCode }}</span>
        <span>{{ proxy.selectDictLabel(applyTypeOptions, item.type) }}</span>
      </div>
      <el-descriptions class="main" :column="1">
        <el-descriptions-item label="姓名：">{{ item.name }}</el-descriptions-item>
        <el-descriptions-item label="产品型号：">{{ item.goodsName }}</el-descriptions-item>
        <el-descriptions-item label="电话号码：">{{ item.mobile }}</el-descriptions-item>
      </el-descriptions>
      <div class="footer between">
        <span>填写时间：{{ item.createTime }}</span>
        <span>{{ proxy.selectDictLabel(repairStatusOptions, item.status) }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { list } from "@/api/mobile/order"
import { useCommon } from "@/hooks/index"

const { applyTypeOptions, repairStatusOptions } = useCommon()

const { proxy } = getCurrentInstance()

document.title = '申请查询'

const data = reactive({
  form: {},
  tableData: []
})

// 是否输入手机号
const isCookie = ref(true)
// 遮罩层
const loading = ref(false)

// 列表
const getList = () => {
  loading.value = true
  list(data.form.mobile).then(res => {
    if (res.code === 0) {
      data.tableData = res.data
      loading.value = false
      isCookie.value = false
      sessionStorage.setItem('mobile', data.form.mobile)
    }
  })
}

onMounted(() => {
  data.form.mobile = sessionStorage.getItem('mobile')
  isCookie.value = data.form.mobile ? false : true
  if(!isCookie.value){
    getList()
  }
})
</script>

<style lang="scss" scoped>
.list {
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 15px;
  border: 1px solid #d0d0d0;
}

.header {
  background-color: #000;
  color: #FFF;
  padding: 8px 10px;
  font-size: 16px;
}

.main {
  padding: 8px 10px 0;
}

.footer {
  padding: 12px 10px;
  border-top: 1px solid #d0d0d0;
  font-size: 14px;
}

.between {
  display: flex;
  justify-content: space-between;
}
</style>