/* *@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' }" />
      查看{{ pageName[mode] }}
    </a-space>
    <viewFormContent ref="form" v-bind="$attrs" :mode="mode" v-on="$listeners" :record="dataView" />
  </p-card>
</template>
<script>
import viewFormContent from './formDetails/viewFormContent.vue';

const titleArr = ['', '查看', '新建', '修改', '复制'];
const pageName = {
  1: '订单信息',
  3: '派车单信息',
};
export default {
  inheritAttrs: false,
  components: { viewFormContent },
  props: {

    record: {
      type: Object,
    },
    mode: {
      type: null,
    },
    url: {
      type: null,

    }
  },
  data() {
    this.pageName=pageName
    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);
    },
  },
  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;
      let _this = this;
      return this.axios({
        url:this.url,
        method: 'post',
        params: { id },
      }).then((response) => {
        this.loading = false;
        if (response.success) {
          _this.shipbillId = id;
          _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>
