<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: DY
 * @LastEditTime: 2024-02-23 19:48:12
 * @Description:
-->
<template>
	<el-drawer
		:visible.sync="visible"
		:show-close="false"
		:wrapper-closable="isdetail"
		class="drawer"
		size="60%">
		<small-title slot="title" :no-padding="true">
			{{ '添加内容' }}
		</small-title>
		<div class="content">
			<div class="visual-part">
				<el-row :gutter="20">
          <el-col :span="8">
            <div class="blodTip">保养计划名称</div>
            <div class="lightTip">{{ dataForm.name }}</div>
          </el-col>
          <el-col :span="8">
            <div class="blodTip">部门</div>
            <div class="lightTip">{{ dataForm.departmentName }}</div>
          </el-col>
          <el-col :span="8">
            <div class="blodTip">产线名</div>
            <div class="lightTip">{{ dataForm.lineName }}</div>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="blodTip">保养频率</div>
            <div class="lightTip">{{ dataForm.maintenancePeriod }}</div>
          </el-col>
          <el-col :span="8">
            <div class="blodTip">保养时长</div>
            <div class="lightTip">{{ dataForm.maintainDuration }}</div>
          </el-col>
          <el-col :span="8">
            <div class="blodTip">计划保养人员</div>
            <div class="lightTip">{{ dataForm.maintainer }}</div>
          </el-col>
        </el-row>
			</div>
			
			<div class="attr-list" v-if="idAttrShow">
				<small-title
					style="margin: 16px 0; padding-left: 8px"
					:no-padding="true">
					保养内容
				</small-title>

				<div v-if="!isdetail" class="action_btn">
          <template>
            <span style="display: inline-block;">
              <el-button type="text" @click="addNew()" icon="el-icon-plus">新增</el-button>
            </span>
          </template>
        </div>
				<base-table
					:table-props="tableProps"
					:page="listQuery.pageNo"
					:limit="listQuery.pageSize"
					:table-data="planList">
					<method-btn
						v-if="!isdetail"
						slot="handleBtn"
						:width="120"
						label="操作"
						:method-list="tableBtn"
						@clickBtn="handleClick" />
				</base-table>
				<pagination
					v-show="listQuery.total > 0"
					:total="listQuery.total"
					:page.sync="listQuery.pageNo"
					:limit.sync="listQuery.pageSize"
					:page-sizes="[5, 10, 15]"
					@pagination="getList" />
			</div>

			<div v-if="!isdetail" class="drawer-body__footer">
				<el-button style="" @click="goback()">取消</el-button>
				<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
			</div>

		</div>

		<attr-add
			v-if="addOrUpdateVisible"
			ref="addOrUpdate"
			:plan-id="dataForm.id"
			@refreshDataList="getList" />
	</el-drawer>
</template>

<script>
import basicAdd from '../../../../core/mixins/basic-add';
import { getPlan, deletePlanDet, getPlanDetPage } from '@/api/equipment/base/maintain/planconfig';
// import { listData } from "@/api/system/dict/data";
import SmallTitle from './SmallTitle';
// import { parseTime } from '../../../../core/mixins/code-filter';
import attrAdd from './attr-add';
// import { getDictDatas } from "@/utils/dict";

const tableBtn = [
	{
		type: 'edit',
		btnName: '编辑',
	},
	{
		type: 'delete',
		btnName: '删除',
	},
];
const tableProps = [
	{
		prop: 'equipmentName',
		label: '设备名称',
	},
	{
		prop: 'program',
		label: '保养项目',
	},
];

export default {
	mixins: [basicAdd],
	components: { SmallTitle, attrAdd },
	data() {
		return {
			tableBtn,
			tableProps,
			addOrUpdateVisible: false,
			urlOptions: {
			  isGetCode: false,
				infoURL: getPlan
			},
			listQuery: {
				pageSize: 99,
				pageNo: 1,
				total: 0
			},
			dataForm: {},
			planList: [],
			visible: false,
			isdetail: false,
			idAttrShow: false
		};
	},
	mounted() {},
	methods: {
		initData() {
			this.planList.splice(0);
			this.listQuery.total = 0;
		},
		handleClick(raw) {
			if (raw.type === 'delete') {
				this.$confirm(
					`是否确认删除保养项目名为"${raw.data.program}"的数据项?`,
					'提示',
					{
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning',
					}
				)
					.then(() => {
						deletePlanDet(raw.data.id).then(({ data }) => {
							this.$message({
								message: '操作成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.getList();
								},
							});
						});
					})
					.catch(() => {});
			} else {
				this.addNew(raw.data.id);
			}
		},
		getList() {
			// 获取物料的属性列表
			getPlanDetPage({
				...this.listQuery,
				planId: this.dataForm.id,
			}).then((response) => {
				this.planList = response.data.list;
				this.listQuery.total = response.data.total;
			});
		},
		init(id, isdetail) {
			this.initData();
			this.isdetail = isdetail || false;
			this.dataForm.id = id || undefined;
			this.visible = true;
			if (id) {
				this.idAttrShow = true
			} else {
				this.idAttrShow = false
			}

			this.$nextTick(() => {

				if (this.dataForm.id) {
					// 获取计划详情
					this.urlOptions.infoURL({ id: id}).then(response => {
            this.dataForm = response.data;
          });
					// 获取详情分页
					this.getList();
				}
			});
		},
		goback() {
			this.$emit('refreshDataList');
			this.visible = false;
			// this.initData();
		},
		// 新增 / 修改
		addNew(id) {
			this.addOrUpdateVisible = true;
			this.$nextTick(() => {
				this.$refs.addOrUpdate.init(id);
			});
		}
	}
};
</script>
<style scoped>
.drawer >>> .el-drawer {
	border-radius: 8px 0 0 8px;
	display: flex;
	flex-direction: column;
}

.drawer >>> .el-form-item__label {
	padding: 0;
}

.drawer >>> .el-drawer__header {
	margin: 0;
	padding: 32px 32px 24px;
	border-bottom: 1px solid #dcdfe6;
}
.drawer >>> .el-drawer__body {
	flex: 1;
	height: 1px;
	display: flex;
	flex-direction: column;
}

.drawer >>> .content {
	padding: 30px 24px;
	flex: 1;
	display: flex;
	flex-direction: column;
	/* height: 100%; */
}

.drawer >>> .visual-part {
	flex: 1 auto;
	max-height: 18vh;
	overflow: hidden;
	overflow-y: scroll;
	padding-right: 10px; /* 调整滚动条样式 */
}

.drawer >>> .el-form,
.drawer >>> .attr-list {
	padding: 0 16px;
}

.drawer-body__footer {
	display: flex;
	justify-content: flex-end;
	padding: 18px;
}
.action_btn {
  float: right;
  margin: -40px 15px;
  font-size: 14px;
}
.add {
	color: #0b58ff;
}
.blodTip {
	height: 16px;
	font-size: 14px;
	font-weight: 600;
	color: rgba(0,0,0,0.85);
	margin-bottom: 8px;
}
.lightTip {
	/* height: 16px; */
	font-size: 14px;
	font-weight: 400;
	color: rgba(102,102,102,0.75);
	margin-bottom: 12px;
}
</style>
