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

export default {
  name: "SeeFormModel",
  props: {
    dict: {
      type: Object,
    },
    selectData: {
      type: [Array],
      require: true,
    },
    title: {
      type: String,
    },
  },
  components: {
    ElSuperDescriptions: () =>
      import("@/components/super-descriptions/index.vue"),
    SubmButton: () => import("../submit/index.vue"),
    ElSuperTable: () => import("@/components/super-table/index.vue"),
    ElSuperForm: () => import("@/components/super-form/index.vue"),
  },
  data() {
    const {
      TabColumns,
      TableColumns,
      TabColumns: [
        {
          item: { key: tabName },
        },
      ],
    } = useColumns();
    return {
      column: 2,
      loading: false,
      loadingText: "",
      params: {},
      tabName: tabName,
      TabColumns: TabColumns,
      TableColumns: TableColumns,
    };
  },
  computed: {
    id: {
      get() {
        const { title, selectData } = this.$props;
        const id = title.split("-")[1];
        return id ? id : selectData[0].id;
      },
      set() {},
    },
  },
  watch: {},
  methods: {
    async fetchItem(prop) {
      try {
        // try
        this.loading = true;
        this.loadingText = "获取合同中";
        const { code, data } = await ITEM(prop);
        if (code === 200) {
          this.params = data;
        } else {
        }
      } catch (err) {
        // catch
        console.error(err);
      } finally {
        // finally
        this.loading = false;
      }
    },
    //
    async open(prop) {
      this.fetchItem(prop ? prop : this.id);
    },
    //
    async hide() {
      this.$emit("close");
    },
    async handleJump(){
      console.log(this.params,'params');

      try {

        const {name} = this.$store.state.user;

        let {code,oaUrl} = await ToOA(name,this.params.flowId);

        if(code == 200){
          window.open(oaUrl);
        }
        
      } catch (error) {
        
      }finally{

      }
    }
  },
  created() {
    this.open();
  },
  mounted() {},
  destroyed() {},
};
</script>
<template>
  <div
    v-loading="loading"
    :element-loading-text="loadingText"
    style="height: 100vh; display: flex; flex-direction: column"
  >
    <div
      style="
        height: 50px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 18px;
      "
    >
      <h4 class="m-0" style="font-weight: 500; flex: 1">
        {{ title.split("-")[0] }}
      </h4>
      <el-button 
        v-if="params.flowId && params.flowId !== ''"
        type="primary" :size="$attrs.size" :loading="loading" @click="handleJump">
          流程跳转
        </el-button>
        <subm-button
          :size="$attrs.size"
          :select-data="[{...this.params}]"
          @success="fetchItem(params.id)"
        ></subm-button>
      <!-- <el-button
        type="primary"
        :size="$attrs.size"
        :loading="loading"
        @click="useSubmit('superForm')"
        >确 认</el-button
      > -->
      <el-button :size="$attrs.size" :loading="loading" @click="hide"
        >取 消</el-button
      >
    </div>
    <div v-if="params.code" style="flex: 1; overflow-y: auto">
      <el-super-form
        v-if="params.code"
        v-model="params"
        :dict="dict"
        :size="$attrs.size"
        :columns="TableColumns"
        ref="superForm"
        label-width="auto"
        label-position="right"
        style="padding: 18px"
      >
       
    </el-super-form>
      <!-- <el-super-descriptions
        v-if="params.code"
        v-model="params"
        :dict="dict"
        :column="column"
        :size="$attrs.size"
        :columns="TableColumns"
        style="padding: 18px"
      >
      </el-super-descriptions> -->
    </div>
    <el-tabs
      v-if="params.code"
      v-model="tabName"
      :size="$attrs.size"
      style="margin: 0 18px 18px"
    >
      <el-tab-pane
        v-for="{ item, TableColumns: columns } in TabColumns"
        :key="item.key"
        :name="item.key"
        :label="item.title"
        lazy
      >
        <div style="height: 25vh; display: flex">
          <el-super-table
            v-model="params[item.key]"
            :size="$attrs.size"
            :dict="dict"
            :columns="columns"
            :iconOperation="false"
          >
          </el-super-table>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
