<script>
import useColumns from "./columns";
import { ITEM } from "@/api/business/purchase/task";

export default {
  name: "SeeDrawer",
  props: {
    dict: {
      type: Object,
    },
    selectData: {
      type: [Array],
      require: true,
    },
  },
  components: {
    ElSuperDescriptions: () =>
      import("@/components/super-descriptions/index.vue"),
  },
  data() {
    const { TableColumns } = useColumns();
    return {
      title: "明 细",
      width: "100%",
      column: 3,
      visible: false,
      loading: false,
      TableColumns: TableColumns,
      params: {},
    };
  },
  computed: {
    disabled: {
      get() {
        return this.selectData.length !== 1;
      },
      set() {},
    },
  },
  watch: {},
  methods: {
    // 查 询
    async fetchItem(prop) {
      try {
        this.loading = true;
        const { code, data } = await ITEM(prop);
        if (code === 200) {
          this.params = data;
          return true;
        } else {
          return false;
        }
      } catch (err) {
        // catch
      } finally {
        // finally
        this.loading = false;
      }
    },
    //
    async open(prop) {
      const { id } = prop;
      this.visible = await this.fetchItem(id);
    },
    //
    async hide() {
      this.visible = false;
    },
   
  },
  created() {},
  mounted() {},
  destroyed() {},
};
</script>
<template>
  <el-button
    v-bind="$attrs"
    v-on="$listeners"
    :disabled="disabled"
    @click="open(selectData[0])"
  >
    {{ title }}
    <el-drawer
      :show-close="false"
      :size="width"
      :title="title"
      :visible.sync="visible"
      append-to-body
    >
      <template slot="title">
        <span>{{ title }}</span>
        
        <el-button :size="$attrs.size" :loading="loading" @click="hide">
          取 消
        </el-button>
      </template>
      <el-super-descriptions
        v-model="params"
        :dict="dict"
        :column="column"
        :size="$attrs.size"
        :columns="TableColumns"
      >
      </el-super-descriptions>
    </el-drawer>
  </el-button>
</template>
