<template>
  <div class="zxDiffOrderDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <div class="detail-page-title">
        <span>工差单详情：</span>
      </div>
      <!-- <status-bar
        v-if="newTime !== ''"
        :newTime="newTime"
        :options="statusOptions"
        :status="status"
      /> -->
       <el-tabs v-model="activeTabs">
        <el-tab-pane label="业务详情" name="1">
      <el-collapse v-model="activeNames" style="margin:-18px 0 0 0">
        <el-collapse-item title="采购工差单信息" name="1">
          <show-form
            :newTime="newTime"
            v-if="newTime !== ''"
            :sitem="sitem"
            :id="queryId"
          />
        </el-collapse-item>
        <el-collapse-item title="业务审核" name="2">
          <add-form
            :sitem="sitem"
            :newTime="newTime"
            v-if="newTime !== ''"
            @refresh="initData()"
          />
        </el-collapse-item>
        <el-collapse-item
          title="通知业务部门"
          name="3"
          v-if="status === '2' && powers.some((item) => item == '044')"
        >
          <div class="tr" style="padding: 0 30px 20px 0">
            <el-button type="primary" plain :size="'mini'" @click="setStatus"
              >我已知晓</el-button
            >
          </div>
        </el-collapse-item>
      </el-collapse>
         </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'ZXGCD'"
            :orderCode="queryId"
          />
        </el-tab-pane>
      </el-tabs>
    </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/sellOut/zxDiffOrder";
import showForm from "./components/showForm";
import addForm from "./components/addForm";
export default {
  name: "zxDiffOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    showForm,
    addForm,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxDiffOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      showModel: false,
      activeNames: ["-1", "0", "1", "2", "3", "4", "5", "10"],
      statusOptions: [
        { value: "1", label: "待业务部门审核" },
        { value: "2", label: "待通知业务部门" },
        { value: "3", label: "审批已完成" },
      ],
      sitem: null,
      orderCode: "",
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
    };
  },
  mounted() {
    this.status = "";
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf() + "";
    },

    async setStatus() {
      if (!this.loading) {
        this.loading = true;

        let model = {
          id: this.queryId,
          remark: "",
          status: "",
        };
        const res = await asyncRequest.fstatus(model);
        this.loading = false;
        if (res && res.code === 0) {
          this.$notify.success({
            title: "通知成功！",
            message: "",
          });
          this.initData();
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(res.message);
        }
      }
    },
    async initData() {
      const res = await asyncRequest.detail({ id: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { can, status } = res.data;
        this.status = status;
        this.sitem.class_cat = "";
        if (can && can.length > 0) {
          can.forEach((x, i) => {
            this.sitem.class_cat += i === 0 ? x.name : "/" + x.name;
          });
        }
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>
   <style lang="scss" scoped>
.zxDiffOrderDetail {
}
</style>
   
   