<template>
  <span>
    <el-button
      v-show="isshow && showBtn && order_type && order_type !== '1'"
      type="primary"
      :size="'mini'"
      class="fr"
      style="margin: 0 0 0 12px"
      @click="diffAdd = true"
      >填写总工差</el-button
    >
    <add-edit-model
      :sitem="showItem"
      :show-model="diffAdd"
      @refresh="initData"
      @cancel="diffAdd = false"
    />
  </span>
</template>

<script>
import addEditModel from "@/views/purchaseIn/purchaseDiffOrder/addEditModel";
import asyncRequest from "@/apis/service/purchaseIn/purchaseOrder";
import resToken from "@/mixins/resToken";
export default {
  name: "tolerance",
  components: {
    addEditModel,
  },
  props: ["id", "sitem", "newTime", "showBtn"],
  mixins: [resToken],
  data() {
    return {
      diffAdd: false,
      order_type: "",
      spuCode: "",
      is_noble: false,
      isshow: false,
      showItem: null,
      cgdNo: "",
    };
  },
  mounted() {
    const { order_type, spuCode, cgdNo } = this.sitem;
    this.order_type = order_type;
    this.spuCode = spuCode;
    this.cgdNo = cgdNo;

    // this.queryId = this.$route.query.id;
    this.initData();
  },

  methods: {
    async initData() {
      // console.log("111111");
      let res = {};
      if (this.order_type === "1" || this.order_type === "2") {
        res = await asyncRequest.cost_detail({ spuCode: this.spuCode });
      } else {
        res = await asyncRequest.re_detail({ spuCode: this.spuCode });
      }

      const { code, data, message } = res;
      if (code === 0) {
        const { cat_info, is_diff, noble_weight } = data;
        if (cat_info && cat_info.length > 0) {
          cat_info.forEach((e) => {
            if (e.id === "6") {
              this.is_noble = true;
            }
          });
        }
        if (this.is_noble && is_diff === "1") {
          this.isshow = true;
          this.showItem = {
            cgdNo: this.cgdNo,
            good_num: this.sitem.good_num,
            weight: noble_weight,
          };
        }

        console.log(this.isshow +'-'+this. showBtn +"-"+ this.order_type);


      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
    },
    showDiffAdd() {
      // diffAdd = true
    },
  },
};
</script>

<style  lang="scss" scoped>
</style>
