<!--
 * @Author: zhp
 * @Date: 2024-07-18 14:56:21
 * @LastEditTime: 2024-07-23 13:47:57
 * @LastEditors: zhp
 * @Description:
-->
<template>
  <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="auto">
    <el-row :gutter="24">
      <el-col :span="24">
        <el-form-item label="巡检项目" prop="program">
          <el-input v-model="dataForm.program" placeholder="请输入保养项目" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="24">
        <el-form-item label="默认巡检结果" prop="resultType">
          <el-select v-model="dataForm.resultType" placeholder="请选择默认保养结果" @change="handleClear">
            <el-option v-for="dict in resultList" :key="dict.id" :label="dict.name" :value="dict.id" />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-if="dataForm.resultType === 0" :gutter="24">
      <el-col :span="24">
        <el-form-item prop="checkResult">
          <el-input v-model="dataForm.checkResult" placeholder="请输入文本内容" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-else-if="dataForm.resultType === 1" :gutter="24">
      <el-col :span="24">
        <el-form-item prop="checkResult">
          <el-input oninput="value=value.replace(/[^\-\d.]/g, '')" v-model="dataForm.checkResult" placeholder="请输入数值" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-else-if="dataForm.resultType === 2" :gutter="24">
      <el-col :span="11">
        <el-form-item prop="minValue">
          <el-input oninput="value=value.replace(/[^\-\d.]/g, '')" v-model="dataForm.minValue" placeholder="请输入最小值" />
        </el-form-item>
      </el-col>
      <el-col :span="4">
        —————
      </el-col>
      <el-col :span="9">
        <el-form-item prop="maxValue" label-width="20">
          <el-input @change="handleChange" oninput="value=value.replace(/[^\-\d.]/g, '')" v-model="dataForm.maxValue"
            placeholder="请输入最大值" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import basicAdd from './basic-add';
import {
  createItemData,
  getItemData,
  updateItemData
} from '@/api/equipment/base/inspection/items';
import { getList,} from "@/api/base/qualityScrapType";

// import { getMaterialList } from "@/api/base/material";

export default {
	mixins: [basicAdd],
	data() {
		return {
			urlOptions: {
        createURL: createItemData,
        updateURL: updateItemData,
        infoURL: getItemData,
      },
      typeList: [],
      resultList: [
        {
          id: 0,
          name:'文本'
        },
        {
          id: 1,
          name: '单一数值'
        },
        {
          id: 2,
          name: '数值范围'
        }
      ],
			dataForm: {
        id: undefined,
        program: undefined,
        resultType: undefined,
        equipmentTypeId: undefined,
        minValue: undefined,
        maxValue: undefined,
        checkResult:undefined,
			},
			// materialList: [],
			dataRule: {
				// materialId: [{ required: true, message: "", trigger: "blur" }],
        program: [{ required: true, message: "巡检项目不能为空", trigger: "blur" }],
        checkResult: [{ required: true, message: "默认巡检结果不能为空", trigger: "blur" }],
        minValue: [{ required: true, message: "最小值不能为空", trigger: "blur" }],
        maxValue: [{ required: true, message: "最大值不能为空", trigger: "blur" }],

        // typeId: [{ required: true, message: "报废类型不能为空", trigger: "change" }],
      }
		};
	},
	mounted() {
		this.getDict()
		console.log('我看看', this.dataForm)
	},
  methods: {
    handleClear() {
      this.dataForm.minValue = undefined
      this.dataForm.maxValue = undefined
      this.dataForm.maintainResult = undefined
    },
		async getDict() {
			// 物料列表
      const res = await getList();
			this.typeList = res.data;
    },
    handleChange(val) {
      if (val && this.dataForm.maxValue) {
        if (parseFloat(this.dataForm.minValue) >= parseFloat(val)) {
          return this.$message({
            message: '最小值不能大于最大值',
            type: 'warning'
          });
        }
      }
    }
		// setMaterialCode() {
		// 	const chooseM = this.materialList.filter(item => {
		// 		return item.id === this.dataForm.materialId
		// 	})
		// 	this.dataForm.materialCode = chooseM[0].code
		// }
	},
};
</script>
