<template>
  <!--回收站列表-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-refresh-right"
          size="small"
          :disabled="single"
          @click="submitForm"
        >撤销</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

          <el-form-item label="邮件主题" prop="mailTheme">
            <el-input
              v-model="queryParams.mailTheme"
              placeholder="请输入邮件主题"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="删除时间" prop="deleteTime">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="queryParams.beginTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择开始时间">
            </el-date-picker>
            至
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="queryParams.endTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择结束时间">
            </el-date-picker>
          </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-col>
    </el-row>
    <el-table border v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="邮件状态" width="130" align="center" prop="flg">
        <template slot-scope="scope">
          <!--{{scope.row}}-->
          <el-tag v-if="scope.row.flg === '1'">收件</el-tag>
          <el-tag v-else-if="scope.row.flg === '0'" type="success">发件</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="发件人" width="180" align="center" prop="senderName" />
<!--      <el-table-column label="收件人" align="center" prop="receiverName" />-->
<!--      <el-table-column label="收件人-账号" align="center" prop="receiverAccount" />-->
      <el-table-column label="邮件主题" align="center" prop="mailTheme" />
<!--      <el-table-column label="邮件详细内容" align="center" prop="mailContent" />-->
      <el-table-column label="删除时间" sortable  align="center" prop="deleteTime" width="180">

      </el-table-column>
      <el-table-column label="操作" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="small"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:info:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info: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"
    />
  </div>
</template>

<script>
  import {revokers,findhs, listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/email/huishouzhan";

  export default {
    name: "Huishouzhan",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        flgs: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          senderName: undefined,
          senderAccount: undefined,
          receiverName: undefined,
          receiverAccount: undefined,
          mailTheme: undefined,
          mailContent: undefined,
          status: undefined,
          deleteTime: undefined,
          beginTime:undefined,
          endTime:undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {

      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        // listInfo(this.queryParams).then(response => {
        findhs(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          mailGuid: undefined,
          senderName: undefined,
          senderAccount: undefined,
          receiverName: undefined,
          receiverAccount: undefined,
          mailTheme: undefined,
          mailContent: undefined,
          createTime: undefined,
          status: "0",
          deleteTime: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.mailGuid)
        this.flgs = selection.map(item => item.flg)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const mailGuid = row.mailGuid || this.ids;
        const flg = row.flg || this.ids;
        console.log(mailGuid);
        getInfo(mailGuid).then(response => {

          this.form = response.data;
          console.log(response.data);
          this.open = true;
          this.title = "撤销";
        });



      },
      /** 提交按钮 */
      submitForm(row) {
        const mailGuid = row.mailGuid || this.ids;
        const flg = row.flg || this.flgs;
        revokers(mailGuid,flg).then(response => {
                    if (response.code === 200) {
                      console.log(mailGuid + "+" + flg);
                      this.msgSuccess("撤销成功");
                      // this.open = false;
                      this.getList();
                    }
                  });

        // this.$refs["form"].validate(valid => {
        //   if (valid) {
        //     if (this.form.mailGuid != undefined) {
        //       updateInfo(this.form).then(response => {
        //         if (response.code === 200) {
        //           console.log(this.form);
        //           this.msgSuccess("撤销成功");
        //           this.open = false;
        //           this.getList();
        //         }
        //       });
        //     } else {
        //       // addInfo(this.form).then(response => {
        //       //   if (response.code === 200) {
        //       //     this.msgSuccess("新增成功");
        //       //     this.open = false;
        //       //     this.getList();
        //       //   }
        //       // });
        //     }
        //   }
        // });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const mailGuids = row.mailGuid || this.ids;
        const flg = row.flg || this.ids;
        let len = flg.length;
        this.$confirm('是否确认删除这' + len + '封邮件?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(mailGuids,flg);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }
    }
  };
</script>
