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

    <!--    搜索-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="发件人" prop="sendperson">
        <el-input
          v-model="queryParams.sendperson"
          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="handleqs"-->
<!--        >签收</el-button>-->
<!--      </el-col>-->
<!--    </el-row>-->

    <!--  列表  -->
    <el-table border v-loading="loading" :data="infoList">
<!--      <el-table-column type="selection" width="55" align="center" />   @selection-change="handleSelectionChange"-->
      <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="sendperson" width="180"/>
      <el-table-column label="接收时间" align="center" prop="sendtime" width="180">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.sendtime, '{yyyy}-{mm}-{dd}') }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="签收状态" align="center" prop="recvstatus" width="180">
        <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" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.recvstatus==1"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handlexx(scope.row)"
          >详情</el-button>
<!--          <div v-if="scope.row.recvstatus!=1">-->
            <el-button v-if="scope.row.recvstatus!=1"
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleqs(scope.row)"
            >签收</el-button>
<!--          </div>-->
        </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="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, qsInfo, addInfo, updateInfo, exportInfo,xxInfo } from "@/api/system/notify_info/mylist";

  export default {
    name: "Info",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
         // orderByColumn:"sendtime",//排序字段
        //  isAsc:"desc",//排序方式
          title: undefined,
          sendperson: undefined,
          endtime:'',
          startime:'',
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          guid: [
            { required: true, message: "收件人不能为空", trigger: "blur" }
          ],
        },
        tztitle:"通知详情",
        tzshow:false,
        xxloading:true,
      };
    },
    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.tzshow = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          guid: undefined,
          title: undefined,
          content: undefined,
          sendtime: 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
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != 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();
                }
              });
            }
          }
        });
      },
      /** 签收按钮操作 */
      handleqs(row) {

        const ids = row.id || this.ids;
      //  alert(ids)
        this.$confirm('是否确认签收通知?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {

          return qsInfo(ids);
        }).then(() => {

          this.handlexx(row);
          this.getList();
          this.msgSuccess("签收成功");
        }).catch(function() {});
      },
      /** 详细按钮操作 */
      handlexx(row) {
        this.reset();
        this.tzshow=true;
        this.xxloading=true;
        xxInfo(row.id).then(response => {
          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;
      },
      /** 导出按钮操作 */
      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>
