<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请人" prop="applyName">
        <el-input
          v-model="queryParams.applyName"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人电话" prop="applyPhone">
        <el-input
          v-model="queryParams.applyPhone"
          placeholder="请输入申请人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="applyDate">
        <el-date-picker clearable
                        v-model="queryParams.applyDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="心愿标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入心愿标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认领人" prop="rlName">
        <el-input
          v-model="queryParams.rlName"
          placeholder="请输入认领人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认领人电话" prop="rlPhone">
        <el-input
          v-model="queryParams.rlPhone"
          placeholder="请输入认领人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认领人居民id" prop="rlId">
        <el-input
          v-model="queryParams.rlId"
          placeholder="请输入认领人居民id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核部门" prop="auditDept">
        <el-input
          v-model="queryParams.auditDept"
          placeholder="请输入审核部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核部门id" prop="auditDeptid">
        <el-input
          v-model="queryParams.auditDeptid"
          placeholder="请输入审核部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人" prop="auditName">
        <el-input
          v-model="queryParams.auditName"
          placeholder="请输入审核人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核结果" prop="auditResult">
        <el-input
          v-model="queryParams.auditResult"
          placeholder="请输入审核结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核原因" prop="auditReason">
        <el-input
          v-model="queryParams.auditReason"
          placeholder="请输入审核原因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人网格" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入申请人网格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入申请人部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入创建者ID"
          clearable
          @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="['szxc:wish: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="['szxc:wish: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="['szxc:wish:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['szxc:wish:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="wishList" @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="applyName" />
      <el-table-column label="申请人电话" align="center" prop="applyPhone" />
      <el-table-column label="申请时间" align="center" prop="applyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="心愿标题" align="center" prop="title" />
      <el-table-column label="心愿类型" align="center" prop="wishType" />
      <el-table-column label="心愿描述" align="center" prop="wishDescrib" />
      <el-table-column label="心愿状态" align="center" prop="wishStatus" />
      <el-table-column label="认领人" align="center" prop="rlName" />
      <el-table-column label="认领人电话" align="center" prop="rlPhone" />
      <el-table-column label="认领人居民id" align="center" prop="rlId" />
      <el-table-column label="审核部门" align="center" prop="auditDept" />
      <el-table-column label="审核部门id" align="center" prop="auditDeptid" />
      <el-table-column label="审核人" align="center" prop="auditName" />
      <el-table-column label="审核结果" align="center" prop="auditResult" />
      <el-table-column label="审核原因" align="center" prop="auditReason" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="申请人网格" align="center" prop="deptName" />
      <el-table-column label="申请人部门id" align="center" prop="deptId" />
      <el-table-column label="创建者ID" align="center" prop="userId" />
      <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="['szxc:wish:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['szxc:wish: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="applyName">
          <el-input v-model="form.applyName" placeholder="请输入申请人" />
        </el-form-item>
        <el-form-item label="申请人电话" prop="applyPhone">
          <el-input v-model="form.applyPhone" placeholder="请输入申请人电话" />
        </el-form-item>
        <el-form-item label="申请时间" prop="applyDate">
          <el-date-picker clearable
                          v-model="form.applyDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="心愿标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入心愿标题" />
        </el-form-item>
        <el-form-item label="心愿描述" prop="wishDescrib">
          <el-input v-model="form.wishDescrib" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="认领人" prop="rlName">
          <el-input v-model="form.rlName" placeholder="请输入认领人" />
        </el-form-item>
        <el-form-item label="认领人电话" prop="rlPhone">
          <el-input v-model="form.rlPhone" placeholder="请输入认领人电话" />
        </el-form-item>
        <el-form-item label="认领人居民id" prop="rlId">
          <el-input v-model="form.rlId" placeholder="请输入认领人居民id" />
        </el-form-item>
        <el-form-item label="审核部门" prop="auditDept">
          <el-input v-model="form.auditDept" placeholder="请输入审核部门" />
        </el-form-item>
        <el-form-item label="审核部门id" prop="auditDeptid">
          <el-input v-model="form.auditDeptid" placeholder="请输入审核部门id" />
        </el-form-item>
        <el-form-item label="审核人" prop="auditName">
          <el-input v-model="form.auditName" placeholder="请输入审核人" />
        </el-form-item>
        <el-form-item label="审核结果" prop="auditResult">
          <el-input v-model="form.auditResult" placeholder="请输入审核结果" />
        </el-form-item>
        <el-form-item label="审核原因" prop="auditReason">
          <el-input v-model="form.auditReason" placeholder="请输入审核原因" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="申请人网格" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入申请人网格" />
        </el-form-item>
        <el-form-item label="申请人部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入申请人部门id" />
        </el-form-item>
        <el-form-item label="创建者ID" prop="userId">
          <el-input v-model="form.userId" 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 { listWish, getWish, delWish, addWish, updateWish } from "@/api/szxc/wish";

  export default {
    name: "Wish",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 心愿管理表格数据
        wishList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          applyName: null,
          applyPhone: null,
          applyDate: null,
          title: null,
          wishType: null,
          wishDescrib: null,
          wishStatus: null,
          rlName: null,
          rlPhone: null,
          rlId: null,
          auditDept: null,
          auditDeptid: null,
          auditName: null,
          auditResult: null,
          auditReason: null,
          deptName: null,
          deptId: null,
          userId: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询心愿管理列表 */
      getList() {
        this.loading = true;
        listWish(this.queryParams).then(response => {
          this.wishList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          applyName: null,
          applyPhone: null,
          applyDate: null,
          title: null,
          wishType: null,
          wishDescrib: null,
          wishStatus: null,
          rlName: null,
          rlPhone: null,
          rlId: null,
          auditDept: null,
          auditDeptid: null,
          auditName: null,
          auditResult: null,
          auditReason: null,
          remark: null,
          deptName: null,
          deptId: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          userId: 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
        getWish(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) {
              updateWish(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addWish(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 delWish(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('szxc/wish/export', {
          ...this.queryParams
        }, `wish_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
