<script>
import {mapState} from "vuex"

const columns = {
  weightList: [
    {label: "序号", type: "index"},
    {label: "重量", prop: "weight"},
    {label: "称重时间", prop: "createTime"},
    {label: "数据来源", prop: "source", dict: "dataSources"},
    {label: "是否变更过", prop: "isUpdate", dict: "yesOrNo"},
  ],
  immunityList: [
    {label: "序号", type: "index"},
    {label: "疫苗名称", prop: "vaccineName"},
    {label: "用药方式", prop: "method"},
    {label: "药量(ml)", prop: "dosage"},
    {label: "生产厂家", prop: "factory"},
    {label: "厂家批号", prop: "batchNumber"},
    {label: "免疫时间", prop: "immunityTime"},
    {label: "登记时间", prop: "createTime"},
    {label: "防疫员", prop: "userName"},
  ],
  treatmentList: [
    {label: "序号", type: "index"},
    {label: "药品名称", prop: "drugName"},
    {label: "药量(ml)", prop: "dosage"},
    {label: "生产厂家", prop: "factory"},
    {label: "厂家批号", prop: "batchNumber"},
    {label: "疾病名称", prop: "diseaseName"},
    {label: "症状", prop: "symptom"},
    {label: "兽医", prop: "userName"},
    {label: "治疗时间", prop: "immunityTime"},
    {label: "登记时间", prop: "createTime"},
  ],
  outList: [
    {label: "序号", type: "index"},
    {label: "养殖场", prop: "userName", format: (v, row) => `${[row.farmName, row.houseName, row.penName].join("-")}`},
    {label: "生物芯片耳标号", prop: "biochipEarNumber"},
    {label: "类别", prop: "category", dict: "category", width: 120},
    {label: "品种", prop: "variety", dict: "variety", width: 120},
    {label: "日龄(天)", prop: "age", width: 80},
    {label: "淘汰时间", prop: "outTime"},
    {label: "淘汰原因", prop: "reason"}
  ],
  deathList: [
    {label: "序号", type: "index"},
    {label: "养殖场", prop: "userName", format: (v, row) => `${[row.farmName, row.houseName, row.penName].join("-")}`},
    {label: "生物芯片耳标号", prop: "biochipEarNumber"},
    {label: "类别", prop: "category", dict: "category", width: 120},
    {label: "品种", prop: "variety", dict: "variety", width: 120},
    {label: "日龄(天)", prop: "age", width: 80},
    {label: "死亡时间", prop: "deathTime"},
    {label: "死亡原因", prop: "reason", dict: "deathReason", width: 80},
    {label: "登记时间", prop: "createTime"},
    {label: "操作人", prop: "userName", width: 100},
  ],
  insuranceList: [
    {label: "序号", type: "index"},
    {label: "保险类型", prop: "insuranceType", dict: "insuranceType"},
    {label: "保单编号", prop: "orderNo"},
  ]
}
const forms = {
  device: [
    {label: "当前温度", prop: "temperature"},
    {label: "温度状态", prop: "temperatureStatus", dict: "temperatureStatus"},
    {label: "运动状态", prop: "sportsSituation", dict: "sportsSituation"},
    {label: "在栏状态", prop: "status", dict: "archiveStatus"},
  ],
  loan: [
    {label: "贷款合同编号", prop: "contractNo"},
  ]
}
const navs = [
  {label: "体重记录", value: "weightList"},
  {label: "免疫记录", value: "immunityList"},
  {label: "治疗记录", value: "treatmentList"},
  {label: "淘汰记录", value: "outList"},
  {label: "死亡记录", value: "deathList"},
  {label: "设备检测", value: "device"},
  {label: "贷款信息", value: "loan"},
  {label: "保险信息", value: "insuranceList"},
]
export default {
  name: "baAdd",
  props: {
    instance: Function,
    permissions: Function,
    dict: Object
  },
  data() {
    return {
      detail: {detailList: []},
      active: "weightList",
      columns, navs, forms
    }
  },
  computed: {
    ...mapState(["user"]),
    userinfo: v => v.user.info || {},
    isAdd: v => !v.$route.query.id,
    isEdit: v => v.$route.query.edit == 1,
    pageTitle: v => {
      const appName = v.$parent.menuName || v.$parent.$options.label
      return v.$route.query.id ? v.isEdit ? `编辑${appName}` : `${appName}详情` : `新增${appName}`
    },
  },
  methods: {
    back(params = {}) {
      this.$router.push(params)
    },
    getDetail() {
      const {id} = this.$route.query
      return id && this.instance.post("/api/report/getInfo", null, {params: {biochipEarNumber: id}}).then(res => {
        if (res?.data) {
          const detail = res.data
          Object.keys(columns).forEach(key => {
            detail[key] = detail[key] || []
          })
          return this.detail = {...detail}
        }
      })
    },
  },
  created() {
    this.dict.load("auditStatus", "category", "variety")
    this.getDetail()
  }
}
</script>

<template>
  <ai-page :title="pageTitle" class="baAdd" showBack content-string="blank">
    <el-form size="small" label-width="120px" :model="detail" ref="detail">
      <ai-card title="基础信息">
        <div class="grid c-3">
          <el-form-item label="养殖户" prop="userName" class="row">
            <b v-text="detail.userName"/>
          </el-form-item>
          <el-form-item label="养殖场" prop="farmId">
            <b v-text="detail.farmName"/>
          </el-form-item>
          <el-form-item label="养殖舍" prop="houseId">
            <b v-text="detail.houseName"/>
          </el-form-item>
          <el-form-item label="养殖栏" prop="penId">
            <b v-text="detail.penName"/>
          </el-form-item>
          <el-form-item label="生物芯片耳标号" prop="penId">
            <b v-text="detail.biochipEarNumber"/>
          </el-form-item>
          <el-form-item label="电子耳标号" prop="penId">
            <b v-text="detail.electronicEarNumber"/>
          </el-form-item>
          <el-form-item label="原厂耳标号" prop="penId">
            <b v-text="detail.originalEarNumber"/>
          </el-form-item>
        </div>
      </ai-card>
      <el-tabs type="border-card" v-model="active">
        <el-tab-pane v-for="(nav,i) in navs" :key="i" :label="nav.label" :name="nav.value" lazy>
          <template v-if="active==nav.value">
            <ai-table v-if="columns[nav.value]" :colConfigs="columns[nav.value]" :table-data="detail[nav.value]" :isShowPagination="!1"/>
            <el-form v-if="forms[nav.value]" size="small" class="grid" label-width="120px">
              <el-form-item v-for="(item,i) in forms[nav.value]" :key="i" :label="item.label" :prop="item.prop">
                <b v-text="dict.getLabel(item.dict||'yesOrNo',detail[item.prop])"/>
              </el-form-item>
            </el-form>
          </template>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer">
      <el-button @click="back">返回</el-button>
    </div>
  </ai-page>
</template>

<style scoped lang="scss">
.baAdd {
}
</style>
