<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input clearable size="mini" v-model="search.keyWord" placeholder="关键字" style="width: 200px;" class="filter-item"/>
      <el-date-picker
        size="mini"
        v-model="searchTime"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd">
      </el-date-picker>
      <el-input clearable size="mini" v-model="search.orderCode" placeholder="订单编号" style="width: 200px;" class="filter-item"/>
      <el-input clearable size="mini" v-model="search.clientName" placeholder="客户名称" style="width: 200px;" class="filter-item"/>
      <el-select clearable size="mini" v-model="search.tsTitle" placeholder="投诉标题" class="filter-item">
        <el-option
          v-for="item in complaintTitleList"
          :label="item.dictLabel"
          :value="item.dictValue"
        ></el-option>
      </el-select>

      <el-input clearable size="mini" v-model="search.crePerson" placeholder="登记人员" style="width: 200px;" class="filter-item"/>
      <el-input clearable size="mini" v-model="search.billCode" placeholder="投诉单号" style="width: 200px;" class="filter-item"/>
      <el-input clearable size="mini" v-model="search.sevPerson" placeholder="客服追踪人" style="width: 200px;" class="filter-item"/>
      <el-select clearable size="mini" v-model="search.billFlag" placeholder="状态" class="filter-item">
        <el-option
          v-for="item in surveyStateOptions"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getInfo" />
        </el-tooltip>
      </div>
    </div>
    <el-table
      :data="tableData"
      v-loading="listLoading"
      style="width: 100%;margin-bottom: 20px;"
      size="mini"
      row-key="id"
      border
      :row-style="customRowStyle"
      default-expand-all>
      <el-table-column
        type="index"
        label="序号"
        width="50">
        <template slot-scope="scope">
          <span>{{ (listData.page - 1) * listData.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="投诉标题"
        prop="tsTitle"
      >
        <template slot-scope="{row}">
          <el-link size="mini" @click="seeDetails(row)" type="primary">{{row.tsTitle}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="tsType"
        label="投诉类型">
        <template slot-scope="{row}">
          <span v-if="row.tsType == '1'">内部投诉</span>
          <span v-else-if="row.tsType == '2'">外部投诉</span>
        </template>
      </el-table-column>
      <el-table-column
        label="投诉单状态"
        width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.billFlag==0" type="primary" size="mini">
            新建
          </el-tag>
          <el-tag v-else-if="row.billFlag==1" type="warning" size="mini">
            待受理
          </el-tag>
          <el-tag v-else-if="row.billFlag==2" type="danger" size="mini">
            待分配
          </el-tag>
          <el-tag v-else-if="row.billFlag==3" type="info" size="mini">
            调查中
          </el-tag>
          <el-tag v-else-if="row.billFlag==4" type="success" size="mini">
            调查完成
          </el-tag>
          <el-tag v-else-if="row.billFlag==5" type="danger" size="mini">
            登记人结单
          </el-tag>
          <el-tag v-else-if="row.billFlag==6" type="green" size="mini">
            行政审核完成
          </el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="billCode"-->
<!--        label="投诉单号"-->
<!--        width="125">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="billCode"
        label="投诉单号"
        width="130">
        <template slot-scope="{row}">
          <el-link type="primary" @click="openStep(row)">{{row.billCode}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="clientName"
        label="客户名称"></el-table-column>
      <el-table-column
        prop="orderCode"
        label="订单编号"
        width="125"></el-table-column>
      <el-table-column
        prop="linkPhone"
        label="联系电话"
        width="125"></el-table-column>
      <el-table-column
        prop="sevPerson"
        label="客服跟踪人"
      width="95"></el-table-column>
      <el-table-column
        prop="relateMoney"
        label="涉及金额"
        width="95"></el-table-column>
      <el-table-column
        prop="crePerson"
        label="登记人"
        width="95"></el-table-column>
      <el-table-column
        prop="creDate"
        label="登记时间"
        width="160">
        <template slot-scope="{row}">
          <span v-if="row.creDate != null">{{ row.creDate | getTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="tsLimitDate"
        label="到期时间"
        width="160">
        <template slot-scope="{row}">
          <span v-if="row.tsLimitDate != null">{{ row.tsLimitDate | getTime }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getInfo"/>

    <complaint-details ref="complaintDetail" :type="detailsType" @tableReload='acceptSuccess'></complaint-details>
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
    <complaint-step ref="complaintStep"></complaint-step>
  </div>
</template>

<script>
import {
  getComplaintBillList,
} from '@/api/complaint/complaintBillList'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'
import Pagination from '@/components/Pagination'
import ComplaintDetails from '@/components/complaintDetails/complaintDetails'
import ClientInfo from "@/views/doc/client/clientList";
import {getDictTypeInfo} from "@/api/complaint/complaintRegister";
import ComplaintStep from "@/components/complaintStep/complaintStep";

const form = {
  tsTitle: '',
  tsType: '',
  idOrder: '',
  orderCode: '',
  clientName: '',
  linkPhone: '',
  finishHours: '',
  tsEven: '',
  tsGoal: '',
  complainReason: '',
  attachmentList: [],
  idClient: '',
}
export default {
  name: 'complaintBillList',
  components: {
    ComplaintStep,
    ClientInfo,
    ComplaintDetails,
    Cancledialog, Pagination
  },
  data() {
    return {
      detailsType: 0,
      complaintDialog: false,
      innerVisible: false,
      dialogVisible: false,
      createInnerVisible: false,
      form: Object.assign({}, form),

      search: {
        keyWord: '',
        beginTime: '',
        endTime: '',
        orderCode: '',
        clientName: '',
        tsTitle: '',
        crePerson: '',
        billCode: '',
        sevPerson: '',
        billFlag: '',
      },
      searchTime: [],

      surveyStateOptions: [
        // {
        //   label: '全部',
        //   value: -1
        // },
        {
          label: '新建',
          value: 0
        },
        {
          label: '待受理',
          value: 1
        },
        {
          label: '待分配',
          value: 2
        },
        {
          label: '调查中',
          value: 3
        },
        {
          label: '调查完成',
          value: 4
        },
        {
          label: '登记人结单',
          value: 5
        },
        {
          label: '行政审核完成',
          value: 6
        }
      ],
      tableData: [],
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      confirmdialog: false,
      listLoading: false,
      dialogTitle: '',
      complaintTitleList: [],
      relationChecked: false,
      orderList: {
        listData: {
          total: 0,
          page: 1,
          pageSize: 10
        },
        search: {
          orderName: '',
          orderCode: '',
          clientName: '',
          beginTime: '',
          endTime: ''
        },
        orderData: [],
        listLoading: false
      },
      disabledFlag: false,
      fileList:[],
      rules: {
        finishHours: [{ required: true, trigger: 'blur', message: '请填写完成时间' }],
      }
    }
  },
  mounted() {
    this.getInfo()
    this.getComplaintTitle()
  },
  methods: {
    // 获取列表
    getInfo() {
      const _that = this
      _that.listLoading = true

      var params = _that.search
      if (_that.searchTime == null || _that.searchTime < 0) {
        _that.search.beginTime = ''
        _that.search.endTime = ''
      } else {
        _that.search.beginTime = _that.searchTime[0]
        _that.search.endTime = _that.searchTime[1]
      }
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }

      getComplaintBillList(data).then(response => {
        console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        // console.log(_that.tableData)
        _that.listData.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    customRowStyle({row, rowIndex}) {
      if (row.tsLimitDate) {
        var times = row.tsLimitDate.substring(0, 19)
        var nowTime = new Date() // 当前时间
        var endD = new Date(times) // 对比时间
        if (nowTime.getTime() > endD.getTime()) {
          return {
            color: 'red'
          }
        }
      }
    },
    // 刷新表格
    tableRefresh() {
      this.getInfo()
    },
    // 搜索
    searchData() {
      this.listData.page = 1
      this.getInfo()
    },
    // 获取投诉标题
    getComplaintTitle() {
      const _that = this
      var data = {
        'dictTypeText': 'complaintTitle'
      }

      getDictTypeInfo(data).then(response => {
        console.log(response)
        _that.complaintTitleList = response.data
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    // 查看
    seeDetails(row) {
      const _that = this
      // console.log(row);
      // _that.complaintDialog = true
      _that.$nextTick(() => {
        _that.$refs.complaintDetail.complaintDialog = true
        _that.$refs.complaintDetail.complaintId = row.id
        _that.$refs.complaintDetail.getInfo()
      })
    },


    // 调查单脚印
    openStep(row) {
      const _that = this
      _that.$refs.complaintStep.idComplaintBill = row.id
      _that.$refs.complaintStep.getComplaintStep()
    },
    // 成功
    acceptSuccess() {
      this.complaintDialog = false
      this.getInfo()
    },
  }
}
</script>
<style>

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
input[type='number'] {
  -moz-appearance: textfield;
}
</style>
<style scoped>
.textRed {
  color: red;
}
</style>
