<template>
  <view class="p4 pt8">
    <navbar-back title="样品查询"></navbar-back>
    <up-input
      v-model="sampleCode"
      placeholder="请扫描或者输入样品编号"
      prefixIcon="scan"
      fontSize="16"
      prefixIconStyle="font-size: 30px;"
    >
      <template #suffix>
        <!-- <up-button type="primary" text="查询" icon="search"></up-button> -->
        <!-- <up-icon size="20" name="search" @click="handleSearch"></up-icon> -->
      </template>
    </up-input>

    <uni-section type="line" title="样品详情">
      <uni-card>
        <view>
          <view class="x-bc">
            <view
              >样品名称：<text>{{ sampleData.sampleName }}</text></view
            >
            <up-tag :text="sampleData.returnStatus_dictText"></up-tag>
          </view>
          <view
            >样品编号：<text>{{ sampleData.sampleCode }}</text></view
          >
          <view class="mt4"
            >归库编码：<text>{{ sampleData.sampleCode }}</text></view
          >
          <view class="mt4"
            >样品库名称：<text>{{ sampleData.sampleCode }}</text></view
          >
          <view class="mt4"
            >库位信息：<text>{{ sampleData.sampleCode }}</text></view
          >
        </view>
      </uni-card>
    </uni-section>
    <up-button type="primary" style="width: 90%" text="打印归库标签" @click="handlePrint"></up-button>
  </view>
</template>

<script setup>
import { ref, computed, onMounted, toRefs, watch } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import nx from '@/nx'

const { scanQRInfo } = toRefs(nx.$store('biz'))
watch(scanQRInfo, newVal => {
  if (newVal && nx.$router.getCurrentPage().route == 'pages/sampleWarehouse/sampleSearch/index') {
    try {
      sampleCode.value = newVal
      handleSearch()
      scanQRInfo.value = ''
    } catch (error) {
      scanQRInfo.value = ''
      uni.showToast({
        title: '请扫描样品编码',
        icon: 'none'
      })
    }
  }
})
onShow(() => {
  scanQRInfo.value = ''
})
let sampleCode = ref('')
function handleSearch() {
  getSampleDetail()
}

let sampleData = ref({})
async function getSampleDetail() {
  sampleData.value = await nx.$api.sample.getSampleDetail({ sampleReturnCode: sampleCode.value })
}
function handlePrint() {}
</script>

<style lang="scss" scoped>
text {
  color: #000;
}
</style>
