<template>
  <div>
    <basicDetails
      ref="details"
      :titleText="mainData.itemname"
      :oldFormPath="{ edit: 'optionSystem/otherFileManage/modules' }"
      :editData="mainData"
      :mainAreaData="mainAreaData"
      turnPageId="20240605145002"
      delApiId="20240605144802"
      idname="itemid"
      ownertable="plm_item"
      tags=""
      :tabs="['基本信息']"
      :statusCheck="[{key:'lectotypestatus',value:'审核'}]"
      @pageChange="pageChange"
      @onEditSuccess="queryMainData($route.query.id)"
    >
      <div slot="customOperation">
        <customBtn
          class="inline-16"
          btnName="审核"
          message="确定审核当前辅件吗?"
          idName="20240605144902"
          keyName="itemids"
          :id="[$route.query.id]"
          :paramData="[{key:'ischeck',value:1}]"
          @onSuccess="queryMainData()"
          v-if="mainData.lectotypestatus == '新建' && tool.checkAuth($route.name,'check')"
        />
        <customBtn
          class="inline-16"
          btnName="反审核"
          message="确定反审核当前辅件吗?"
          idName="20240605144902"
          keyName="itemids"
          :id="[$route.query.id]"
          :paramData="[{key:'ischeck',value:0}]"
          @onSuccess="queryMainData()"
          v-if="mainData.lectotypestatus == '审核' && tool.checkAuth($route.name,'nocheck')"
        />
      </div>
      <div slot="slot0">
        <DetailInfo :more="true" :data="detailInfo"></DetailInfo>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import DetailInfo from "@/components/detailInfo/index";
export default {
  name: "detail",
  components:{DetailInfo},
  data() {
    return {
      mainData: {},
      mainAreaData: {},
      detailInfo: [],
      othertype:[]
    };
  },
  provide() {
    return {
      othertype: () => {
        return this.othertype;
      },
    };
  },
  methods: {
    async queryMainData(id) {
      const res = await this.$api.requested({
        id:20240605144702,
        content: {
          itemid: this.$route.query.id,
        },
      });
      this.mainData = res.data;
      console.log(this.mainData,'详情');
      this.changeDataStructure();
    },
    changeDataStructure() {
        let that = this
      this.mainAreaData = [
        {
          label: "辅件料号",
          value: this.mainData.itemno,
        },
        {
          label: "名称",
          value: this.mainData.itemname,
        },
        {
          label: "品牌",
          value: this.mainData.actuatorbrand,
        },
        {
          label: "辅件类型",
          value: this.mainData.othertype,
        },
        {
          label: "规格",
          value: this.mainData.spec,
        },
        {
          label: "品牌",
          value: this.mainData.actuatorbrand,
        },
        {
          label: "价格",
          value: this.tool.formatAmount(this.mainData.marketprice,2),
        },
        {
          label: "状态",
          value:this.mainData.lectotypestatus,
          style:function () {
            let style = {}
            switch (that.mainData.lectotypestatus) {
              case '新建':
                style = {color:"#000000"}
                break;
              case '审核':
                style = {color:"#52C41A"}
                break;
              default:
                break;
            }
            return style
          }
        },
      ];
      this.detailInfo = [
        {
          title: "基本信息",
          info: [
            {
              label: "辅件料号",
              value: this.mainData.itemno,
            },
            {
              label: "名称",
              value: this.mainData.itemname,
            },
            {
              label: "辅件类型",
              value: this.mainData.othertype,
            },
            {
              label: "规格",
              value: this.mainData.spec,
            },
            {
              label: "品牌",
              value: this.mainData.actuatorbrand,
            },
            {
              label: "价格",
              value: this.tool.formatAmount(this.mainData.marketprice,2),
            },
            {
              label: "备注",
              value: this.mainData.remarks,
            },
            {
              label: "状态",
              value:this.mainData.lectotypestatus,
              style:function () {
                let style = {}
                switch (that.mainData.lectotypestatus) {
                  case '新建':
                    style = {color:"#000000"}
                    break;
                  case '审核':
                    style = {color:"#52C41A"}
                    break;
                  default:
                    break;
                }
                return style
              }
            },
          ],
        },
        {
          title: "系统信息",
          info: [
            { label: "创建人", value: this.mainData.createby },
            { label: "创建时间", value: this.mainData.createdate },
            { label: "最近编辑人", value: this.mainData.changeby },
            { label: "最近编辑时间", value: this.mainData.changedate },
            { label: "审核人", value: this.mainData.checkby },
            { label: "审核时间", value: this.mainData.checkdate },
          ],
        },
      ];
      console.log(this.mainAreaData);
    },
    // 监听切换数据,上一页,下一页
    pageChange(id, rowindex, tabIndex) {
      this.flag = false;
      tabIndex = this.$route.query.tabIndex;
      this.$router.replace({
        path: "/otherFileDetail",
        query: { id: id, rowindex: rowindex, tabIndex: tabIndex },
      });
      this.queryMainData(id);
    },
    onSuccess() {
      this.visible = false;
      this.queryMainData(this.$route.query.id);
      this.$emit("onSuccess");
    },
    optionList() {
      this.$store.dispatch("optiontypeselect", "othertype").then((res) => {
        this.othertype = res.data;
        console.log(this.othertype, "辅件类型");
      });
    },
  },
  created() {
    this.optionList()
    this.queryMainData(this.$route.query.id)
  },
};
</script>

<style scoped>
</style>
