<template>
  <business-page-layout title="录入详情" :show-back="true">
    <view class="detail-wrap" v-if="info.id">
      <view class="row" v-for="f in fields" :key="f.k"><text class="k">{{ f.l }}</text><text class="v">{{ display(f.k) }}</text></view>
      <view v-if="canEdit" class="actions">
        <button @click="goEdit">继续编辑</button>
      </view>
      <view v-if="canAudit" class="actions">
        <button class="ok" @click="audit(1)">审核通过</button>
        <button class="no" @click="audit(2)">审核拒绝</button>
      </view>
    </view>
  </business-page-layout>
</template>

<script>
import BusinessPageLayout from '@/subPackages/sub_business_shared/components/business-page-layout.vue'
import businessMixin from '@/subPackages/sub_business_shared/common/businessMixin.js'

export default {
  mixins: [businessMixin],
  components: { BusinessPageLayout },
  props: {
    inputType: { type: String, default: 'store' },
    editPath: { type: String, default: '' },
  },
  data() { return { id: 0, info: {} } },
  computed: {
    fields() {
      if (this.inputType === 'doctor') {
        return [
          { k: 'name', l: '姓名' }, { k: 'mobile', l: '手机' }, { k: 'depart_id', l: '科室ID' },
          { k: 'good_at', l: '擅长' }, { k: 'intro', l: '简介' },
        ]
      }
      return [
        { k: 'name', l: '名称' }, { k: 'mobile', l: '电话' }, { k: 'contact', l: '联系人' },
        { k: 'position', l: '地址' }, { k: 'erp_id', l: 'ERP ID' },
      ]
    },
    canEdit() { return !this.canAudit && Number(this.info.status) === 0 },
    canAudit() {
      if (this.inputType === 'doctor') return !!this.bizCap.canDoctorInputAudit
      return !!this.bizCap.canStoreInputAudit
    },
  },
  onLoad(q) { this.id = Number(q.id || 0); this.load() },
  methods: {
    detailApi() {
      return this.inputType === 'doctor'
        ? this.bizApi.getDoctorInputDetail(this.id)
        : this.bizApi.getStoreInputDetail(this.id)
    },
    auditApi(data) {
      return this.inputType === 'doctor'
        ? this.bizApi.auditDoctorInput(data)
        : this.bizApi.auditStoreInput(data)
    },
    load() {
      this.detailApi().then(w => { if (w.ok) this.info = w.data || {} })
    },
    display(k) { return this.info[k] != null && this.info[k] !== '' ? this.info[k] : '-' },
    goEdit() { if (this.editPath) uni.navigateTo({ url: `${this.editPath}?id=${this.id}` }) },
    audit(status) {
      this.auditApi({ id: this.id, status, audit_remark: '' }).then(w => {
        if (w.ok) { uni.showToast({ title: '操作成功' }); setTimeout(() => uni.navigateBack(), 500) }
      })
    },
  },
}
</script>

<style scoped>
.detail-wrap { padding: 24rpx; background: #fff; min-height: 100vh; }
.row { display: flex; padding: 24rpx 0; border-bottom: 1rpx solid #F2F3F5; }
.k { width: 180rpx; color: #86909C; }
.v { flex: 1; }
.actions { display: flex; gap: 16rpx; margin-top: 40rpx; }
.ok { flex: 1; background: #6acdbb; color: #fff; }
.no { flex: 1; background: #F53F3F; color: #fff; }
</style>
