<template>
  <div class="zxReturnDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <!-- {{ status }}--{{ powers }} -->
      <div class="detail-page-title">
        <span>咨询退货单编号：</span><span v-if="sitem">{{ sitem.id }}</span>
        <el-button
          @click="statusConfirm('-1', '作废该条信息')"
          type="danger"
          plain
          :size="'mini'"
          v-if="
            status !== '' &&
            status !== '3' &&
            powers.some((item) => item == '015')
          "
          >作废该条信息</el-button
        >
      </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"
                @refresh="initData()"
              />
            </el-collapse-item>
            <!-- v-if="status === '0' && powers.some((item) => item == '012')" -->
            <el-collapse-item title="发起审核流程" name="0">
              <div style="height: 45px; padding: 0 20px 20px 0">
                <el-button
                  type="primary"
                  plain
                  class="fr"
                  :size="'mini'"
                  style="margin: 0 0 0 10px"
                  @click="statusConfirm('2', '发起审核流程')"
                  >发起审核流程
                </el-button>
              </div>
            </el-collapse-item>

            <el-collapse-item title="采购反馈" name="1">
              <purchase-feedback
                :newTime="newTime"
                v-if="newTime !== ''"
                :sitem="sitem"
                :id="queryId"
                @refresh="initData()"
              />
            </el-collapse-item>
            <el-collapse-item title="采购审核" name="1">
              <purchase-exam
                :newTime="newTime"
                v-if="newTime !== ''"
                :sitem="sitem"
                :id="queryId"
                @refresh="initData()"
              />
            </el-collapse-item>

            <el-collapse-item title="通知采购部门" name="1">
              <div style="height: 45px; padding: 0 20px 20px 0">
                <el-button
                  type="primary"
                  plain
                  class="fr"
                  :size="'mini'"
                  style="margin: 0 0 0 10px"
                  @click="statusConfirm('2', '通知采购部门')"
                  >我已知晓
                </el-button>
              </div>
            </el-collapse-item>

            <el-collapse-item title="通知财务部门" name="1">
              <div style="height: 45px; padding: 0 20px 20px 0">
                <el-button
                  type="primary"
                  plain
                  class="fr"
                  :size="'mini'"
                  style="margin: 0 0 0 10px"
                  @click="statusConfirm('2', '通知财务部门')"
                  >我已知晓
                </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="'ZXTHD'"
            :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/zxReturn";
import showForm from "./components/showForm";
import purchaseFeedback from "./components/purchase-feedback";
import purchaseExam from "./components/purchase-exam";
export default {
  name: "zxReturnDetail",
  mixins: [mixinPage, resToken],

  components: {
    purchaseFeedback,
    purchaseExam,
    // addEdit1,
    showForm,
    // addForm,
    // feedbackForm,
    // orderOutTable,
    // editAdd,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxReturnDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },

  data() {
    return {
      activeNames: ["-1", "0", "1", "2", "3", "4", "5", ],
      statusOptions: [
        { value: "0", label: "待发起流程" },
        // { value: "1", label: "待业务审核" },
        { value: "2", label: "待采购反馈" },
        { value: "3", label: "待采购审核" },
        { value: "4", label: "待通知采购部门" },
        { value: "5", label: "待通知财务部门" },
        { value: "6", label: "退货已完成" },
      ],
      sitem: null,
      s_sitem: null,
      orderCode: "",
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
    };
  },
  mounted() {
    this.status = "";
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    async statusConfirm(status, message) {
      await this.$confirm(`确定要${message}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          if (status === "-1") {
            await this.deleteById(message);
          } else {
            await this.setStatus(status, message);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    getNewTime() {
      this.newTime = new Date().valueOf() + "";
    },

    async deleteById(message) {
      const res = await asyncRequest.delete({ returnCode: this.queryId });
      if (res && res.code === 0) {
        this.$notify.success({
          title: message + "成功！",
          message: "",
        });

        this.routeGoto("check", {});
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },

    async setStatus(status, message, remark) {
      let model = {
        returnCode: this.queryId,
        remark: remark || "",
        status: status,
      };
      const res = await asyncRequest.status(model);
      this.loading = false;
      if (res && res.code === 0) {
        this.$notify.success({
          title: message + "成功！",
          message: "",
        });
        this.initData();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
    async examForm(e) {
      if (!this.loading) {
        let type = e.state === "1" ? "2" : "0";
        await this.setStatus(type, "提交入库方审核", e.remark);
      }
    },
    async initData() {
      this.loading = true;
      const res = await asyncRequest.detail({ returnCode: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        this.status = this.sitem.status;
        this.orderCode = this.sitem.orderCode;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      this.loading = false;
    },
    openModal(id, isDetail, sitem) {
      if (sitem == "sell") {
        this.showModel = true;
      } else {
        this.showModell = true;
      }
      console.log(id, isDetail, sitem);

      this.modelId = id;
      this.isDetail = isDetail;
      // this.sitem = sitem;
      // this.sitem.info[0].edit = false;
      this.s_sitem = this.sitem;
    },
  },
};
</script>
   <style lang="scss" scoped>
.zxReturnDetail {
}
</style>
   
   