<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-09-22 14:38:38
 * @Description: file content
 * @FilePath: \labsop小程序\pages\schedule\myAppoint\index.vue
-->
<template>
  <div class="panel-wrap">
    <van-empty v-if="appointList.length == 0" mode="list" description="暂无待审核预约"></van-empty>
    <van-list v-else v-model:loading="listloading" class="data-list" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <div class="inst-item mb40" v-for="(v, index) in appointList" :key="index">
        <div class="flex mb20">
          <div class="equ-tit">
            <span class="fontSize14 bold">设备名称：</span>
          </div>
          <div>
            <span class="fontSize14">{{ v.instName }}</span>
          </div>
        </div>
        <div class="flex mb20">
          <div class="equ-tit">
            <span class="fontSize14 bold">设备型号：</span>
          </div>
          <div>
            <span class="fontSize14">{{ v.instNameEn }}</span>
          </div>
        </div>
        <div class="flex mb20" v-if="v.projectName">
          <div class="equ-tit">
            <span class="fontSize14 bold">课题组：</span>
          </div>
          <div>
            <span class="fontSize14">{{ v.projectName }}</span>
          </div>
        </div>
        <div class="flex mb20" v-if="v.serviceName">
          <div class="equ-tit">
            <span class="fontSize14 bold">服务：</span>
          </div>
          <div>
            <span class="fontSize14">{{ v.serviceName }}</span>
          </div>
        </div>
        <div class="flex mb20">
          <div class="equ-tit">
            <span class="fontSize14 bold">所在位置：</span>
          </div>
          <div>
            <span class="fontSize14">{{ v.placeAddress + '(' + v.laboratoryName + ')' }}</span>
          </div>
        </div>
        <div class="flex flex-between">
          <div class="flex">
            <div class="equ-tit">
              <span class="fontSize14 bold">开始时间：</span>
            </div>
            <div>
              <span class="fontSize14">{{ v.startTime }}</span>
            </div>
          </div>
          <div>
            <span class="fontSize14 bold primary-color" @click="handleCancelAppoint(v)">取消预约</span>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
  import { useMyAppointApi } from '/@/api/appoint'
  const myAppointApi = useMyAppointApi()
  import instAppointApi from '/@/api/instr/instAppoint'
  import to from 'await-to-js'
  import { showConfirmDialog, showNotify } from 'vant'
  export default {
    data() {
      return {
        instStatus: {
          10: '正常',
          20: '故障',
          30: '报废'
        },
        appointList: [],
        current: 1,
        queryForm: {
          pageNum: 1,
          pageSize: 10
        },
        total: 0,
        listloading: false,
        finished: false
      }
    },
    mounted() {
      this.queryForm.pageNum = 1
      this.getInstList()
    },
    methods: {
      onLoad() {
        this.queryForm.pageNum++
        this.getInstList()
      },
      handleCancelAppoint(row) {
        showConfirmDialog({
          title: '提示',
          message: '确认取消预约？'
        })
          .then((e) => {
            this.cancelAppoint(row.id)
          })
          .catch(() => {
            console.log('ssss')
          })
      },
      async cancelAppoint(id) {
        const params = { id }
        const [err, res] = await to(instAppointApi.userCancelAppoint(params))
        this.modalVisible = false
        if (err) return
        if (res?.code === 200) {
          this.queryForm.pageNum = 1
          this.appointList = []
          this.getInstList()
          showNotify({ type: 'success', message: '取消成功' })
        }
      },

      // 查询列表
      async getInstList() {
        this.listloading = true
        const [err, res] = await to(myAppointApi.myAppoint(this.queryForm))
        this.listloading = false
        if (err) return
        if (res?.code === 200) {
          this.appointList = this.queryForm.pageNum == 1 ? [...(res?.data?.list || [])] : [...this.appointList, ...(res?.data?.list || [])]
          this.total = res?.data?.total
          if (this.queryForm.pageNum * this.queryForm.pageSize >= res.data.total) {
            this.finished = true
          }
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  * {
    box-sizing: border-box;
  }
  .panel-wrap {
    height: 100%;
    .data-list {
      height: 100%;
      padding: 20px;
      overflow: auto;
      .inst-item {
        border-radius: 10px;
        padding: 15px;
        box-shadow: -2px 0px 9px rgba(0, 0, 0, 0.12);
        margin-bottom: 20px;
        .equ-tit {
          width: 74px;
        }
      }
    }
  }
</style>
