<template>
  <div class="zxOrderDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <!-- {{ status }}--{{ powers }} -->
      <div class="tl" style="padding: 10px 0 50px 0">
        <span>咨询订单编号：</span>
        <span v-if="sitem">{{ sitem.orderCode }}</span>
        <el-button
          @click="statusConfirm('-1', '作废该条信息')"
          type="danger"
          plain
          class="fr"
          :size="'mini'"
          style="margin: 0 0 0 10px"
          v-if="
            (status == '0' || status == '1') &&
            powers.some((item) => item == '007')
          "
          >作废该条信息</el-button
        >
        <el-button
          v-if="
            (status == '3' || status == '4' || status == '5') &&
            powers.some((item) => item == '051')
          "
          style="margin: 0 0 0 10px"
          class="fr"
          type="primary"
          plain
          :size="'mini'"
          @click="openModal('add', false, 'sell')"
          >新建销售退货单
        </el-button>

        <!-- <el-button
          type="primary"
          plain
          class="fr"
          :size="'mini'"
          style="margin: 0 0 0 10px"
          @click="statusConfirm('3', '开始发货')"
          v-if="status === '2' && powers.some((item) => item == '026')"
          >开始发货
        </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="0">
          <add-form
            :newTime="newTime"
            v-if="newTime !== ''"
            :sitem="sitem"
            :id="queryId"
            @refresh="initData()"
          />
        </el-collapse-item>
        <el-collapse-item
          title="发起审核流程"
          name="0"
          v-if="status === '0' && powers.some((item) => item == '012')"
        >
          <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('1', '发起审核流程')"
              >发起审核流程
            </el-button>
          </div>
        </el-collapse-item>
        <el-collapse-item title="发货申请单" name="3">
          <order-out-table
            :newTime="newTime"
            v-if="newTime !== '' && status != '0'"
            :sitem="sitem"
            :id="queryId"
            @refresh="initData()"
          />
        </el-collapse-item>

        <!-- <el-collapse-item title="出库物流" name="3">
          <add-edit1
            :newTime="newTime"
            v-if="newTime !== '' && status != '0'"
            :sitem="sitem"
            :id="queryId"
            @refresh="initData()"
          />
        </el-collapse-item>  -->
      </el-collapse>
         </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
         <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'ZXQRD'"
            :orderCode="orderCode"
          />
        </el-tab-pane>
      </el-tabs>
      <add-edit
        :id="modelId"
        :sitem="s_sitem"
        :show-model="showModel"
        :is-detail="isDetail"
        @refresh="searchList"
        @cancel="showModel = false"
      />
      <!-- <edit-add
        :id="modelId"
        :sitem="sitem"
        :show-model="showModell"
        :is-detail="isDetail"
        @refresh="searchList"
        @cancel="showModel = false"
      /> -->
    </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/zxOrder/detail";
import addForm from "./components/addForm";
import feedbackForm from "./components/feedback-form";
import orderOutTable from "./components/order-out-table";
import addEdit from "./addEdit";
export default {
  name: "zxOrderDetail",
  mixins: [mixinPage, resToken],

  components: {
    // addEdit1,
    addEdit,
    addForm,
    feedbackForm,
    orderOutTable,
    // editAdd,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      activeTabs:"1",
      finishStatus: "finish",
      activeNames: ["-1", "0", "1", "2", "3", "4", "5", "10"],
      statusOptions: [
        { value: "0", label: "待发起流程" },
        { value: "1", label: "待发货" },
        { value: "2", label: "发货中" },
        { value: "3", label: "部分发货" },
        { value: "4", 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({ id: 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 = {
        id: 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({ id: 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;
      }

      this.modelId = id;
      this.isDetail = isDetail;
      this.s_sitem = this.sitem;
    },
  },
};
</script>
   <style lang="scss" scoped>
.zxOrderDetail {
}
</style>
   
   