<template>
  <clinic-salesperson-page-layout title="传方记录" :show-back="true">
    <view class="page">
      <view v-if="!list.length" class="empty">暂无传方记录</view>
      <view v-for="item in list" :key="item.id" class="row" @click="goDetail(item.id)">
        <view class="top">
          <text class="name">{{ item.patient_name }} {{ item.patient_mobile }}</text>
          <u-tag :text="item.is_imported ? '已导入' : '待导入'" :type="item.is_imported ? 'success' : 'warning'" size="mini" />
        </view>
        <text class="diag">诊断：{{ item.clinical_diagnose || '-' }}</text>
        <text class="time">{{ item.transfer_time_text }}</text>
      </view>
      <u-button v-if="list.length" plain type="primary" class="mt" @click="goForm">新建传方</u-button>
    </view>
  </clinic-salesperson-page-layout>
</template>

<script>
import ClinicSalespersonPageLayout from '@/subPackages/sub_clinic_salesperson/components/clinic-salesperson-page-layout.vue'
import { getClinicSalespersonTransferPrescriptionList } from '@/api/clinicSalesperson.js'

export default {
  components: { ClinicSalespersonPageLayout },
  data() {
    return { list: [] }
  },
  onShow() {
    this.loadList()
  },
  methods: {
    async loadList() {
      const wrap = await getClinicSalespersonTransferPrescriptionList({ page: 1, pageSize: 50 })
      if (wrap && wrap.ok) {
        this.list = wrap.data?.items || []
      }
    },
    goForm() {
      uni.navigateTo({ url: '/subPackages/sub_clinic_salesperson/transfer-prescription/form' })
    },
    goDetail(id) {
      uni.showToast({ title: `传方#${id}`, icon: 'none' })
    },
  },
}
</script>

<style lang="scss" scoped>
.page { padding: 24rpx; }
.empty { text-align: center; color: #999; padding: 80rpx 0; }
.row { background: #fff; border-radius: 12rpx; padding: 24rpx; margin-bottom: 16rpx; }
.top { display: flex; justify-content: space-between; align-items: center; }
.name { font-size: 28rpx; font-weight: 600; }
.diag, .time { display: block; font-size: 24rpx; color: #666; margin-top: 8rpx; }
.mt { margin-top: 24rpx; }
</style>
