<template>
  <div class="page">
    <div>
      <a-form layout='vertical'>
        <a-tabs :activeKey='tabKey' @change="callback" tabPosition='left' size='large'>
          <a-tab-pane :key="'1'" :tab="$t('plan.basic-information')">
            <a-collapse :defaultActiveKey="'1'">
              <a-collapse-panel :header="$t('plan.basic-information')" key="1" :style="'margin-top:5px;'">
                <a-card class="mb-2">
                  <div>
                    <a-form layout="vertical">
                      <a-row :gutter="24">
                        <!-- 项目编号 -->
                        <a-col :lg='8' :md='12' :sm='24' :xl='6' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.project-number')">
                            <a-input
                                v-model='BaseInfo.projectCode'
                                :disabled='true'
                                allowClear
                            />
                          </a-form-item>
                        </a-col>
                        <!-- 项目名称 -->
                        <a-col :lg='8' :md='12' :sm='24' :xl='6' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.project-name')">
                            <a-input
                                v-model='BaseInfo.projectName'
                                :disabled='true'
                                allowClear
                            />
                          </a-form-item>
                        </a-col>
                        <!-- 项目状态 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.project-state')" class='projectNoBox'>
                            <a-input v-model="BaseInfo.projectState" :disabled='true' :label="$t('plan.basic-information.project-state')" />
                          </a-form-item>
                        </a-col>
                        <!-- 年 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.project-year')" class='projectNoBox'>
                            <a-input :disabled='true' v-model="BaseInfo.year">
                            </a-input>
                          </a-form-item>
                        </a-col>
                        <!-- 机台/设备编号 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.machine-equipment-code')">
                            <a-input :disabled="true" v-model="BaseInfo.equipmentCode"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- 机台设备名称 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.machine-equipment-name')">
                            <a-input :disabled="true" v-model="BaseInfo.equipmentName"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- MFMEA编号 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.mfmea-number')">
                            <a-input :disabled="true" v-model="BaseInfo.mfmeaCode"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- MFMEA创建人 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label=" $t('plan.basic-information.mfmea-creator')">
                            <a-input :disabled="true" v-model="BaseInfo.mfmeaCreator"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- MFMEA Owner -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.mfmea-owner')">
                            <a-input :disabled="true" v-model="BaseInfo.mfmeaOwner"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- 部门 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.department')">
                            <a-input :disabled="true" v-model="BaseInfo.departmentName"></a-input>
                          </a-form-item>
                        </a-col>
                        <!-- 计划完成时间 -->
                        <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
                          <a-form-item :label="$t('plan.basic-information.planning-completion-time')">
                            <a-input :disabled="true" v-model="BaseInfo.planCompleteTime">
                            </a-input>
                          </a-form-item>
                        </a-col>
                        <!-- 公司 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.company')" class='projectNoBox'>
                            <a-input allowClear :disabled='true' v-model='BaseInfo.company' />
                          </a-form-item>
                        </a-col>
                        <!-- 工程地点 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.project-location')" class='projectNoBox'>
                            <a-input allowClear :disabled='true' v-model='BaseInfo.manufactureAddress' />
                          </a-form-item>
                        </a-col>
                        <!-- 客户名称 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.customer-name')" class='projectNoBox'>
                            <a-input allowClear :disabled='true' v-model='BaseInfo.customer' />
                          </a-form-item>
                        </a-col>
                        <!-- 型号/平台 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.model-or-platform')" class='projectNoBox'>
                            <a-input allowClear :disabled='true' v-model='BaseInfo.modelOrPlatform' />
                          </a-form-item>
                        </a-col>
                        <!-- 编辑语言 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.edit-language')" class='projectNoBox'>
                            <a-input allowClear :disabled='true' v-model='BaseInfo.modelOrPlatform' />
                          </a-form-item>
                        </a-col>
                        <!-- 保密级别 -->
                        <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24'>
                          <a-form-item :label="$t('plan.basic-information.confidentiality-level')" class='projectNoBox'>
                            <a-input :disabled='true' v-model='BaseInfo.secrecyLevel'></a-input>
                          </a-form-item>
                        </a-col>
                      </a-row>
                    </a-form>
                  </div>
                </a-card>
                <a-card class="mb-2" :title="$t('plan.basic-information.other-information')">
                  <a-form layout='vertical'>
                    <a-row :gutter="24">
                      <a-col :xl='24' :lg='24' :md='24' :sm='24' :xs='24'>
                        <a-form-item>
                          <a-checkbox-group :disabled='true' v-model='checkData' class="checkbox-class">
                            <a-row :gutter="[24, 12]">
                              <a-col v-for="item in derivativeList" :key="item.value" :xl='6' :lg='6' :md='6' :sm='6' :xs='24'>
                                <a-checkbox :value='item.value'>
                                  {{ item.label }}
                                </a-checkbox>
                              </a-col>
                            </a-row>
                          </a-checkbox-group>
                        </a-form-item>
                      </a-col>
                    </a-row>
                    <a-row :gutter="24">
                      <!-- 产品阶段 -->
                      <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24' v-if="featureListFlag">
                        <a-form-item :label="$t('plan.basic-information.product-stage')" class='projectNoBox'>
                          <a-input :disabled='true' v-model='BaseInfo.productStage' :maxLength="128"/>
                        </a-form-item>
                      </a-col>
                      <!-- 客户代码 -->
                      <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24' v-if="featureListFlag">
                        <a-form-item :label="$t('plan.basic-information.customer-code')" class='projectNoBox'>
                          <a-input :disabled='true' v-model='BaseInfo.customerCode'/>
                        </a-form-item>
                      </a-col>
                      <!-- 规格 -->
                      <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24' v-if="featureListFlag">
                        <a-form-item :label="$t('plan.basic-information.specifications')" class='projectNoBox'>
                          <a-input :disabled='true' v-model='BaseInfo.specifications' :maxLength="128"/>
                        </a-form-item>
                      </a-col>
                      <!-- 图纸号 -->
                      <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24' v-if="checkListFlag">
                        <a-form-item :label="$t('plan.basic-information.drawing-number')" class='projectNoBox'>
                          <a-input :disabled='true' v-model='BaseInfo.drawingNo'/>
                        </a-form-item>
                      </a-col>
                      <!-- 点检表编号 -->
                      <a-col :xl='6' :lg='8' :md='12' :sm='24' :xs='24' v-if="checkListFlag">
                        <a-form-item :label="$t('plan.basic-information.equipment-inspection-checklist-code')" class='projectNoBox'>
                          <a-input :disabled='true' v-model='BaseInfo.spotCheckCode' :maxLength="128"/>
                        </a-form-item>
                      </a-col>
                    </a-row>
                  </a-form>
                </a-card>
              </a-collapse-panel>
            </a-collapse>
          </a-tab-pane>
          <a-tab-pane :key="'2'" :tab="$t('plan.team-members')">
            <TeamMembers :isOwner="isOwner"></TeamMembers>
          </a-tab-pane>
          <a-tab-pane :key="'3'" :tab="$t('plan.experience-lesson')">
            <ExperienceLesson
                :from="$route.query.from"
                :fmeaId="$route.query.fmeaId"
            ></ExperienceLesson>
          </a-tab-pane>
          <a-tab-pane :key="'4'" :tab="$t('plan.review-comments')">
            <review-comments :from="$route.query.from" :fmeaId="$route.query.fmeaId"
              :masterFmeaId="BaseInfo.masterFmeaId" :fmeaType="BaseInfo.fmeaType"></review-comments>
          </a-tab-pane>
          <a-tab-pane :key="'75'" :tab="$t('plan.approval-record')">
            <approval-record :from="$route.query.from" :fmeaId="$route.query.fmeaId"
              :masterFmeaId="BaseInfo.masterFmeaId" :fmeaType="BaseInfo.fmeaType"></approval-record>
          </a-tab-pane>
          <a-tab-pane :key="'6'" :tab="$t('plan.log-managent')">
            <!-- 日志管理 -->
            <LogManagent :from="$route.query.from" :fmeaId="$route.query.fmeaId" :masterFmeaId="BaseInfo.masterFmeaId"
              :fmeaType="BaseInfo.fmeaType"></LogManagent>
          </a-tab-pane>
          <a-tab-pane :key="'97'" :tab="$t('plan.change-record')">
            <changeRecord :from="$route.query.from" :fmeaId="$route.query.fmeaId" :masterFmeaId="BaseInfo.masterFmeaId"
              :fmeaType="BaseInfo.fmeaType"></changeRecord>
          </a-tab-pane>
        </a-tabs>
      </a-form>
    </div>
  </div>
</template>
<script>
import ReviewComments from "./components/project/ReviewComments.vue";
import ApprovalRecord from "./components/project/ApprovalRecord.vue";
import LogManagent from "./components/project/LogManagent";
import changeRecord from "./components/project/ChangeRecord";
import ExperienceLesson from "./components/project/ExperienceLesson.vue";
import TeamMembers from "./components/project/TeamMembers.vue";

export default {
  components: {
    LogManagent,
    ReviewComments,
    ApprovalRecord,
    changeRecord,
    ExperienceLesson,
    TeamMembers
  },
  data() {
    return {
      fmeaType: "",
      fmeaId: this.$com.fmeaId,
      from: this.$com.from,
      BaseInfo: {
        fmeaType: undefined
      },
      isOwner: false,
      tabKey: '1',
      // 复选框默认选中数据
      checkData: [],
      derivativeList: [
        {
          label: this.$t('plan.basic-information.feature-list'),
          value: 'featureList'
        },
        {
          label: this.$t('plan.basic-information.equipment-inspection-checklist'),
          value: 'equipmentInspectionChecklist'
        }
      ],
      featureListFlag: false,
      checkListFlag: false
    };
  },
  computed: {},
  mounted() {
    localStorage.setItem("historyText", null);
    this.initBaseInfo();
    this.$com.setCookie("from", this.$route.query.from);
    // 储存fmeaId
    this.$store.dispatch("fmeaTree/set", {
      key: "fmeaId",
      value: this.$route.query.fmeaId
    });
    // 储存rfmeaId
    this.$store.dispatch("fmeaTree/set", {
      key: "rfmeaId",
      value: this.$route.query.rfmeaId
    });
    // 编制页面进入时初始化
    this.initDraw();
  },
  methods: {
    //获取基本信息
    async initBaseInfo() {
      var t = this.fmeaId;
      let url = "/DFMEA/mfmea/plan/getMfmBasicInfo.do?fmeaId=" + this.fmeaId;
      this.$api.post(url, null).then((response) => {
        if (response.flag) {
          this.drawFlag = response.data.drawFlag;
          this.BaseInfo = {
            key: 1,
            projectCode: response.data.projectNo,
            mfmeaCode: response.data.fmeaCode,
            equipmentCode: response.data.equipmentCode,
            equipmentName: response.data.equipmentName,
            mfmeaCreator: response.data.fullName,
            mfmeaOwner: response.data.ownerName,
            isOrganization: response.data.drawFlag,
            planCompleteTime: response.data.planCompleteTime,
            departmentName: response.data.departmentName,
            flag: response.data.flag,
            lifeState: response.data.lifeState,
            company: response.data.company,
            customer: response.data.customer,
            manufactureAddress: response.data.manufactureAddress,
            modelOrPlatform: response.data.modelOrPlatform,
            secrecyLevel: response.data.secrecyLevel,
            projectName: response.data.projectName,
            projectState: response.data.projectState,
            year: response.data.year,
            companyCode: response.data.companyCode,
            customerCode: response.data.customerCode,
            productStage: response.data.productStage,
            specifications: response.data.specifications,
            drawingNo: response.data.drawingNo,
            spotCheckCode: response.data.spotCheckCode
          };
          // 根据详情信息中的衍生物信息是否为空设置复选按钮的选中状态
          // 特性清单
          if ((response.data.productStage !== null && response.data.productStage.length > 0) &&
              (response.data.specifications !== null && response.data.specifications.length > 0) &&
              (response.data.customerCode !== null && response.data.customerCode.length > 0)) {
            this.featureListFlag = true;
            this.checkData.push('featureList');
          }
          // 设备点检表
          if ((response.data.drawingNo !== null && response.data.drawingNo.length > 0) &&
              (response.data.spotCheckCode !== null && response.data.spotCheckCode.length > 0)) {
            this.checkListFlag = true;
            this.checkData.push('equipmentInspectionChecklist');
          }

          let userInfo = response.data.currentUser;
          localStorage.setItem("userInfo", JSON.stringify(userInfo));

          this.isOwner = userInfo.userId == response.data.ownerId && response.data.lifeState === '10';
          //储存 是否能添加评审意见 flag
          this.$store.dispatch("fmeaTree/set", {
            key: "commentsFlag",
            value: response.data.commentsFlag
          });
        } else {
          this.$message.error(response.message, 1);
        }
      });
    },
    /**
     * 编制页面进入时初始化
     */
    initDraw() {
      this.$api.initDraw({
        fmeaId: this.$store.getters.rfmeaId
      }).then((res) => {
        if (!res.flag) {
          this.$message.error(res.message, 1);
        }
      });
    },
    callback(key) {
      this.tabKey = key;
    },
  }
};
</script>

<style lang="less">
.checkbox-class {
  width: 50% !important;
  min-width: 450px !important;
}
</style>
<style lang="scss" scoped>
.page {
  overflow: auto;
  height: calc(90vh);
  background-color: white;
}
</style>
