<template>
  <div class="sellOutOrderDetail 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>
            </el-collapse-item>
            <el-collapse-item title="商品信息" name="2">
              <show-goods-data-table
                :newTime="newTime"
                v-if="newTime !== ''"
                :type="sitem.order_type"
                :skucode="sitem.skuCode"
                :spucode="sitem.good_code"
              />
            </el-collapse-item>
            <el-collapse-item
              title="库管发货"
              name="3"
              v-if="status === '0' && powers.some((item) => item == '080')"
            >
              <want-deliver
                :newTime="newTime"
                v-if="newTime !== ''"
                :sitem="sitem"
                @refresh="initData"
              />
            </el-collapse-item>
            <!-- <el-collapse-item title="填写售后申请单" name="3" v-if="status === '4'">
          <sell-return-apply
            :sitem="sitem"
            v-if="newTime != '' || true"
            :newTime="newTime"
            @refresh="updateStatus"
          />
        </el-collapse-item> -->
          </el-collapse>
        </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'CKD'"
            :orderCode="code"
          />
        </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/sellOutOrder";
import addEditForm from "./components/addEditForm.vue"; //发货申请单详情
import addEditA from "./components/addEditA";
import ShowDataTableColumns from "./ShowDataTableColumns";
import wantDeliver from "./components/want-deliver.vue";
export default {
  name: "sellOutOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    addEditForm,
    addEditA,
    wantDeliver,
  },
  computed: {
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "sellOutOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      activeTabs: "1",
      activeNames: ["0", "1", "2", "3", "4"],
      status: "", //存储详情接口状态
      statusList: [],
      ShowDataTableColumns: ShowDataTableColumns,
      sitem: null,
      newTime: "",
      showModel: false,
      loading: false,
      statusOptions: [
        { value: "0", label: "待发货" },
        { value: "1", label: "待库管发货" },
        { value: "2", label: "待收货" },
        { value: "3", label: "已收货" },
        { value: "4", label: "已全部退货" },
      ],
      code: "",
      did: "", //详情页上的id
    };
  },
  mounted() {
    this.code = this.$route.query.id;
    this.initData();
  },
  methods: {
    async updateStatus(e) {
      await this.setstatus(e.status);
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async setstatus(status) {
      const model = {
        id: this.did,
        status: status,
      };
      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(e) {
      let model = {
        outCode: this.code,
      };
      const res = await asyncRequest.detail(model);
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { status, can, id } = this.sitem;
        this.status = status;
        this.did = id;
        if (can && can.length > 0) {
          this.sitem.class_cat = "";
          can.forEach((x, i) => {
            this.sitem.class_cat += i === 0 ? x.name : "/" + x.name;
          });
        }

        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },

    async goodsCheck() {
      let model = {
        outCode: this.code,
        status: "2",
      };
      this.$confirm("客户是否已收到货？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await asyncRequest.salecustomer(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);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
  },
};
</script>
   
   