<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button
					type="primary"
					icon="el-icon-plus"
					@click="add"
					v-auth="'ptest.create'"
					>新增</el-button
				>
			</div>
			<div class="right-panel">
				<!-- <el-select
					v-model="query.testitem"
					clearable
					style="width: 150px"
					@change="testitemChange"
				>
					<el-option
						v-for="item in behaviors"
						:key="item.id"
						:label="item.name"
						:value="item.id"
					>
					</el-option>
				</el-select> -->
				<el-date-picker
					v-model="query.test_date"
					type="date"
					value-format="YYYY-MM-DD"
					style="width: 150px"
				/>
				<el-input
					v-model="query.search"
					placeholder="编号"
					clearable
					style="width: 150px"
				></el-input>
				<el-button
					type="primary"
					icon="el-icon-search"
					@click="handleQuery"
					>查询</el-button
				>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable
				ref="table"
				:data="tableData"
				:apiObj="apiObj"
				row-key="id"
				stripe
				:params="query"
				:query="query"
			>
				<el-table-column type="index" width="50" />
				<el-table-column label="样品编号" prop="sample_number" show-overflow-tooltip>
				</el-table-column>
				<el-table-column label="实验日期" prop="test_date" show-overflow-tooltip>
				</el-table-column>
				<el-table-column
					label="仪器状态"
					prop="factory"
					show-overflow-tooltip
				>
					<template #default="scope">
						<el-tag>{{state_[scope.row.equip_state]}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					label="折射率(589nm)"
					prop="val_zsl"
				>
				</el-table-column>
				<el-table-column
					label="样品厚度/mm"
					prop="val_hd"
				>
				</el-table-column>
				<el-table-column
					label="透过率(550nm)"
					prop="val_tgl"
				>
				</el-table-column>
				<el-table-column
					label="Ts/℃"
					prop="val_ts"
				>
				</el-table-column>
				<el-table-column
					label="型号规格"
					prop="specification"
				>
				</el-table-column>
				<el-table-column
					label="30-300℃膨胀系数"
					prop="val_pzxs"
				>
				</el-table-column>
				<el-table-column
					label="Tg/℃"
					prop="val_tg"
				>
				</el-table-column>
				<el-table-column
					label="Tf/℃"
					prop="val_tf"
				>
				</el-table-column>
				<el-table-column
					label="样品数量"
					prop="sample_count"
				>
				</el-table-column>
				<el-table-column
					label="析晶"
					prop="val_xj"
				>
					<template #default="scope">
						<el-tag>{{state_xj[scope.row.val_xj]}}</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					label="样品密度"
					prop="sample_density"
				>
				</el-table-column>
				<el-table-column
					label="升至最高温度/℃"
					prop="val_zgwd"
				>
				</el-table-column>
				<el-table-column
					label="检验员"
					prop="test_user_name"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column label="操作" fixed="right" width="160">
					<template #default="scope">
						<el-link
							type="primary"
							@click="table_edit(scope.row)"
							v-auth="'ptest.update'"
							>编辑</el-link
						>
						<el-divider
							direction="vertical"
							v-auth="'ptest.update'"
						></el-divider>
						<el-link
							type="primary"
							@click="table_show(scope.row)"
							>查看</el-link
						>
						<el-divider
							direction="vertical"
							v-auth="'ptest.delete'"
						></el-divider>
						<el-link
							type="danger"
							@click="table_del(scope.row)"
							v-auth="'ptest.delete'"
							>删除</el-link
						>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
		
		<save-dialog
			v-if="visible"
			ref="saveDialog"
			@success="handleSuccess"
			@closed="visible = false"
		>
		</save-dialog>
		<!-- <el-dialog
            title="上传"
            destroy-on-close
            v-model="visible"
            @closed="visible = false"
        >
            <el-form ref="dialogForm" :model="form" :rules="rules" label-width="120px">
                <el-form-item label="模板文件">
                    <el-link href="" target="_blank" type="primary" style="margin-right:10px">模板一</el-link>
                    <el-link href="" target="_blank" type="primary">模板二</el-link>
                </el-form-item>
                <el-form-item label="上传文件">
                    <span>{{ form.fileName }}</span>
                    <sc-upload-file
                        v-model="form.file"
                        :multiple="false"
                        :limit="1"
                        accept="xlsx"
                        tip="文件不要超过10M,请上传xlsx格式文件"
                        >
                        <el-button type="primary" icon="el-icon-upload"
                            >上传</el-button
                        >
                    </sc-upload-file>
                </el-form-item>
            </el-form>
            <el-footer>
                <el-button type="primary" :loading="isSaveing" @click="submitFile">提交</el-button>
                <el-button @click="visible = false">取消</el-button>
            </el-footer>
        </el-dialog> -->
	</el-container>
</template>
<script>
import saveDialog from "./behavior_form.vue";
export default {
	name: "rparty",
	components: { saveDialog },
	data() {
		return {
			apiObj: null,
			query: {
				testitem: "",
				test_date: "",
			},
			state_: {
				R: "正常",
				T: "异常",
			},
			state_xj: {
				S: "析晶",
				R: "不析晶",
				θ: "未化",
			},
			form: {
				file: "",
				fileName: "",
			},
			rules: {
				file: [
					{
						required: true,
						message: "请上传上传文件",
						trigger: "blur",
					},
				],
			},
			// activeName: "折射率",
			visible: false,
			isSaveing: false,
			selection: [],
			behaviors: [],
			tableData: [],
		};
	},
	mounted() {
		this.getTextItem();
	},
	methods: {
		//获取检验项目
		getTextItem() {
			let that = this;
			that.$API.qm.getTestItem
				.get({ tags__contains: "performance", page: 0 })
				.then((res) => {
					that.behaviors = res;
					// that.query.testitem = res[0].id;
					that.apiObj = that.$API.qm.ptest.list;
				});
		},
		testitemChange(){
			let that = this;
			that.behaviors.forEach((item) => {
			    if(item.id==that.query.testitem){
					that.activeName = item.name;
				}
				that.$refs.table.refresh();
			})
		},
		add() {
			this.visible = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("add");
			});
		},
		table_edit(row) {
			this.visible = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("edit").setData(row);
			});
		},
		table_del(row) {
			let that = this;
			that.$confirm(`确定删除吗？`, "提示", {
				type: "warning",
			}).then(() => {
				that.$API.qm.ptest.delete.req(row.id).then((res) => {
					that.$message.success("操作成功");
					that.$refs.table.refresh();
				});
			});
		},
		importInspect() {
			this.visible = true;
		},
		submitFile() {},
		closeVisible() {
			this.visible = false;
		},
		handleSuccess() {
			this.visible = false;
			this.$refs.table.refresh();
		},
		//查看
		table_show(row) {
			this.visible = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open("show").setData(row);
			});
		},
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		resetQuery() {
			this.query = {};
		},
	},
};
</script>
