<template>
  <!--收件箱列表-->
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit-outline"
          size="small"
          :disabled="single"
          @click="replyinfo"
        >回复</el-button>
      </el-col>
      <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="mailTheme">
            <el-input
              v-model="queryParams.mailTheme"
              placeholder="请输入邮件主题"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="阅读状态" prop="readFlag">
            <el-select v-model="queryParams.readFlag" placeholder="阅读状态">
              <el-option label="已读" value="1"></el-option>
              <el-option label="未读" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态" prop="status" v-show="false">
            <el-input
              value="1"
              v-model="queryParams.status"
              clearable
              size="small"
            />
          </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="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="阅读状态" width="130" align="center" prop="readFlag">
        <template slot-scope="scope">
<!--          {{scope.row}}-->
          <el-tag type="danger" v-if="scope.row.readFlag === '0'">未读</el-tag>
          <el-tag type="success" v-if="scope.row.readFlag === '1'">已读</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="发件人" width="180" align="center" prop="senderName">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark"  placement="top">
            <div slot="content">{{scope.row.senderAccount}}</div>
            <span>{{scope.row.senderName}}</span>
          </el-tooltip>
        </template>

      </el-table-column>
      <el-table-column label="邮件主题" align="center" prop="mailTheme" />
      <!--<el-table-column label="收件人-账号" align="center" prop="receiverAccount" />-->
      <el-table-column label="收件人" align="center" prop="receiverName" v-if="receiverAccount != 'admin'" />
      <el-table-column label="接收时间" width="180" align="center" prop="readTime"/>
      <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="handleUpdate(scope.row)"
          >详情</el-button>
          <el-button v-if="scope.row.senderAccount != 'admin'"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
          <!--<reply></reply>-->
          <!--<router-link to="/replyinfo">User</router-link>-->
        </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 {list1, listDetail, getDetail, delDetail, addDetail, updateDetail, exportDetail } from "@/api/system/email/detail";


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

      // 回复跳转
      replyinfo(row){
        const mailDetailGuid = row.mailDetailGuid || this.ids
        const senderName = row.senderName || this.names

        // const replyname = row.senderName || this.ids

        // this.$router.push({path:"/Emile/receiveList/replyinfo",query:{alert:"页面跳转成功"}})

        this.$router.push({path:'/email/receiveList/replyinfo',query: {id:mailDetailGuid }})
      },

      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listDetail(this.queryParams).then(response => {
          this.detailList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getList1() {
        this.loading = true;
        list1(this.queryParams).then(response => {
          this.detailList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.getList();
      },
      // 表单重置
      reset() {
        this.form = {
          mailDetailGuid: undefined,
          mailGuid: undefined,
          receiverName: undefined,
          receiverAccount: undefined,
          readFlag: undefined,
          readTime: undefined,
          status: "0",
          deleteTime: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList1();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        // this.handleQuery();
        this.getList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.mailDetailGuid)
        this.flgs = selection.map(item => item.flg)
        this.names = selection.map(item => item.senderName)
        this.single = selection.length!=1
        this.single1 = selection.length!=1
        this.multiple = !selection.length
        this.multiple1 = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const mailDetailGuid = row.mailDetailGuid || this.ids
          console.log(mailDetailGuid);
          this.$router.push({path:'/email/receiveList/receiptdetails',query: {id:mailDetailGuid }})
        getDetail(mailDetailGuid).then(response => {
          // this.form = response.data;
          this.form = response.data[0];
          console.log(response.data);
          // this.open = true;
          // this.title = "修改【请填写功能名称】";
        });
        this.getList1();
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.mailDetailGuid != undefined) {
              updateDetail(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addDetail(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const mailDetailGuids = row.mailDetailGuid || this.ids;
        const flg = row.flg || this.ids;
        let len = flg.length;
        this.$confirm('是否确认删除这' + len + '封邮件?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(mailDetailGuids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
    }
  };
</script>
