<template>
  <div class="zxAfterSaleOrderDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <p>{{ status }}---{{ powers }}</p>
      <div class="detail-page-title">
        <span>咨询售后退后单编号：</span
        ><span v-if="sitem">{{ orderCode }}</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-data-table
                :newTime="newTime"
                v-if="newTime !== ''"
                :sitem="sitem"
                :columns="ShowDataTableColumns"
              >
                <template slot="status">
                  <el-tag
                    :size="'mini'"
                    :type="sitem.status == '0' ? 'warning' : ''"
                    v-text="
                      (
                        statusOptions.find(
                          (item) => item.value == sitem.status
                        ) || {}
                      ).label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="order_type">
                  <el-tag :size="'mini'" :type="''">{{
                    sitem.status === "1"
                      ? "销售出库单"
                      : sitem.status === "2"
                      ? "咨询出库单"
                      : "--"
                  }}</el-tag>
                </template>
                <template slot="except_code">
                  <el-tag :size="'mini'" :type="''">{{
                    sitem.except_code === "1"
                      ? "退货"
                      : sitem.except_code === "2"
                      ? "换货"
                      : sitem.except_code === "2"
                      ? "改变售价"
                      : "--"
                  }}</el-tag>
                </template>
              </show-data-table>
            </el-collapse-item>
            <el-collapse-item title="退货验收记录" name="0">
              <return-record
                v-if="newTime !== ''"
                :sitem="sitem"
                @refresh="initData"
                :newTime="newTime"
              />
            </el-collapse-item>

            <el-collapse-item title="退货验收审核" name="1">
              <return-check
                v-if="newTime !== ''"
                :newTime="newTime"
                :sitem="sitem"
                @refresh="initData"
              />
            </el-collapse-item>
            <el-collapse-item
              title="业务审核"
              name="2"
              v-if="powers.some((item) => item == '042')"
            >
              <exam-form
                v-if="newTime !== ''"
                :statusList="statusList"
                :newTime="newTime"
                :disabled="false"
                :isMust="true"
                @searchChange="exam_form_change"
              />
            </el-collapse-item>
          </el-collapse>
        </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'ZXCKTHD'"
            :orderCode="qid"
          />
        </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/zxAfterSaleOrder";
import ReturnRecord from "./components/return-record";
import ReturnCheck from "./components/returnCheck";
// import addEdit from "./components/addEdit";
import ShowDataTableColumns from "./ShowDataTableColumns";
export default {
  name: "zxAfterSaleOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    ReturnRecord,
    ReturnCheck,
    // addEdit,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxAfterSaleOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      activeTabs: "1",
      ShowDataTableColumns: ShowDataTableColumns,
      statusOptions: [
        { value: "0", label: "待申请" },
        { value: "1", label: "待验收" },
        { value: "2", label: "待验收审核" },
        { value: "3", label: "待业务审核" },
        { value: "4", label: "完成退货" },
      ],
      orderCode: "",
      activeNames: ["-1", "0", "1", "2", "10"],
      sitem: null,
      status: "", //存储详情接口状态
      statusList: [
        {
          value: "0",
          label: "退货验收记录",
        },
        {
          value: "2",
          label: "退货验收审核",
        },
      ],
      newTime: "",
      loading: false,
      qid: "",
    };
  },
  mounted() {
    this.qid = this.$route.query.id;
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    // 点击业务审核的保存按钮
    async exam_form_change(e) {
      if (!this.loading) {
        let type = e.state === "1" ? "4" : e.rebut;
        await this.setstatus(type, "提交业务审核", e.remark);
      }
    },
    async setstatus(type, detail, remark) {
      await this.$confirm(`确定要${detail}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let _model = {
            thNo: this.qid,
            status: type,
            remark: remark,
          };
          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 = {
        thNo: this.qid,
      };
      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.orderCode;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      // }
    },
  },
};
</script>
   
   