<template>
  <div>
    <a-row class="content-box">
      <a-card class="layout-card">
        <a-form layout='vertical'>
          <a-row :gutter="24">
            <!--系统名称-->
            <a-col :lg='6' :md='12' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('base.info.system-name')">
                <a-input
                  v-model.trim="formData.systemName"
                  :maxLength='500'
                  :placeholder="$t('base.info.please-enter-system-name')"
                  allowClear/>
              </a-form-item>
            </a-col>
            <!--需求资源-->
            <a-col :lg='6' :md='12' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('base.info.required.resources')">
                <a-input
                  v-model.trim="formData.assets"
                  :maxLength='500'
                  :placeholder="$t('base.info.please-enter-required.resources')"
                  allowClear/>
              </a-form-item>
            </a-col>
            <!--验证内容-->
            <a-col :lg='6' :md='12' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('base.info.verification-content')">
                <a-input
                  v-model.trim="formData.verify"
                  :maxLength='500'
                  :placeholder="$t('base.info.please-enter-verification-content')"
                  allowClear/>
              </a-form-item>
            </a-col>
            <!--开发目标要求-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('base.info.development-objective-requirements')">
                <a-input
                  v-model.trim="formData.targetRequire"
                  :maxLength='1000'
                  :placeholder="$t('base.info.please-enter-development-objective-requirements')"
                  allowClear/>
              </a-form-item>
            </a-col>
            <span v-show="advanceExpand">
            <!--试验标准-->
						<a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
							<a-form-item :label="$t('base.info.Test-standards')">
								  <a-input
                    v-model.trim="formData.testStandard"
                    :maxLength='1000'
                    :placeholder="$t('base.info.please-enter-test-standards')"
                    allowClear/>
							</a-form-item>
						</a-col>
            <!--是否开展试验项目-->
							<a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
								<a-form-item :label="$t('base.info.whether-to-develop-experimental-projects')">
									<a-select v-model="formData.isCarryOut" allowClear :placeholder="$t('base.info.please-enter-whether-to-develop-experimental-projects')">
                    <a-select-option :value="1">{{ $t('global-btn.yes') }}</a-select-option>
                    <a-select-option :value="0">{{ $t('global-btn.no') }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            <!--试验来源 DVP模板/DFMEA:0/1-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('plan.dvp.test-source')">
                <a-select v-model="formData.testSource" :placeholder="$t('plan.dvp.please-enter-test-source')" allowClear>
                    <a-select-option :value="0">{{ $t('plan.dvp.test-source-dvp-template') }}</a-select-option>
                    <a-select-option :value="1">{{ $t('plan.dvp.test-source-DFMEA') }}</a-select-option>
                    <a-select-option :value="2">{{ $t('plan.dvp.test-source-manual-modification') }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
              <!--试验资质 是/否:1/0-->
              <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
                <a-form-item :label="$t('plan.dvp.test-qualification')">
                  <a-select v-model="formData.testCertification" :placeholder="$t('plan.dvp.please-enter-test-qualification')" allowClear>
                    <a-select-option :value="1">{{ $t('global-btn.yes') }}</a-select-option>
                    <a-select-option :value="0">{{ $t('global-btn.no') }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
            <!--试验地点-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('plan.dvp.test-location')">
                <a-input
                  v-model.trim="formData.testSite"
                  :maxLength='50'
                  :placeholder="$t('plan.dvp.please-enter-test-location')"
                  allowClear/>
              </a-form-item>
            </a-col>
            <!--试验责任方-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('base.info.test-responsible-party')">
                <a-select allowClear v-model="formData.testOwner" @change="handleTestOwner" :placeholder="$t('plan.dvp.please_select-study-director')">
                  <a-select-option
                    v-for='item in testOwnerList'
                    :key='item.label'
                    :value='item.value'
                  >
                    <a-tooltip placement="right">
                      <template #title>
                        <div style="white-space: pre-wrap; word-break: break-all;">
                          {{ formatDetailInfo(item.detailInfo, 40) }}
                        </div>
                      </template>
                      <span>{{ item.label }}</span>
                    </a-tooltip>
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <!--试验阶段-->
              <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
                <a-form-item :label="$t('plan.dvp.test-stage')">
                  <a-select allowClear v-model="formData.testStage" :options="testStageList"  :placeholder="$t('plan.dvp.please-enter-test-stage')"/>
                </a-form-item>
              </a-col>
            <!--样件类型-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('plan.dvp.sample-type')">
                <a-select allowClear v-model="formData.sampleType" :options="sampleTypeList" :placeholder="$t('global-btn.please-enter') + $t('plan.dvp.sample-type')"/>
              </a-form-item>
            </a-col>
            <!--计划开始时间-->
            <a-col :lg='6' :md='24' :sm='24' :xl='6' :xs='24'>
              <a-form-item :label="$t('plan.dvp.scheduled-start-time')">
                <a-range-picker v-model="startTime" @change="handleStartTime" allowClear valueFormat="YYYY-MM-DD" style="width: 100%" />
              </a-form-item>
            </a-col>
            <!--计划结束时间-->
            <a-col :xl='6' :lg='6' :md='24' :sm='24' :xs='24'>
              <a-form-item :label="$t('plan.dvp.scheduled-end-time')">
                <a-range-picker v-model="endTime" @change="handleEndTime" allowClear valueFormat="YYYY-MM-DD" style="width: 100%" />
              </a-form-item>
            </a-col>
          </span>
        </a-row>
          <a-row :gutter="24">
            <a-form-item class='tr' :label="'\xa0'">
              <a-col :xl='24' :lg='24' :md='24' :sm='24' :xs='24'>
                <!-- 展开/收起 -->
                <a @click="toggleAdvance" class="mr10">
                  {{ advanceExpand ? $t('plan.dvp.collapse') : $t('plan.dvp.expand') }}
                  <a-icon :type="advanceExpand ? 'up' : 'down'"/>
                </a>
                <!-- 重置 -->
                <a-button @click='reset' type="primary" class="mr10">
                  {{ $t('global-btn.reset') }}
                </a-button>
                <!-- 查询 -->
                <a-button @click='search' type="primary" class="mr10">
                  {{ $t('global-btn.search') }}
                </a-button>
              </a-col>
            </a-form-item>
          </a-row>
        </a-form>
      </a-card>
      <a-card class="layout-card" :style="{ height: tableHeight }">
        <a-form-item class='tr' >
          <!-- 二次试验 -->
          <a-button @click='SecondTest' type="primary" class="mr10" :disabled="isDisabled()">
            {{ $t('plan.dvp.secondary-test') }}
          </a-button>
          <!-- 变更 -->
          <a-button @click='changeDvp' type="primary" class="mr10" :disabled="isLook || !applyButtonFlag || dvpChangeState || !isChange">
            {{ $t('global-btn.changes') }}
          </a-button>
          <!-- 取消变更 -->
          <a-button @click='cancelChangeDvp' type="primary" class="mr10" :disabled="isLook || !applyButtonFlag || !dvpChangeState">
            {{ $t('global-btn.cancel-change') }}
          </a-button>
          <!-- 导出 -->
          <a-button @click='exportFile'>
            {{ $t('global-btn.export') }}
          </a-button>
        </a-form-item>
        <a-table
            ref="tableRefs"
            size="small"
            class="table-mr"
            :columns='tableColumns'
            :dataSource='tableData'
            :rowKey='(record, index) => { return index; }'
            :scroll='{ x: tableWidth, y: tableHeightValue }'
            :pagination='pagination'
            :loading='tableLoading'
            @change='handlePageChange'
            :components='components'
					  bordered
        >
          <!-- 序号列 -->
          <template slot='index' slot-scope='text, record, index'>
            <span>{{ (pagination.current - 1) * pagination.pageSize + index + 1 }}</span>
          </template>
          <!-- 试验来源 -->
          <template slot="testSource" slot-scope="text, record">
            <span>{{ testSourceMap[record.testSource] || '-' }}</span>
          </template>
          <!-- 是否开展试验 -->
          <template slot="isCarryOut" slot-scope="text, record">
            <span>{{ isOrNotMap[record.isCarryOut] || '-' }}</span>
          </template>
          <!-- 试验资质 -->
          <template slot="testCertification" slot-scope="text, record">
            <span>{{ isOrNotMap[record.testCertification] || '-' }}</span>
          </template>
          <!-- 样件类型 -->
          <template slot="sampleType" slot-scope="text, record">
            <span>{{ sampleTypeMap[record.sampleType] || '-' }}</span>
          </template>
          <!-- 操作 -->
          <template slot="action" slot-scope="text, record">
            <span>
              <!-- 编辑 -->
                <a class='operation-btn ml16' @click='editInit(record)' :disabled="isDisabled()">
                  <a-tooltip :title="$t('global-btn.edit')">
                    <i class="iconfont iconicon-bainji"></i>
                  </a-tooltip>
                </a>
            </span>
          </template>
        </a-table>
      </a-card>
    </a-row>
    <!-- 编辑模态框 -->
    <a-modal v-model="isEdit" :title="isSecondTest ? $t('plan.dvp.secondary-test') : $t('plan.dvp.edit-dvp')" @ok="save" @cancel="offModal" :width="1000" :maskClosable="false">
      <a-row :gutter="24">
        <a-form>
          <!-- 系统名称 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item :label="$t('base.info.system-name')">
              <a-input
                v-model="editParam.systemName"
                :disabled="true"
              />
            </a-form-item>
          </a-col>
          <!-- 验证内容 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.verification-content')">
              <a-select v-if="isSecondTest" v-model="editParam.verify" :disabled="false" :placeholder="$t('global-btn.please-enter') + $t('dvp.full.vehicle.dvp.test-content')" @change="isChangeVerify">
                <a-select-option v-for="option in verifyList" :key="option.value" :value="option.value" >
                  {{ option.label }}
                </a-select-option>
              </a-select>
              <a-input v-else v-model="editParam.verify" :disabled="true"/>
            </a-form-item>
          </a-col>
          <!-- 备注 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item :label="$t('dvp.full.vehicle.dvp.notes')">
              <a-input
                  allowClear
                  v-model="editParam.remark"
                  :placeholder="$t('global-btn.please-enter') + $t('dvp.full.vehicle.dvp.notes')"
              />
            </a-form-item>
          </a-col>
          <!-- 开发目标要求 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.development-objective-requirements')">
              <a-input
                allowClear
                :maxLength='1000'
                v-model="editParam.targetRequire"
                :disabled="this.editParam.testSource === 1"
                :placeholder="$t('global-btn.please-enter') + $t('base.info.development-objective-requirements')"
              />
            </a-form-item>
          </a-col>
          <!-- 试验标准 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.Test-standards')">
              <a-input
                allowClear
                :maxLength='1000'
                v-model="editParam.testStandard"
                :disabled="this.editParam.testSource === 1"
                :placeholder="$t('global-btn.please-enter') + $t('base.info.Test-standards')"
              />
            </a-form-item>
          </a-col>
          <!-- 需求资源 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.required-resources (vehicle rack)')">
              <!-- 当试验来源是模板（testSource = 0）时不可编辑，是FMEA（testSource = 1）时可以编辑 -->
              <a-input
                allowClear
                v-model="editParam.assets"
                :disabled="this.editParam.testSource === 0"
                :placeholder="$t('base.info.please-required-resources (vehicle rack)')"
              />
            </a-form-item>
          </a-col>
          <!-- 是否开展试验项目 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.whether-to-develop-experimental-projects')">
              <a-select v-model="editParam.isCarryOut" allowClear @change="handleCarryOut" :placeholder="$t('base.info.please-enter-whether-to-develop-experimental-projects')">
                <a-select-option :value="1">{{ $t('global-btn.yes') }}</a-select-option>
                <a-select-option :value="0">{{ $t('global-btn.no') }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- 试验责任方 -->
          <a-col v-if="causeShowFlag" :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('base.info.test-responsible-party')">
              <a-select allowClear v-model="editParam.testOwnerId" @change="handleEditTestOwner" :placeholder="$t('plan.dvp.please_select-study-director')">
                <a-select-option
                  v-for='item in testOwnerList'
                  :key='item.label'
                  :value='item.value'
                >
                  <a-tooltip placement="right">
                    <template #title>
                      <div style="white-space: pre-wrap; word-break: break-all;">
                        {{ formatDetailInfo(item.detailInfo, 40) }}
                      </div>
                    </template>
                    <span>{{ item.label }}</span>
                  </a-tooltip>
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-form>
      </a-row>
      <a-row v-if="causeShowFlag" :gutter="24">
        <a-form>
          <!--试验资质-->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.test-qualification')">
              <a-select allowClear v-model="editParam.testCertification"  :placeholder="$t('global-btn.please-enter') + $t('plan.dvp.test-qualification')">
                <a-select-option :value="1">{{ $t('global-btn.yes') }}</a-select-option>
                <a-select-option :value="0">{{ $t('global-btn.no') }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- 试验地点 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.test-location')">
              <a-input
                v-model.trim="editParam.testSite"
                :placeholder="$t('global-btn.please-enter') + $t('plan.dvp.test-location')"
                allowClear
                :maxLength='17'
              />
            </a-form-item>
          </a-col>
          <!-- 试验阶段 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.test-stage')">
              <a-select allowClear v-model="editParam.testStage" :options="testStageList"  :placeholder="$t('plan.dvp.please-enter-test-stage')"/>
            </a-form-item>
          </a-col>
          <!-- 试验频次 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.test-frequency')">
              <a-input-number
                  v-model.number="editParam.testFrequency"
                  :defaultValue="0"
                  :min="1"
                  :max="999999999"
                  @change="handleTestFrequency"
                  :placeholder="$t('global-btn.please-enter') + $t('plan.dvp.test-frequency')"
                  style="width: 100%">
              </a-input-number>
            </a-form-item>
          </a-col>
          <!-- 样本数量 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.number-of-samples')">
              <a-input-number
                  v-model.number="editParam.count"
                  :defaultValue="0"
                  :min="1"
                  :max="999999999"
                  @change="handleCount"
                  :placeholder="$t('plan.dvp.please_select-number-of-vehicles')"
                  style="width: 100%">
              </a-input-number>
            </a-form-item>
          </a-col>
          <!-- 样件类型 -->
          <a-col :lg="16" :md="24" :sm="24" :xl="12" :xs="24">
            <a-form-item required :label="$t('plan.dvp.sample-type')">
              <a-select allowClear v-model="editParam.sampleType" :options="sampleTypeList" :placeholder="$t('global-btn.please-enter') + $t('plan.dvp.sample-type')"/>
            </a-form-item>
          </a-col>
          <!--计划开始时间-->
          <a-col :lg='16' :md='24' :sm='24' :xl='12' :xs='24'>
            <a-form-item required :label="$t('plan.dvp.scheduled-start-time')">
              <a-date-picker v-model="editParam.planStartTime" :disabled-date="disabledStartDate" @change="handleEditStartTime" allowClear valueFormat="YYYY/MM/DD" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <!--计划结束时间-->
          <a-col :lg='16'  :md='24' :sm='24' :xl='12'  :xs='24'>
            <a-form-item required :label="$t('plan.dvp.scheduled-end-time')">
              <a-date-picker v-model="editParam.planEndTime"
              :disabled-date="disabledEndDate"
              @change="handleEditEndTime"
              style="width: 100%"
              valueFormat="YYYY/MM/DD"
              allowClear />
            </a-form-item>
          </a-col>
        </a-form>
      </a-row>
      <!--不开展试验原因-->
      <a-row v-else :gutter="24">
        <a-form>
          <a-col :xl='24' :lg='24' :md='24' :sm='24' :xs='24'>
            <a-form-item required :label="$t('base.info.reason-for-not-conducting-the-experiment')">
              <a-textarea rows='6' v-model.trim="editParam.notCarryOutCause" style="width: 100%;" :placeholder="$t('base.info.please-enter-reason-for-not-conducting-the-experiment')" :maxLength='50'></a-textarea>
            </a-form-item>
          </a-col>
        </a-form>
      </a-row>
      <a-row :gutter="24">
        <!-- 变更原因 -->
        <a-col :lg='16' :md='24' :sm='24' :xl='24' :xs='24' v-if="applyButtonFlag">
          <a-form-item required :label="$t('base.info.change-reason')">
            <a-textarea
              v-model.trim="changeReason"
              :placeholder="$t('base.info.please-enter-change-reason')"
              allowClear
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-modal>
  </div>
</template>

<script>

import moment from "moment";
import VueDraggableResizable from 'vue-draggable-resizable';
import lodash from 'lodash';

export default {
  components: {
    VueDraggableResizable,
    lodash
  },
  data() {
    this.components = {
			header: {
				cell: (h, props, children) => {
					const { key, ...restProps } = props;
					// 此处的this.columns 是定义的table的表头属性变量
					const col = this.tableColumns.find((col) => {
						const k = col.dataIndex || col.key;
						return k === key;
					});
					if (!col || !col.width) {
						return h('th', { ...restProps }, [...children]);
					}
					const dragProps = {
						key: col.dataIndex || col.key,
						class: 'table-draggable-handle',
						attrs: {
							w: 10,
							x: col.width,
							z: 1,
							axis: 'x',
							draggable: true,
							resizable: false
						},
						on: {
							dragging: (x, y) => {
								col.width = Math.max(x, 100);
							}
						}
					};
					const drag = h('vue-draggable-resizable', { ...dragProps });
					return h('th', { ...restProps, class: 'resize-table-th' }, [...children, drag]);
				}
			}
		};
    return{
      /** 查询数据 */
      formData:{
        systemName: undefined,          // 系统名称
        assets: undefined,              // 需求资源
        verify: undefined,              // 验证内容
        testSource: undefined,          // 试验来源
        targetRequire: undefined,       // 开发目标要求
        testStandard: undefined,        // 试验标准
        isCarryOut: undefined,          // 是否开展
        testCertification: undefined,   // 试验资质
        testSite: undefined,            // 试验地点
        testOwner: undefined,           // 试验负责人
        testStage: undefined,           // 试验阶段
        sampleType: undefined,          // 样本类型
        planStartTime: undefined,      // 计划开始时间
        planEndTime: undefined,        // 计划结束时间
      },
      /** 编辑弹框 用于记录初始值 */
      planStartTime: undefined,
      planEndTime: undefined,
      /** 清除时间选框用的 */
      endTime: undefined,
      startTime: undefined,
      /** 编辑模态框显隐 */
      isEdit: false,
      /** 二次验证标识 */
      isSecondTest: false,
      /** 是否修改 */
      isFormModified: false,
      /** 验证内容下拉选 */
      verifyList: [],
      /** 编辑模态框数据 */
      editParam: {
        targetRequire: undefined,            // 开发目标要求
        testStandard: undefined,             // 试验标准
        remark:undefined,                    // 备注
        systemName: undefined,               // 系统名称
        dvpId: undefined,                    // DVP ID
        testId: undefined,                   // 试验ID
        isCarryOut: undefined,               // 是否开展试验项目 0否 1是
        notCarryOutCause: undefined,         // 不开展试验原因
        testOwnerId: undefined,              // 试验负责人
        testCertification: undefined,        // 试验资质
        testSite: undefined,                 // 试验地点
        testStage: undefined,                // 试验阶段
        testFrequency: undefined,            // 试验频率
        count: undefined,                    // 样本数量
        sampleType: undefined,               // 样本类型
        planStartTime: undefined,            // 计划开始时间
        planEndTime: undefined,              // 计划结束时间
        assets: undefined,                   // 需求资源
      },
      // 变更原因
      changeReason: undefined,
      // 变更状态下编辑模态框数据
      originalEditParam:{},
      /** 编辑模态框修改前内容 */
      originalFormData:{},
      /** 折叠 展开 */
      advanceExpand: false,
      /** 不适用原因文本框显示/隐藏 */
      causeShowFlag: true,
      /** 试验责任方 */
      testOwnerList: [],
      /** 分页 */
      pagination: {
        size: 'small',
        current: 1,
        pageNo: 1,
        pageSize: 10, // 默认每页显示数量
        showTotal: total => this.$t('global-constant.table.show-total', {total: `${total}`}), // 显示总数
        showSizeChanger: true, // 显示可改变每页数量
        pageSizeOptions: ['10', '20', '50', '100', '200'], // 每页数量选项
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize), // 改变每页数量时更新显示
        total: 0, //总条数
        showQuickJumper: true,
      },
      /** 表格高度 */
      tableHeight: window.innerHeight - 352 + 'px',
      tableHeightValue: window.innerHeight - 560,
      // 表格总宽度
      tableWidth: 0,
      //表格各列宽度总和
      columnsWidth: 0,
      /** 表格加载状态 */
      tableLoading: false,
      /** 表格数据 */
      tableData: [],
      /** 表格列 */
      tableColumns: [
        //序号
        {
          title: this.$t('plan.dvp.serial-number'),
          dataIndex: 'index',
          width: 100,
          fixed: 'left',
          align: 'center',
          scopedSlots: {
            customRender: 'index'
          },
          ellipsis: true
        },
        //系统名称
        {
          title: this.$t('base.info.system-name'),
          width: 180,
          dataIndex: 'systemName',
          align: 'center',
          ellipsis: true
        },
        //需求资源(整车,台架)
        {
          title: this.$t('base.info.required-resources (vehicle rack)'),
          width: 180,
          dataIndex: 'assets',
          align: 'center',
          ellipsis: true
        },
        //试验来源
        {
          title: this.$t('plan.dvp.test-source'),
          width: 120,
          dataIndex: 'testSource',
          align: 'center',
          ellipsis: true,
          scopedSlots: {
            customRender: 'testSource'
          }
        },
        //验证内容
        {
          title: this.$t('base.info.verification-content'),
          width: 180,
          dataIndex: 'verify',
          align: 'center',
          ellipsis: true,
          customCell: (record, index) => {
            let style = {};
            if (record.isNew === '1') {
              style = {'background-color': '#f2f070'};
            }
            return {style: style};
          }
        },
        // 备注
        {
          title: this.$t('dvp.full.vehicle.dvp.notes'),
          width: 180,
          dataIndex: 'remark',
          align: 'center',
          ellipsis: true
        },
        //开发目标要求(接受标准)
        {
          title: this.$t('base.info.development-objective-requirements (acceptance criteria)'),
          width: 180,
          dataIndex: 'targetRequire',
          align: 'center',
          ellipsis: true
        },
        //试验标准
        {
          title: this.$t('base.info.Test-standards'),
          width: 180,
          dataIndex: 'testStandard',
          align: 'center',
          ellipsis: true
        },
        //是否开展试验项目
        {
          title: this.$t('base.info.whether-to-develop-experimental-projects'),
          width: 150,
          dataIndex: 'isCarryOut',
          align: 'center',
          ellipsis: true,
          scopedSlots: {
            customRender: 'isCarryOut'
          }
        },
        //不开展试验原因
        {
          title: this.$t('base.info.reason-for-not-conducting-the-experiment'),
          width: 200,
          dataIndex: 'notCarryOutCause',
          align: 'center',
          ellipsis: true
        },
        //试验责任方
        {
          title: this.$t('base.info.test-responsible-party'),
          width: 120,
          dataIndex: 'testOwner',
          align: 'center',
          ellipsis: true
        },
        //试验资质
        {
          title: this.$t('plan.dvp.test-qualification'),
          width: 180,
          dataIndex: 'testCertification',
          align: 'center',
          ellipsis: true,
          scopedSlots: {
            customRender: 'testCertification'
          }
        },
        //试验地点
        {
          title: this.$t('plan.dvp.test-location'),
          width: 120,
          dataIndex: 'testSite',
          align: 'center',
          ellipsis: true
        },
        //试验阶段
        {
          title: this.$t('plan.dvp.test-stage'),
          width: 120,
          dataIndex: 'testStageName',
          align: 'center',
          ellipsis: true
        },
        //试验频次
        {
          title: this.$t('plan.dvp.test-frequency'),
          width: 120,
          dataIndex: 'testFrequency',
          align: 'center',
          ellipsis: true
        },
        //样本数量
        {
          title: this.$t('plan.dvp.number-of-samples'),
          width: 100,
          dataIndex: 'count',
          align: 'center',
          ellipsis: true
        },
        //样件类型
        {
          title: this.$t('plan.dvp.sample-type'),
          width: 120,
          dataIndex: 'sampleType',
          align: 'center',
          scopedSlots: {
            customRender: 'sampleType'
          }
        },
        //计划开始时间
        {
          title: this.$t('plan.dvp.scheduled-start-time'),
          width: 150,
          dataIndex: 'planStartTime',
          align: 'center',
          ellipsis: true
        },
        //计划结束时间
        {
          title: this.$t('plan.dvp.scheduled-end-time'),
          width: 150,
          dataIndex: 'planEndTime',
          align: 'center',
          ellipsis: true
        },
        //变更原因
        {
          title: this.$t('base.info.change-reason'),
          width: 150,
          dataIndex: 'changeReason',
          align: 'center',
          ellipsis: true
        },
         //变更时间
         {
          title: this.$t('base.info.change-time'),
          width: 150,
          dataIndex: 'changeTime',
          align: 'center',
          ellipsis: true
        },
        //操作
        {
          title: this.$t('global-constant.operation'),
          dataIndex: 'action',
          align: 'center',
          width: 100,
          fixed: 'right',
          scopedSlots: {customRender: 'action'},
          ellipsis: true
        }
      ],
      /** 试验来源Map 用于表格插槽显示 */
      testSourceMap: {
        0: this.$t("plan.dvp.test-source-dvp-template"),
        1: this.$t("plan.dvp.test-source-DFMEA"),
        2: this.$t("plan.dvp.test-source-manual-modification")
      },
      /** 是/否Map 用于表格插槽显示 试验资质/是否开展试验 */
      isOrNotMap: {
        0: this.$t("global-btn.no"),
        1: this.$t("global-btn.yes")
      },
      /** 样件类型下拉选 */
      sampleTypeList: [
        {
          label: this.$t('plan.dvp.sample-type.soft-modules'),
          value: '0'
        },
        {
          label: this.$t('plan.dvp.sample-type.hard-module'),
          value: '1'
        },
        {
          label: this.$t('plan.dvp.sample-type.fixture-parts'),
          value: '2'
        }
      ],
      /** 样件类型 用于表格插槽显示 */
      sampleTypeMap: {
        0: this.$t('plan.dvp.sample-type.soft-modules'),
        1: this.$t('plan.dvp.sample-type.hard-module'),
        2: this.$t('plan.dvp.sample-type.fixture-parts')
      },
      /** 试验阶段下拉选项 */
      testStageList: [],
      /** 申请变更弹窗标识 */
      applyFlag: false,
      /** 申请变更弹窗表格数据 */
      applyTableData: [],
      /** 变更申请按钮显隐 */
      applyButtonFlag: false,
      /** 权限 */
      isLook: false,
      /** dvpType system:系统DVP，components:零部件DVP */
      dvpType: "system",
      // 变更标识
      dvpChangeState: false,
      isChange: false,
    }
  },
  watch: {
    tableColumns: {
      handler() {
        this.$nextTick(() => {
          // 获取表格的总宽度
          this.handleResize();
          // 计算 width 属性的总和
          this.getColumnWidthTotal();
          // 动态修改fixe属性
          this.changeFixed();
          // 修改table表格表头外边盒子的背景颜色以及外边距，以适应表格动态变化
          // this.getTableDivCss();
        });
      },
      deep: true,
      immediate: true
    },
    tableWidth:{
      handler() {
        this.$nextTick(() => {
          // 获取表格的总宽度
          this.handleResize();
          // 计算 width 属性的总和
          this.getColumnWidthTotal();
          // 动态修改fixe属性
          this.changeFixed();
          // 修改table表格表头外边盒子的背景颜色以及外边距，以适应表格动态变化
          // this.getTableDivCss();
        });

      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.isLook = this.$api.isLook === '1'
    this.initData();
    this.getTestOwner();
    this.getProjectNodeList();
    window.onresize = () => {
      this.tableHeight = window.innerHeight - 352 + 'px';
      this.tableHeightValue = window.innerHeight - 560;
    };
    // 监听页面窗体大小变化
    window.addEventListener('resize', this.handleResize);
    // 修改table表格表头外边盒子的背景颜色以及外边距，以适应表格动态变化
    // this.getTableDivCss();
  },
  //剔除页面窗体大小变化得监听事件
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize);
  },
  methods: {
    // 修改table表格表头外边盒子的背景颜色以及外边距，以适应表格动态变化
    // getTableDivCss(){
    //   // 选中包裹表格的 div 元素
    //   let tableHeaderDiv = document.querySelector('.ant-table-header.ant-table-hide-scrollbar');
    //   let tableHeaderReal = document.querySelector('.resize-table-th');
    //   // 检查是否成功选中
    //   if (tableHeaderDiv) {
    //     // 设置背景颜色为灰色
    //     tableHeaderDiv.style.backgroundColor = 'rgb(245, 246, 247)';
    //     // 表头外层盒子的的实际样式
    //     let computedDivStyle = window.getComputedStyle(tableHeaderDiv);
    //     // 表头外层盒子的的实际高度
    //     let tableDivHeight = parseFloat(computedDivStyle.getPropertyValue('height'));
    //     // 表头的实际样式
    //     let computedTableStyle = window.getComputedStyle(tableHeaderReal);
    //     // 表头的实际高度
    //     let tableHeight = parseFloat(computedTableStyle.getPropertyValue('height'));
    //     // 设置底部外边距，一下会是负值，用于将表头下的数据单元格纵向对齐
    //     tableHeaderDiv.style.marginBottom = (tableHeight-tableDivHeight)+'px';
    //   }
    // },
    // 获取表格的总宽度
    handleResize() {
      this.tableWidth = this.$refs.tableRefs.$el.offsetWidth;
    },
    // 计算表格各列宽度总和
    getColumnWidthTotal(){
      this.columnsWidth = this.tableColumns.reduce((sum, column) => sum + column.width, 0);
    },
    // 动态修改fixe的属性以便表格样式不出现空白列,并平和各列与表格的总宽度
    changeFixed(){
      if (this.columnsWidth <= this.tableWidth) {
        // 遍历 tableColumns 数组，将有 fixed 属性的元素的 fixed 值设置为 false（当有固定列时，列宽总和小于表格总宽度时会串行）
        this.tableColumns.forEach((column) => {
          if (column.fixed) {
            column.fixed = false;
          }
        });
        // 获取除最后一列以外其他列的宽度总和
        let otherColumnsWidth = this.tableColumns.slice(0, -1).reduce((total, column) => {
          return total + column.width;
        }, 0);
        // 将最后一列的宽度设置为剩余宽度，避免页面表头与内容显示串行
        this.tableColumns[this.tableColumns.length - 1].width = this.tableWidth - otherColumnsWidth;
      }else {
        // 恢复固定列原始定位属性
        this.tableColumns[0].fixed='left';
        this.tableColumns[this.tableColumns.length - 1].fixed='right';
        // 恢复最后一列原始宽度
        this.tableColumns[this.tableColumns.length - 1].width = 150;
      }
    },
    // 编辑按钮禁用判断
    isDisabled() {
      let _that = this;
      if (_that.isLook) {
        return true;
      } else {
        if (_that.applyButtonFlag) {
          if (_that.dvpChangeState) {
            return false;
          } else {
            return true;
          }
        } else {
          return false;
        }
      }
    },
    /**
     * 初始化表格数据
     */
    initData() {
      let _that = this;
      _that.tableLoading = true;
      _that.formData.dvpId = _that.$store.getters.dvpId;
      _that.formData.pagination = {
        pageSize: _that.pagination.pageSize,
        pageCurrent: _that.pagination.current
      }
      _that.$api.initDvpPlanList(_that.formData).then(res => {
        if (res.flag) {
          _that.tableData = res.data.data;
          _that.pagination.total = res.data.total;
          _that.dvpChangeState = res.data.data[0].dvpChangeState === '1';
          _that.isChange = res.data.data[0].dvpChangeState === '0' || res.data.data[0].dvpChangeState === '3';
          _that.isDisabled();
        } else {
          _that.$message.error(res.message,1);
          _that.tableData = [];
          _that.pagination.total = 0;
        }
      }).finally( () => {
        _that.tableLoading = false;
      });
      // 变更申请按钮显示隐藏，如果DVP编制进行到DVP验证阶段，则显示
      let data = {
        dvpId: _that.$store.getters.dvpId,
        dvpType: _that.$store.getters.dvpType
      }
      _that.$api.getDvpCurrentStep(data).then(res => {
        if (res.flag) {
          _that.applyButtonFlag = res.data === 2 ;
        }
      });
    },
    /**
     * 获取试验负责人下拉选项
     */
    getTestOwner() {
      let data = {
        dvpId: this.$store.getters.dvpId,
        dvpType: this.$store.getters.dvpType
      }
      // 获取DVP团队成员中有编辑权限的用户
      this.$api.getSystemDvpTeamMember(data).then(res => {
        if (res.flag) {
          let userList = res.data.teamMemberModels;
          userList.forEach(item =>{
            if (item.permission === 1){
              let options = {
                label: item.name,
                value: item.userId,
                detailInfo: item.name + '|' + item.fullLevelDepartment + '|' + item.jobNumber
              };
              this.testOwnerList.push(options);
            }
          });
          // 是否包含Owner
          let ownerFlag = this.testOwnerList.find(item => item.value === this.$store.getters.dvpOwnerId);
          let ownerName = this.$store.getters.dvpOwnerName;
          let ownerJobNumber = this.$store.getters.ownerJobNumber;
          let ownerFullDepartment = this.$store.getters.ownerFullDepartment;
          if (!ownerFlag) {
            // 测试负责人要包括DVP的Owner
            let owner = {
              label: this.$store.getters.dvpOwnerName,
              value: this.$store.getters.dvpOwnerId,
              detailInfo: ownerName + '|' + ownerFullDepartment + '|' + ownerJobNumber
            }
            this.testOwnerList.push(owner);
          }
        }
      });
    },
    // 格式化detailInfo 每40个字符换行
    formatDetailInfo(detailInfo, maxLength) {
      return detailInfo.replace(/.{1,${maxLength}}/g, text => text + ' ');
    },
    /**
     * 查询
     */
    search() {
      this.initData();
    },

    /**
     * 重置
     */
    reset() {
      this.startTime = undefined;
      this.endTime = undefined;
      this.formData = {};
      this.pagination.current = 1;
      this.pagination.pageSize = 10;
      this.advanceExpand = false;
      this.initData();
    },

    /**
     * 收起/展开
     */
    toggleAdvance() {
      this.advanceExpand = !this.advanceExpand;
      if(this.advanceExpand) {
        this.tableHeightValue -= 180
      } else {
        this.tableHeightValue = window.innerHeight - 560;
      }
    },

    /**
     * 非空校验 判断是否为空
     * @returns {boolean}
     */
    isNull() {
      let _that = this;
      let message = [];
      // 是否开展试验项目
      if (_that.editParam.isCarryOut == undefined && _that.editParam.isCarryOut == null) {
        message.push(_that.$t('global-constant.please-enter') + _that.$t('base.info.whether-to-develop-experimental-projects'));
      } else if (_that.editParam.isCarryOut === 1) { // 如果点击是，则校验以下值，点击否只校验不适用原因
        // 开发目标要求
        if (!_that.editParam.targetRequire) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('base.info.development-objective-requirements'));
        }
        // 试验标准
        if (!_that.editParam.testStandard) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('base.info.Test-standards'));
        }
        // 试验责任人
        if (!_that.editParam.testOwnerId) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('base.info.test-responsible-party'));
        }
        // 试验资质
        if (_that.editParam.testCertification == undefined && _that.editParam.testCertification == null) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.test-qualification'));
        }
        // 样本数量
        if (!_that.editParam.count) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.number-of-samples'));
        }
        // 试验地点
        if (!_that.editParam.testSite) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('plan.dvp.test-location'));
        }
        // 试验阶段
        if (!_that.editParam.testStage) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.test-stage'));
        }
        // 试验频次
        if (!_that.editParam.testFrequency) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.test-frequency'));
        }
        // 样件类型
        if (!_that.editParam.sampleType) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.sample-type'));
        }
        // 计划开始时间
        if (!_that.editParam.planStartTime) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.scheduled-start-time'));
        }
        // 计划结束时间
        if (!_that.editParam.planEndTime) {
          message.push(_that.$t('global-constant.please-select') + _that.$t('plan.dvp.scheduled-end-time'));
        }
        // 需求资源
        if (!_that.editParam.assets) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('plan.dvp.required-resources (vehicle rack)'))
        }
      } else {
        // 不适用原因
        if (!_that.editParam.notCarryOutCause || _that.editParam.notCarryOutCause.trim().length === 0) {
          message.push(_that.$t('global-btn.please-enter') + _that.$t('base.info.reason-for-not-conducting-the-experiment'));
        }
      }
      // 变更原因
      if (_that.applyButtonFlag) {
        if (!_that.changeReason) {
          message.push(_that.$t('global-constant.please-enter') + _that.$t('base.info.change-reason'))
        }
      }
      if (message && message.length > 0) {
        for (let i = 0; i < message.length; i++) {
          _that.$notification.warning({message: message[i]});
        }
        return false;
      }
      return true;
    },

    /**
     * 关闭模态框
     */
    closeModal() {
      // 申请变更弹窗 关闭
      this.applyFlag = false;
      this.applyTableData = [];
    },

    /** 判断二次试验编辑是否修改 **/
    deepEqual(obj1, obj2) {
      const keys1 = Object.keys(obj1);
      const keys2 = Object.keys(obj2);
      // 过滤掉不同属性
      const commonKeys = keys1.filter(key => keys2.includes(key));

      for (const key of commonKeys) {
        // 判断相同属性值是否相等 不相等返回false
        if (String(obj1[key]) != String(obj2[key])) {
          return false;
        }
      }
      return true;
    },

    // 比较变更数据是否进行了修改
    compareData() {
      // 使用lodash的isEqual进行深度比较
      return lodash.isEqual(this.editParam, this.originalEditParam);
    },

    /** 编辑 保存 */
    save() {
      if (!this.isNull()) {
        return false;
      }
      if (this.applyButtonFlag && this.dvpChangeState) {
        if (this.compareData()) {
          this.$notification.warning({message: this.$t('base.info.please-modify-saving')})
          return;
        }
      }
      // 如果是否开展试验选择了否，则清除试验相关的信息
      if (this.editParam.isCarryOut === 0) {
        this.editParam.planEndTime = undefined;
        this.editParam.planStartTime = undefined;
        this.editParam.count = undefined;
        this.editParam.sampleType = undefined;
        this.editParam.testOwnerId = undefined;
        this.editParam.testFrequency = undefined;
        this.editParam.testStage = undefined;
        this.editParam.testSite = undefined;
        this.editParam.testCertification = undefined;
      } else { // 如果选择了是，则清除不适用原因
        this.editParam.notCarryOutCause = undefined;
      }
      // 是否是二次试验
      if (this.isSecondTest === true) {
        Object.keys(this.originalFormData).forEach(key => {
          // 检查值是否为 null
          if (this.originalFormData[key] === null) {
            // 如果是 null，则替换为 undefined
            this.originalFormData[key] = undefined;
          }
        });
        this.isFormModified = this.deepEqual(this.originalFormData, this.editParam)
        // 不相同保存新增一条试验计划
        if (!this.isFormModified) {
          let data = {
            dvpId: this.editParam.dvpId,
            testId: this.editParam.testId,
            isCarryOut: this.editParam.isCarryOut,
            notCarryOutCause: this.editParam.notCarryOutCause,
            engineerUserId: this.editParam.testOwnerId,
            testCertification: this.editParam.testCertification,
            testSite: this.editParam.testSite,
            testStage: this.editParam.testStage,
            testFrequency: this.editParam.testFrequency,
            count: this.editParam.count,
            sampleType: this.editParam.sampleType,
            planStartTime: this.editParam.planStartTime,
            planEndTime: this.editParam.planEndTime,
            assets: this.editParam.assets,
            targetRequire: this.editParam.targetRequire,
            testStandard: this.editParam.testStandard,
            remark: this.editParam.remark,
            changeReason: this.changeReason
          };
          this.$api.getSysDvpVerifySave(data).then(res => {
            if (!res.flag) {
              this.$notification.error({message: res.message});
            } else {
              this.$notification.success({message: res.message});
              this.initData();
              this.offModal();
            }
          })
        } else {
          // 相同提示未更新任何信息
          let message = [];
          message.push(this.$t('plan.dvp.no-information-has-been-updated'));
          this.$notification.warning({message: message});
        }
      } else {
        let data = {
          dvpId: this.editParam.dvpId,
          testId: this.editParam.testId,
          isCarryOut: this.editParam.isCarryOut,
          notCarryOutCause: this.editParam.notCarryOutCause,
          testOwnerId: this.editParam.testOwnerId,
          testCertification: this.editParam.testCertification,
          testSite: this.editParam.testSite,
          testStage: this.editParam.testStage,
          testFrequency: this.editParam.testFrequency,
          count: this.editParam.count,
          sampleType: this.editParam.sampleType,
          planStartTime: this.editParam.planStartTime,
          planEndTime: this.editParam.planEndTime,
          assets: this.editParam.assets,
          targetRequire: this.editParam.targetRequire,
          testStandard: this.editParam.testStandard,
          remark: this.editParam.remark,
          changeReason: this.changeReason
        };
        this.$api.editTest(data).then(res => {
          if (!res.flag) {
            this.$notification.error({message: res.message});
          } else {
            this.$notification.success({message: res.message});
            this.initData();
            this.isEdit = false;
          }
        });
      }
    },

    /**
     * 根据所选验证内容显示数据
     */
    isChangeVerify(){
      this.$api.getSysDvpVerify({dvpId: this.$store.getters.dvpId,testId:this.editParam.verify}).then(res =>{
          if (res.flag) {
            let data = res.data || [];
            // 暂存用于后期校验是否修改
            this.originalFormData = res.data;
            this.editParam.isCarryOut = (data.isCarryOut === 0 || data.isCarryOut === 1) ? data.isCarryOut : undefined;
            this.editParam.assets = data.assets;
            this.editParam.verify = data.verify;
            this.editParam.testSource = data.testSource;
            this.editParam.targetRequire = data.targetRequire;
            this.editParam.testCertification = data.testCertification;
            this.editParam.planEndTime = data.planEndTime;
            this.editParam.planStartTime = data.planStartTime;
            this.editParam.count = data.count || undefined;
            this.editParam.sampleType = data.sampleType || undefined;
            this.editParam.testOwnerId = data.engineerUserId;
            this.editParam.testFrequency = data.testFrequency || undefined;
            this.editParam.testStage = data.testStage || undefined;
            this.editParam.testSite = data.testSite;
            this.editParam.testStandard = data.testStandard;
            this.editParam.notCarryOutCause = data.notCarryOutCause;
            this.editParam.dvpId = this.$store.getters.dvpId;
            this.editParam.testId = data.testId;
            this.editParam.remark = data.remark;
            this.testOwnerList.forEach( item => {
              if (item.label === data.testOwner) {
                this.editParam.testOwnerId = item.value;
              }
            });
            this.planStartTime = data.planStartTime;
            this.planEndTime = data.planEndTime;
            if (data.isCarryOut === 0) {
              this.causeShowFlag = false;
            } else {
              this.causeShowFlag = true;
            }
          }
      })
    },
    /**
     * 编辑弹框 初始化
     */
    editInit(val) {
      // 判断是否是多轮试验
      if(this.isSecondTest) {
        let selectOption = [];
        this.verifyList = [];
        this.editParam.verify = undefined;
        this.$api.getSysDvpVerifyList({dvpId: this.$store.getters.dvpId}).then(res => {
          if (res.flag) {
            let data = res.data || [];
            data.forEach(item => {
              selectOption = {
                label: item.verify,
                value: item.testId
              };
              this.verifyList.push(selectOption);
            });
            this.editParam.systemName = res.inputData;
            if (data.isCarryOut === 0) {
              this.causeShowFlag = false;
            } else {
              this.causeShowFlag = true;
            }
          }
        })
      } else {
        //以下写法会导致更改编辑弹框内容，连同编辑弹框外的表格对应的字段也更改
        // this.editParam = val;
        //所以这样写 this.editParam = {...val};
        //或者如下写，挨个赋值
        this.editParam.isCarryOut = (val.isCarryOut === 0 || val.isCarryOut === 1) ? val.isCarryOut : undefined;
        this.editParam.systemName = val.systemName;
        this.editParam.assets = val.assets;
        this.editParam.verify = val.verify;
        this.editParam.testSource = val.testSource;
        this.editParam.targetRequire = val.targetRequire;
        this.editParam.testCertification = val.testCertification || undefined;
        this.editParam.planEndTime = val.planEndTime;
        this.editParam.planStartTime = val.planStartTime;
        this.editParam.count = val.count || undefined;
        this.editParam.sampleType = val.sampleType || undefined;
        this.editParam.testOwnerId = val.testOwnerId;
        this.editParam.testFrequency = val.testFrequency || undefined;
        this.editParam.testStage = val.testStage || undefined;
        this.editParam.testSite = val.testSite;
        this.editParam.testStandard = val.testStandard;
        this.editParam.notCarryOutCause = val.notCarryOutCause;
        this.editParam.dvpId = this.$store.getters.dvpId;
        this.editParam.testId = val.testId;
        this.editParam.remark = val.remark;
        this.testOwnerList.forEach( item => {
          if (item.label === val.testOwner) {
            this.editParam.testOwnerId = item.value;
          }
        });
        this.planStartTime = val.planStartTime;
        this.planEndTime = val.planEndTime;
        this.changeReason = val.changeReason;
        if (val.isCarryOut === 0) {
          this.causeShowFlag = false;
        } else {
          this.causeShowFlag = true;
        }
        this.isEdit = true;
        // 将editParam的值拷贝给originalEditParam
        this.originalEditParam = {...this.editParam};
      }
    },

    /**
     * 获取试验阶段下拉选项（项目节点）
     */
    getProjectNodeList() {
      this.$api.getSysDvpProjectNodeList({dvpId: this.$store.getters.dvpId}).then(res => {
        if (res.flag) {
          let data = res.data || [];
          data.forEach(item => {
            let selectOption = {
              label: item.milestoneName,
              value: item.id
            };
            this.testStageList.push(selectOption);
          });
        } else {
          this.$message.error(res.message);
          this.testStageList = [];
        }
      });
    },
    /** 二次试验 */
    SecondTest(){
      this.isEdit = true;
      this.isSecondTest = true;
      this.editParam.targetRequire = undefined;
      this.editParam.testStandard = undefined;
      this.editParam.remark = undefined;
      this.editParam.isCarryOut = undefined;
      this.editParam.planEndTime = undefined;
      this.editParam.planStartTime = undefined;
      this.editParam.count = undefined;
      this.editParam.sampleType = undefined;
      this.editParam.testOwnerId = undefined;
      this.editParam.testFrequency = undefined;
      this.editParam.testStage = undefined;
      this.editParam.testSite = undefined;
      this.editParam.testCertification = undefined;
      this.editParam.assets = undefined;
      this.editParam.notCarryOutCause = undefined;
      this.editInit(null);
    },
    /** 编辑 取消 */
    offModal() {
      this.isEdit = false;
      this.isSecondTest = false;
      this.editParam.targetRequire = undefined;
      this.editParam.testStandard = undefined;
      this.editParam.remark = undefined;
      this.editParam.isCarryOut = undefined;
      this.editParam.planEndTime = undefined;
      this.editParam.planStartTime = undefined;
      this.editParam.count = undefined;
      this.editParam.sampleType = undefined;
      this.editParam.testOwnerId = undefined;
      this.editParam.testFrequency = undefined;
      this.editParam.testStage = undefined;
      this.editParam.testSite = undefined;
      this.editParam.testCertification = undefined;
      this.editParam.assets = undefined;
    },
    /**
     * 导出
     */
    exportFile() {
      this.download('/DFMEA/dvp/system/dvpPlanExcelExport', {
        dvpId: this.$store.getters.dvpId || '',
        systemName: this.formData.systemName || '',
        assets: this.formData.assets || '',
        verify: this.formData.verify || '',
        testSource: this.formData.testSource || '',
        targetRequire: this.formData.targetRequire || '',
        testStandard: this.formData.testStandard || '',
        isCarryOut: this.formData.isCarryOut || '',
        testCertification: this.formData.testCertification || '',
        testSite: this.formData.testSite || '',
        testOwner: this.formData.testOwner || '',
        testStage: this.formData.testStage || '',
        sampleType: this.formData.sampleType || '',
        planStartTime: this.formData.planStartTime || '',
        planEndTime: this.formData.planEndTime || '',
      });
    },

    /**
     * 变更
     */
    changeDvp() {
      this.$api.systemDvpChange({dvpId: this.$store.getters.dvpId}).then(res=>{
        if (res.flag) {
          this.$message.success(res.message, 1);
          this.initData();
        } else {
          this.$message.error(res.message, 1);
        }
      });
    },
    /**
     * 取消变更
     */
    cancelChangeDvp() {
      this.$confirm({
        title: this.$t('fmea.warn'),
				content: this.$t('base.info.changed-data-rolled-back'),
        icon: 'exclamation-circle',
				okText: this.$t('global-btn.confirm'),
				cancelText: this.$t('global-btn.cancel'),
        onOk:() => {
          this.$api.cancelSystemDvpChange({dvpId: this.$store.getters.dvpId}).then(res=>{
            if (res.flag) {
              this.$message.success(res.message, 1);
              this.initData();
            } else {
              this.$message.error(res.message, 1);
            }
          });
        }
      });
    },

    /**
     * 表格 - 点击分页中数字触发的方法
     * @param pagination
     */
    handlePageChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.pagination.pageNo = pagination.current;
      this.initData();
    },

    /**
     * 计划开始时间 时间选择器Change方法 查询
     */
    handleStartTime(date, dateString){
      this.formData.planStartStartTime = dateString[0];
      this.formData.planStartEndTime = dateString[1];
    },

    /**
     * 计划结束时间 时间选择器Change方法 查询
     */
    handleEndTime(date, dateString){
      this.formData.planEndStartTime = dateString[0];
      this.formData.planEndEndTime = dateString[1];
    },

    /**
     * 开始时间不能选择当天
     * @param current
     * @returns {boolean}
     */
    disabledStartDate(current) {
      // return current && current < moment().subtract(1,"day").endOf('day');
      // 有结束时间，则返回不能选择日期为结束时间之后的日期
      if (this.editParam.planEndTime) {
        return current && current > moment(this.editParam.planEndTime).endOf('day');
      } else { // 无开始时间，则返回不能选择日期为当前时间之前的日期
        return current && current < moment().subtract(1,"day").endOf('day');
      }
    },

    /**
     * 结束时间不能选择开始时间前的时间
     * @param current
     * @returns {boolean}
     */
    disabledEndDate(current) {
      // 有开始时间，则返回不能选择日期为开始时间之前的日期
      if (this.editParam.planStartTime) {
        return current && current < moment(this.editParam.planStartTime).endOf('day');
      } else { // 无开始时间，则返回不能选择日期为当前时间之前的日期
        return current && current < moment().subtract(1,"day").endOf('day');
      }
    },

    /**
     * 计划开始时间 时间选择器Change方法 编辑
     */
    handleEditStartTime(date, dateString){
      if (!dateString) {
        this.editParam.planStartTime = "";
        return;
      }
      this.editParam.planStartTime = dateString;
      // 当选择的开始时间大于结束时间时，清空结束时间，让用户重新选择结束时间
      // if (Date.parse(this.editParam.planStartTime) > Date.parse(this.editParam.planEndTime)) {
      //   this.editParam.planEndTime = undefined;
      //   this.$confirm({
      //     title: this.$t('fmea.warn'),
      //     content: this.$t('fmea.task.management.whether-to-delete-the-dvp-task'),
      //     icon: 'exclamation-circle',
      //     okText: _that.$t('report.confirm'),
      //     cancelText: _that.$t('workbench.cancel'),
      //     onOk() {
      //       _that.delTasks(taskIds);
      //     },
      //     onCancel() {
      //     }
      //   });
      // }
    },
    /**
     * 计划结束时间 时间选择器Change方法 编辑
     */
    handleEditEndTime(date, dateString) {
      if (!dateString) {
        this.editParam.planEndTime = "";
        return;
      }
      this.editParam.planEndTime = dateString;
    },

    /**
     * 试验负责人下拉改变 查询
     * @param val
     */
    handleTestOwner(val) {
      this.formData.testOwner = val;
    },

    /**
     * 试验负责人下拉改变 编辑
     * @param val
     */
    handleEditTestOwner(val) {
      this.editParam.testOwnerId = val;
    },

    /**
     * 样本数量下拉改变 编辑
     * @param val
     */
    handleCount(val) {
      this.editParam.count = val;
    },

    /**
     * 样本数量下拉改变 编辑
     * @param val
     */
    handleTestFrequency(val) {
      this.editParam.testFrequency = val;
    },

    /**
     * 是否开展试验项目 编辑
     * @param val
     */
    handleCarryOut(val){
      this.editParam.isCarryOut = val;
      // 当选择了不开展试验 val=0,开展试验表单标志causeShowFlag = false,不开展试验表单显示
      if (val === 0) {
        this.causeShowFlag = false;
      } else {
        this.causeShowFlag = true;
      }
    },
  }
}

</script>
<style lang="less" scoped>
.content-box {
  padding: 0 12px;
}

.layout-card {
 padding: 12px;
}

.table-mr {
  margin-top: 12px;
}

/deep/ .ant-table-fixed-header .ant-table-scroll .ant-table-header {
  overflow: hidden!important;
  margin-bottom: 0!important;
  padding-right: 10px;
  background: rgb(250, 250, 250);
}
</style>
