<template>
  <div class="purchaseOrderDetail 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">{{ sitem.outCode }}</span>
        <el-button
          class="fr"
          v-if="status === '2' && powers.some((item) => item == '049')"
          type="primary"
          plain
          :size="'mini'"
          style="margin: 0 0 0 10px"
          @click="showModel = true"
          >新建售后申请单
        </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="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'?'发货申请单':"咨询发货申请单"}}</el-tag>
            </template>
          </show-data-table>
          <!-- <add-edit-form
            :sitem="sitem"
            :newTime="newTime"
            v-if="newTime != ''"
          ></add-edit-form> -->
        </el-collapse-item>
        <el-collapse-item
          title="填写物流"
          name="2"
          v-if="
            (status === '0' && powers.some((item) => item == '045')) ||
            status === '1' ||
            status === '2'
          "
        >
          <logistics-form
            :sitem="sitem"
            :newTime="newTime"
            v-if="newTime != ''"
            @refresh="initData()"
          />
        </el-collapse-item>
        <el-collapse-item
          title="客户验收"
          name="3"
          v-if="status === '1' && powers.some((item) => item == '052')"
        >
          <div class="tr" style="padding: 0 20px 20px 0">
            <el-button
              type="primary"
              plain
              :size="'mini'"
              @click="customerCheck"
              >客户已收到货</el-button
            >
          </div>
        </el-collapse-item>
      </el-collapse>
      </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'ZXCKD'"
            :orderCode="sitem.outCode"
          />
        </el-tab-pane>
      </el-tabs>
      <div>
        <add-Edit-A
          :id="'add'"
          :sitem="sitem"
          :show-model="showModel"
          :is-detail="false"
          @refresh="initData"
          @cancel="showModel = false"
        />
      </div>
    </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/zxoutOrder";
import addEditForm from "./components/addEditForm.vue";
import logisticsForm from "./components/logisticsForm";
import addEditA from "./components/addEditA";
import ShowDataTableColumns from "./ShowDataTableColumns";
export default {
  name: "zxoutOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    addEditForm,
    addEditA,
    logisticsForm,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxoutOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      activeTabs:"1",
      activeNames: ["0", "1", "2", "3", "4", "10"],
      status: "", //存储详情接口状态
      statusList: [],
      ShowDataTableColumns: ShowDataTableColumns,
      sitem: null,
      newTime: "",
      showModel: false,
      loading: false,
      statusOptions: [
        { value: "0", label: "待发货" },
        { value: "1", label: "待验收" },
        { value: "2", label: "已完成" },
        // { value: "3", label: "已完成" },
      ],
      code: "",
    };
  },
  mounted() {
    this.code = this.$route.query.id;
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async setstatus() {
      const model = {
        orderCode: "",
        status: "",
        outCode: this.code,
      };
      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);
      }
    },
    async initData() {
      let model = {
        outCode: this.code,
      };
      const res = await asyncRequest.detail(model);
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { can } = this.sitem;
        this.sitem.class_cat = "";
        if (can && can.length > 0) {
          can.forEach((x, i) => {
            this.sitem.class_cat += i === 0 ? x.name : "/" + x.name;
          });
        }
        const { status } = res.data;
        this.status = status;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
    async customerCheck() {
      let model = {
        outCode: this.code,
        orderCode: this.sitem.orderCode,
        status: "3",
      };

      const res = await asyncRequest.status(model);
      if (res && res.code === 0) {
        await this.initData();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>
   
   