<template>
  <div class="queryTemplate">
    <Search title="编辑查询模板" :isSearch="false">
      <button class="btnAner">测试</button>
      <button class="btnAn" @click="addSubmit">保存</button>
    </Search>
    <el-form
      style="margin-top: 10px"
      :inline="true"
      :model="ruleForm"
      label-width="auto"
      ref="ruleForm"
      class="demo-ruleForm"
    >
      <el-row :gutter="24" class="b24">
        <el-col :span="5">
          <el-form-item label="查询模板名称">
            <el-input
              size="medium"
              placeholder="暂无数据"
              v-model="ruleForm.queryTemplateName"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="查询协议">
            <el-select
              v-model="ruleForm.protocolID"
              placeholder="暂无数据"
              :disabled="true"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="查询模板描述">
            <el-input
              size="medium"
              placeholder="暂无数据"
              v-model="ruleForm.queryTemplateDescribe"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="查询配置" style="margin-bottom: 24px">
        <el-input
          v-model="ruleForm.queryTemplatetConfig"
          class="desc"
          type="textarea"
          resize="none"
          :autosize="{ minRows: 4, maxRows: 4 }"
          placeholder="描述内容···"
          size="small"
        />
      </el-form-item>
      <el-form-item label="查询语句">
        <el-input
          v-model="ruleForm.queryTemplate"
          class="desc"
          type="textarea"
          resize="none"
          :autosize="{ minRows: 26, maxRows: 26 }"
          placeholder="描述内容···"
          size="small"
        />
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import Search from "@/layout/components/Search/index.vue";
import { GeneralDataReception } from "@/api/dataIntegration";
export default {
  data() {
    return {
      ruleForm: {
        queryTemplateName: "",
        protocolID: 1,
        queryTemplateDescribe: "",
        queryTemplatetConfig: "",
        queryTemplate: "",
        operate: "",
      },
      options: [],
      rules: {
        queryTemplateName: [
          { required: true, message: "请输入查询模板名称", trigger: "blur" },
        ],
        protocolID: [
          { required: true, message: "请输入查询协议", trigger: "blur" },
        ],
        queryTemplateDescribe: [
          { required: true, message: "请输入查询模板描述", trigger: "blur" },
        ],
        queryTemplatetConfig: [
          { required: true, message: "请选查询配置", trigger: "change" },
        ],
        queryTemplate: [
          { required: true, message: "请选择查询语句", trigger: "change" },
        ],
      },
    };
  },
  created() {
    this.ruleForm = this.$route.query;
    this.ruleForm.operate = "2";
  },
  methods: {
    async addSubmit() {
      try {
        const res = await GeneralDataReception({
          serviceId: "20",
          dataContent: JSON.stringify(this.ruleForm),
        });
        if (res.code === "0") {
          this.$message.success(res.message ?? "成功");
          this.$router.push("/systemSettings/queryTemplate");
        } else {
          this.$message.error(res.message ?? "失败");
        }
      } catch (error) {
        console.log("错误", error);
      }
    },
  },
  components: {
    Search,
  },
};
</script>
<style lang="scss" scoped>
.queryTemplate {
  padding: 20px 30px 0 24px;
  height: 87vh;
  background: #ffffff;
  border-radius: 4px;
  .btnAner {
    width: 64px;
    height: 32px;
    background: #ffffff;
    border: 1px solid #9ebbf7;
    border-radius: 4px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #2d67e3;
    margin-right: 16px;
  }
  ::v-deep .el-form-item {
    margin-bottom: 0px;
    margin-right: 0px;
  }
  .b24 {
    ::v-deep .el-input__inner {
      height: 32px;
    }
  }
  ::v-deep .el-form-item__content {
    width: calc(100% - 96px);
  }
  ::v-deep .el-form-item {
    width: 100%;
  }
  // .desc {
  //   ::v-deep .el-input__inner {
  //     height: 96px;
  //   }
  // }
}
</style>