<template>
  <div class="app-container">


    <div class = "search-bx"  >

        <div class="search">
          <el-row :gutter="0">

              <!-- <el-select v-model="tableObj.getdataListParm.parammaps.customerId" placeholder="客户名称" class="filter-item" style="width: 120px;" clearable filterable remote :remote-method="change_custormer_remote" :loading="loading">
                  <el-option v-for="(item,index) in customerNameList" :key="index" :label="item.name" :value="item.id" />
                </el-select> -->

                <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 120px " class="filter-item" @select="change_customer_select" @clear="clear_customer_select" @blur="customer_search_blur" clearable>
                  <template slot-scope="{ item }">
                    <span class="name">{{ item.name }}</span>
                  </template>
                </el-autocomplete> -->

                <el-input v-model="tableObj.getdataListParm.parammaps.customerName" placeholder="客户名称" style="width: 180px;" class="filter-item" clearable />

                <el-select v-model="tableObj.getdataListParm.parammaps.groupId" placeholder="集团" class="filter-item" style="width: 120px;" clearable filterable>
                  <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>

                <el-input v-model="tableObj.getdataListParm.parammaps.proposerId" placeholder="投诉人" style="width: 180px;" class="filter-item" clearable />

                <el-select v-model="tableObj.getdataListParm.parammaps.respondentId" placeholder="被投诉人" class="filter-item" style="width: 120px;" clearable>
                  <el-option v-for="item in respondentNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
                <el-select v-model="tableObj.getdataListParm.parammaps.status" placeholder="处理状态" class="filter-item" style="width: 120px;" clearable>
                  <el-option v-for="item in statusNameList" :key="item.id" :label="item.name" :value="item.name" />
                </el-select>

                <el-date-picker v-model="tableObj.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />


                <el-button class="successBorder" @click="form_search">查询</el-button>
                <el-button class="successBorder" @click="form_clear">重置</el-button>

                <el-button v-if="isComplaintAdd" class="success" icon="el-icon-plus" @click="form_add">新增</el-button>
                <!-- <el-button  class="success" icon="el-icon-upload2" @click="form_export">导出</el-button> -->


          </el-row>
        </div>


        </div>


    <div class="table" >
      <el-table :key="tableObj.tableKey" v-loading="tableObj.listLoading" element-loading-text="给我一点时间" :data="tableObj.list" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable table-fixed" :max-height="myHeight" >
        <!-- <el-table-column type="selection" align="center" width="50" /> -->
        <el-table-column label="序号" align="center" type="index" width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + (tableObj.pageNum-1) * tableObj.pageSize + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column label="客户名称" min-width="120px" align="center" show-overflow-tooltip fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="集团" min-width="110px" align="center" show-overflow-tooltip  fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.groupName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="投诉日期" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.cdate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="投诉人" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.proposerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="投诉电话" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.telephone }}</span>
          </template>
        </el-table-column>
        <el-table-column label="投诉接收人" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.receiverName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="被投诉人" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.respondentName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="投诉内容" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.content }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="120px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <el-table-column label="录入日期" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.created }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理状态" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.statusName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center"   :width="autoWidth"  v-if="autoWidth !== 0"   class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <!-- <el-button v-if="isRoleEdit" class="miniSuccess" @click="form_edit(row)">编辑</el-button>
            <el-button v-if="isRoleEdit" class="miniDanger" @click="form_delete(row)">删除</el-button> -->
            <el-button class="miniPrimary" @click="form_see(row)">查看</el-button>
            <el-button v-if="isComplaintAdd  && row.isModify == 1 && row.createrId == employeid" class="miniSuccess" @click="form_edit(row)">编辑</el-button>
            <el-button v-if="isComplaintAdd  && row.isDel == 1 && row.createrId == employeid" class="miniDanger" @click="form_delete(row)">删除</el-button>
            <el-button class="miniPrimary" v-if="row.statusName == '未处理' && isComplaintDeal" @click="handleDealWith(row)">处理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="tableObj.total>=0" :total="tableObj.total" :page.sync="tableObj.getdataListParm.offset" :limit.sync="tableObj.getdataListParm.pagecount" @pagination="get_table_data" />
    </div>

    <!-- 新增/编辑 -->
    <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="40%">
      <div class="app-add">
        <el-form ref="createTemp" :rules="create.rules" :model="create.temp" label-position="right" label-width="150px" style="width: 80%;margin:0 auto 50px">

          <!-- <el-form-item label="客户名称：" prop="customerName">
            <el-autocomplete ref="customerName"  v-model="create.temp.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 100%;margin-right:10px" @select="changeCustomer" v-if="create.dialogStatus=='create' || create.dialogStatus=='update'" @clear="clear_customer_selectTemp" @blur="customer_search_blurTemp" clearable>
              <template slot-scope="{ item }">
                <span class="name">{{ item.name }}</span>
              </template>
            </el-autocomplete>
          </el-form-item>
         -->
          <!-- <el-form-item label="所属集团：" prop="groupId">
              <el-select v-model="create.temp.groupId" placeholder="所属集团" class="filter-item" style="width: 100%;" filterable  @change="change_group" clearable :disabled="create.dialogStatus=='see' || create.dialogStatus=='update' " >
                  <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
           </el-form-item> -->

          <el-form-item label="客户名称：" prop="customerId">
              <el-select v-model="create.temp.customerId" filterable placeholder="客户名称" class="filter-item"  style="width: 100%;" clearable @change="change_customer" :disabled="create.dialogStatus=='see' || create.dialogStatus=='update' " >
                  <el-option v-for="item in create.customerNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
          </el-form-item>

          <el-form-item label="集团：" prop="groupName">
            <el-input ref="groupName" v-model="create.temp.groupName" class="filter-item" style="width: 100%;" disabled />
          </el-form-item>

          <el-form-item label="投诉日期：" prop="cdate">
            <el-date-picker v-model="create.temp.cdate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" :disabled="create.dialogStatus=='see'" />
          </el-form-item>

          <el-form-item label="投诉人：" prop="proposerId">
            <el-select ref="proposerId" v-model="create.temp.proposerId" filterable placeholder="请输入或选择投诉人" class="filter-item" style="width: 100%;" @change="changeReceiver" allow-create :disabled="create.dialogStatus=='see'">
              <el-option v-for="item in create.proposerNameList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item label="投诉人电话：" prop="telephone">
            <el-input ref="telephone" v-model="create.temp.telephone" class="filter-item" style="width: 100%;" maxlength="11" placeholder="请输入投诉人电话" :disabled="create.dialogStatus=='see'" />
          </el-form-item>

          <el-form-item label="投诉接收人：" prop="receiverId">
            <el-select ref="receiverId" v-model="create.temp.receiverId" filterable placeholder="请选择投诉接收人" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'">
              <el-option v-for="item in receiverNameList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item label="被投诉人：" prop="respondentId">
            <el-select ref="respondentId" v-model="create.temp.respondentId" filterable placeholder="请选择拜访人" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'">
              <el-option v-for="item in respondentNameList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="投诉内容：" prop="content">
              <el-input ref="content" v-model="create.temp.content" type="textarea" placeholder="请输入情况说明" maxlength="255" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'" />
            </el-form-item>
          </el-row>

          <el-row>
            <el-form-item label="备注：" prop="remark">
              <el-input ref="remark" v-model="create.temp.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" placeholder="请输入备注，最多255个字" maxlength="255" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'" />
            </el-form-item>
          </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="create.dialogFormVisible = false;get_table_data()">关闭</el-button>
          <el-button v-if="create.dialogStatus==='create' || create.dialogStatus==='update'" class="success" :disabled="isokDisable" @click="create.dialogStatus==='create'?add_dialog_save():form_edit_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog title="查看" :visible.sync="see.dialogFormVisible" :close-on-click-modal="false" width="40%">
      <div class="app-add">
        <el-tabs v-model="activeName">
          <el-tab-pane label="投诉详情" name="first">

            <el-form ref="seeTemp" :rules="see.rules" :model="see.temp" label-position="right" label-width="150px" style="width: 80%;margin:0 auto 50px">
              <!-- <el-form-item label="客户名称：" prop="customerId">
                <el-select ref="customerId" v-model="see.temp.customerId" filterable placeholder="请选择客户" class="filter-item" style="width: 100%;" @change="changeCustomer" disabled>
                  <el-option v-for="item in customerNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item> -->
              <el-form-item label="客户名称：" prop="customerName">
                <el-input ref="customerName" v-model="see.temp.customerName" class="filter-item" style="width: 100%;" disabled />
              </el-form-item>

              <el-form-item label="集团：" prop="groupName">
                <el-input ref="groupName" v-model="see.temp.groupName" class="filter-item" style="width: 100%;" disabled />
              </el-form-item>

              <el-form-item label="投诉日期：" prop="cdate">
                <el-date-picker v-model="see.temp.cdate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" disabled/>
              </el-form-item>

              <el-form-item label="投诉人：" prop="proposerName">
                <el-input v-model="see.temp.proposerName" type="proposerName" placeholder="" style="width: 100%;" :clearable="false" disabled/>
              </el-form-item>

              <!-- <el-form-item label="投诉人：" prop="proposerId">
                <el-select ref="proposerId" v-model="see.temp.proposerId" filterable placeholder="请输入或选择投诉人" class="filter-item" style="width: 100%;" @change="changeReceiver" allow-create disabled>
                  <el-option v-for="item in see.proposerNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item> -->

              <el-form-item label="投诉人电话：" prop="telephone">
                <el-input ref="telephone" v-model="see.temp.telephone" class="filter-item" style="width: 100%;" maxlength="11" placeholder="请输入投诉人电话" disabled/>
              </el-form-item>

              <el-form-item label="投诉接收人：" prop="receiverName">
                <el-input v-model="see.temp.receiverName" type="receiverName" placeholder="" style="width: 100%;" :clearable="false" disabled/>
              </el-form-item>


              <!-- <el-form-item label="投诉接收人：" prop="receiverId">
                <el-select ref="receiverId" v-model="see.temp.receiverId" filterable placeholder="请选择投诉接收人" class="filter-item" style="width: 100%;" disabled>
                  <el-option v-for="item in receiverNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item> -->

              <el-form-item label="被投诉人：" prop="respondentId">
                <el-select ref="respondentId" v-model="see.temp.respondentId" filterable placeholder="请选择拜访人" class="filter-item" style="width: 100%;" disabled>
                  <el-option v-for="item in respondentNameList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="投诉内容：" prop="content">
                  <el-input ref="content" v-model="see.temp.content" type="textarea" placeholder="请输入情况说明" maxlength="255" class="filter-item" style="width: 100%;" disabled />
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="备注：" prop="remark">
                  <el-input ref="remark" v-model="see.temp.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" placeholder="请输入备注，最多255个字" maxlength="255" class="filter-item" style="width: 100%;" disabled />
                </el-form-item>
              </el-row>

            </el-form>

          </el-tab-pane>
          <el-tab-pane label="处理情况" name="second">
            <el-form ref="seeTemp2" :rules="see.rules" :model="see.temp" label-position="right" label-width="150px" style="width: 80%;margin:0 auto 50px">

              <el-form-item label="处理人：" prop="handlerName">
                <el-input ref="handlerName" v-model="see.temp2.handlerName" type="textarea" maxlength="255" class="filter-item" style="width: 100%;" disabled />
              </el-form-item>
              <el-form-item label="处理日期：" prop="hdate">
                <el-date-picker v-model="see.temp2.hdate" type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" disabled />
              </el-form-item>
              <el-form-item label="处理方式：" prop="content">
                <el-input ref="content" v-model="see.temp2.hcontent" type="textarea" maxlength="255" class="filter-item" style="width: 100%;" disabled />
              </el-form-item>
              <el-form-item label="备注：" prop="remark">
                <el-input ref="remark" v-model="see.temp2.hremark" type="textarea" maxlength="255" class="filter-item" style="width: 100%;" disabled/>
              </el-form-item>
            </el-form>

            </el-form>
          </el-tab-pane>

        </el-tabs>

        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="see.dialogFormVisible = false;get_table_data()">关闭</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 处理 -->
    <el-dialog title="处理" :visible.sync="dealwith.dialogFormVisible" :close-on-click-modal="false" width="40%">
      <div class="app-add">
        <el-form ref="dealTemp" :rules="dealwith.rules" :model="dealwith.temp" label-position="right" label-width="150px" style="width: 80%;margin:0 auto 50px">

          <el-form-item label="处理人：" prop="handlerId">
            <el-select ref="handlerId" v-model="dealwith.temp.handlerId" filterable placeholder="请选择处理人" class="filter-item" style="width: 100%;">
              <el-option v-for="item in handlerNameList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="处理日期：" prop="hdate">
            <el-date-picker v-model="dealwith.temp.hdate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" />
          </el-form-item>
          <el-form-item label="处理方式：" prop="content">
            <el-input ref="content" v-model="dealwith.temp.content" type="textarea" placeholder="请输入情况说明" maxlength="255" class="filter-item" style="width: 100%;" />
          </el-form-item>
          <el-form-item label="备注：" prop="remark">
            <el-input ref="remark" v-model="dealwith.temp.remark" type="textarea" placeholder="请输入情况说明" maxlength="255" class="filter-item" style="width: 100%;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="dealwith.dialogFormVisible = false;get_table_data()">取消</el-button>
          <el-button class="success" @click="completeData()">确认</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons, calculativeWidth } from '@/api/common'
import Cookies from 'js-cookie'
import {  parseTime, json2excel } from '@/utils/index.js'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
export default {
  name: 'ComplaintRecord',
  components: { Pagination },
  data() {
    return {
      myHeight:document.documentElement.clientHeight - 85 - 160,
      employeid: Cookies.get('employeid'),
      isRoleEdit: [],isComplaintAdd: [],isComplaintDeal: [],

      activeName: 'second',
      send_select_list: [
        { name: 'getCustomerSelect', offset: 0, pagecount: 0, parammaps: {} },
        { name: 'getDictListSelect', offset: 0, pagecount: 0, parammaps: { "pid": "54" } },
        { name: 'getEmployeesSelect', offset: 0, pagecount: 0, parammaps: {} },
        { name: 'getEmployeesSelect2', offset: 0, pagecount: 0, parammaps: {} }
      ],

      customerNameList: [], // 客户名称
      groupNameList: [], // 集团
      respondentNameList: [], // 被投诉人

      proposerNameList: [], // 投诉人
      receiverNameList: [], // 投诉接受人
      statusNameList: [{ "id": "已处理", "name": "已处理" }, { "id": "未处理", "name": "未处理" }],


      handlerNameList: [], // 处理人

      //表格请求参数~~
      tableObj: {
        getdataListParm: {
          name: 'getComplaint',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pagecount')),
          returntype: 'Map',
          parammaps: {
            roleId: Cookies.get('g_roleId'),
            userId: Cookies.get('g_userId'),
            customerName: "",
            customerId: '',
            groupId: '',
            proposerId: '',
            respondentId: '',
            status: "",
            beginDate: '',
            endDate: '',
            inputDatetime: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      download: {
        getdataListParm: {
          name: 'getComplaint',
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: 'Map',
          parammaps: {
            customerName: "",
            customerId: '',
            groupId: '',
            proposerId: '',
            respondentId: '',
            status: "",
            beginDate: '',
            endDate: '',
            inputDatetime: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { customerId: '', customerName: '',groupId: '', groupName: '', cdate: parseTime(new Date(), '{y}-{m}-{d}'), telephone: '', receiverId: '', receiverName: '', respondentId: '', content: '', remark: '', modifyName: 'add', receiverChoose: 'true' },
        rules: {
          customerId: [{ required: true, message: '必填', trigger: 'blur' }],
          //  groupId: [{ required: true, message: '必填', trigger: 'blur' }],
          cdate: [{ required: true, message: '必填', trigger: 'blur' }],
          proposerId: [{ required: true, message: '必填', trigger: 'blur' }],
          telephone: [{ required: true, message: '必填', trigger: 'blur' }],
          receiverId: [{ required: true, message: '必填', trigger: 'blur' }],
          respondentId: [{ required: true, message: '必填', trigger: 'blur' }],
          content: [{ required: true, message: '必填', trigger: 'blur' }],
        },
        // 客户名称
        getdataListParmCust: {
          name: 'getCustomerByGroupId',
          returntype: 'Map',
          parammaps: { groupId: "" }
        },
        customerNameList:[],
        // 投诉人
        getdataListParm: {
          name: 'getContacts',

          returntype: 'Map',
          parammaps: { customerId: "" }
        },

        getdataListParm2: {
          name: 'getgroupNameById',

          returntype: 'Map',
          parammaps: { id: "" }
        },
        // 接待人电话
        getdataListParm3: {
          name: 'getTelById',

          returntype: 'Map',
          parammaps: { id: "" }
        },
        proposerNameList: [], // 投诉人

      },
      // 查看
      see: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { customerId: '', customerName:"",groupId: '', groupName: '', cdate: parseTime(new Date(), '{y}-{m}-{d}'), telephone: '', receiverId: '', receiverName: '', respondentId: '', content: '', remark: '', modifyName: 'add', receiverChoose: 'true', handlerId: '', hdate: '', content: '', remark: '', handlerName: '' },
        temp2: { handlerId: '', hdate: parseTime(new Date(), '{y}-{m}-{d}'), hcontent: '', hremark: '', cid: "" },
        rules: {
          customerName: [{ required: true, message: '必填', trigger: 'input' }],
          cdate: [{ required: true, message: '必填', trigger: 'blur' }],
          proposerId: [{ required: true, message: '必填', trigger: 'blur' }],
          telephone: [{ required: true, message: '必填', trigger: 'blur' }],
          receiverId: [{ required: true, message: '必填', trigger: 'blur' }],
          respondentId: [{ required: true, message: '必填', trigger: 'blur' }],
          content: [{ required: true, message: '必填', trigger: 'blur' }],
        },
        // 投诉人
        getdataListParm: {
          name: 'getContacts',

          returntype: 'Map',
          parammaps: { customerId: "" }
        },

        getdataListParm2: {
          name: 'getgroupNameById',

          returntype: 'Map',
          parammaps: { id: "" }
        },
        // 接待人电话
        getdataListParm3: {
          name: 'getTelById',

          returntype: 'Map',
          parammaps: { id: "" }
        },
        proposerNameList: [], // 投诉人

      },
      textMap: {
        create: '新增',
        see: '查看',
        update: '编辑'
      },


      // 处理
      dealwith: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { handlerId: '', hdate: parseTime(new Date(), '{y}-{m}-{d}'), content: '', remark: '', cid: "" },
        rules: {
          handlerId: [{ required: true, message: '必填', trigger: 'blur' }],
          hdate: [{ required: true, message: '必填', trigger: 'blur' }],
          content: [{ required: true, message: '必填', trigger: 'blur' }]
        },
      },

      autoWidth: 130,
      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },

  created() {
    this.get_table_data()
    this.get_select_list()
    this.get_auto_buttons()
  },

  methods: {
    //获取按钮权限
    get_auto_buttons() {
      const Edit = 'complaintRecord'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit

      const ComplaintAdd = 'business:complaint:add'
      const isComplaintAdd = checkButtons(this.$store.state.user.buttons, ComplaintAdd)
      this.isComplaintAdd = isComplaintAdd

      const ComplaintDeal = 'business:complaint:deal'
      const isComplaintDeal= checkButtons(this.$store.state.user.buttons, ComplaintDeal)
      this.isComplaintDeal = isComplaintDeal

      //操作的宽度
      // var widthCount = calculativeWidth(isComplaintAdd,isComplaintAdd,isComplaintDeal)  + 90
      // this.autoWidth = widthCount

    },
    //获取所有下拉框的内容
    get_select_list() {


      GetDataByNames(this.send_select_list).then(response => {
        this.create.customerNameList = response.data.getCustomerSelect.list
        console.log("客户名称下拉框", this.create.customerNameList)
        this.groupNameList = response.data.getDictListSelect.list
        console.log("集团下拉框", this.groupNameList)
        this.respondentNameList = response.data.getEmployeesSelect.list
        this.handlerNameList = response.data.getEmployeesSelect.list
        console.log("被投诉人下拉框", this.respondentNameList)
        console.log("处理人下拉框", this.respondentNameList)
        this.receiverNameList = response.data.getEmployeesSelect2.list
        console.log("投诉接受人下拉框", this.receiverNameList)


      })


    },
    //加载表格
    get_table_data() {
      this.tableObj.listLoading = true
      GetDataByName(this.tableObj.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {

          this.tableObj.list = response.data.list
          this.tableObj.pageNum = response.data.pageNum
          this.tableObj.pageSize = response.data.pageSize
          this.tableObj.total = response.data.total

           //计算操作栏宽度
           var btnNum = 0
              var arrList = response.data.list
              arrList.forEach(function(row){
                  var itemBtnNum = 0
                  if(me.isComplaintAdd  && row.isModify == 1 && row.createrId == me.employeid){
                    itemBtnNum = itemBtnNum + 1
                  }
                  if(me.isComplaintAdd  && row.isDel == 1 && row.createrId == me.employeid){
                    itemBtnNum = itemBtnNum + 1
                  }
                  if(row.statusName == '未处理' && me.isComplaintDeal){
                    itemBtnNum = itemBtnNum + 1
                  }


                  console.log(itemBtnNum)
                  if(itemBtnNum > btnNum){
                    btnNum = itemBtnNum
                  }
              })
              console.log("btnNum=============",btnNum)
              me.autoWidth = btnNum * 90


        } else {
          this.tableObj.list = []
        }
        setTimeout(() => {
          this.tableObj.listLoading = false
        }, 100)
      })
    },
    form_search() {
      console.log('点击了查询')
      if (this.tableObj.getdataListParm.parammaps.inputDatetime !== '' && this.tableObj.getdataListParm.parammaps.inputDatetime !== null) {
        this.tableObj.getdataListParm.parammaps.beginDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.tableObj.getdataListParm.parammaps.endDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime = ''
        this.tableObj.getdataListParm.parammaps.beginDate = ''
        this.tableObj.getdataListParm.parammaps.endDate = ''
      }
      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()
    },
    form_clear() {
      console.log('点击了重置')

      this.tableObj.getdataListParm.parammaps.customerName = ''

      this.tableObj.getdataListParm.parammaps.customerId = ''
      this.tableObj.getdataListParm.parammaps.groupId = ''
      this.tableObj.getdataListParm.parammaps.proposerId = ''
      this.tableObj.getdataListParm.parammaps.respondentId = ''
      this.tableObj.getdataListParm.parammaps.status = ''
      this.tableObj.getdataListParm.parammaps.beginDate = ''
      this.tableObj.getdataListParm.parammaps.endDate = ''
      this.tableObj.getdataListParm.parammaps.inputDatetime = ''
      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()
    },

    // 新增
    form_reset() {
      this.create.temp = { customerId: '',  customerName: '', groupId: '', groupName: '', cdate: parseTime(new Date(), '{y}-{m}-{d}'), telephone: '', receiverId: '', receiverName: '', respondentId: '', content: '', remark: '', modifyName: 'add', receiverChoose: 'true' }
      this.dealwith.temp = { handlerId: '', hdate: parseTime(new Date(), '{y}-{m}-{d}'), content: '', remark: '', cid: "" }
      this.create.proposerNameList = []

    },


    clear_customer_selectTemp(item) {
      document.activeElement.blur()
      this.create.temp.customerId = ""
      this.create.temp.customerName = ""
      this.create.temp.groupName = ""
      this.$forceUpdate();
    },

    //客户失去焦点
    customer_search_blur(item) {
      console.log("客户失去焦点")
      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""
      this.customerNameList = []
    },
    customer_search_blurTemp(item) {
      this.create.temp.customerId = ""
      this.create.temp.customerName = ""
      this.create.temp.groupName = ""
      this.customerNameList = []
      this.$forceUpdate();
    },


    //模糊查询客户
    customer_search(queryString, cb) {
      console.log('模糊查询输入值', queryString)
      GetDataByName({ name: 'getCustomerNameFuzzy', page: 1, offset: 1, pagecount: 10, returntype: 'Map', parammaps: { inputvalue: queryString } }).then(response => {
        this.customerNameList = response.data.list
        console.log("客户名称下拉框", response)
        cb(response.data.list)
      })
    },

    //模糊查询客户选择
    change_customer_select(item) {
      console.log('客户名称模糊查询选中值', item)
      this.tableObj.getdataListParm.parammaps.customerId = item.id
      this.tableObj.getdataListParm.parammaps.customerName = item.name
    },

    //清空客户选择
    clear_customer_select(item) {
      document.activeElement.blur()
      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""
    },


    //监听 - 集团
    change_group(item) {
      console.log(item)
      console.log(this.create.temp.groupId)
      this.create.temp.groupId = item
      this.create.getdataListParmCust.parammaps.groupId = item

      this.create.temp.customerName = ""
      this.create.temp.customerId = ""
      this.create.customerNameList = []

      this.get_customer_list()
      this.$forceUpdate();

    },
// 弹窗中的客户
    get_customer_list() {
      GetDataByName(this.create.getdataListParmCust).then(response => {
        if (response.data.list !== null) {
          this.create.customerNameList = response.data.list
          console.log('弹窗中的客户数据', response.data.list)
        } else {
          this.create.customerNameList = []
        }
      })
    },


    //监听 - 下拉中客户名称
    change_customer(item) {
      console.log(item)
      this.create.temp.customerId = item

      this.create.getdataListParm.parammaps.customerId = item
      this.getProposerNameList()


      this.get_groupName(item)

    },

    // 获取集团名称
    get_groupName(customerId) {
      var me = this
      var send_data = {
        name: 'getgroupNameById',  returntype: 'Map',  parammaps: {  id: customerId }
      }
      GetDataByName(send_data).then(response => {

        console.log(response)
        if (response.data.list !== null) {
           me.create.temp.groupName = response.data.list[0].groupName
           me.create.temp.groupId = response.data.list[0].groupId
        } else {
           me.create.temp.groupName = ""
           me.create.temp.groupId = ""
        }
      })
    },


    //监听 - 下拉中客户名称
    changeCustomer(item) {
      console.log(item)
      this.create.temp.customerId = item.id
      this.create.temp.customerName = item.name
      this.$forceUpdate();

      this.create.getdataListParm.parammaps.customerId = item.id
      this.getProposerNameList()
      this.create.getdataListParm2.parammaps.id = item.id
      this.getGroupNameId()
    },

    // 集团名称
    getGroupNameId() {
      GetDataByName(this.create.getdataListParm2).then(response => {
        if (response.data.list !== null) {
          this.create.temp.groupName = response.data.list[0].groupName
          this.create.temp.groupId = response.data.list[0].groupId
          console.log('集团名称', response.data.list)
        }
      })
    },


    // 投诉人
    getProposerNameList() {
      GetDataByName(this.create.getdataListParm).then(response => {
        if (response.data.list !== null) {
          this.create.proposerNameList = response.data.list
          console.log('投诉人数据', response.data.list)
        } else {
          this.create.proposerNameList = []
        }
      })
    },

    // 监听 - 投诉人
    changeReceiver(item) {
      this.create.getdataListParm3.parammaps.id = item
      this.create.temp.proposerName = this.create.proposerNameList.find(obj => obj.id === item).name
      this.getTelephoneName()
    },

    // 投诉人电话
    getTelephoneName() {
      GetDataByName(this.create.getdataListParm3).then(response => {
        if (response.data.list !== null) {
          this.create.temp.telephone = response.data.list[0].telephone
          console.log('投诉人电话', response.data.list)
        }
      })
    },

    //新增
    form_add() {
      console.log('点击了新增')
      this.form_reset()
      this.getProposerNameList()
      this.create.dialogStatus = 'create'
      this.create.dialogFormVisible = true
    },
    //新增保存
    add_dialog_save() {
      console.log('点击了新增保存')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          this.isokDisable = true
          setTimeout(() => {
            this.isokDisable = false
          }, 1000)

          this.requestParam.name = 'modifyComplaint'
          this.create.temp.modifyName = "add"
          this.create.temp.id = ""


          if (this.create.proposerNameList.find(obj => obj.id == this.create.temp.proposerId)) {
            console.log("receiverNameList下拉直接选的！")
            this.create.temp.receiverChoose = "true"
          } else {
            this.create.temp.proposerName = this.create.temp.proposerId
            this.create.temp.receiverChoose = "false"
            console.log("receiverNameList下拉自己填的！")
          }

          this.create.temp.createrId = Cookies.get('employeid')
          this.create.temp.receiverId2 = ""
          var send_data = {
            "common": { "returnmap": "0" },
            "data": [
              {
                "name": "insertContactsNew", "type": "e",
                "parammaps": {
                  "customerId": this.create.temp.customerId,
                  "contactName": this.create.temp.proposerName,
                  "telephone": this.create.temp.receiverTel,
                  "address": "",
                  "remark": this.create.temp.remark,
                  "receiverChoose": this.create.temp.receiverChoose
                }
              },
              {
                "name": "insertComplaint",
                "resultmaps": {
                  "list": [this.create.temp]
                },
                "children": [{
                  "name": "insertComplaint",
                  "type": "e",
                  "parammaps": {
                    "customerId": "@insertComplaint.customerId",
                    "groupId": "@insertComplaint.groupId",
                    "cdate": "@insertComplaint.cdate",
                    "proposerId": "@insertComplaint.proposerId",
                    "proposerId2": "@insertContactsNew.LastInsertId",
                    "telephone": "@insertComplaint.telephone",
                    "receiverId": "@insertComplaint.receiverId",
                    "respondentId": "@insertComplaint.respondentId",
                    "remark": "@insertComplaint.remark",
                    "content": "@insertComplaint.content",
                    "createrId": "@insertComplaint.createrId",
                    "receiverChoose": "@insertComplaint.receiverChoose"

                  }
                }]
              }
            ]
          }
          console.log('新增保存发送参数 ', send_data)


          ExecDataByConfig(send_data).then(response => {
            if (response.msg !== 'fail') {
              this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
              this.create.dialogFormVisible = false
              this.get_table_data()
            } else {
              this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
            }
          })
        }
      })
    },
    // 查看
    form_see(row) {
      this.form_reset()
      console.log('点击了查看', row)

      this.see.temp = Object.assign({}, row)
      this.see.temp2 = Object.assign({}, row)

      if (row.statusName == "已处理") {

        this.activeName = 'second'
      } else {
        this.activeName = 'first'
      }


      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()


      this.create.getdataListParm.parammaps.customerId = row.customerId
      this.getProposerNameList()
      this.see.temp.id = row.id

      this.see.dialogStatus = 'see'
      this.see.dialogFormVisible = true

    },


    // 编辑
    form_edit(row) {
      console.log('点击了编辑', row)
      this.$nextTick(() => {
        this.$refs.createTemp.resetFields()
      })
      this.create.temp = Object.assign({}, row)

      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()

      this.create.getdataListParm.parammaps.customerId = row.customerId
      this.getProposerNameList()
      this.create.temp.id = row.id
      this.create.dialogStatus = 'update'
      this.create.dialogFormVisible = true
    },


    // 编辑保存
    form_edit_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          this.isokDisable = true
          setTimeout(() => {
            this.isokDisable = false
          }, 1000)

          this.create.temp.modifyName = "update"
          this.requestParam.name = 'modifyComplaint'

          if (this.create.proposerNameList.find(obj => obj.id == this.create.temp.proposerId)) {
            console.log("receiverNameList下拉直接选的！")
            this.create.temp.receiverChoose = "true"
          } else {
            this.create.temp.proposerName = this.create.temp.proposerId
            this.create.temp.receiverChoose = "false"
            console.log("receiverNameList下拉自己填的！")
          }


          this.create.temp.receiverId2 = ""
          var send_data = {
            "common": { "returnmap": "0" },
            "data": [
              {
                "name": "insertContactsNew", "type": "e",
                "parammaps": {
                  "customerId": this.create.temp.customerId,
                  "contactName": this.create.temp.proposerName,
                  "telephone": this.create.temp.receiverTel,
                  "address": "",
                  "remark": this.create.temp.remark,
                  "receiverChoose": this.create.temp.receiverChoose
                }
              },
              {
                "name": "updateComplaint",
                "resultmaps": {
                  "list": [this.create.temp]
                },
                "children": [{
                  "name": "updateComplaint",
                  "type": "e",
                  "parammaps": {
                    "customerId": "@updateComplaint.customerId",
                    "groupId": "@updateComplaint.groupId",
                    "cdate": "@updateComplaint.cdate",
                    "proposerId": "@updateComplaint.proposerId",
                    "proposerId2": "@insertContactsNew.LastInsertId",
                    "telephone": "@updateComplaint.telephone",
                    "receiverId": "@updateComplaint.receiverId",
                    "respondentId": "@updateComplaint.respondentId",
                    "remark": "@updateComplaint.remark",
                    "content": "@updateComplaint.content",
                    "receiverChoose": "@updateComplaint.receiverChoose",
                    "id": "@updateComplaint.id"

                  }
                }]
              }
            ]
          }


          ExecDataByConfig(send_data).then(response => {

            if (response.msg !== 'fail') {
              this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
              this.create.dialogFormVisible = false
              this.get_table_data()
            } else {
              this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
            }
          })
        }
      })
    },

    // 删除
    form_delete(row) {
      MessageBox.confirm('是否确认删除此信息?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {

        var send_data = {
          "common": { "returnmap": "0" },
          "data": [
            { "name": "delComplaint", "type": "e", "parammaps": { "id": row.id } }
          ]
        }

        ExecDataByConfig(send_data).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
            this.get_table_data()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },


    // 处理
    resetDealwithTemp() {
      this.dealwith.temp = { handlerId: '', hdate: parseTime(new Date(), '{y}-{m}-{d}'), content: '', remark: '', cid: "" }
    },
    // 处理
    handleDealWith(row) {
      this.resetDealwithTemp()
      console.log('点击了处理', row)
      this.dealwith.temp.cid = row.id
      this.dealwith.dialogFormVisible = true
    },


    // 处理保存
    completeData() {
      console.log('点击了处理保存')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['dealTemp'].validate(valid => {
        if (valid) {
          this.isokDisable = true
          setTimeout(() => {
            this.isokDisable = false
          }, 1000)
          var send_data = {
            "common": { "returnmap": "0" },
            "data": [
              {                "name": "insertHandle", "type": "e",
                "parammaps": this.dealwith.temp
              },
              {                "name": "updateComplaintStatus", "type": "e",
                "parammaps": { "cid": this.dealwith.temp.cid }              }]          }
          ExecDataByConfig(send_data).then(response => {
            if (response.msg !== 'fail') {
              this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
              this.dealwith.dialogFormVisible = false
              this.get_table_data()
            } else {
              this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
            }
          })
        }
      })
    },


    // 导出
    form_export(item) {

       this.download.getdataListParm.parammaps = this.tableObj.getdataListParm.parammaps

       GetDataByName(this.download.getdataListParm).then(response => {
         if (response.data.list !== null) {
           this.download.list = response.data.list
         } else {
           this.download.list = []
         }
         var excelDatas = [
           {
             tHeader: ['序号',  '客户名称', '客户集团', '投诉日期', '投诉人', '投诉电话', '投诉接收人', '被投诉人', '投诉内容', '备注','录入日期',  '处理状态' ],
             filterVal: ['sort','customerName','groupName','cdate','proposerName','telephone','receiverName','respondentName','content','remark','created','statusName'],
             tableDatas: this.download.list,
             sheetName: 'Sheet1'
           }
         ]
         json2excel(excelDatas, '投诉处理', true, 'xlsx')
       })

     },

    // 导入
    form_inport() {
      console.log('点击了导入')
    }

  }
}
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}

/deep/ .el-input.is-disabled .el-input__inner {color: #000000!important;}
/deep/ .el-textarea.is-disabled .el-textarea__inner {color: #000000!important;}
/deep/ .el-radio__input.is-disabled+span.el-radio__label {color: #000000!important;}
/deep/ .el-checkbox__input.is-disabled+span.el-checkbox__label { color: #000000!important;}

</style>
