<template>
  <div class="app-container">
    <h4 class="form-header h4">基本信息</h4>
    <el-form ref="form" :model="form" label-width="80px">
      <el-row>
        <el-col :span="8" :offset="2">
          <el-form-item label="标题" prop="title">
            <el-input v-model="form.title" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="2">
          <el-form-item label="类型" prop="type">
            <el-select v-model="form.type" disabled style="width: 100%">
              <el-option v-for="dict in dict.type.sys_notice_type" :key="dict.value" :label="dict.label"
                :value="dict.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <h4 class="form-header h4">详情列表</h4>
    <el-row class="mb8" :gutter="10">
      <!--<el-col :span="1.5">-->
      <!--  <el-button-->
      <!--    type="primary"-->
      <!--    plain-->
      <!--    size="mini"-->
      <!--    icon="el-icon-plus"-->
      <!--    @click="handleAdd"-->
      <!--  >新增-->
      <!--  </el-button>-->
      <!--</el-col>-->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain size="mini" icon="el-icon-delete" :disabled="!isMultiple" @click="handleDelete">删除
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="info" plain size="mini" icon="el-icon-close" @click="handleClose">关闭
        </el-button>
      </el-col>
    </el-row>
    <el-table ref="receiveList" stripe style="width: 100%;" :data="receiveList" @selection-change="handleSelectChange">
      <el-table-column type="selection" align="center" width="55"></el-table-column>
      <el-table-column label="姓名" prop="userName" align="center"></el-table-column>
      <el-table-column label="电话" prop="phonenumber" align="center"></el-table-column>
      <el-table-column label="是否阅读" prop="status" align="center">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.status == 1">已阅读</el-tag>
          <el-tag type="warning" v-else>未阅读</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <ExPagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
      @pagination="getList"></ExPagination>

    <el-dialog :visible.sync="open" title="选择推送人" width="960px">
      <el-form :model="pushForm" inline size="small">
        <el-form-item label="姓名" porp="userName">
          <el-input v-model="pushForm.userName"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="pushForm.phonenumber"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" icon="el-icon-search" @click="handlePushQuery">搜索
          </el-button>
          <el-button plain size="small" icon="el-icon-refresh" @click="resetPushQuery">重置
          </el-button>
        </el-form-item>
      </el-form>
      <el-table ref="assignorList" stripe width="100%" v-loading="loading" :data="pushList"
        @selection-change="handleSelectChange" @row-click="handleRowClick">
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column type="index" label="序号" align="center"></el-table-column>
        <el-table-column label="用户姓名" prop="userName" align="center"></el-table-column>
        <el-table-column label="手机号" prop="phonenumber" align="center"></el-table-column>
      </el-table>

      <ExPagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
        @paginaiton="getList"></ExPagination>

      <div slot="footer">
        <el-button :disabled="!isSimple" type="primary" size="small" @click="handleSelect">确 认</el-button>
        <el-button plain size="small" @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { deleteReceive, getList } from "@/api/smartSchool/informationPush/schoolDetail";
import {
  getUser,// 根据分类id获取人员信息
} from "@/api/smartSchool/informationPush/personnelGrouping";
export default {
  name: "SchoolDetail",
  dicts: ['sys_user_sex', 'sys_notice_type'],
  data() {
    return {
      form: {
        title: '',
        type: ''
      },
      // 主键id
      pushId: '',
      total: 0,
      receiveList: [],
      loading: false,
      isSimple: false,
      isMultiple: false,
      ids: [],
      // 选中教师对话框、
      open: false,
      // 主页列表查询
      queryForm: {
        pageNum: 1,
        pageSize: 10
      },
      pushForm: {
        pageNum: 1,
        pageSize: 10
      },
      // 推送人列表
      pushList: [],
    }
  },
  created() {
    this.init();
  },
  methods: {
    /** 初始化参数数据、列表数据查询 */
    init() {
      const { title, type } = this.$route.query;
      this.pushId = this.$route.query && this.$route.query.id;
      this.form = { title, type };
      this.getList();
    },
    //根据组id查询组成员
    getList() {
      this.loading = true;
      this.notificationId = this.$route.query.id;
      console.log('this..notificationId', this.notificationId);
      getUser(this.notificationId).then(response => {
        this.userList = response.rows;
        console.log('this.userList', this.userList);
        this.loading = false;
      });
    },
    /** 获取列表数据 */
    getList() {
      this.loading = true;
      getList(this.pushId, this.queryForm).then(response => {
        this.loading = false;
        this.receiveList = response.rows;
        this.total = response.total;
      }).catch(error => {
        this.loading = false;
      })
    },

    /** 选中项发生变化 */
    handleSelectChange(selection) {
      this.ids = selection.map(item => item.id);
      this.isSimple = selection.length === 1;
      this.isMultiple = selection.length > 0;
    },

    /** 新增 */
    handleAdd() {
      this.open = true;
    },

    /** 删除 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除选中推送人?').then(() => {
        this.$modal.loading('正在处理数据，请稍等...');
        return deleteReceive(this.pushId, ids);
      }).then(response => {
        this.$modal.closeLoading();
        this.$modal.msgSuccess('删除成功');
      }).catch(error => {
        this.$modal.closeLoading();
      })
    },
    /** 关闭 */
    handleClose() {
      this.$tab.closeOpenPage({
        path: '/schoolManage/schoolNotice/school'
      });
    },

    /** 选中推送人列表 */
    getPushList() {

    },

    /** 对话框模糊查询 */
    handlePushQuery() {
      this.getPushList();
    },

    /** 重置对话框表单 */
    resetPushQuery() {
      this.reset();
      this.handlePushQuery();
    },

    /** 重置对话框表单 */
    reset() {
      this.pushForm = {
        pageNum: 1,
        pageSize: 10,
        userName: '',
        phonenubmer: ''
      };
    },

    /** 单击选中 */
    handleRowClick(row, column, event) {
      this.$refs.receiveList.clearSelection();
      this.$refs.receiveList.toggleRowSelection(row, true);
    },

    /** 选择 */
    handleSelect() {

    }
  }
}
</script>

<style scoped></style>
