<!-- 基础数据-岗位物料配置 -->
<template>
  <div class="examination postMaterials">
    <div class="common-head-search">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label='通知人'>
                <el-input v-model="search.userCode" size="small" placeholder="请输入通知人" style="width: 150px;"></el-input>
            </el-form-item>
        <el-form-item label="创建日期">
          <el-date-picker
           v-model="search.entrTime"
           type="daterange"
           range-separator="至"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           size="small"
           style="width:270px"
           format="yyyy-MM-dd"
           value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="goon" size="mini" @click="searchData">查询</el-button>
          <el-button icon="el-icon-refresh" type="info" plain size="mini" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="common-title-div">
      <div class="common-title-name">
        <img style="width: 25px; height: 25px" src='../../../assets/img/imgScreen/logo.png' />
        消息推送配置
      </div>
    </div>
      <el-tabs v-model="activeName" type="border-card" class="testManagement_left">
        <el-tab-pane label="未读消息" name="first">
          <span slot="label"
              >未读消息<el-badge
                :max="10"
                :hidden="total_main == 0"
                style="margin-top: -18px"
                :value="total_main"
              ></el-badge
            ></span>
          <div class="common-table-div" style="margin-bottom:0;margin-top:0">
            <el-table v-loading="dataLoading1" ref="dataTable" border :height="height_top" highlight-current-row
            :data="table.list1" :icore-filter-flag="icoreFilterFlag">
              <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
              <el-table-column show-overflow-tooltip sortable min-width="120" fixed align='center' prop="memo1" label="中心编号">
                  <template slot-scope="scope">
                    <div :class="{'color-blue' : scope.row.memo1}"
                        @click.stop="showHistory(scope.row)">{{scope.row.memo1}}
                    </div>
                  </template>
              </el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="memo4" label="物料名称" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="memo3" label="项目任务" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgName" label="消息名称" align="center"></el-table-column> -->
              <el-table-column sortable min-width="200px" show-overflow-tooltip prop="memo" label="消息内容" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgContent" label="消息配置内容" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="itemTypeName" label="消息类型" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="dealUrl" label="消息地址" align="center"></el-table-column> -->
              <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" label="消息地址" align="center">
                <template slot-scope="scope">
                  <span @click.stop="pathQuery(scope.row)" style="cursor: pointer;"
                          :class="{'color-blue' : scope.row.dealUrl}">
                      {{ scope.row.dealUrl }}
                    </span>
                  <!-- <keep-alive>
                    <router-link style="color:blue" tag='a' :to="{path: scope.row.dealUrl ,query:{Name: scope.row.memo1}}" >跳转到页面</router-link>
                  </keep-alive> -->
                </template>
              </el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgShown" label="消息发布" align="center"></el-table-column> -->
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="userNo" label="消息用户" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="createTime" label="创建时间" align="center"></el-table-column>
              <el-table-column sortable min-width="0px" show-overflow-tooltip prop="memo5" label="參數" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="createMan" label="创建人" align="center"></el-table-column> -->
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="已读消息" name="first1">
          <div class="common-table-div" style="margin-bottom:0;margin-top:0">
            <el-table v-loading="dataLoading1" ref="dataTable" border :height="height_top" highlight-current-row
            @selection-change="handleSelectionChange" :data="table.list2" :icore-filter-flag="icoreFilterFlag">
              <el-table-column type="index" label="NO" fixed="left" align="center"></el-table-column>
              <!-- <el-table-column type="selection" width="45" align="center"></el-table-column> -->
              <el-table-column show-overflow-tooltip sortable min-width="120" fixed align='center' prop="memo1" label="中心编号">
                  <template slot-scope="scope">
                    <div :class="{'color-blue' : scope.row.memo1}"
                        @click.stop="showHistory(scope.row)">{{scope.row.memo1}}
                    </div>
                  </template>
              </el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="memo4" label="物料名称" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="memo3" label="项目任务" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgName" label="消息名称" align="center"></el-table-column> -->
              <el-table-column sortable min-width="200px" show-overflow-tooltip prop="memo" label="消息内容" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgContent" label="消息配置内容" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="itemTypeName" label="消息类型" align="center"></el-table-column>
              <el-table-column sortable min-width="120px" show-overflow-tooltip prop="userNo" label="消息用户" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="dealUrl" label="消息地址" align="center"></el-table-column> -->
              <el-table-column sortable :show-overflow-tooltip="true" min-width="140px" label="消息地址" align="center">
                <template slot-scope="scope">
                  <span @click.stop="pathQuery(scope.row)" style="cursor: pointer;"
                          :class="{'color-blue' : scope.row.dealUrl}">
                      {{ scope.row.dealUrl }}
                    </span>
                  <!-- <keep-alive>
                    <router-link style="color:blue" tag='a' :to="{path: scope.row.dealUrl ,query:{Name: scope.row.memo1}}" >跳转到页面</router-link>
                  </keep-alive> -->
                </template>
              </el-table-column>
              <el-table-column sortable min-width="0px" show-overflow-tooltip prop="memo5" label="參數" align="center"></el-table-column>
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="msgShown" label="消息发布" align="center"></el-table-column> -->
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="createTime" label="创建时间" align="center"></el-table-column> -->
              <!-- <el-table-column sortable min-width="120px" show-overflow-tooltip prop="createMan" label="创建人" align="center"></el-table-column> -->
            </el-table>
          </div>
          <div class="common-foot-style">
              <el-pagination 
                @size-change="pageSizeChange" 
                @current-change="getDataList2()"
                :current-page.sync="page.pageNum" 
                :page-sizes="[10, 20, 50, 100, 200]" 
                :page-size="page.pageSize" 
                layout="total, sizes, prev, pager, next, jumper"
                :total="page.totalPage" background>
              </el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>
    <div>
      <el-dialog @close="closeDialog('baseData')" :visible.sync="dialogTableVisible" >
          <div slot="title" class="titleBox">
          <i :class="tableType === 0? 'el-icon-document':'el-icon-edit-outline'" style="font-size: 20px"></i>
          <span style="margin-left:10px;font-size:18px">{{tableTypeDsc}}</span>
          </div>
        <el-form ref="baseData" label-width="80px" :rules="ruleValidate" :model="baseData">
          <el-row>
            <el-col :span="8">
              <el-form-item prop="msgNane" label="消息名称">
                <el-input v-model="baseData.msgNane" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="itemTypeName" label="消息类型">
                <el-input v-model="baseData.itemTypeName" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="msgContent" label="消息内容">
                <el-input v-model="baseData.msgContent" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item prop="userNo" label="消息用户">
                <el-input v-model="baseData.userNo" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="msgSelect" label="消息提取">
                <el-input v-model="baseData.msgSelect" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="msgShown" label="消息发布">
                <el-input v-model="baseData.msgShown" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="memo" label="备注">
                <el-input v-model="baseData.memo" clearable size="small"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button type="goon" size="mini" icon="el-icon-check" @click="tableType === 0 ? addData('baseData'):modifyData('baseData')">确定</el-button>
          <el-button size="mini" type="goon" icon="el-icon-remove-outline" @click="cancel()">取消</el-button>
        </span>
      </el-dialog>
    </div>
    <div
          is="historyAlert"
          :showFlag="historyShowFlag"
          :Params="Params"
          @refresh="refresh"
        ></div>
  </div>
</template>
<script>
import {getCookie} from '@/utils/util.js';
import historyAlert from '../../testAnalysis/components/testManagement/historyAlert';
import {cookieUserId, cookieUserName} from '@/config/config.js';
let userName = getCookie(cookieUserName);
let userId = getCookie(cookieUserId);
export default {
  components: {historyAlert},
  data () {
    return {
      icoreFilterFlag: true,
      dataLoading: false,
      dataLoading1: false,
      dialogTableVisible: false,
      historyShowFlag:false,
      Params: {},
      table: {
        list: [],
        list1: [],
        list2: []
      },
      activeName:'first',
      tableType:0,
      tableTypeDsc: '新增推送消息',
      page: {
        pageSize: 50,
        pageNum: 1,
        totalPage: 0
      },
      search: {
        userCode: '',
        entrTime:[]
      },
      total_main: 0,
      baseData:{
        msgNane:'',
        userNo:'',
        itemTypeCode:'',
        itemTypeName:'',
        msgContent:'',
        dealUrl:'',
        stateFlag:'',
        memo:''
      },
      multipleSelection:[],
      //必选
      ruleValidate: {
        
      },
      height_top: 500
    }
  },
  created() {
    this.search.entrTime=  [this.getYNM(new Date()), this.getYNM(new Date())]
    this.search.userCode = userId
    this.searchData();
  },
  mounted () {
    this.axios.post("pass/baseManagement/v1/limsbaseinfos/queryBaseInfoByBaseCode", { validFlag: 1, baseCode: 4851 }, { individualType: 'json' }).then(res => {
      console.log(res.date);
    });
  },
  methods: {
    getYNM(date) {
      let year = date.getFullYear().toString();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      return `${year}-${month}-${day}`;
    },
    reset () {
      this.search.entrTime = [this.getYNM(new Date()), this.getYNM(new Date())]
      this.search.matNo = '';
      this.search.postNo = '';
      this.searchData();
    },
    searchData () {
        this.page.pageNum = 1;
        this.getDataList();
        this.getDataList1();
        this.getDataList2()
    },
    showHistory(row){
          if (!row){
            return this.$message.warning('查询历史记录失败，参数错误!')
          }
          this.axios.post('pass/testManagement/v1/limssamplehistorys/queryHistoryTest1',row,{ individualType: 'json'}).then(res => {
            if (res.code == 0 || res.code == 200){
              //打开窗口
              this.historyShowFlag = !this.historyShowFlag
              this.Params = Object.assign([{}], res.data)
            }else {
              this.$message.warning('查询历史记录失败!')
            }
          }).catch(e => {
            this.$message.error(e.message);
          })
        },
      refresh () {

      },
    pathQuery(row){
      if (!row){
        return this.$message.warning('参数错误!')
      }
      this.axios.post('pass/testManagement/v1/limsdatamsgs/updateStateFlag?msgId='+row.msgId,{individualType: 'json'})
      this.$router.push({path: row.dealUrl+row.memo5 ,query:{Name: row.memo5}});
    },
    getDataList2 () {
        let that = this;
        that.dataLoading1 = true;
        if (!this.search.entrTime) {
          this.startTime = ''
          this.endTime = ''
        }else {
          this.startTime = this.search.entrTime[0] + ' 00:00:00'
          this.endTime = this.search.entrTime[1]  + ' 23:59:59'
        }
        let params = {
          object: {
            userNo: this.search.userCode,
            stateFlag: '1',
          },
          'pageIndex':that.page.pageNum,
          'pageSize':that.page.pageSize,
          'startTime':this.startTime,
          'endTime':this.endTime,
          stateFlag: 1,
        
        }
        this.axios.post('pass/testManagement/v1/limsdatamsgs/queryListByStateFlag1',params,{individualType: 'json'}).then(res => {
          if (res.code == 0 || res.code == 200) {
            this.table.list2 = res.data.list;
            // this.total_main = res.data.total
            that.dataLoading1 = false;
          }else{
            this.$message.error(res.message)
          }
          this.dataLoading1 = false
          this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading1 = false;
          this.$message.error(e.message)
        });
      },
    getDataList1 () {
        let that = this;
        that.dataLoading1 = true;
        if (!this.search.entrTime) {
          this.startTime = ''
          this.endTime = ''
        }else {
          this.startTime = this.search.entrTime[0] + ' 00:00:00'
          this.endTime = this.search.entrTime[1]  + ' 23:59:59'
        }
        let params = {
          object: {
            userNo: this.search.userCode,
            stateFlag: '0',
          },
          'pageIndex':that.page.pageNum,
          'pageSize':that.page.pageSize,
          'startTime':this.startTime,
          'endTime':this.endTime,
          stateFlag: 0,
        }
        this.axios.post('pass/testManagement/v1/limsdatamsgs/queryListByStateFlag',params,{individualType: 'json'}).then(res => {
          if (res.code == 0 || res.code == 200) {
            this.table.list1 = res.data.list;
            this.total_main = res.data.total
            that.dataLoading1 = false;
          }else{
            this.$message.error(res.message)
          }
          this.dataLoading1 = false
          this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading1 = false;
          this.$message.error(e.message)
        });
      },
      getDataList () {
        let that = this;
        that.dataLoading = true;
        if (!this.search.entrTime) {
          this.startTime = ''
          this.endTime = ''
        }else {
          this.startTime = this.search.entrTime[0] + ' 00:00:00'
          this.endTime = this.search.entrTime[1]  + ' 23:59:59'
        }
        let params = {
          object: {
            userNo: this.search.userCode
          },
          'pageIndex':that.page.pageNum,
          'pageSize':that.page.pageSize,
          'startTime':this.startTime,
          'endTime':this.endTime
        }
        this.axios.post('pass/testManagement/v1/limsdatamsgs/queryList',params,{individualType: 'json'}).then(res => {
          if (res.code == 0 || res.code == 200) {
            this.table.list = res.data.list;
            that.dataLoading = false;
          }else{
            this.$message.error(res.message)
          }
          this.dataLoading = false
          this.page.totalPage = res.data.total;
        }).catch(e => {
          this.dataLoading = false;
          this.$message.error(e.message)
        });
      },
      //添加
      but_add(){
        this.dialogTableVisible= true;
      },
      addData (formName) {
        let _this = this;
        _this.$refs[formName].validate((valid) => {
          if (valid) {
            this.axios.post('pass/baseManagement/v1/limsbasemsgs/addLimsBaseMsg',this.baseData,{individualType: 'json'}).then(res => {
              if (res.code == 0 || res.code == 200) {
                this.cancel();
                this.$message.success('添加成功')
                this.getDataList();
              }else{
                this.$message.error(res.message)
              }
            }).catch(e => {
              this.$message.error(e.message)
            });
          }
        })
      },
      //修改
      modify(){
        if (this.multipleSelection.length !== 1) {
          this.$message.warning('请勾选您要修改的一条数据！')
          return
        }
        this.tableType = 1
        this.tableTypeDsc = '修改推送消息'
        this.baseData = Object.assign({},this.multipleSelection[0])
        this.dialogTableVisible = true
      },
      //弹窗修改操作
      modifyData (formName) {
        let that = this;
        that.$refs[formName].validate((valid) => {
        if (valid) {
          that.axios.post('pass/baseManagement/v1/limsbasemsgs/updateLimsBaseMsg', that.baseData,{individualType: 'json'}).then(res => {
              if (res.code == 0 || res.code == 200) {
                this.cancel();
                this.$message.success('修改成功')
                this.getDataList();
              }else{
                this.$message.error(res.message)
              }
            }).catch(e => {
              that.$message.error(e.message)
            })
          }
        })
      },
      //删除
      deleteData(){
        if (this.multipleSelection.length < 1) {
          this.$message.warning('请勾选您要停用的数据！')
        } else {
          this.dialogTableVisible = false;
          this.axios.post('pass/baseManagement/v1/limsbasemsgs/deleteLimsBaseMsg',this.multipleSelection, {individualType: 'json'}).then(res => {
          if (res.succeed) {
            this.$message.success('删除成功！');
            this.getDataList();
            } else {
            this.$message.error(res.message)
            }
            }).catch(e => {
            this.$message.error(e.message)
          })
        }
      },
      //关闭弹窗
      closeDialog (formName){
        this.$refs[formName].resetFields();
        this.tableType = 0
        this.tableTypeDsc = '新增消息配置'
      },
      //取消
      cancel () {
        let that = this;
        that.dialogTableVisible = false
        that.baseData = {
          msgNane:'',
          userNo:'',
          itemTypeCode:'',
          msgContent:'',
          dealUrl:'',
          stateFlag:'',
          memo:''
        }
        that.tableType = 0
        that.tableTypeDsc = '新增消息配置'
      },
      pageSizeChange (size) {
        this.page.pageNum = 1;
        this.page.pageSize = size;
        this.getDataList();
      },
      handleSelectionChange (val) {
        this.multipleSelection = val;
      }
    }
}
</script>
<style lang="less">
.postMaterials {
  .common-table-div{
    .el-table .el-table__body tr.error-row {
      background-color: rgb(253, 89, 89) !important;
    }
    .el-table .el-table__body tr.error-row > td{
      background-color: rgb(253, 89, 89) !important;
    }
  }
}
</style>
