<!--
  @description: app菜单列表
  @Modifier: zxl
  @routerPath:
  @date: 2020-2-20-14:56
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :search-form.sync="searchForm"
      search-label-width="100px"
      :menu="true"
      @on-load="loadData"
    >
      <template v-slot:header>
        推送消息列表
      </template>
      <template v-slot:search="search">
        <el-form-item label="消息标题" prop="msgTitle">
          <el-input v-model.trim="searchForm.msgTitle" placeholder="请输入" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <el-form-item label="消息类型" prop="msgType">
          <el-select v-model="searchForm.msgType" placeholder="请选择" style="width:228px">
            <el-option
              v-for="(item,index) in msgTypeList"
              :key="index"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <el-button type="primary" @click="addMenu">
          新增
        </el-button>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            header-align="center"
            prop="msgTitle"
            label="消息标题"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            prop="msgContent"
            label="消息内容"
            min-width="230"
            align="center"
          />

          <el-table-column
            header-align="center"
            prop="msgType"
            label="消息类型"
            min-width="80"
            align="center"
          >
            <template slot-scope="scope">
              <span>
                {{ filterDictText(msgTypeList, scope.row.msgType) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="msgUserName"
            label="发消息的人"
            min-width="180"
            align="center"
          />
          <!--          <el-table-column
            header-align="center"
            prop="msgUserId"
            label="发消息人id"
            min-width="180"
            align="center"
          />
          <el-table-column
            header-align="center"
            prop="msgDepartId"
            label="消息发起单位id"
            min-width="180"
            align="center"
          />-->
          <el-table-column
            header-align="center"
            prop="msgDepartName"
            label="消息发起单位名称"
            min-width="180"
            align="center"
          />
          <el-table-column
            header-align="center"
            prop="msgUrl"
            label="消息源地址"
            min-width="180"
            align="center"
          />
          <el-table-column
            header-align="center"
            prop="receiveUser"
            label="接收人用户名"
            min-width="180"
            align="center"
          />
          <el-table-column
            header-align="center"
            prop="readStatus"
            label="阅读状态"
            min-width="180"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.msgType === '02'">
                {{ scope.row.readStatus === '01'?'已读':'未读' }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="readTime"
            label="阅读时间"
            min-width="180"
            align="center"
          />

          <el-table-column
            header-align="center"
            prop="createTime"
            label="创建时间"
            min-width="180"
            align="center"
          />

          <el-table-column label="操作" align="center" width="125">
            <template slot-scope="scope">
              <!--              <el-link
                type="primary"
                @click="toEdit(scope.row)"
              >
                [编辑]
              </el-link>-->
              <el-link
                type="primary"
                @click="toDel(scope.row,scope.$index)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>

    <!--    <platform-add-dialog v-if="dialogData.flag" :dialog-data="dialogData" @change="callBack" />-->
    <msg-add-dialog v-if="dialogData.flag" :dialog-data="dialogData" @change="callBack" />
  </div>
</template>

<script>

/* 混合开发方法-参数字段*/
import { filterDictText } from '../../../assets/js/utils'
import { delMsg, queryMsgListPageByManage } from '../../../api/appManagement/msg'
import msgAddDialog from './msgAdd-dialog'
export default {
  components: {
    msgAddDialog
  },
  data() {
    return {
      loading: true,
      searchForm: {
        msgTitle: '', // 消息标题
        msgType: ''// 消息类型01公开消息02指定消息
      },
      tableData: [],
      msgTypeList: [{
        typename: '公开消息',
        typecode: '01'
      }, {
        typename: '指定消息',
        typecode: '02'
      }],
      dialogData: {
        flag: false,
        row: null
      }
    }
  },
  created() {
    /*    this.initGroup()*/
  },
  methods: {
    filterDictText, // 字典值替换文本通用方法
    // 字典请求
    initGroup() {
      this.$store.dispatch('getGroupType', ['appType', 'appCategory']).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 获取数据
    loadData(params, callback) {
      queryMsgListPageByManage(params).then(response => {
        this.tableData = response.data.records
        this.loading = false
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    addMenu() {
      this.dialogData.row = null
      this.dialogData.flag = true
    },
    toEdit(row) {
      this.dialogData.row = row
      this.dialogData.flag = true
    },
    toDel(row, index) {
      this.$confirm('确认是否删除该条数据？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        /*    delAppPlatformConfig({ id: row.id }).then(res => {
          this.tableData.splice(index, 1)
        }).catch(() => {
        })*/
        delMsg({ id: row.id }).then(res => {
          this.tableData.splice(index, 1)
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 详情
    handleDetail(row) {

    },
    // 操作回调
    callBack() {
      this.$refs.tableCrud.onSearchChange()
    }
  }
}
</script>

<style lang="less" scoped>
.img_pic {
  max-height: 50px;
}
</style>
