<template>
  <div class="app-container">

    <!--    搜索-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="收件人" prop="recvperson">
        <el-input
          v-model="queryParams.recvperson"
          placeholder="请输入收件人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发送时间" prop="sendtime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.startime"
                        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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </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="通知标题" align="center" prop="title" />
      <el-table-column label="接收主体" align="center" prop="deptflg" width="180" />
      <el-table-column label="收件人" align="center" prop="recvPerson" />
      <el-table-column label="发送时间" align="center" prop="sendtime" width="180">
        <!--        <template slot-scope="scope">-->
        <!--          <span>{{ parseTime(scope.row.sendtime, '{y}-{m}-{d}') }}</span>-->
        <!--        </template>-->
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handlexx(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="qsxq(scope.row)"
          >签收详情</el-button>
          <el-button
            size="mini"
            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"
    />



    <!-- 签收详情 -->
    <el-dialog :title="qstitle" :visible.sync="qsshow" width="1000px" append-to-body>
      <el-table :data="listqs" v-loading="qsloading">
        <el-table-column label="签收人/部门" align="center" prop="recvperson" />
        <el-table-column label="签收状态" align="center" prop="recvstatus" >
          <template slot-scope="scope">
            <span v-if="scope.row.recvstatus==1">已签收</span>
            <span v-else>未签收</span>
          </template>
        </el-table-column>
        <el-table-column label="签收时间" align="center" prop="recvtime" width="180">
          <!--          <template slot-scope="scope">-->
          <!--            <span>{{ parseTime(scope.row.recvtime, '{y}-{m}-{d}') }}</span>-->
          <!--          </template>-->
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 通知详情 -->
    <el-dialog :title="tztitle" :visible.sync="tzshow" width="1000px" append-to-body>
      <el-form :model="form" label-width="100px"  v-loading="xxloading">
        <el-form-item label="通知标题：">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="通知内容：">
          <div v-html="form.content" style="border: 1px solid #e5e5e5;border-radius: 4px;"></div>
        </el-form-item>
        <el-form-item label="附件列表：">
          <div v-html="form.fj" style="border: 1px solid #e5e5e5;border-radius: 4px;">{{form.fj}}</div>
        </el-form-item>
        <el-form-item label="发送时间：">
          <el-input v-model="form.sendtime"></el-input>
        </el-form-item>
        <el-form-item label="联系人：">
          <el-input v-model="form.contactperson"></el-input>
        </el-form-item>
        <el-form-item label="联系电话：">
          <el-input v-model="form.contacttel"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listInfo, delInfo, exportInfo,qslist } from "@/api/system/notify_info/list";
  import { xxInfo } from "@/api/system/notify_info/mylist";

  export default {
    name: "Info",
    data() {
      return {
        // 遮罩层
        loading: true,
        qsloading:true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        infoList: [],
        listqs:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        qsshow: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderByColumn:"id",//排序字段
          isAsc:"desc",//排序方式
          guid: undefined,
          title: undefined,
          content: undefined,
          sendtime: undefined,
          sendstatus: undefined,
          sendaccount: undefined,
          sendperson: undefined,
          deptflg: undefined,
          filename: undefined,
          filepath: undefined,
          contactperson: undefined,
          contacttel: undefined,
          recvperson: undefined,
          endtime:'',
          startime:'',
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          guid: [
            { required: true, message: "收件人不能为空", trigger: "blur" }
          ],
        },
        qstitle:'签收详情',
        tztitle:"通知详情",
        tzshow:false,
        xxloading:true,
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          let datas=this.infoList;
          for (let i = 0; i <datas.length; i++) {
            if (datas[i].deptflg=="部门"){
              //  alert("asd")
              var a=datas[i].recvPerson.split(",");
              for (let b=0;b<a.length;b++){
                if (a.length>4){
                  //console.log(a[b].substring(0,4))
                   datas[i].recvPerson=a[0]+a[1]+a[2]+"..."
                  console.log(datas[i].recvPerson)
                }
              }

            }
          }
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.qsshow = false;
        this.tzshow=false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          guid: undefined,
          title: undefined,
          content: undefined,
          sendtime: undefined,
          sendstatus: "0",
          sendaccount: undefined,
          sendperson: undefined,
          deptflg: undefined,
          filename: undefined,
          filepath: undefined,
          contactperson: undefined,
          contacttel: undefined,
          recvperson: 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.id)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },

      qsxq(row){
        this.qsloading = true;
        this.qsshow=true;
        qslist(row.id).then(response => {
          //debugger;
          this.listqs = response.data;
          this.qsloading = false;
        });
      },

      //通知详细
      handlexx(row) {
        this.reset();
        this.tzshow=true;
        this.xxloading=true;
        xxInfo(row.id).then(response => {
          //debugger;
          this.form.title = response.data.title;
          this.form.content = response.data.content;
          this.form.sendtime = response.data.sendtime;
          this.form.contactperson = response.data.contactperson;
          this.form.contacttel = response.data.contacttel;
          this.form.fj = "";
          let fjname=response.data.filename.split(",");
          let fjpath=response.data.filepath.split(",");
          for (let i = 0; i <fjname.length ; i++) {
            this.form.fj+="<a href='"+process.env.VUE_APP_BASE_API+fjpath[i]+"' target='_blank'>"+fjname[i]+'</a><br/>';
          }
        });
        this.xxloading=false;
      },

      /** 删除按钮操作 */
      handleDelete(row) {
        //debugger;
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除通知?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(ids);
        }).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>
