<template>
  <div class="zxAfterSaleDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <p>{{ status }}---{{ powers }}</p>
      <div class="tl" style="padding: 15px 0 22px 0">
        <span>咨询售后申请编号：</span>
        <span v-if="sitem">{{ sitem.returnCode }}</span>
      </div>
      <status-bar
        v-if="newTime !== ''"
        :newTime="newTime"
        :options="statusOptions"
        :status="status"
      />
      <el-collapse v-model="activeNames">
        <el-collapse-item title="售后申请详情" name="1">
          <add-edit-form
            :sitem="sitem"
            :newTime="newTime"
            v-if="newTime != ''"
          ></add-edit-form>
        </el-collapse-item>
        <el-collapse-item
          title="业务审核"
          name="1"
          v-if="status == '0' && powers.some((item) => item == '043')"
        >
          <exam-form
            v-if="newTime != ''"
            :statusList="statusList"
            :newTime="newTime"
            :disabled="false"
            :isMust="false"
            @searchChange="examForm"
          />
        </el-collapse-item>
        <el-collapse-item
          title="供应商反馈"
          name="2"
          v-if="
            (status == '1' && powers.some((item) => item == '046')) ||
            status == '2' ||
            status == '3' ||
            status == '4' ||
            status == '5'
          "
        >
          <supplier-feedback
            v-if="newTime != ''"
            :sitem="sitem"
            :newTime="newTime"
            @refresh="initData()"
          />
        </el-collapse-item>

        <el-collapse-item
          title="采购审核"
          name="3"
          v-if="
            (status == '2' && powers.some((item) => item == '036')) ||
            status == '3' ||
            status == '4' ||
            status == '5'
          "
        >
          <purchase-check
            v-if="newTime != ''"
            :sitem="sitem"
            :newTime="newTime"
            @refresh="initData()"
          />
        </el-collapse-item>
        <el-collapse-item title="填写物流" name="4"   v-if="
            (status == '3' && powers.some((item) => item == '045')) ||
            status == '4' ||
            status == '5'
          ">
          <return-express
            v-if="newTime != ''"
            :sitem="sitem"
            :newTime="newTime"
            @refresh="initData"
          ></return-express>
        </el-collapse-item>
        <el-collapse-item title="审批记录" name="10">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'SHD'"
            :orderCode="orderCode"
          />
        </el-collapse-item>
      </el-collapse>
      {{ orderCode }}
    </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/sheetOrder/zxAfterSale";
import addEditForm from "./components/addEditForm.vue";
import supplierFeedback from "./components/supplier_feedback";

import PurchaseCheck from "./components/purchase_check";
import ReturnExpress from "./components/returnExpress";
export default {
  name: "zxAfterSaleDetail",
  mixins: [mixinPage, resToken],
  components: {
    addEditForm,
    PurchaseCheck,
    ReturnExpress,
    supplierFeedback,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxAfterSaleDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      activeNames: ["0", "1", "2", "3", "4", "10"],
      s_status: "", //存储详情接口状态
      statusList: [],
      sitem: null,
      newTime: "",
      loading: false,
      statusOptions: [
        { value: "0", label: "业务审核" },
        { value: "1", label: "物流信息反馈" },
        // { value: "2", label: "反馈物流费" },
        { value: "3", label: "填写退货信息" },
        // { value: "4", label: "已退货" },
        { value: "5", label: "售后退货单创建成功" },
      ],
      orderCode: "",
      return_code: "",
      code: "",
    };
  },
  mounted() {
    this.code = this.$route.query.id;

    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    // 点击业务审核的保存按钮
    async examForm(e) {
      console.log(e);
      if (!this.loading) {
        let type = e.state === "1" ? "1" : "0";
        console.log(type);
        await this.setstatus(type, "提交业务审核", e.remark);
      }
    },
    //
    async setstatus(type, detail, remark) {
      await this.$confirm(`确定要${type === "1" ? "同意" : "驳回"}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          // if (this.sitem) {
          // let { returnCode } = this.sitem;
          const model = {
            remark,
            returnCode: this.code,
            status: type,
          };
          let res = await asyncRequest.status(model);

          if (res && res.code === 0) {
            this.$notify.success({
              title: "修改成功！",
              message: "",
            });
            await this.initData();
          } else if (res && res.code >= 100 && res.code <= 104) {
            await this.logout();
          } else {
            this.$message.warning(res.message);
          }
          // }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    async initData() {
      let model = {
        returnCode: this.code,
      };
      const res = await asyncRequest.detail(model);
      if (res && res.code === 0 && res.data) {
        this.status = res.data.status;
        this.sitem = res.data;
        this.orderCode = res.data.returnCode;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>
   
   