<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入标题"></el-input>
      </el-form-item>
      <el-form-item label="新闻状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择新闻状态" clearable filterable>
          <el-option v-for="status in statusOptionList" :key="status.value" :label="status.label" :value="status.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @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="primary" icon="el-icon-plus" @click="handleAdd" v-hasPermi="['business:COUNSELINGMESSAGE:add']">新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button type="warning" icon="el-icon-download" @click="handleExport" v-hasPermi="['business:COUNSELINGMESSAGE:export']">导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--列表-->
    <el-table  :data="COUNSELINGMESSAGEList" @selection-change="handleSelectionChange" height="calc(100vh - 300px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标题信息" align="center" prop="title" width="220px"/>
      <el-table-column label="创建时间" align="center" prop="createTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核日期" align="center" prop="auditTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="信息状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0"><el-tag type="info">草稿</el-tag></span>
          <span v-if="scope.row.status == 1"><el-tag type="warning">审核中</el-tag></span>
          <span v-if="scope.row.status == 2"><el-tag type="danger">审核驳回</el-tag></span>
          <span v-if="scope.row.status == 3"><el-tag type="success">已审核</el-tag></span>
          <span v-if="scope.row.status == 4"><el-tag type="success">已上报</el-tag></span>
          <span v-if="scope.row.status == 5"><el-tag>已发布</el-tag></span>
          <span v-if="scope.row.status == 6"><el-tag type="info">已下架</el-tag></span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 5" size="mini" type="text"  @click="handleDownOrUp(scope.row)">下架</el-button>
          <el-button v-if="scope.row.status == 0 || scope.row.status == 2" size="mini" type="text" @click="handleCommit(scope.row)">提交审核</el-button>
          <el-button v-if="scope.row.status == 3" size="mini" type="text"  @click="handleDownOrUp(scope.row)">上报</el-button>
          <el-button v-if="scope.row.status == 6 || scope.row.status == 4" size="mini" type="text" @click="handleDownOrUp(scope.row)">发布</el-button>
          <el-button v-if="scope.row.status == 0 || scope.row.status == 2 || scope.row.status == 3 || scope.row.status == 4 || scope.row.status == 5 || scope.row.status == 6" size="mini" type="text" @click="handleUpdate(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="title" :visible.sync="open" width="800px" append-to-body >-->
<!--     -->
<!--    </el-dialog>-->


  </div>
</template>

<script>
import { listCOUNSELINGMESSAGE, getCOUNSELINGMESSAGE, delCOUNSELINGMESSAGE, addCOUNSELINGMESSAGE, updateCOUNSELINGMESSAGE, upload, newCommit } from '@/api/portal/COUNSELINGMESSAGE/COUNSELINGMESSAGE';
import edit from './edit.vue'

export default {
  name: 'COUNSELINGMESSAGE',
  data() {
    return {
      //预览
      dialogVisible: false,
      statusOptionList: [
        { label: '草稿', value: 0 },
        { label: '审核中', value: 1 },
        { label: '审核驳回', value: 2 },
        { label: '已审核', value: 3 },
        { label: '已上报', value: 4 },
        { label: '已发布', value: 5 },
        { label: '已下架', value: 6 },
      ],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 咨询信息表格数据
      COUNSELINGMESSAGEList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        deptId: null,
        title: null,
        content: null,
        fileUrl: null,
        picture: null,
        status: null,
        auditTime: null,
        reportDate: null,
        releaseDate: null
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查询咨询信息列表 */
    getList() {
      this.loading = true;
      listCOUNSELINGMESSAGE(this.queryParams).then(response => {
        this.COUNSELINGMESSAGEList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    /** 发布 */
    handleDownOrUp(row) {
      //修改发布、下架状态
      if (row.status == '5') {
        //已发布 已审核
        row.status = '6';
        updateCOUNSELINGMESSAGE(row).then(response => {
          this.$modal.msgSuccess('下架成功');
          this.open = false;
          this.getList();
        });
      } else if (row.status == '4'|| row.status == '6') {
        //已下架
        row.status = '5';
        updateCOUNSELINGMESSAGE(row).then(response => {
          this.$modal.msgSuccess('发布成功');
          this.open = false;
          this.getList();
        });
      } else if (row.status == '3') {
        //已上报
        row.status = '4';
        updateCOUNSELINGMESSAGE(row).then(response => {
          this.$modal.msgSuccess('上报成功');
          this.open = false;
          this.getList();
        });
      }
    },
    /** 提交审核 */
    handleCommit(row) {
      let CbNewsVo = row;
      newCommit(CbNewsVo).then(response => {
        this.$modal.msgSuccess('提交审核成功!');
        this.getList();
      });
    },
    /** 搜索按钮操作 */
    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.iframe({ obj: edit, param: {}, title: '添加资讯', width: '1050px', height: '750px' });
      // this.open = true;
      // this.title = '添加咨询信息';
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      this.iframe({ obj: edit, param: { id: id }, title: '修改资讯', width: '1050px', height: '750px' });
    },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   const id = row.id || this.ids;
    //   getCOUNSELINGMESSAGE(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = '修改咨询信息';
    //     if (this.form.fileUrl != null){
    //       this.fileList.push({ name: 'xxx', url: this.form.fileUrl });
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除咨询信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delCOUNSELINGMESSAGE(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'business/COUNSELINGMESSAGE/export',
        {
          ...this.queryParams
        },
        `COUNSELINGMESSAGE_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
