<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="谈心人员" prop="talkPeople">
        <el-input
          v-model="queryParams.talkPeople"
          placeholder="请输入谈心人员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="unitName">
        <el-input
          v-model="queryParams.unitName"
          placeholder="请输入单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位id" prop="unitId">
        <el-input
          v-model="queryParams.unitId"
          placeholder="请输入单位id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="谈心对象" prop="talkObject">
        <el-input
          v-model="queryParams.talkObject"
          placeholder="请输入谈心对象"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="谈心对象id" prop="talkObjectId">
        <el-input
          v-model="queryParams.talkObjectId"
          placeholder="请输入谈心对象id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建人姓名" prop="createName">
        <el-input
          v-model="queryParams.createName"
          placeholder="请输入创建人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人id" prop="createId">
        <el-input
          v-model="queryParams.createId"
          placeholder="请输入创建人id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件路径" prop="filePath">
        <el-input
          v-model="queryParams.filePath"
          placeholder="请输入文件路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="谈话时间" prop="talkTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.talkTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择谈话时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="谈话地点" prop="talkAddress">
        <el-input
          v-model="queryParams.talkAddress"
          placeholder="请输入谈话地点"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录人" prop="recorder">
        <el-input
          v-model="queryParams.recorder"
          placeholder="请输入记录人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录人id" prop="recorderId">
        <el-input
          v-model="queryParams.recorderId"
          placeholder="请输入记录人id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['thought:talk:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['thought:talk:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['thought:talk:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['thought:talk:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="talkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="谈心人员" align="center" prop="talkPeople" />
      <el-table-column label="单位名称" align="center" prop="unitName" />
      <el-table-column label="单位id" align="center" prop="unitId" />
      <el-table-column label="谈心对象" align="center" prop="talkObject" />
      <el-table-column label="谈心对象id" align="center" prop="talkObjectId" />
      <el-table-column label="开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人姓名" align="center" prop="createName" />
      <el-table-column label="创建人id" align="center" prop="createId" />
      <el-table-column label="文件路径" align="center" prop="filePath" />
      <el-table-column label="文件名称" align="center" prop="fileName" />
      <el-table-column label="谈话内容" align="center" prop="talkContent" />
      <el-table-column label="谈话时间" align="center" prop="talkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.talkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="谈话地点" align="center" prop="talkAddress" />
      <el-table-column label="记录人" align="center" prop="recorder" />
      <el-table-column label="记录人id" align="center" prop="recorderId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['thought:talk:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['thought:talk:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改谈心记录卡对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="谈心人员" prop="talkPeople">
          <el-input v-model="form.talkPeople" placeholder="请输入谈心人员" />
        </el-form-item>
        <el-form-item label="单位名称" prop="unitName">
          <el-input v-model="form.unitName" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="单位id" prop="unitId">
          <el-input v-model="form.unitId" placeholder="请输入单位id" />
        </el-form-item>
        <el-form-item label="谈心对象" prop="talkObject">
          <el-input v-model="form.talkObject" placeholder="请输入谈心对象" />
        </el-form-item>
        <el-form-item label="谈心对象id" prop="talkObjectId">
          <el-input v-model="form.talkObjectId" placeholder="请输入谈心对象id" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable size="small"
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker clearable size="small"
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人姓名" prop="createName">
          <el-input v-model="form.createName" placeholder="请输入创建人姓名" />
        </el-form-item>
        <el-form-item label="创建人id" prop="createId">
          <el-input v-model="form.createId" placeholder="请输入创建人id" />
        </el-form-item>
        <el-form-item label="文件路径" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入文件路径" />
        </el-form-item>
        <el-form-item label="文件名称" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名称" />
        </el-form-item>
        <el-form-item label="谈话内容">
          <editor v-model="form.talkContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="谈话时间" prop="talkTime">
          <el-date-picker clearable size="small"
            v-model="form.talkTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择谈话时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="谈话地点" prop="talkAddress">
          <el-input v-model="form.talkAddress" placeholder="请输入谈话地点" />
        </el-form-item>
        <el-form-item label="记录人" prop="recorder">
          <el-input v-model="form.recorder" placeholder="请输入记录人" />
        </el-form-item>
        <el-form-item label="记录人id" prop="recorderId">
          <el-input v-model="form.recorderId" placeholder="请输入记录人id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTalk, getTalk, delTalk, addTalk, updateTalk, exportTalk } from "@/api/thought/talk";

export default {
  name: "Talk",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 谈心记录卡表格数据
      talkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        talkPeople: null,
        unitName: null,
        unitId: null,
        talkObject: null,
        talkObjectId: null,
        startTime: null,
        endTime: null,
        createName: null,
        createId: null,
        filePath: null,
        fileName: null,
        talkContent: null,
        talkTime: null,
        talkAddress: null,
        recorder: null,
        recorderId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询谈心记录卡列表 */
    getList() {
      this.loading = true;
      listTalk(this.queryParams).then(response => {
        this.talkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        talkPeople: null,
        unitName: null,
        unitId: null,
        talkObject: null,
        talkObjectId: null,
        startTime: null,
        endTime: null,
        createTime: null,
        updateTime: null,
        createName: null,
        createId: null,
        filePath: null,
        fileName: null,
        talkContent: null,
        talkTime: null,
        talkAddress: null,
        recorder: null,
        recorderId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加谈心记录卡";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTalk(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改谈心记录卡";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTalk(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTalk(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除谈心记录卡编号为"' + ids + '"的数据项？').then(function() {
        return delTalk(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有谈心记录卡数据项？').then(() => {
        this.exportLoading = true;
        return exportTalk(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
