<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <!--          <a-col :xl='6' :lg='7' :md='8' :sm='24'>-->
          <!--            <a-form-item label='反馈人员'>-->
          <!--              <a-input placeholder='请输入反馈人员' v-model='queryParam.wxUserId'></a-input>-->
          <!--            </a-form-item>-->
          <!--          </a-col>-->
          <a-col :lg='7' :md='8' :sm='24' :xl='6'>
            <a-form-item label='反馈类型'>
              <j-dict-select-tag v-model='queryParam.type' dictCode='feedback_type' placeholder='请选择反馈类型' />
            </a-form-item>
          </a-col>
          <a-col :lg='7' :md='8' :sm='24' :xl='6'>
            <a-form-item label='反馈内容'>
              <j-input v-model='queryParam.content' placeholder='请输入内容'></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg='11' :md='12' :sm='24' :xl='10'>
            <a-form-item label='反馈时间'>
              <j-date v-model='queryParam.feedbackTime_begin' :show-time='true' class='query-group-cust'
                      date-format='YYYY-MM-DD HH:mm:ss' placeholder='请选择开始时间'></j-date>
              <span class='query-group-split-cust'></span>
              <j-date v-model='queryParam.feedbackTime_end' :show-time='true' class='query-group-cust'
                      date-format='YYYY-MM-DD HH:mm:ss' placeholder='请选择结束时间'></j-date>
            </a-form-item>
          </a-col>
          <a-col :lg='7' :md='8' :sm='24' :xl='6'>
            <span class='table-page-search-submitButtons' style='float: left;overflow: hidden;'>
              <a-button icon='search' type='primary' @click='searchQuery'>查询</a-button>
              <a-button icon='reload' style='margin-left: 8px' type='primary' @click='searchReset'>重置</a-button>
              <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>
      <a-table
        ref='table'
        :columns='columns'
        :dataSource='dataSource'
        :loading='loading'
        :pagination='ipagination'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        :scroll='{x:true}'
        bordered
        class='j-table-force-nowrap'
        rowKey='id'
        size='middle'
        @change='handleTableChange'>

        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <span slot='action' slot-scope='text, record'>
          <a @click='handleDetail(record)'>详情</a>
          <a-divider type='vertical' />
          <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>
    <j-modal
      :okButtonProps="{ class:{'jee-hidden': true} }"
      :title='modal.title'
      :visible.sync='modal.visible'
      :width='800'
      switchFullscreen
    >
      <template>
        <a-descriptions :column='2' bordered title=''>
          <a-descriptions-item label='反馈人员'>
            {{ info.wxUserId_dictText }}
          </a-descriptions-item>
          <a-descriptions-item label='反馈时间'>
            {{ info.feedbackTime }}
          </a-descriptions-item>
          <a-descriptions-item :span='2' label='问题类型'>
            {{ info.type_dictText }}
          </a-descriptions-item>
          <a-descriptions-item :span='2' label='问题描述'>
            <div class='describe'>{{ info.content }}</div>
          </a-descriptions-item>
          <a-descriptions-item v-if='info.imgUrls !=null && info.imgUrls !=undefined' :span='2'
                               label='问题图片'>
            <img v-for='img in info.imgUrls' :src='img' class='imgbox' />
          </a-descriptions-item>
        </a-descriptions>
      </template>
    </j-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { Base64 } from 'js-base64'
import { filterObj } from '@/utils/util'

export default {
  name: 'FeedbackList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    var that = this
    let ellipsis = (v, l = 40) => (<j-ellipsis value={that.textReplaceAll(v)} length={l} />)
    return {
      description: '问题反馈',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '反馈人员',
          align: 'center',
          dataIndex: 'wxUserId_dictText',
          customRender: (text) => {
            //字典值翻译通用方法
            return Base64.decode(text)
          }
        },
        {
          title: '问题类型',
          align: 'center',
          dataIndex: 'type_dictText'
        },
        {
          title: '问题描述',
          align: 'center',
          dataIndex: 'content',
          customRender: (t) => ellipsis(t)
        },
        {
          title: '反馈时间',
          align: 'center',
          dataIndex: 'feedbackTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/inspect/feedback/list',
        delete: '/inspect/feedback/delete',
        deleteBatch: '/inspect/feedback/deleteBatch',
        exportXlsUrl: '/inspect/feedback/exportXls',
        importExcelUrl: 'inspect/feedback/importExcel'

      },
      dictOptions: {},
      superFieldList: [],
      /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
      queryParam: {},
      modal: {
        title: '详情',
        visible: false
      },
      info: {},
      Base64
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    //详情
    handleDetail: function(record) {
      this.modal.visible = true
      var info = record
      if (null != info && null != info.imgUrls && '' != info.imgUrls) {
        var imgs = info.imgUrls.split(',')
        info.imgUrls = imgs.slice(0, -1)
      }
      // console.log(info.wxUserId_dictText)
      if (null != info && null != info.wxUserId_dictText && '' != info.wxUserId_dictText) {
        var wxUserId_dictText = Base64.decode(info.wxUserId_dictText)
        info.wxUserId_dictText = wxUserId_dictText
      }
      this.info = info
      console.log(info)
    },
    textReplaceAll: function(text) {
      var reg = /<[^<>]+>/g
      var afterText = text.replace(reg, '').replace(/&nbsp;/ig, '').replace(/&ldquo;/ig, '').replace(/&rdquo;/ig, '')
      return afterText
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'Text', value: 'content', text: '内容', dictCode: '' })
      fieldList.push({ type: 'string', value: 'wxUserId', text: '反馈人员', dictCode: '' })
      fieldList.push({ type: 'int', value: 'type', text: '反馈类型', dictCode: 'feedback_type' })
      fieldList.push({ type: 'datetime', value: 'feedbackTime', text: '反馈时间' })
      this.superFieldList = fieldList
    },
    getQueryParams() {
      //获取查询条件
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var queryParam = this.queryParam
      // if (queryParam.content != null && queryParam.content != '' && queryParam.content != undefined) {
      //   queryParam.content = '*' + queryParam.content + '*'
      // }
      var param = Object.assign(sqp, queryParam, this.isorter, this.filters)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      return filterObj(param)
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.describe {
  max-width: 580px;
}

.imgbox {
  margin-right: 20px;
  width: 120px;
  height: 120px;
  object-fit: cover;
}
</style>