<template>
  <!--草稿箱列表-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate1"
          v-hasPermi="['system:info:edit']"
        >修改</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="creataTime">-->
            <!--<el-date-picker clearable size="small" style="width: 200px"-->
                            <!--v-model="queryParams.creataTime"-->
                            <!--type="date"-->
                            <!--value-format="yyyy-MM-dd"-->
                            <!--placeholder="选择创建时间">-->
            <!--</el-date-picker>-->
          <!--</el-form-item>-->
          <el-form-item label="创建时间" prop="creataTime">
            <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="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0">草稿</el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column label="发件人-中文" align="center" prop="senderName" />-->
<!--      <el-table-column label="发件人-账号" align="center" prop="senderAccount" />-->
      <el-table-column label="收件人" width="180" 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="创建时间" width="180" align="center" prop="createTime" >
<!--        <template slot-scope="scope">-->
<!--          <span>{{scope.row.createTime | format('yyyy-MM-dd hh:mm')}}</span>-->
<!--        </template>-->
      </el-table-column>
      <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-edit"
            @click="handleUpdate1(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 { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/system/email/caogao";

  export default {
    name: "Caogao",
    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 => {
          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/draftList/draftinfo',query: {id:mailGuid }})
        getInfo(mailGuid).then(response => {
          this.form = response.data;
          // this.open = true;
          // this.title = "修改";
        });
      },
      /** 删除按钮操作 */
      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() {});
      },
    }
  };
</script>
