<template>
  <el-dialog
    :title="title"
    :center="true"
    align="left"
    top="5vh"
    width="1040px"
    @close="showModelThis = false"
    :close-on-click-modal="false"
    :visible.sync="showModelThis"
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <el-card style="margin-top: -20px">
      <el-row :gutter="10">
        <el-col :span="24">
          <wsm-in-order-addEdit-form
            v-if="newTime !== ''"
            :id="id"
            :newTime="newTime"
            :modelSitem="modelSitem"
            :sitem="sitem"
            @refresh="(showModelThis = false), $emit('refresh')"
          />
     
        </el-col>
      </el-row>
    </el-card>
  </el-dialog>
</template>
   <script>
import asyncRequest from "@/apis/service/purchaseIn/purchaseOrder/detail";
import resToken from "@/mixins/resToken";
import wsmInOrderAddEditForm from "./wsm-in-order-addEdit-form";

export default {
  name: "purchaseOrder",
  props: ["showModel", "id", "btn_code", "modelSitem"],
  components: { wsmInOrderAddEditForm},
  mixins: [resToken],
  data() {
    return {
      showModelThis: this.showModel,
      loading: false,
      title: "",
      sitem: null,
      newTime: "",
    };
  },
  watch: {
    showModel: function (val) {
      this.showModelThis = val;
      if (val) {
        this.initForm();
      }
    },
    showModelThis(val) {
      if (!val) {
        this.$emit("cancel");
      }
    },
  },
  methods: {
    
    async initForm() {
      this.loading = true;
      this.sitem = null;
      // btn_code
      switch (this.btn_code) {
        case "028":
          this.title = "新建备货入库单";
          break;
        case "007":
          this.title = "备货入库单详情";
          break;
        default:
          this.title = "新建备货入库单";
      }
      if (this.btn_code !== "028") {
        await this.initData();
      } else {
        this.sitem = {};
        this.getNewTime();
      }

      this.loading = false;
    },

    async initData() {
      const res = await asyncRequest.orderininfo({ wsm_in_code: this.id });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
  },
};
</script>

   <style lang="scss" scoped>
.purchaseOrder {
}
</style>
   