<template>
  <div class="newProcess pagePadding">
    <div v-if="powers.some((i) => i == '007')">
      <!-- v-if="v-if="status === 0"" -->
      <div style="width: 500px">
        <add-edit-form
          :id="this.$route.query.id"
          :sitem="sitem"
          :newTime="newTime"
          :show-model="showModel"
          :is-detail="!isDetail"
          @resData="initForm"
          @refreshDom="refreshDom"
        />
      </div>
      <!-- 

  <exam-form :id="$route.query.id" v-if="status==1"
          :newTime="newTime"/>

          status 0:新建后未发起流程   1 :已发起流程 未审核  2:审核已完成
-->

      <!-- <div style="width: 500px">
        <add-edit-form
          :id="this.$route.query.id"
          :show-model="showModel"
          :is-detail="isDetail"
          @refreshList="searchList"
        />
      </div> -->
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
<script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/interest/handover";
import { mapGetters } from "vuex";
import addEditForm from "./components/addEditForm.vue";

export default {
  name: "newProcess",
  mixins: [mixinPage, resToken],
  components: {
    addEditForm, //详情组件
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "newProcess") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      sitem: null,
      newTime: 0,
      type: "", //模拟节点
      parmValue1: {
        id: "",
      },
    };
  },

  mounted() {
    this.restSearch();
    this.setTime();
  },

  methods: {
    initForm() {
      this.setTime();
    },
    setTime() {
      this.newTime = new Date().valueOf();
    },
    restSearch() {
      this.parmValue = {};
    },
    async refreshDom(val) {
      val.hand_uid = val.hand_uid.toString();
      val.resign_uid = val.resign_uid.toString();
      this.loading = true;
      const res = await asyncRequest.update(val);
      if (res && res.code === 0 && res.data) {
        // 获取到当前的type值，
        // this.type = 1;
        this.updateStatus(val);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        // this.tableData = [];
        // this.pageInfo.total = 0;
      }
      this.loading = false;
    },
    async updateStatus(val) {
      let { id, type } = val;
      let model = {
        id: id,
        remark: "123",
        status: type,
      };
      console.log(model);
      const res = await asyncRequest.updateStatus(model);
      if (res && res.code === 0) {
        const title = this.id === "add" ? "添加成功！" : "修改成功！";
        this.$notify.success({
          title,
          message: "",
        });
        this.showModelThis = false;
        // 刷新
        this.$emit("refresh", false);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>
