<template>
  <div class="app-container">
    <div class="box-container">
      <div class="contain-title">查看专家回复</div>
    </div>
    <div class="content-container">
      <div class="lit-tit">{{demandTitle}}</div>
      <complex-table :tableData="tableData" :tableItem="tableItem" :total='total' :jump="'expert'" v-on:current="current"></complex-table>
    </div>
  </div>
</template>

<script>
  import crossDomain from '@/utils/CrossDomain'
  import complexTable from '@/components/complexTable'
  import comTable from '@/utils/comTable'
  import { urlParse } from '@/utils'
  import { pqDemandPro, qoDemand } from '@/api/demand'

  export default {
    data() {
      return {
        pageSize: 10,
        pageNo: 1,
        total: 0,
        actived: '',
        tableData: [],
        tableLoading: true,
        demandId: '',
        demandTitle: '',
        tableItem: [
          {
            prop: 'name',
            tit: '真实姓名',
            active: 'active',
            width: '200'
          },
          {
            prop: 'title',
            tit: '职称',
            width: '200'
          },
          {
            prop: 'orgName',
            tit: '所在机构'
          },
          {
            prop: 'phone',
            tit: '联系电话',
            width: '160'
          },
          {
            prop: 'email',
            tit: '联系邮箱',
            width: '160'
          },
          {
            prop: 'descp',
            tit: '回复内容'
          }
        ]
      }
    },
    components: {
      complexTable
    },
    created() {
      if (urlParse('id')) {
        this.demandId = urlParse('id')
        this.getDemandInfo()
        if (urlParse('m')) {
          this.actived = 1
        }
        this.pageQuery()
      }
    },
    methods: {
      getDemandInfo() {
        var that = this
        that.$http.get(qoDemand, {
          id: that.demandId
        }, function(res) {
          if (res.success) {
            that.demandTitle = res.data.title
          }
        })
      },
      pageQuery() {
        var that = this
        this.$http.get(pqDemandPro, {
          id: that.demandId,
          actived: that.actived,
          pageSize: that.pageSize,
          pageNo: that.pageNo
        }, function(res) {
          that.tableLoading = false
          if (res.success && res.data) {
            const obj = res.data.data
            var h = 0
            if (obj.length > 0) {
              for (let i = 0; i < obj.length; ++i) {
                h++
                if (obj[i].uid) {
                  crossDomain.getUserInfo(obj[i].uid, data => {
                    h--
                    Object.assign(obj[i], data)
                    if (h === 0) {
                      that.tableData = obj
                      that.total = res.data.total
                    }
                    comTable.gapFilling(that.tableData)
                  })
                }
              }
            } else {
              that.total = 0
              that.tableData = []
            }
          } else {
            that.total = 0
            that.tableData = []
          }
        })
      },
      current(val) {
        this.pageNo = val
        this.pageQuery()
      }
    }
  }
</script>
<style>
  .lit-tit{
    font-size: 17px;
    line-height: 30px;
    margin-bottom: 10px;
  }
</style>

