<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投诉人" prop="complainName">
        <el-input
          v-model="queryParams.complainName"
          placeholder="请输入投诉人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="指派单位" prop="complainAssignEnterproseId" v-if="deptId==-2" >
        <el-select v-model="queryParams.complainAssignEnterproseId" placeholder="请选择预案等级" clearable size="small">
          <el-option
            v-for = "dict in enterpriseList"
            :key = "dict.enterpriseId"
            :label = "dict.enterpriseName"
            :value = "dict.enterpriseId"
          />
        </el-select>
      </el-form-item>

      <!--<el-form-item label="指派人" prop="complainAssignManId">-->
        <!--<el-select v-model="queryParams.complainAssignManId" placeholder="请选择预案等级" clearable size="small">-->
          <!--<el-option-->
            <!--v-for = "dict in userList"-->
            <!--:key = "dict.id"-->
            <!--:label = "dict.nickName"-->
            <!--:value = "dict.id"-->
          <!--/>-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <el-form-item label="任务状态" prop="complainStatus">
        <el-select v-model="queryParams.complainStatus" placeholder="请选择任务状态" clearable size="small">
            <el-option
              v-for="dict in taskStateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
        </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"
          v-if="deptId==-2"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['complainDeal:complainDeal:add']"
        >新增</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="['complainDeal:complainDeal:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="complainDealList" @selection-change="handleSelectionChange">
      <!--<el-table-column label="投诉处置id" align="center" prop="complainDealId" />-->
      <el-table-column label="投诉人姓名" align="center" prop="complainName" />
      <el-table-column label="投诉人电话" align="center" prop="complainPhone" />
      <el-table-column label="投诉事项" align="center" prop="complainMatter" />
      <!--<el-table-column label="反馈内容" align="center" prop="dealCondition" />-->
      <el-table-column label="指派单位名称" align="center" prop="complainAssignEnterproseName" />
      <el-table-column label="指派人" align="center" prop="complainAssignMan" />
      <el-table-column label="任务状态" align="center" prop="complainStatus" :formatter="taskStateFormat" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" align="center" prop="dealTime" width="180" >
        <!--<template slot-scope="scope">-->
          <!--<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
        <!--</template>-->
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope" >
          <el-button
            size="mini"
            v-if="scope.row.complainStatus==1"
            style="color: red"
            type="text"
            icon="el-icon-edit"
            @click="handlefankui(scope.row)"
            v-hasPermi="['complainDeal:complainDeal:edit']"
          >反馈</el-button>
          <el-button
            size="mini"
            v-if="scope.row.complainStatus==2 && deptId==-2"
            style="color: #30B46B"
            type="text"
            icon="el-icon-edit"
            @click="handlegui(scope.row)"
            v-hasPermi="['complainDeal:complainDeal:edit']"
          >归档</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.complainStatus==1 && deptId==-2"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['complainDeal:complainDeal:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="handleDtail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['complainDeal:complainDeal: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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <div class="division">
          <div style="width: 50%;">
            <el-form-item label="投诉人姓名" prop="complainName">
              <el-input v-model="form.complainName" placeholder="请输入投诉人姓名" :disabled="readonly"/>
            </el-form-item>
            <el-form-item label="指派单位" prop="complainAssignEnterproseId" >
              <el-select style="width: 100%" v-model="form.complainAssignEnterproseName" placeholder="请选择预案等级"  @change="qiyechang" :disabled="readonly">
                <el-option
                  v-for = "dict in enterpriseList"
                  :key = "dict.enterpriseId"
                  :label = "dict.enterpriseName"
                  :value = "dict.enterpriseId"
                />

              </el-select>
            </el-form-item>

          </div>
          <div style="width: 50%;">
            <el-form-item label="投诉人电话" prop="complainPhone">
              <el-input v-model="form.complainPhone" placeholder="请输入投诉人电话" :disabled="readonly"/>
            </el-form-item>
            <el-form-item label="指派人" prop="complainAssignManId">
              <el-select v-model="form.complainAssignMan" placeholder="请选择预案等级" clearable style = "width: 100%" @change="manChang" :disabled="readonly">
                <el-option
                  v-for = "dict in peopleList"
                  :key = "dict.id"
                  :label = "dict.nickName"
                  :value = "dict.id"
                />
              </el-select>
            </el-form-item>

          </div>
        </div>
        <el-form-item label="投诉事项" prop="complainMatter">
          <el-input v-model="form.complainMatter" type = "textarea" placeholder="请输入投诉事项" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="反馈内容" prop="dealCondition" :style="display">
          <el-input v-model="form.dealCondition" type = "textarea" placeholder="请输入办理情况" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="转办记录" prop="transferRecord" :style="display">
          <el-input v-model="form.transferRecord" type="textarea"  placeholder="请输入转办记录" :disabled="readonly"/>
        </el-form-item>
        <el-form-item label="任务状态" :style="display">
          <el-select v-model="form.complainStatus" placeholder="请选择任务状态"   :disabled="readonly">
            <el-option
              v-for="dict in taskStateOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" :disabled="readonly"/>
        </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="反馈内容" :visible.sync="dialogFormVisible" width="600px">
      <el-form :model="form2">
        <div style="width: 100%;min-height: 100px;margin-top: -20px">
          <el-form-item label="投诉事项" prop="complainMatter">
            <textarea class="inputstyle1" v-model="form2.complainMatter"  readonly></textarea>
          </el-form-item>
        </div>
        <el-form-item label="反馈" style = "margin-top: -15px;">
            <textarea class="inputstyle" v-model="form2.concent" type ="textarea" ></textarea>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -30px;">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary"  @click="submint2">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComplainDeal, getComplainDeal, delComplainDeal, addComplainDeal, updateComplainDeal, exportComplainDeal,getUserList } from "@/api/complainDeal/complainDeal";
import {enterpriseList} from "@/api/system/eventInfo";
import { getUserProfile } from "@/api/system/user";
export default {
  name: "ComplainDeal",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投诉处置表格数据
      complainDealList: [],
      enterpriseList:[],
      peopleList:[],
      readonly:false,
      display:"display:none",
      // 投书状态类型：1.派发中 2.反馈 3.归档
      taskStateOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dialogFormVisible:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        complainName: null,
        complainPhone: null,
        complainMatter: null,
        transferRecord: null,
        dealCondition: null,
        complainAssignEnterproseName: null,
        complainAssignEnterproseId: null,
        complainAssignManId: null,
        complainAssignMan: null,
        complainStatus: null,
        isDel: null,
        remarks: null
      },
      // 表单参数
      form: {
        peopleList:[],
      },
      form2:{
        complainDealId:'',
        complainMatter:'',
        concent:'',
      },
      //身份
      deptId:'',
      // 表单校验
      rules: {
        complainName: [
          { required: true, message: "投诉人不能为空", trigger: "blur" }
        ],
        complainPhone: [
          { required: true, message: "投诉人电话不能为空", trigger: "blur" }
        ],
        complainMatter: [
          { required: true, message: "投诉事项不能为空", trigger: "blur" }
        ],
        complainAssignEnterproseId: [
          { required: true, message: "指派单位不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getUser();
    this.getEnterpriseList();
    this.getDicts("task_state").then(response => {
      this.taskStateOptions = response.data;
    });
  },
  methods: {
    //获取deptId
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.deptId = response.data.deptId;
        //console.log(this.deptId)
    });
    },
    /** 查询投诉处置列表 */
    getList() {
      this.loading = true;
      listComplainDeal(this.queryParams).then(response => {
        this.complainDealList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //公司列表
    getEnterpriseList() {
      console.log(this.uploadImgUrl)
      enterpriseList(this.queryParams).then(response => {
        this.enterpriseList = response.data;
      });
    },
    qiyechang(value){
      this.form.complainAssignMan="";
      let obj = {};
      obj = this.enterpriseList.find((item)=>{
        return item.enterpriseId === value;
      });
      this.form.complainAssignEnterproseName = obj.enterpriseName;
      this.form.complainAssignEnterproseId = value;
      getUserList(value).then(response => {
        console.log(response.data)
        //console.log(this.peopleList)
        this.peopleList=response.data;
      });
    },
    manChang(value){
      let obj = {};
      obj = this.peopleList.find((item)=>{
        return item.id === value;
      });
      this.form.complainAssignManId === value;
      this.form.complainAssignMan = obj.nickName;
      console.log(this.form);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        complainDealId: null,
        complainName: null,
        complainPhone: null,
        complainMatter: null,
        transferRecord: null,
        dealCondition: null,
        complainAssignEnterproseName: null,
        complainAssignEnterproseId: null,
        complainAssignManId: null,
        complainAssignMan: null,
        complainStatus: "1",
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDel: null,
        remarks: 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.complainDealId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    taskStateFormat(row, column) {
      var status = this.selectDictLabel(this.taskStateOptions, row.complainStatus);
      if(status=='派发中'){
        return <p style='color: #ff7272'>派发中</p>
      }else if(status=="已反馈"){
        return <p style='color: #1890ff'>已反馈</p>
      }else{
        return <p style='color: #30B46B'>已归档</p>
      }
      return this.selectDictLabel(this.taskStateOptions, row.complainStatus);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.display="display:none";
      this.readonly = false;
      this.peopleList=[];
      this.reset();
      this.open = true;
      this.title = "添加投诉处置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.display="display:none";
      this.readonly = false;
      this.peopleList=[];
      this.reset();
      const complainDealId = row.complainDealId || this.ids
      getComplainDeal(complainDealId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改投诉处置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.complainDealId != null) {
            updateComplainDeal(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addComplainDeal(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //详情
    handleDtail(row) {
      this.display="display:";
      this.readonly = true;
      this.reset();
      const complainDealId = row.complainDealId || this.ids
      getComplainDeal(complainDealId).then(response => {
        this.form = response.data;
      this.open = true;
      this.title = "修改投诉处置";
    });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const complainDealIds = row.complainDealId || this.ids;
      this.$confirm('是否确认删除选中的投诉处置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delComplainDeal(complainDealIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    //归档
    handlegui(row) {
      const complainDealIds = row.complainDealId || this.ids;
      this.$confirm('是否确认归档选中的投诉处置数据项?', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "success"
      }).then(() => {
        var a = {"complainDealId":complainDealIds,"complainStatus":3}
        return updateComplainDeal(a);
      }).then(() => {
        this.msgSuccess("归档成功");
        this.getList();
      }).catch(() => {});
    },
    //反馈
    handlefankui(row){
      this.form2.concent="";
      this.dialogFormVisible = true;
      this.form2.complainDealId=row.complainDealId;
      this.form2.complainMatter = row.complainMatter;
    },
    //提交反馈信息
    submint2(){
      var a = {"complainDealId":this.form2.complainDealId,"complainStatus":2,"dealCondition":this.form2.concent}
      updateComplainDeal(a).then(response => {
        this.msgSuccess("修改成功");
        this.dialogFormVisible = false;
        this.getList();
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有投诉处置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportComplainDeal(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style>
  .division{
    display:flex;
    flex-direction:row;
    justify-content:flex-start;
  }
  .inputstyle{
    min-height: 200px;
    max-height: 300px;
    width: 100%;
    border-color: 0.5px #99a9bf;
    outline:none;
  }
  .inputstyle1{
    min-height: 50px;
    max-height: 200px;
    width: 100%;
    border : none;
    resize:none;
    outline:none;
  }
</style>

