<template>
  <div class="purchaseOrderDetail pagePadding">
    <div
      style="width: 100%"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <div class="detail-page-title">
        <span class="title">采购单编号：{{ queryId }}</span>

        <div class="fr">
          <el-button
            type="primary"
            :size="'mini'"
            class="fr"
            @click="diffAdd = true"
            >填写总工差</el-button
          >
        </div>

        <!-- <span class="fr">
          <el-tag>
            {{
              (statusList.find((item) => item.code == status) || {}).label ||
              "--"
            }}
          </el-tag>
        </span> -->
      </div>
      <status-bar
        v-if="newTime !== ''"
        :newTime="newTime"
        :options="statusOptions"
        :status="status"
      />
      <el-collapse v-model="activeNames">
        <el-collapse-item title="采购单信息" name="1">
          <purchase-order-addEdit
            style="padding: 0 0 20px 0"
            :newTime="newTime"
            v-if="newTime !== ''"
            :sitem="sitem"
            :id="queryId"
            @refresh="initData()"
          />
        </el-collapse-item>
        <el-collapse-item title="备货入库单" name="2">
          <purchase-order-in-table
            :newTime="newTime"
            v-if="newTime !== '' && status !== '' && status !== '0'"
            :sitem="sitem"
            :id="queryId"
            @refresh="initData()"
          />
        </el-collapse-item>
        <!--  -->
        <el-collapse-item title="审批记录" name="10">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'CGD'"
            :orderCode="orderCode"
          />
        </el-collapse-item>
      </el-collapse>
      <diff-order-add
        :sitem="sitem"
        :show-model="diffAdd"
        @refresh="initData"
        @cancel="diffAdd = 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/purchaseIn/purchaseOrder/detail";
import purchaseOrderAddEdit from "./components/purchase-order-addEdit";
import purchaseOrderInTable from "./components/purchase-order-in-table";
import diffOrderAdd from "@/views/purchaseIn/purchaseDiffOrder/addEditModel";

export default {
  name: "purchaseOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    purchaseOrderAddEdit,
    purchaseOrderInTable,
    diffOrderAdd,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "purchaseOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  mounted() {
    console.log(this.$route);
  },
  data() {
    return {
      isMetal: false,
      finishStatus: "finish",
      activeNames: ["0", "1", "2", "3", "4", "5", "10"],
      sitem: null,
      statusOptions: [
        { value: "0", label: "发货意见" },
        { value: "1", label: "填写发货单" },
        { value: "2", label: "部分发货" },
        { value: "3", label: "发货完成" },
        // { value: "4", label: "发货中" },
        // { value: "5", label: "已发货" },
      ],
      statusList: [
        {
          code: "0",
          label: "待同意发货",
        },
        {
          code: "1",
          label: "待发货",
        },
        {
          code: "2",
          label: "部分发货",
        },
        {
          code: "3",
          label: "发货完成",
        },
      ],
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
      diffAdd: false,
      orderCode: "",
    };
  },
  mounted() {
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },

    openModal() {
      this.diffAdd = true;
    },
    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({ cgdNo: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { status, can } = this.sitem;
        this.status = status;
        console.log(res.data);
        this.orderCode = res.data.cgdNo;
        console.log(this.orderCode);
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      this.loading = false;
    },
  },
};
</script>
   <style lang="scss" scoped>
.purchaseOrderDetail {
}
</style>
   
   