/* *@description:查看 *@author: hudw *@date: 2022-04-26 16:41:46 */
<template>
  <p-card class="full-card-panel" :bordered="false" :loading="loading">
    <a-space slot="title">
      <a-icon type="arrow-left" @click="back" :style="{ color: '#08c' }" />
      {{ title }}
    </a-space>
    <viewFormContent ref="form" v-bind="$attrs" v-on="$listeners" :record="dataView"/>
  </p-card>
</template>
<script>
import viewFormContent from '../formDetails/viewFormContent.vue'
import { mainViewUrl } from '../api.js'

const titleArr = ['', '查看', '新建', '修改', '复制']
const pageName = {
  main: '订单信息',
  children: '商品信息',
}
export default {
  inheritAttrs: false,
  components: { viewFormContent },
  props: {
    record: {
      type: Object,
    },
    url: {
      type: String,
      default: mainViewUrl
    },
  },
  data() {
    return {
      ...this.$attrs,
      activeKey: 1,
      shipbillId: '',
      dataView: null,
      loading: false,
    }
  },
  mounted() {},
  watch: {
    record(value) {
      if (this.$el.style.display == 'none') return

      if (!value) {
        this.shipbillId = ''
        this.$refs.form.init(1, value)
        return
      }
      this.getView(value.id)
      // this.shipbillId = value.shipbillId
      // this.$refs.form.init(3, value)
    },
  },
  computed: {
    title() {
      let { st, formName } = this.$attrs
      return titleArr[st] + pageName[formName]
    },
  },
  methods: {
    back() {
      if (this.$refs.form) {
        this.$refs.form.back(this.record && this.record.id, false)
      } else {
        this.$emit('back', 'mainTable', this.record && this.record.id, false)
      }
    },
    getView(id) {
      this.loading = true

      return this.axios({
        url: this.url,
        method: 'post',
        params: { id }
      }).then((response) => {
        this.loading = false
        if (response.success) {
          this.shipbillId = id
          if (response.data.shipBillDTO) {
            this.dataView=response.data.shipBillDTO
          } else {
            this.dataView = response.data
          }

        } else {
          this.$exception(response)
        }
      })
    },
    form() {
      if (this.$refs.form.$refs[this.formName]) {
        return this.$refs.form.$refs[this.formName].form
      }
      return undefined
    },

    reload(args) {
      return this.$refs.form.$refs.table.reload(args)
    },
  },
}
</script>
<style lang="less"></style>
