<template>
  <div class="app-container">
    <el-form v-model="queryParams" :inline="true">
      <el-form-item label="点位编码" label-width="80px">
        <el-input placeholder="请输入点位编码"></el-input>
      </el-form-item>
      <el-form-item label="点位名称" label-width="80px">
        <el-input placeholder="请输入点位名称"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
          size="mini"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery" size="mini"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          plain
          size="mini"
          @click="add"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" icon="el-icon-edit" plain size="mini"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" plain size="mini"
          >删除</el-button
        >
      </el-col>
    </el-row>
    <el-table :data="tableData" style="width: 100%; margin-bottom: 20px">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column prop="date" label="点位编码" align="center">
      </el-table-column>
      <el-table-column prop="date" label="点位名称" align="center">
      </el-table-column>
      <el-table-column label="智能识别类型" align="center">
        <template slot-scope="scope">
          <span @click="tableTyle()" class="intelligenceType">11111</span>
        </template>
      </el-table-column>
      <el-table-column prop="date" label="巡检内容" align="center">
      </el-table-column>
      <el-table-column prop="date" label="用途" align="center">
      </el-table-column>
      <el-table-column prop="address" label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
    />

    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form v-model="dialogForm">
        <el-form-item label="点位编码" label-width="100px">
          <el-input placeholder="请输入点位编码"></el-input>
        </el-form-item>
        <el-form-item label="点位名称" label-width="100px">
          <el-input placeholder="请输入点位名称"></el-input>
        </el-form-item>
        <el-form-item label="主设备类型ID" label-width="100px">
          <el-input placeholder="请输入主设备类型ID"></el-input>
        </el-form-item>
        <el-form-item label="主设备id" label-width="100px">
          <el-input placeholder="请输入主设备id"></el-input>
        </el-form-item>
        <el-form-item
          label="设备id，真正配置点位的主设备id或者部件id"
          label-width="100px"
        >
          <el-input
            placeholder="设备id，真正配置点位的主设备id或者部件id"
          ></el-input>
        </el-form-item>
        <el-form-item label="巡检内容" label-width="100px">
          <Editor :height="200" />
        </el-form-item>
        <el-form-item label="用途" label-width="100px">
          <el-input placeholder="请输入用途"></el-input>
        </el-form-item>
        <el-form-item label="删除标志，0：正常；2：删除" label-width="100px">
          <el-input placeholder="删除标志，0：正常；2：删除"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      :title="typeTitle"
      :visible.sync="typedialogVisible"
      width="50%"
      :before-close="typehandleClose"
    >
      <el-table
        :data="tableData"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        row-key="id"
        height="500px"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column type="index" label="序号" width="55" align="center" />
        <el-table-column label="算法名称"  prop="name" />
        <el-table-column
          label="阀值上限"
          align="center"
          prop="name"
          :render-header="addRedStar"
        >
          <template slot-scope="scope" v-if="scope.row.type == 0">
            <el-input v-model="scope.row.name" />
          </template>
        </el-table-column>
        <el-table-column
          label="阀值下限"
          align="center"
          :render-header="addRedStar"
          prop="name"
        >
          <template slot-scope="scope"  v-if="scope.row.type == 0">
            <el-input v-model="scope.row.name" />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
// import Editor from "@/components/Editor";
export default {
  data() {
    return {
      queryParams: {},
      tableData: [
        {
          id: 1,
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          type:0
        },
        {
          id: 2,
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          id: 3,
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
          children: [
            {
              id: 31,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
            {
              id: 32,
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄",
            },
          ],
        },
        {
          id: 4,
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      total: 10,
      dialogVisible: false,
      title: "添加巡检点位",
      typeTitle: "设置智能识别类型",
      typedialogVisible: false,
    };
  },
  mounted() {},
  methods: {
    // 给表头加必填符号*
    addRedStar(h, { column }) {
      return [
        h("span", { style: "color: red" }, "*"),
        h("span", " " + column.label),
      ];
    },
    add(){
      this.dialogVisible = true;
    },
    tableTyle() {
      this.typedialogVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.intelligenceType {
  cursor: pointer;
  color: #409eff;
}
</style>
