<template>
  <!--发件箱列表-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
        >删除</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="receiverName">
            <el-input
              v-model="queryParams.receiverName"
              placeholder="请输入收件人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <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="receiverAccount">
            <el-input
              v-model="queryParams.receiverAccount"
              placeholder="请输入收件邮箱"
              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-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="status">
          <template slot-scope="scope">
<!--            {{scope.row}}-->
            <el-tag v-if="scope.row.status === 0">草稿</el-tag>
            <el-tag v-else-if="scope.row.status === 1" type="success">发送</el-tag>
            <el-tag  v-else="scope.row.status === -1" type="info">删除</el-tag>
          </template>
        </el-table-column>
      <el-table-column class="apple" label="收件人" width="180" align="center" prop="receiverName" >
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark"  placement="top">
            <div slot="content">{{scope.row.receiverAccount}}</div>
            <span>{{scope.row.receiverName}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
<!--      <el-table-column label="收件人-账号" align="center" prop="receiverAccount" />-->
      <el-table-column sortable label="邮件主题" align="center" prop="mailTheme" />
<!--      <el-table-column label="邮件详细内容" align="center" prop="mailContent" />-->
      <el-table-column sortable label="发送时间" align="center" prop="createTime" width="180" value-format="yyyy-MM-dd"/>
      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small" type="text"
            icon="el-icon-document"
            @click="handleUpdate1(scope.row)"
          >详情</el-button>
          <el-button
            size="small" type="text"
            icon="el-icon-delete"
            @click="handleDelete(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"
      @pagination="getList"
    />

  </div>
</template>

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

        openda(){
            this.open1 = false;
        },
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listInfo(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
        getInfo(mailGuid).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "邮件详情";
        });
      },
        handleUpdate1(row) {
            this.reset();
            const mailGuid = row.mailGuid || this.ids
          this.$router.push({path:'/email/sendList/senddetails',query: {id:mailGuid }})
            getInfo(mailGuid).then(response => {
                this.form = response.data;
                // this.open1 = true;
                this.title = "修改【请填写功能名称】";
            });
        },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.mailGuid != undefined) {
              updateInfo(this.form).then(response => {
                if (response.code === 200) {
                  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);
        }).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>

<style lang="less" scoped>
  .apple{
    width: 150px;
    overflow :hidden;
    white-space :nowrap;
    text-overflow: ellipsis;
  }

</style>
