<template>
  <div>
    <a-collapse :defaultActiveKey="'1'" v-if="fmeaType !== '3'">
      <a-collapse-panel :header="$t('plan.citation-family-dfmea')" key="1" >
				<a-card class='card card-bottom' id="grid-card">
					<!-- 表格列设置-->
					<template slot="extra">
						<a-dropdown>
							<a-menu slot="overlay">
								<draggable v-model="sortedColumns" handle=".drag-handle" filter=".cant-handle" :move="onMove"
													 class="m-2 mr-1" tag="div" animation="500">
									<a-menu-item v-for="column in sortedColumns" :key="column.dataIndex" :disabled='true'
															 class="custom-menu-item mb-1" :class="column.cantHandle ? 'cant-handle' : ''">
										<div class="drag-handle" @mousedown="startDrag = true" @mouseup="startDrag = false"
												 @mouseleave="startDrag = false">
											<i class="icon iconfont iconshangxiayidong-"></i>
										</div>
										<a-checkbox v-model="editColumnVisibilities[column.dataIndex]" :disabled="column.cantHide"
																@change="handleCheckboxChange(column.dataIndex, $event.target.checked)">
											{{ column.title }}
										</a-checkbox>
									</a-menu-item>
								</draggable>
								<a-menu-item class="dropdown-footer" :disabled='true'>
									<a-button size="small" class="mr-2" @click='handleCheckBoxReset'>{{
											$t('global-btn.reset')
										}}
									</a-button>
									<a-button type="primary" size="small" @click="handleSaveTableConfig">{{
											$t('plan.change-record.save')
										}}
									</a-button>
								</a-menu-item>
							</a-menu>
							<a-button icon="setting" type="link" :title="($t('fmeamanager.setting.col'))"></a-button>
						</a-dropdown>
					</template>
					<a-table
						id="citation-family-dfmea"
						ref='tableRef'
						size="small"
						:pagination="pagination"
						:rowKey="(record, index) => {return index;}"
						bordered
						:scroll='{ x: scrollWidth, y: tableHeightValue }'
						:columns='sortedColumns.filter(column => column.visible)'
						:components='components'
						:dataSource="quoteMasterData"
						:loading="loading"
						@change="handleQuoteMasterTableChange">
						<template slot="sortNumber" slot-scope="text, row, index">{{
								(pagination.pageNo - 1) * pagination.pageSize + 1 + index
							}}
						</template>
					</a-table>
				</a-card>
      </a-collapse-panel>
    </a-collapse>
    <a-collapse :defaultActiveKey="'1'" v-if="fmeaType === '3'">
      <a-collapse-panel :header="$t('plan.project-dfmea-call-list')" key="1">
				<a-card class='card card-bottom' id="project-grid-card">
					<!-- 表格列设置-->
					<template slot="extra">
						<a-dropdown>
							<a-menu slot="overlay">
								<draggable v-model="sortedColumns" handle=".drag-handle" filter=".cant-handle" :move="onMove"
													 class="m-2 mr-1" tag="div" animation="500">
									<a-menu-item v-for="column in sortedColumns" :key="column.dataIndex" :disabled='true'
															 class="custom-menu-item mb-1" :class="column.cantHandle ? 'cant-handle' : ''">
										<div class="drag-handle" @mousedown="startDrag = true" @mouseup="startDrag = false"
												 @mouseleave="startDrag = false">
											<i class="icon iconfont iconshangxiayidong-"></i>
										</div>
										<a-checkbox v-model="editColumnVisibilities[column.dataIndex]" :disabled="column.cantHide"
																@change="handleCheckboxChange(column.dataIndex, $event.target.checked)">
											{{ column.title }}
										</a-checkbox>
									</a-menu-item>
								</draggable>
								<a-menu-item class="dropdown-footer" :disabled='true'>
									<a-button size="small" class="mr-2" @click='handleCheckBoxReset'>{{
											$t('global-btn.reset')
										}}
									</a-button>
									<a-button type="primary" size="small" @click="handleSaveTableConfig">{{
											$t('plan.change-record.save')
										}}
									</a-button>
								</a-menu-item>
							</a-menu>
							<a-button icon="setting" type="link" :title="($t('fmeamanager.setting.col'))"></a-button>
						</a-dropdown>
					</template>
					<a-table
						id="project-dfmea-call-list"
						ref='projectTableRef'
						size="small"
						:pagination="paginationSync"
						:rowKey="(record, index) => {return index;}"
						bordered
						:scroll='{ x: scrollWidth, y: tableHeightValue }'
						:columns='sortedColumns.filter(column => column.visible)'
						:components='components'
						:dataSource="DFMEAList"
						:loading="loadingSync"
						@change="handleTableChangeSync">
						<template slot="lifeState" slot-scope="text, record">
							<span>{{ lifeStateMap[record.lifeState] || "-" }}</span>
						</template>
						<template slot="syncBtn" slot-scope="text, record">
							<a href="javascript:void(0);" @click="toCompare(record)">
								<i :class="'iconfont iconhechabidui'"></i>
							</a>
						</template>
					</a-table>
				</a-card>
      </a-collapse-panel>
    </a-collapse>
  </div>
</template>
<script>

import {dateFormat} from "@/utils/date";
import VueDraggableResizable from 'vue-draggable-resizable';
import draggable from 'vuedraggable';
export default {
  name: "QuoteMasterFMEA",
	components: {
		VueDraggableResizable,
		draggable
	},
  props: {
    from: {
      type: String,
      default: "dfmea"
    },
    fmeaId: {
      type: String | Number,
      default: ""
    },
    masterFmeaId: {
      type: String | Number,
      default: ""
    },
    fmeaType: {
      type: String | Number,
      default: "1"
    }
  },
  data() {
			this.components = {
				header: {
					cell: (h, props, children) => {
						const { key, ...restProps } = props;
						// 此处的this.sortedColumns 是定义的table的表头属性变量
						const col = this.sortedColumns.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 {
      // 沿用MasterFMEA
      loading: false,
      pagination: {
        pageNo: 1,
        pageSize: 10, // 默认每页显示数量
        showTotal: (total) => this.$t('global-constant.table.show-total', [total]), // 显示总数
        showSizeChanger: true, // 显示可改变每页数量
        pageSizeOptions: ["10", "20", "50", "100", "200"], // 每页数量选项
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize), // 改变每页数量时更新显示
        // onChange: (page, pageSize) => self.changePage(page, pageSize), //点击页码事件
        total: 0 //总条数
      },
			// 表格操作列配置
			sortedColumns: [],
			startDrag: false,
			editColumnVisibilities: [],
			scrollWidth: 0,
			tableHeightValue: 0,
			// 复选框控制的状态
			columnVisibilities: {
				sortNumber: true,
				dfmeaCode: true,
				partName: true,
				version: true,
				dfmeaOwnerName: true,
				departmentName: true,
				svpps: true,
				fmeaBusiType: true,
				insertTime: true,
				updateTime: true,
				extendsCount: true
			},
      quoteMasterColumns: [
        {
          title: 'plan.citation-family-dfmea.serial-number',
					dataIndex: "sortNumber",
          width: 150,
          align: "center",
					fixed: "left",
					visible: true,
					cantHide: true,
					cantHandle: true,
          ellipsis: true,
          scopedSlots: {
            customRender: "sortNumber"
          },
        },
        {
          title: 'plan.citation-family-dfmea.family-dfmea-number',
          width: 200,
          align: "center",
          dataIndex: "dfmeaCode",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.part/system-name',
          width: 200,
          align: "center",
          dataIndex: "partName",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.version',
          width: 100,
          align: "center",
          dataIndex: "version",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.owner',
          width: 100,
          align: "center",
          dataIndex: "dfmeaOwnerName",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.department',
          width: 120,
          align: "center",
          dataIndex: "departmentName",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.structure-code',
          width: 150,
          align: "center",
          dataIndex: "svpps",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.type',
          width: 100,
          align: "center",
          dataIndex: "fmeaBusiType",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.create-time',
          width: 120,
          align: "center",
          dataIndex: "insertTime",
					visible: true,
          customRender: val => {
            return dateFormat(val);
          },
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.update-time',
          width: 120,
          align: "center",
          dataIndex: "updateTime",
					visible: true,
          customRender: val => {
            return dateFormat(val);
          },
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.citations-number',
          width: 200,
          align: "center",
          dataIndex: "extendsCount",
					visible: true,
          ellipsis: true
        }
      ],
      quoteMasterData: [],
      // 项目DFMEA管理
      loadingSync: false,
      paginationSync: {
        pageNo: 1,
        pageSize: 10, // 默认每页显示数量
        showTotal: (total) => this.$t('global-constant.table.show-total', [total]), // 显示总数
        showSizeChanger: true, // 显示可改变每页数量
        pageSizeOptions: ["10", "20", "50", "100", "200"], // 每页数量选项
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize), // 改变每页数量时更新显示
        // onChange: (page, pageSize) => self.changePage(page, pageSize), //点击页码事件
        total: 0 //总条数
      },
      lifeStateMap: {
        '10': this.$t('global-dict.fmea-status.in-preparation'),
        '50': this.$t('global-dict.fmea-status.under-approval'),
        '51': this.$t('global-dict.fmea-status.archive'),
        '60': this.$t('global-dict.fmea-status.abandoned'),
        '1': this.$t('global-dict.fmea-status.disable'),
      },
			// 复选框控制的状态
			proiectColumnVisibilities: {
				sortNumber: true,
				dfmeaCode: true,
				partName: true,
				lifeState: true,
				dfmeaOwnerName: true,
				projectNo: true,
				departmentName: true,
				svpps: true,
				version: true,
				fmeaBusiType: true,
				partTg2Time: true,
				syncBtn: true
			},
      tSync: [
        {
          title: 'plan.citation-family-dfmea.serial-number',
					dataIndex: "sortNumber",
          width: 50,
          align: "center",
          customRender: (value, row, index) => `${index + 1}`,
					fixed: "left",
					visible: true,
					cantHide: true,
					cantHandle: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.project-dfmea-number',
          width: 300,
          align: "center",
          dataIndex: "dfmeaCode",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.part/system-name',
          width: 300,
          align: "center",
          dataIndex: "partName",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.status',
          width: 150,
          align: "center",
          dataIndex: "lifeState",
          scopedSlots: {
            customRender: "lifeState"
          },
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.owner',
          width: 150,
          align: "center",
          dataIndex: "dfmeaOwnerName",
					visible: true,
          ellipsis: true
        },

        {
          title: 'plan.citation-family-dfmea.project-number',
          width: 300,
          align: "center",
          dataIndex: "projectNo",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.department',
          width: 200,
          align: "center",
          dataIndex: "departmentName",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.structure-code',
          width: 200,
          align: "center",
          dataIndex: "svpps",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.version',
          width: 200,
          dataIndex: "version",
					visible: true,
          align: "center",
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.fmea-type',
          width: 200,
          align: "center",
          dataIndex: "fmeaBusiType",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.basic-information.planning-completion-time',
          width: 200,
          align: "center",
          dataIndex: "partTg2Time",
					visible: true,
          ellipsis: true
        },
        {
          title: 'plan.citation-family-dfmea.operation',
          width: 100,
					dataIndex: "syncBtn",
          align: "center",
          scopedSlots: {
            customRender: "syncBtn"
          },
          fixed: 'right',
					visible: true,
					cantHide: true,
					cantHandle: true,
          ellipsis: true
        }
      ],
      DFMEAList: []
    };
  },
	watch: {
		sortedColumns: {
			handler() {
				this.$nextTick(() => {
					// 获取表格滚动区域的总宽度
					let scrollX = $('.ant-table-fixed').width();
					// 获取表格的总宽度
					let tableWidth = $('.ant-table-body').width();
					// a-table的scrollX宽度需要减去固定列宽度
					this.scrollWidth = scrollX - 260;
					if (scrollX <= tableWidth) {
						this.cancelFixedColmuns();
					} else {
						if (this.fmeaType !== '3') {
							this.reloadFixedColmuns([0], []);
						}
						if (this.fmeaType === '3') {
							this.reloadFixedColmuns([0], [this.sortedColumns.length - 1]);
						}
					}
				});
			},
			deep: true,
			immediate: true
		}
	},
  methods: {
		/**
		 * 初始化加载已保存的表格列顺序及显隐
		 */
		async initTableColumns() {
			// 获取用户信息，如果当前组件的userInfo为空，则从localStorage中获取
			let userInfo = this.userInfo || JSON.parse(localStorage.getItem('userInfo'));
			try {
				// 调用接口获取表格列数据
				let res = await this.$api.getTableColumnsData({
					userId: userInfo.userId,
					pagePath: this.$route.path,
					pageName: this.$route.name,
				});
				// 如果接口返回成功
				if (res.flag) {
					// 如果返回的数据中包含当前表格的配置映射，并且映射中有数据
					if (res.data.currentTableConfigMap && Object.keys(res.data.currentTableConfigMap).length > 0) {
						// 获取当前表格的配置信息
						let tableConfig;
						if (this.fmeaType !== '3') {
							tableConfig = res.data.currentTableConfigMap['citation-family-dfmea']
						}
						if (this.fmeaType === '3') {
							tableConfig = res.data.currentTableConfigMap['project-dfmea-call-list']
						}
						// 如果表格配置存在
						if (tableConfig) {
							// 解析表格列数据 将从数据库中获取的表格title通过$t方法翻译后存储到新的数组中 再将其赋值给sortedColumns
							let oldColumns = JSON.parse(tableConfig.tableColumns);
							oldColumns.forEach((column) => {
								// 处理表格列的title
								column.title = this.$t(column.title);
							});
							this.sortedColumns = [...oldColumns];
							// 解析表格列显示状态
							this.editColumnVisibilities = JSON.parse(tableConfig.tableVisibilities);
						} else {
							// 如果没有表格配置，则使用默认的表格列和显示状态
							// 处理表格列的title 将默认表格配置数据中的title通过$t方法翻译后存储到新的数组中 再将其赋值给sortedColumns 避免污染tableColumns默认数据
							let newTableColumns = [];
							if (this.fmeaType !== '3') {
								this.quoteMasterColumns.forEach((column) => {
									let newColumn = { ...column };
									newColumn.title = this.$t(column.title);
									newTableColumns.push(newColumn);
								});
								this.sortedColumns = [...newTableColumns];
								this.editColumnVisibilities = { ...this.columnVisibilities };
							}
							if (this.fmeaType === '3') {
								this.tSync.forEach((column) => {
									let newColumn = {...column};
									newColumn.title = this.$t(column.title);
									newTableColumns.push(newColumn);
								});
								this.sortedColumns = [...newTableColumns];
								this.editColumnVisibilities = { ...this.proiectColumnVisibilities };
							}
						}
					} else {
						// 如果没有表格配置，则使用默认的表格列和显示状态
						// 处理表格列的title 将默认表格配置数据中的title通过$t方法翻译后存储到新的数组中 再将其赋值给sortedColumns 避免污染tableColumns默认数据
						let newTableColumns = [];
						if (this.fmeaType !== '3') {
							this.quoteMasterColumns.forEach((column) => {
								let newColumn = { ...column };
								newColumn.title = this.$t(column.title);
								newTableColumns.push(newColumn);
							});
							this.sortedColumns = [...newTableColumns];
							this.editColumnVisibilities = { ...this.columnVisibilities };
						}
						if (this.fmeaType === '3') {
							this.tSync.forEach((column) => {
								let newColumn = {...column};
								newColumn.title = this.$t(column.title);
								newTableColumns.push(newColumn);
							});
							this.sortedColumns = [...newTableColumns];
							this.editColumnVisibilities = { ...this.proiectColumnVisibilities };
						}
					}
					// 如果接口返回失败
				} else {
					console.error('Failed to retrieve table column data.');
				}
			} catch (error) {
				// 捕获异常，并输出错误信息
				console.error('Error occurred while fetching table columns:', error);
			}
		},
		/**
		 * 处理窗口大小调整事件
		 *
		 * @returns 无返回值
		 */
		handleResize() {
			// 获取窗口宽度
			const width = window.innerWidth;
			// 获取窗口高度
			const height = Math.max(window.innerHeight, 0);
			// 获取用户信息容器的高度
			let searchCardHeight = $("#search-card").height();
			// 系统内菜单栏、标签栏的高度恒定为64 + 40 = 104，其他页边距需根据每个页面布局自行计算
			if (this.fmeaType !== '3') {
				$("#grid-card").height(height - 104 - searchCardHeight - 40);
				this.scrollWidth = this.$refs.tableRef?.$el.offsetWidth;
			}
			if (this.fmeaType === '3') {
				$("#project-grid-card").height(height - 104 - searchCardHeight - 40);
				this.scrollWidth = this.$refs.projectTableRef?.$el.offsetWidth;
			}
			this.tableHeightValue = height - 104 - searchCardHeight - 222;
			// 获取表格滚动区域的总宽度
			let scrollX = $('.ant-table-fixed').width() - 260;
			// 获取表格的总宽度
			let tableWidth = $('.ant-table-body').width();
			// 超过2K屏时取消固定列
			if (width > 2560 || scrollX <= tableWidth) {
				this.cancelFixedColmuns();
			} else {
				if (this.fmeaType !== '3') {
					this.reloadFixedColmuns([0], []);
				}
				if (this.fmeaType === '3') {
					this.reloadFixedColmuns([0], [this.sortedColumns.length - 1]);
				}
			}
		},
		/**
		 * 移动事件处理函数
		 *
		 * @param event 事件对象
		 * @returns 如果当前元素不包含禁止移动属性则返回true，否则返回false
		 */
		onMove(event) {
			// 禁止移动到包含禁止移动元素的行
			return !event.relatedContext.element.cantHandle;
		},
		/**
		 * 处理表格列显隐复选框变化事件
		 *
		 * @param key 列的唯一标识符
		 * @param checked 列的显示状态，true表示显示，false表示隐藏
		 */
		handleCheckboxChange(key, checked) {
			// 更新全局的columnVisibilities对象
			this.$set(this.editColumnVisibilities, key, checked);
			// 更新列配置中的visible属性（如果需要的话）
			this.sortedColumns.forEach(column => {
				if (column.dataIndex === key) {
					column.visible = checked;
				}
			});
		},
		/**
		 * 重置表格列显示隐藏
		 */
		handleCheckBoxReset() {
			if (this.fmeaType !== '3'){
				this.editColumnVisibilities = { ...this.columnVisibilities };
			}
			if (this.fmeaType === '3'){
				this.editColumnVisibilities = { ...this.proiectColumnVisibilities };
			}
			// 重置时，将默认表格配置数据中的title通过$t方法翻译后存储到新的数组中 再将其赋值给sortedColumns 避免污染tableColumns默认数据
			let resetColumns = [];
			if (this.fmeaType !== '3') {
				this.quoteMasterColumns.forEach(column => {
					let newColumn = {...column};
					newColumn.title = this.$t(column.title);
					resetColumns.push(newColumn);
				});
			}
			if (this.fmeaType === '3') {
				this.tSync.forEach(column => {
					let newColumn = {...column};
					newColumn.title = this.$t(column.title);
					resetColumns.push(newColumn);
				});
			}
			this.sortedColumns = [...resetColumns];
			this.sortedColumns.forEach(column => {
				this.$set(column, 'visible', true);
			});
		},
		/**
		 * 保存表格配置信息
		 */
		handleSaveTableConfig() {
			// 创建一个对象用于保存需要保存的配置数据
			// 将sortedColumns中的title替换为tableColumns中的title
			let newSortedColumns = [];
			let tableId;
			if (this.fmeaType !== '3') {
				this.sortedColumns.forEach(column => {
					let newColumn = {...column};
					if (this.quoteMasterColumns.find(item => item.dataIndex === column.dataIndex)) {
						let item = this.quoteMasterColumns.find(item => item.dataIndex === column.dataIndex);
						newColumn.title = item.title;
					}
					newSortedColumns.push(newColumn);
				});
				tableId = 'citation-family-dfmea'
			}
			if (this.fmeaType === '3'){
				this.sortedColumns.forEach(column => {
					let newColumn = {...column};
					if (this.tSync.find(item => item.dataIndex === column.dataIndex)) {
						let item = this.tSync.find(item => item.dataIndex === column.dataIndex);
						newColumn.title = item.title;
					}
					newSortedColumns.push(newColumn);
				});
				tableId = 'project-dfmea-call-list'
			}

			let data = {
				pagePath: this.$route.path,
				pageName: this.$route.name,
				// 表格列信息，转为JSON字符串
				tableColumns: JSON.stringify(newSortedColumns),
				// 表格列可见性信息，转为JSON字符串
				tableVisibilities: JSON.stringify(this.editColumnVisibilities),
				// 表格id
				tableId: tableId
			};
			// 调用API保存表格配置
			this.$api.saveTableConfig(data).then(res => {
				// 如果返回结果中的flag为true，表示保存成功
				if (res.flag) {
					// 显示成功提示信息
					this.$message.success(res.message, 1);
					// 重新初始化数据
					if (this.fmeaType !== '3') {
						this.getQuoteMasterFMEAPageList();
					}
					if (this.fmeaType === '3') {
						this.getProjectDMFMAEPageList();
					}
				} else {
					// 显示错误提示信息
					this.$message.error(res.message, 1);
				}
			}).finally(() => {
				// 重新初始化数据
				if (this.fmeaType !== '3') {
					this.getQuoteMasterFMEAPageList();
				}
				if (this.fmeaType === '3') {
					this.getProjectDMFMAEPageList();
				}
			});
		},
		/**
		 * 取消固定列
		 *
		 * @returns 无返回值
		 */
		cancelFixedColmuns() {
			// 遍历已排序的列
			this.sortedColumns.forEach((column) => {
				// 如果列的固定属性为true
				if (column.fixed) {
					// 将列的固定属性设置为false
					column.fixed = false;
				}
			});
		},
		/**
		 * 重新设置固定列的固定状态
		 *
		 * @param fixedLeftColumns 左侧固定列名数组
		 * @param fixedRightColumns 右侧固定列名数组
		 */
		reloadFixedColmuns(fixedLeftColumns, fixedRightColumns) {
			fixedLeftColumns.forEach((column) => {
				if (this.sortedColumns[column]) {
					this.sortedColumns[column].fixed = 'left';
				}
			});
			fixedRightColumns.forEach((column) => {
				if (this.sortedColumns[column]) {
					this.sortedColumns[column].fixed = 'right';
				}
			});
		},
    toCompare(record) {
      let dUrl = this.$api.MOrDFEBaseUrl;
      let backUrl = '/fmea/master/list';
      var url = dUrl + '/#/project?fmeaId=' + record.fmeaId + '&rfmeaId=' + record.rfmeaId + '&from=dfmea' + "&back=" + backUrl + '&ntimet=' + new Date().getTime();
      window.open(url, '_top').location.reload();
    },
    handleQuoteMasterTableChange(pagination) {
      this.pagination.pageNo = pagination.pageNo;
      this.pagination.pageSize = pagination.pageSize;
      this.getQuoteMasterFMEAPageList();
    },
    getQuoteMasterFMEAPageList() {
      // this.masterFmeaId = 10129;
      if (!this.masterFmeaId || this.fmeaType == "3") {
        return false;
      }
      this.loading = true;
      this.$api
          .post("/DFMEA/plan/getMasterDFMEAPageList.do", {
            pageNo: this.pagination.pageNo,
            pageSize: this.pagination.pageSize,
            masterFmeaId: this.masterFmeaId
          })
          .then((res) => {
            if (res.flag) {
              this.quoteMasterData = res.data.data;
              this.pagination.total = res.data.total;
            } else {
              this.quoteMasterData = [];
              this.pagination.total = 0;
            }
            this.loading = false;
          });
    },
    handleTableChangeSync(pagination) {
      this.paginationSync.pageNo = pagination.pageNo;
      this.paginationSync.pageSize = pagination.pageSize;
      this.getProjectDMFMAEPageList();
    },
    getProjectDMFMAEPageList() {
      if (!this.fmeaId || this.fmeaType != "3") {
        return false;
      }
      var data = {
        masterFmeaId: this.fmeaId,
        pageNo: this.paginationSync.pageNo,
        pageSize: this.paginationSync.pageSize
      };
      this.loadingSync = true;
      var url = "/DFMEA/plan/getChildProjectDFMEAPageList.do";
      this.$api.post(url, data).then((response) => {
        if (response.flag) {
          this.DFMEAList = response.data.data;
          this.paginationSync.total = response.data.total;
        } else {
          this.DFMEAList = [];
          this.paginationSync.total = 0;
        }
        this.loadingSync = false;
      });
    }
  },
  mounted() {
    this.getQuoteMasterFMEAPageList();
    this.getProjectDMFMAEPageList();
		// 获取表格配置
		this.initTableColumns();
		this.handleResize();
		// 监听页面窗体大小变化
		window.addEventListener('resize', this.handleResize);
  },
	//剔除页面窗体大小变化得监听事件
	beforeDestroy() {
		window.removeEventListener('resize', this.handleResize);
	}
};
</script>

<style lang="less" scoped>
/** 表格头部自动换行 */
/deep/ .ant-table-thead {
  .ant-table-row-cell-ellipsis .ant-table-column-title {
    white-space: normal;
  }
}
/deep/ .ant-table-fixed-header .ant-table-scroll .ant-table-header {
   overflow: hidden!important;
   margin-bottom: 0!important;
   padding-right: 8px;
   background: rgb(250, 250, 250);
 }

</style>
