<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"},
  ]
}
const navs = [
  {label: "体重记录", value: "weightList"}
]
export default {
  name: "baAdd",
  props: {
    instance: Function,
    permissions: Function,
    dict: Object
  },
  data() {
    return {
      detail: {detailList: []},
      active: "weightList",
      columns, navs
    }
  },
  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
          return this.detail = {detailList: [], ...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>
      <ai-card title="记录">
        <ai-table :colConfigs="columns[active]" :table-data="detail[active]" :isShowPagination="!1"/>
      </ai-card>
    </el-form>
    <div slot="footer">
      <el-button @click="back">返回</el-button>
    </div>
  </ai-page>
</template>

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