<template>
  <div class="page-body">
    <div class="head-box">
      <div class="head-box-top">
        <div class="top-call" />
        <div class="top-call"><img src="@/assets/home_images/cisnet_logo_b.png"></div>
        <div class="top-call"><title-menus ref="titleMenus" menu-index="99" style="padding-top: 15px" /></div>
        <div class="top-call"><user-login ref="userLogin" /></div>
        <div class="top-call"><language-setting ref="languageSetting" /></div>
      </div>
    </div>
    <div class="content-box">
      <div style="width: 88%;padding-left: 9%;">
        <el-row :gutter="20" style="padding-top: 10px">
          <el-col :span="3">
            <user-menus menu-index="5" />
          </el-col>
          <el-col :span="21" style="padding: 0 20px">
            <!-- 表格 -->
            <div class="content" style="padding-top: 4px">
              <el-table id="dataTable" ref="dataTable" v-loading="loading" :data="tableData" border height="65vh" :header-cell-style="{background:'#F8F8F8',color:'#333'}" tooltip-effect="dark" @selection-change="handleSelectionChange">
                <el-table-column type="index" width="55" label="序号" :index="indexMethod" />
                <el-table-column prop="productName" label="询价产品" align="center" />
                <el-table-column prop="productId" label="咨询内容" align="center" />
                <el-table-column label="状态" align="center" width="120">
                  <template slot-scope="scope">
                    <div :style="'color:'+textColors[scope.row.status]">{{ dict.label.consult_status[scope.row.status] }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="createTime" label="咨询日期" align="center" width="180" />
                <el-table-column prop="handleTime" label="处理日期" align="center" width="180" />
                <el-table-column label="操作" align="center" width="120">
                  <template slot-scope="scope">
                    <el-button type="text" @click="toView(scope.row)">详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!--分页组件-->
              <el-pagination :total="total" :current-page="page" :page-size="pageSize" style="margin-top: 8px;" layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <home-footer ref="homeFooter" />
    <inquiry-view ref="inquiryView" />
    <el-backtop />
    <view-page ref="viewPage" />
  </div>
</template>
<script>
import default_product from '@/assets/home_images/default_product.png'

import titleMenus from '../components/titleMenusV2'
import userLogin from '../components/userLoginV2'
import languageSetting from '../components/languageSettingV2'
import homeFooter from '../components/homeFooter'
import inquiryView from '../components/inquiryView'
import userMenus from '../components/userMenus'
import { HttpReq } from '@/api/common'
import viewPage from './replyView'

export default {
  components: { titleMenus, userLogin, languageSetting, homeFooter, inquiryView, userMenus, viewPage },
  dicts: ['consult_status'],
  data() {
    return {
      defaultImgProduct: default_product,
      imgSrcStart: process.env.VUE_APP_BASE_API,
      textColors: ['#ccc', '#00008b', '#F98052', '#bba'],
      loading: false,
      page: 1,
      pageSize: 20,
      total: 0,
      query: {},
      tableData: [],
      multipleSelection: [],
      tabIndex: '1',
      throttle: null, // 节流器
      throttleTime: 300
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    indexMethod(index) {
      return 1 + index + this.page * this.pageSize - this.pageSize
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    loadData() {
      // 清除参数无值的情况
      Object.keys(this.query).length !== 0 && Object.keys(this.query).forEach(item => {
        if (this.query[item] === null || this.query[item] === '') this.query[item] = undefined
      })
      HttpReq.webClientApi.translateInquiryRecord({
        page: this.page - 1,
        pageSize: this.pageSize,
        ...this.query
      }).then((res) => {
        this.tableData = res.data.data
        this.total = res.data.total
      })
    },
    batchOperate(type, row) {
      if (!row && !this.multipleSelection.length) {
        return this.$message({
          message: '未选取数据',
          type: 'info'
        })
      }
      HttpReq.backstageApi.batchInformationProcessing({
        ids: row ? [row.informationId] : this.multipleSelection.map(item => { return item.informationId })
      }).then((res) => {
        this.$notify({
          title: res.msg,
          type: res.code === 200 ? 'success' : 'error',
          duration: 2500
        })
        this.loadData()
      })
    },
    toView(item) {
      this.$refs.viewPage.loadData(item.informationId)
    },
    toSearch() {
      this.page = 1
      this.loadData()
    },
    clearLimit() {
      this.query = {}
      this.loadData()
    },
    pageChange(e) {
      this.page = e
      this.loadData()
    },
    sizeChange(e) {
      this.page = 1
      this.pageSize = e
      this.loadData()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.touch {
  cursor:pointer;
}
.clear {
  clear: both
}
.inline-block {
  display: inline-block;
}
.ellipsis {
  // 多行溢出省略号
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
}
.pagination {
  margin-top: 23px;
  text-align: center;
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  >>>.el-pagination.is-background .el-pager li {
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    text-align: center;
    background-color: #fff;
    color: #000000;
    border: 1px solid #e5e5ea;
  }
  /* 激活后的样式 */
  >>>.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #ffffff;
    color: #0366ed;
    border: 1px solid #0366ed;
    text-align: center;
  }
  /* 修改左右箭头样式 */
  >>>.el-pagination .btn-next .el-icon, >>>.el-pagination .btn-prev .el-icon {
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    text-align: center;
    background-color: #fff;
    color: #e5e5ea;
    border: 1px solid #e5e5ea;
  }
  >>>.el-pager {
    height: 35.5px !important;
  }
  >>>.number, >>>.el-icon {
    height: 35.5px !important;
    line-height: 35.5px !important;
  }
}
.head-box {
  top: 0;
  background: none repeat scroll 0 0 white;
  z-index: 999;
  box-shadow: 0px 3px 7px 0px rgba(0,0,0,0.2);
  .head-box-top {
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    .top-call {
      height: 80px;
      padding-top: 15px;
    }
  }
}
.content-box {
  min-height: 70vh;
  margin-top: 94px;
  font-family: Source Han Sans CN;
  user-select: none;
  >>>.el-table--mini {
    font-size: 14px;
  }
  >>>.el-button--mini {
    font-size: 14px;
  }
}
.toolbar {
  display: flex;
  justify-content: space-between;
}
.content {
  margin-top: 10px;
  .table-btn {
    display: inline-block;
    margin: 0 10px;
    color: #1791E7;
    opacity: 0.8;
  }
  .table-btn:hover {
    opacity: 1;
  }
}
.tab-box {
  margin: 20px 0;
  width: 100%;
  display: flex;
  justify-content: flex-start;
  border-bottom: 2px solid rgba(3,66,171,0.2);
  .tab-item {
    width: 120px;
    padding-top: 10px;
    padding-bottom: 8px;
    text-align: center;
    font-size: 14px;
    color: #666;
  }
  .active {
    background: rgba(183,210,248,0.25);
    color: #1961C5;
    border-bottom: 3px solid rgba(3,66,171,0.8);
  }
}
</style>
