<template>
	<div>
    <el-descriptions  title="农产品质量安全抽样单" :column="2" border style="margin-top:20px">
            <el-descriptions-item label="抽样单编号" prop="cyd_data.cyd_code" style="width:200px" class="labelItem" size="mini" required >
                {{cyd_data.cyd_code}}
            </el-descriptions-item>
        <!-- 抽样单位信息 -->
                        <el-descriptions-item label="单位名称" prop="taskProfile_unit.name" size="mini" required>
                            {{taskProfile_unit.name}}
                        </el-descriptions-item>
                        <el-descriptions-item label="单位组别" prop="taskProfile_unit.groupname" size="mini" required>
                            {{taskProfile_unit.groupname}}
                        </el-descriptions-item>
                        <el-descriptions-item label="联系人" prop="taskProfile_unit.contact_name" size="mini" required>
                            {{taskProfile_unit.contact_name}}
                        </el-descriptions-item>
                        <el-descriptions-item label="联系电话" prop="taskProfile_unit.contact_phone" size="mini" required>
                            {{taskProfile_unit.contact_phone}}
                        </el-descriptions-item>
                        <el-descriptions-item label="别名" prop="taskProfile_unit.name_other" size="mini">
                            {{taskProfile_unit.name_other}}
                        </el-descriptions-item>
        <!-- 样品信息 -->
                <el-descriptions-item label="样品信息">
                    <el-descriptions-item label="样品名称" prop="sample.sample_name" size="mini" required>
                        {{sample.sample_name}}
                    </el-descriptions-item>
                </el-descriptions-item>
    </el-descriptions>
<!-- 底部按钮 -->
		<el-form>
				<el-form-item class="btn">
				<el-button type="primary" @click="back()">返回任务详情</el-button>
                </el-form-item>
		</el-form>
        </div>
</template>

<script>
	const token = window.sessionStorage.getItem('token')
	import {
		provinceAndCityData,
		regionData,
		provinceAndCityDataPlus,
		regionDataPlus,
		CodeToText,
		TextToCode
	} from 'element-china-area-data'
	export default {
		data() {
			return {
				myHeaders: {
					Authorization: 'bearer' + token
				},
				fileList: [],
				form: {},
				cyd_data: {},//抽样单信息
                taskProfile_unit:{},//抽样单位信息
				inspected_unit: {},//受检单位信息
				sample: {},//样品信息
				units: [],
				production: [],
				// 样品下拉框
				sampleList: [],
				task_id: '',
				undertake_id: '',
				// 产地
				options: regionData,
				selectedOptions: []
			}
		},
		created() {
			this.cyd_id = this.$route.params.cyd_id
			console.log(this.cyd_id)
			this.getCyd()
		},
		methods: {
			// 获取抽样单信息
			async getCyd() {
				const result = await this.$http.post('getCyd', {
					cyd_id: this.cyd_id
				})
				console.log(result.data.data)
				this.cyd_data = result.data.data//抽样单信息
                this.taskProfile_unit = result.data.data.taskProfile//抽样单位信息
				this.inspected_unit = result.data.data.inspectedUnit//受检单位信息
				this.sample = result.data.data.sample//样品信息
				console.log(this.cyd_data)
                console.log(this.taskProfile_unit)
				console.log(this.inspected_unit)
				console.log(this.sample)
                console.log(this.cyd_id)
			},
			// 生成样品编码
			async createCode() {
				var that = this
				const result = await this.$http.post('getSampleId', {
					task_id: this.task_id
				})
				console.log(result.data.data.id)
				if (result.data.code == 0) {
					that.cyd_data.sample_id = result.data.data.id
					this.getTestObj()
				}
			},
			// 获取选择产地
			handleChange() {
				var that = this
				var loc = "";
				// console.log(this.form.place)
				for (let i = 0; i < this.selectedOptions.length; i++) {
					loc += CodeToText[this.selectedOptions[i]];
				}
				// console.log(loc)
				that.cyd_data.place = loc
				console.log(that.cyd_data.place)
			},
			// 上传成功(要确认数据)
			uploadSuccess(res) {
				console.log(res.data)
				this.cyd_data.file_url = res.data.fileUrl
				this.cyd_data.file_name = res.data.fileName
			},
			async onSubmit() {
				console.log(this.cyd_data.sample_name)
				var that = this
				console.log(that.cyd_data)
				that.cyd_data.task_id = that.task_id
				that.cyd_data.undertake_id = that.undertake_id
				that.form.cyd_data = that.cyd_data
				that.form.unit_test = that.unit_test
				that.form.unit_production = that.unit_production
				that.form.unit_sample = that.unit_sample
				console.log(that.form)
				const result = await this.$http.post('saveSample', this.form)
				if (result.data.code == 0) {
					// that.form.sample_id = result.data.data.id
					this.$message({
						type: 'success',
						message: '提交抽样单成功!'
						
					});
				}
			},
			// 返回
			back() {
				var that = this
				console.log(that.task_id)
				this.$router.push({
					name: 'setTaskcd',
					params: {
						id: that.task_id
					}
				})
			}
		},
	}
</script>

<style lang="less" scoped>
	.form {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-content: flex-start;
	}

	.el-descriptions {
		width: 80%;
		margin: auto;
	}

	/deep/ .el-descriptions__title {
		margin: auto;
		font-size: 1.25rem;
		// font-weight: 31.25rem !important;
	}
	.btn{
		margin-top:20px ;
		// float: right;
		text-align: center;
	}
	/deep/ #sampleReport{
		.el-descriptions-item__label.is-bordered-label{
		width: 15rem;}
	}
</style>
