<template>
  <div
    class="hd-rect-suggest-wrapper"
  >
    <div class="hd-rect-suggest-tools-wrapper">
      <el-button type="primary" @click="createRectSuggest">新增</el-button>
      <el-button type="warning" @click="updateRectSuggest">修改</el-button>
      <el-button type="danger" @click="delRectSuggest">删除</el-button>
    </div>
    <div class="hd-rect-suggest-content-wrapper">
      <el-table
        :data="hdRectSuggesetTableData"
        border
        @selection-change="handleSelectionChange"        
      >
        <el-table-column
          type="selection"
          width="55"
        ></el-table-column>
        <el-table-column
          prop="hddiscover"
          label="问题"
          width="240"
        ></el-table-column>
        <el-table-column
          prop="hdrectsuggest"
          label="整改建议"
        ></el-table-column>
      </el-table>
    </div>
    <el-dialog
      title="添加整改建议"
      :visible.sync="addDialogVisible"
      width="50%"
    >
      <el-form
        ref="addform"
        :model="addFormInfo"
        label-width="80px"
        :rules="addFormRules"
        v-if="addDialogVisible"
      >
        <el-form-item
          prop="hddiscover"
          label="发现问题"
        >
          <el-select
            v-model="addFormInfo.hddiscover"
          >
            <el-option
              v-for="item in hdDiscovers"
              :key="item.id"
              :label="item.hddiscover"
              :value="item.hddiscover"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="hdrectsuggest"
          label="整改建议"
        >
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            maxlength="500"
            v-model="addFormInfo.hdrectsuggest">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="info" @click="cancelAddForm">取消</el-button>
        <el-button type="primary" @click="submitAddForm">新增</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="编辑整改建议"
      :visible.sync="editDialogVisible"
    >
      <el-form
        ref="editform"
        :model="editFormInfo"
        label-width="80px"
        :rules="editFormRules"
        v-if="editDialogVisible"
      >
        <el-form-item
          prop="hddiscover"
          label="发现问题"
        >
          <el-select
            v-model="editFormInfo.hddiscover"
          >
            <el-option
              v-for="item in hdDiscovers"
              :key="item.id"
              :label="item.hddiscover"
              :value="item.hddiscover"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          prop="hdrectsuggest"
          label="整改建议"
        >
          <el-input
            type="textarea"
            autosize
            placeholder="请输入内容"
            maxlength="500"
            v-model="editFormInfo.hdrectsuggest">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="info" @click="cancelEditForm">取消</el-button>
        <el-button type="primary" @click="submitEditForm">新增</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hdRectSuggesetTableData: [
        {
          hddiscover: '问题1',
          hddiscoverId: 1,
          hdrectsuggest: '整改建议1',
          hdrectsuggestId: 1
        },
        {
          hddiscover: '问题2',
          hddiscoverId: 2,
          hdrectsuggest: '整改建议2',
          hdrectsuggestId: 2
        },
        {
          hddiscover: '问题3',
          hddiscoverId: 3,
          hdrectsuggest: '整改建议3',
          hdrectsuggestId: 3
        }
      ],
      multiSelection: [],
      hdDiscovers: [
        {
          id: 1,
          hddiscover: '发现问题1'
        },
        {
          id: 2,
          hddiscover: '发现问题2'
        },
        {
          id: 3,
          hddiscover: '发现问题3'
        }
      ],
      addDialogVisible: false,
      addFormInfo: {
        hddiscover: '',
        hddiscoverId: -1,
        hdrectsuggest: ''
      },
      addFormRules: {
        hddiscover: [
          {
            required: true,
            message: '请输入发现问题',
            trigger: 'change'
          }
        ],
        hdrectsuggest: [
          {
            required: true,
            message: '请输入整改建议',
            trigger: 'blur'
          }
        ]
      },
      editDialogVisible: false,
      editFormInfo: {
        hddiscover: '',
        hddiscoverId: -1,
        hdrectsuggest: '',
        hdrectsuggestId: -1
      },
      editFormRules: {
        hddiscover: [
          {
            required: true,
            message: '请输入发现问题',
            trigger: 'change'
          }
        ],
        hdrectsuggest: [
          {
            required: true,
            message: '请输入整改建议',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multiSelection = val
    },
    createRectSuggest() {
      this.addDialogVisible = true
    },
    updateRectSuggest() {
      this.editDialogVisible = true
    },
    delRectSuggest() {
      this.$confirm('此操作将删除所选项, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // axios
      }).catch(() => {
        // 取消删除
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    cancelAddForm() {
      this.addDialogVisible = false
    },
    submitAddForm() {
      this.$refs.addform.validate((valid) => {
        if(valid) {}
      })
    },
    cancelEditForm() {
      this.editDialogVisible = false
    },
    submitEditForm() {
      this.$refs.editform.validate((valid) => {
        if (valid) {}
      })
    }
  }
}
</script>

<style lang="scss">
  .hd-rect-suggest-wrapper {
    width: 80%;
    margin: 30px auto;
    padding: 30px;
    border-radius: 30px;
    box-shadow: 0 0 9px 1px #eee;
    .hd-rect-suggest-tools-wrapper {
      width: 80%;
      margin: 30px auto;
      padding: 20px;
      border-radius: 20px;
      box-shadow: 0 0 9px 1px #eee;
    }
    .hd-rect-suggest-content-wrapper {
      width: 80%;
      margin: 30px auto;
      padding: 20px;
      border-radius: 20px;
      box-shadow: 0 0 9px 1px #eee;
    }
  }
</style>