<template>
  <div class="purchaseOrderDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <p>{{ powers }}</p>
      <p>status{{ status }}</p>
      <!-- <div class="detail-page-title">
        <span class="title">售后申请详情</span>
        <add-edit-form :sitem="sitem"></add-edit-form>
      </div> -->
      <el-collapse v-model="activeNames">
        <el-collapse-item title="售后申请详情" name="1">
          <add-edit-form :sitem="sitem"></add-edit-form>
        </el-collapse-item>
        <el-collapse-item
          title="业务审核"
          name="1"
          v-if="powers.some((item) => item == '034')"
        >
          <exam-form
            v-if="status == '0'"
            :statusList="statusList"
            :newTime="newTime"
            :disabled="false"
            :isMust="false"
            @searchChange="examForm"
          />
        </el-collapse-item>
        <el-collapse-item
          title="物流反馈"
          name="2"
          v-if="powers.some((item) => item == '040')"
        >
          <!-- v-if="status == '2'" -->
          <express-feedback
            @refresh="searchList"
            :returnCode="returnCode"
            v-if="status == '2' || status == '1'"
          ></express-feedback>
        </el-collapse-item>
        <!-- <el-collapse-item
          title="采购审核"
          name="3"
          v-if="powers.some((item) => item == '036')"
        >
          <purchase-check></purchase-check>
        </el-collapse-item> -->
        <el-collapse-item
          title="退货物流"
          name="4"
          v-if="powers.some((item) => item == '040')"
        >
          <return-express
            :returnCode="returnCode"
            v-if="status == '3'"
          ></return-express>
        </el-collapse-item>
      </el-collapse>
    </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/purchaseIn/purchaseOrder/detail";
import asyncRequest from "@/apis/service/goodsService";

import addEditForm from "./components/addEditForm.vue";
import ExpressFeedback from "./components/express_feedback.vue";

import PurchaseCheck from "./components/purchase_check";
import ReturnExpress from "./components/returnExpress";
export default {
  name: "serviceDetail",
  mixins: [mixinPage, resToken],
  components: {
    addEditForm,
    ExpressFeedback,
    PurchaseCheck,
    ReturnExpress,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "serviceDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      returnCode: "",
      activeNames: ["0", "1", "2", "3", "4"],
      sitem: null,
      status: "", //存储详情接口状态
      statusList: [],
      sitem: null,
      newTime: "",
      loading: false,
    };
  },
  mounted() {
    this.sitem = this.$route.query.id;
    console.log(this.sitem);
    this.returnCode = this.sitem.returnCode;
    this.searchList();
  },
  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,
              status: type,
            };
            let res = await asyncRequest.status(model);

            if (res && res.code === 0) {
              this.$notify.success({
                title: "修改成功！",
                message: "",
              });
              await this.searchList();
            } else if (res && res.code >= 100 && res.code <= 104) {
              await this.logout();
            } else {
              this.$message.warning(res.message);
            }
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    async searchList() {
      console.log(this.sitem);
      if (this.sitem) {
        let { returnCode } = this.sitem;
        let model = {
          returnCode,
        };
        const res = await asyncRequest.detail(model);
        if (res && res.code === 0 && res.data) {
          this.status = res.data.status;
          // let { error_num, error_img, error_remark, except_code, error_code } =
          //   res.data;
          // console.log(res.data);
          // this.ruleForm = {
          //   stock_out_numbers: "", //出库单编号
          //   anomalous_numbers: error_num, //异常数量
          //   anomalous_reason: error_code, //异常原因
          //   expect_wish: except_code, //期望意愿
          //   anomalous_images: [error_img],
          //   anomalous_remark: error_remark, //异常备注
          // };
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(res.message);
        }
      }
    },
  },
};
</script>
   
   