<script>
import Column from "../add/column";
import useData from "../hooks/data";
import useDicts from "../hooks/dicts";
import useMethods from "../hooks/function";

export default {
  name: "SeeDrawer",
  dicts: useDicts(Column),
  data() {
    return {
      column: 3,
      title: "明 细",
      ...useData(Column),
    };
  },
  computed: {
    hasPowerEdit: function () {
      return this.$parent.$parent.hasPowerEdit;
    },
    hasPowerSubmit: function () {
      return this.$parent.$parent.hasPowerSubmit;
    },
  },
  watch: {},
  methods: {
    //
    async open(prop) {
      this.visible = true;
      this.tabName = this.tabColumns[0].key;
      const { fetchItem } = useMethods();
      this.params = await fetchItem({ _this: this, prop });
    },
    //
    async hide() {
      this.visible = false;
    },
    //
    async useDelete(prop) {
      const { useDelete } = this.$parent.$parent;
      await useDelete(prop).then(() => this.hide());
    },
    //
    async useCopy(prop) {
      const { useCopy } = this.$parent.$parent;
      await useCopy(prop);
    },
    //
    async useEdit(prop) {
      const { useEdit } = this.$parent.$parent;
      await useEdit(prop);
    },
    //
    async useSubmit(prop) {
      const { useSubmit } = this.$parent.$parent;
      await useSubmit(prop).then(() => {
        const { id } = this.params;
        const { fetchItem } = useMethods();
        fetchItem({ _this: this, prop: id });
      });
    },
  },
  created() {},
  mounted() {},
  destroyed() {},
};
</script>
<template>
  <el-drawer
    :size="width"
    :title="title"
    :show-close="false"
    :visible.sync="visible"
  >
    <template slot="title">
      <span>{{ title }}</span>
      <span>
        <el-tooltip
          class="item"
          effect="dark"
          content="删 除"
          placement="bottom-end"
        >
          <el-button
            :size="size"
            circle
            icon="el-icon-delete"
            @click="useDelete([params])"
          ></el-button>
        </el-tooltip>
        <el-tooltip
          class="item"
          effect="dark"
          content="复 制"
          placement="bottom-end"
        >
          <el-button
            :size="size"
            circle
            icon="el-icon-document-copy"
            @click="useCopy([params])"
          ></el-button>
        </el-tooltip>
        <el-tooltip
          v-if="hasPowerEdit([params])"
          class="item"
          effect="dark"
          content="编 辑"
          placement="bottom-end"
        >
          <el-button
            :size="size"
            circle
            icon="el-icon-edit"
            @click="useEdit([params])"
          ></el-button>
        </el-tooltip>
        <el-tooltip
          v-if="hasPowerSubmit([params])"
          class="item"
          effect="dark"
          content="审 核"
          placement="bottom-end"
        >
          <el-button
            :size="size"
            circle
            icon="el-icon-check"
            @click="useSubmit([params])"
          ></el-button>
        </el-tooltip>
        <el-button
          :size="size"
          circle
          type="danger"
          icon="el-icon-close"
          @click="hide"
        ></el-button>
      </span>
    </template>
    <el-descriptions :size="size" :column="column" border style="margin: 10px">
      <el-descriptions-item
        v-if="params[column.key]"
        v-for="(column, index) in formColumns"
        :key="index"
        :label="column.title"
      >
        <dict-tag
          v-if="column.inputType === 'Select'"
          :size="size"
          :value="params[column.key]"
          :options="dict.type[column.referName]"
        />
        <span v-else-if="column.inputType === 'Upload'">
          <dr-file-preview v-model="params[column.key]"></dr-file-preview>
        </span>
        <span v-else>{{ params[column.key] }}</span>
      </el-descriptions-item>
    </el-descriptions>
    <el-tabs v-model="tabName" :size="size" style="margin: 10px">
      <el-tab-pane
        v-for="(column, index) in tabColumns"
        :key="index"
        :name="column.key"
        :label="column.title"
        lazy
      >
        <el-table :size="size" :data="params[column.key]">
          <el-table-column
            v-for="(cColumn, cIndex) in column.tableColumns"
            :key="cIndex"
            :prop="cColumn.key"
            :label="cColumn.title"
            :width="cColumn.width || 200"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <dict-tag
                v-if="cColumn.inputType === 'Select'"
                :size="size"
                :value="scope.row[cColumn.key]"
                :options="dict.type[cColumn.referName]"
              />
              <span v-else>{{ scope.row[cColumn.key] }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </el-drawer>
</template>
