<template>
  <div class="supplierDetail">
    <div class="supplierDetail-main" v-if="powers.some((i) => i == '001')">
      <el-tabs v-model="activeTabs">
        <el-tab-pane label="新建供应商" name="0" v-if="queryType === 'add'">
          <base-form
            v-if="newTime !== ''"
            :type="queryType"
            :id="queryId"
            :newTime="newTime"
            :sitem="sitem"
            @refresh="refresh"
          />
        </el-tab-pane>
        <el-tab-pane label="供应商详情" name="1" v-if="queryType !== 'add'">
          <base-form
            v-if="newTime !== ''"
            :type="queryType"
            :id="queryId"
            :newTime="newTime"
            :sitem="sitem"
            @refresh="refresh"
          />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/operate/supplier";
import resToken from "@/mixins/resToken";
import { mapGetters } from "vuex";
import baseForm from "./components/baseForm";
export default {
  name: "supplierDetail",
  mixins: [resToken],
  components: {
    baseForm,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "supplierDetail") ||
        {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },

  data() {
    return {
      size: "small",
      activeTabs: "1",
      activeNames: ["0", "1"],
      editColumns: [
        {
          prop: "code",
          label: "供应商编号",
          span: 6,
        },
        {
          prop: "status",
          label: "使用状态",
          _slot_: "status",
          span: 4,
        },
        {
          prop: "ocr_status",
          label: "执照识别状态",
          _slot_: "ocr_status",
          span: 5,
        },

        {
          prop: "creater",
          label: "创建人",
          span: 4,
        },
        {
          prop: "addtime",
          label: "创建时间",
          span: 5,
        },
      ],
      ocr_status: [
        { id: "0", label: "未上传" },
        { id: "1", label: "识别成功" },
        { id: "2", label: "识别失败" },
      ],
      newTime: "",
      loading: false,
      queryType: "",
      queryId: "",
      status: "",
      sitem: null,
    };
  },
  mounted() {
    this.initForm();
  },
  methods: {
    async initForm() {
      const { id, type } = this.$route.query;
      this.queryId = id;
      this.queryType = type;
      this.activeTabs = type === "add" ? "0" : "1";
      this.loading = true;
      if (this.queryType === "add") {
        this.sitem = {};
        this.getNewTime();
      } else {
        await this.initData();
      }

      this.loading = false;
    },
    // 点击业务审核的保存按钮
    // async examForm(e) {
    //   console.log(e);
    //   if (!this.loading) {
    //     let type = e.state === "1" ? "1" : e.rebut;
    //     await this.setstatus(type, "提交采购部门审核", e.remark);
    //   }
    // },
    async setstatus(type, detail, remark) {
      await this.$confirm(`确定要${detail}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let _model = {
            spuCode: this.queryId,
            status: type,
            remark: remark
          };
          let res = await asyncRequest.status(_model);
          if (res && res.code === 1) {
            this.$notify.success({
              title: "提交成功！",
              message: "",
            });
            await this.initForm();
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    handleClick(row) {
      console.log(row);
    },
    async refresh(e) {
      this.routeGoto("supplier", {});
    },
    async initData() {
      this.loading = true;
      const { code, message:_, data } = await asyncRequest.detail({
        id: this.queryId,
      });
      this.loading = false;
      if (code === 1) {
        this.sitem = JSON.parse(JSON.stringify(data));
        const { status } = this.sitem;
        this.status = status;
        this.getNewTime();
       }
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
  },
};
</script>
<style lang="scss" scoped>
.supplierDetail {
  position: relative;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  .supplierDetail-main {
    position: relative;
    padding: 10px;
    height: 100%;
    width: 100%;
  }
  .supplierDetail-title {
    border-top: 1px solid #ebeef5;
    span {
      height: 50px;
      line-height: 50px;
      font-family: "微软雅黑", sans-serif;
      font-weight: 400;
      font-style: normal;
      font-size: 16fpx;
      text-align: left;
    }
  }
  /deep/ .ddiv {
    border-top: 1px solid #dcdfe6;
  }
  /deep/ .dtitle {
    width: 40px;
    text-align: center;
    height: 100%;
    min-height: 100%;
    ul {
      padding: 12px 0 0 0;
    }
  }
  /deep/ .dmain {
    padding: 20px 0 0 0;
    width: calc(100% - 40px);
    border-left: 1px solid #dcdfe6;
  }
}
</style>
