<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <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="enterpriseId">-->
        <!--<el-input-->
          <!--v-model="queryParams.enterpriseId"-->
          <!--placeholder="请输入指派企业"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="未处置" value="0" />
          <el-option label="已处置" value="1" />
        </el-select>
      </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:sentiment:add']"
        >新增</el-button>
      </el-col>
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="success"-->
          <!--plain-->
          <!--icon="el-icon-edit"-->
          <!--size="mini"-->
          <!--:disabled="single"-->
          <!--@click="handleUpdate"-->
          <!--v-hasPermi="['system:sentiment:edit']"-->
        <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="danger"-->
          <!--plain-->
          <!--icon="el-icon-delete"-->
          <!--size="mini"-->
          <!--:disabled="multiple"-->
          <!--@click="handleDelete"-->
          <!--v-hasPermi="['system:sentiment:remove']"-->
        <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:sentiment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sentimentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="舆情标题" align="center" prop="title" />
      <el-table-column label="舆情内容" align="center" prop="content" />
      <el-table-column label="舆情文件" align="center" prop="sentimentFile" >
        <template slot-scope="scope">
          <span
            class="dbtn"
            @click="checkFile(scope.row.sentimentFile)"
            v-if="scope.row.sentimentFile != null && scope.row.sentimentFile!=''"
          >
            <i class="el-icon el-icon-view"></i>查看/下载
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="发生时间" align="center" prop="startTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发生区域" align="center" prop="region" :formatter="regionFormat" />
<!--      <el-table-column label="指派企业" align="center" prop="enterpriseName" />-->
      <el-table-column label="状态" align="center" prop="status">
      <template slot-scope="scope">
        <span v-if="scope.row.status == '0' ">未处置</span>
        <span v-else>已处置</span>
      </template>
      </el-table-column>
      <el-table-column label="处置标题" align="center" prop="disposeTitle" />
      <el-table-column label="处置内容" align="center" prop="disposeContent" />
      <el-table-column label="处置文件" align="center" prop="disposeFile" >
        <template slot-scope="scope">
          <span
            class="dbtn"
            @click="checkFile(scope.row.disposeFile)"
            v-if="scope.row.disposeFile != null && scope.row.disposeFile!=''"
          >
            <i class="el-icon el-icon-view"></i>查看/下载
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="处置人" align="center" prop="person" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:sentiment:edit']"
          >处置</el-button>
          <el-button
            size="mini"
            type="text"
            @click="report(scope.row)"
          >上报</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:sentiment:remove']"
          >删除</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="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="舆情标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入舆情标题" />
        </el-form-item>
        <el-form-item label="舆情内容" prop="content">
          <el-input v-model="form.content" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="舆情文件">
          <!--<fileUpload v-model="form.sentimentFile"/>-->
          <FileUpload
            listType="picture"
            @resFun="getFileInfo"
            @remove="listRemove"
            :fileArr="fileList"
          />
        </el-form-item>
<!--        <el-form-item label="指派企业" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入指派企业" />
        </el-form-item>-->
        <el-form-item label="发生区域" prop="region">
          <el-select v-model="form.region" placeholder="请选择所属区域">
            <el-option
              v-for="dict in regionOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发生时间" prop="startTime">
          <el-date-picker clearable size="small"
                          v-model="form.startTime"
                          type="date"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择发生时间">
          </el-date-picker>
        </el-form-item>
        <!--<el-form-item label="状态 0未反馈 1已反馈">-->
        <!--<el-radio-group v-model="form.status">-->
        <!--<el-radio label="1">请选择字典生成</el-radio>-->
        <!--</el-radio-group>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="处置标题" prop="disposeTitle">-->
        <!--<el-input v-model="form.disposeTitle" placeholder="请输入处置标题" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="处置内容">-->
        <!--<el-input v-model="form.disposeContent" type="textarea" placeholder="请输处置内容"/>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="处置文件">-->
        <!--<fileUpload v-model="form.disposeFile"/>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="处置人" prop="person">-->
        <!--<el-input v-model="form.person" placeholder="请输入处置人" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="联系方式" prop="phone">-->
        <!--<el-input v-model="form.phone" placeholder="请输入联系方式" />-->
        <!--</el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改舆情处置对话框 -->
    <el-dialog :title="title" :visible.sync="open2" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="处置标题" prop="disposeTitle">
        <el-input v-model="form.disposeTitle" placeholder="请输入处置标题" />
        </el-form-item>
        <el-form-item label="处置内容" prop="disposeContent">
        <el-input v-model="form.disposeContent" type="textarea" placeholder="请输处置内容"/>
        </el-form-item>
        <el-form-item label="处置文件">
          <FileUpload
            listType="picture"
            @resFun="getFileInfo2"
            @remove="listRemove2"
            :fileArr="fileList2"
          />
        </el-form-item>
        <el-form-item label="处置人" prop="person">
        <el-input v-model="form.person" placeholder="请输入处置人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSentiment, getSentiment, delSentiment, addSentiment, updateSentiment, exportSentiment } from "@/api/system/sentiment";
import FileUpload from '@/components/FileUpload';
import Editor from '@/components/Editor';
import {updateTask} from "@/api/inspectionWork/workTask";
let uploadfile = require("@/assets/uploadfile.png");
export default {
  name: "Sentiment",
  components: {
    FileUpload,
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 舆情处置表格数据
      sentimentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        enterpriseId: null,
        status: null,
      },
      fileList:[],
      fileList2:[],
      // 表单参数
      form: {},
      // 所属区域字典
      regionOptions:[],
      // 表单校验
      rules: {
        title: [
          { required: true, message: "舆情标题不能为空", trigger: "blur" }
        ],
        content: [
          { required: true, message: "舆情内容不能为空", trigger: "blur" }
        ],
        disposeTitle: [
          { required: true, message: "处置标题不能为空", trigger: "blur" }
        ],
        disposeContent: [
          { required: true, message: "处置内容不能为空", trigger: "blur" }
        ],
      },
      rules2: {
        disposeTitle: [
          { required: true, message: "处置标题不能为空", trigger: "blur" }
        ],
        disposeContent: [
          { required: true, message: "处置内容不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getDicts("t_township").then(response => {
      this.regionOptions = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询舆情处置列表 */
    getList() {
      this.loading = true;
      listSentiment(this.queryParams).then(response => {
        this.sentimentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 字典状态字典翻译
    regionFormat(row, column) {
      return this.selectDictLabel(this.regionOptions, row.region);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.open2 = false;
      this.fileList=[]
      this.fileList2=[]
    },

    //上传
    getFileInfo(res){
      //this.form.dealPlan = res.fileName;
      this.form.sentimentFile = res.url;
      this.fileList.push({
        name: res.fileName,
        url: uploadfile,
      });
    },
    listRemove(e) {
      this.form.sentimentFile = "";
      this.fileList = [];
    },
    //上传
    getFileInfo2(res){
      //this.form.dealPlan = res.fileName;
      this.form.disposeFile = res.url;
      this.fileList2.push({
        name: res.fileName,
        url: uploadfile,
      });
    },
    listRemove2(e) {
      this.form.disposeFile = "";
      this.fileList2 = [];
    },


    checkFile(url) {
      window.open(url,'_blank');
    },

    // 表单重置
    reset() {
      this.fileList=[],
        this.fileList2=[],
      this.form = {
        sentimentId: null,
        shengId: null,
        title: null,
        content: null,
        sentimentFile: null,
        enterpriseId: null,
        status: "0",
        disposeTitle: null,
        disposeContent: null,
        disposeFile: null,
        person: null,
        phone: null,
        createTime: null,
        isDel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sentimentId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加舆情处置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const sentimentId = row.sentimentId || this.ids
      getSentiment(sentimentId).then(response => {
        this.form = response.data;
        if(this.form.sentimentFile!=null && this.form.sentimentFile!=''){
          this.fileList.push({
            name: "督导文件",
            url: uploadfile,
          });
        }
        if(this.form.disposeFile && this.form.disposeFile!=''){
          this.fileList2.push({
            name: "督导文件",
            url: uploadfile,
          });

        }
        this.open2 = true;
        this.title = "舆情处置";
      });
    },

    report(row){
      this.$confirm('是否确认上报入户舆情标题为"' + row.title + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        //return updateTask({taskId:row.taskId,isReport:"1"});
      }).then(() => {
        this.getList();
        this.msgSuccess("上报成功");
      }).catch(() => {});
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sentimentId != null) {
            updateSentiment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.open2 = false;
              this.getList();
            });
          } else {
            addSentiment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sentimentIds = row.sentimentId || this.ids;
      this.$confirm('是否确认删除舆情处置编号为"' + sentimentIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSentiment(sentimentIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有舆情处置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportSentiment(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style scoped lang="scss">
  ::v-deep .el-select{
    width: 100%;
  }
  .dbtn {
    display: inline-block;
    line-height: normal;
    padding-left: 2px;
    padding-right: 2px;
    cursor: pointer;
    border-radius: 3px;
    border-style: solid;
    border-width: 0;
    color: rgb(48, 180, 107);
  }
</style>
