<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="demandlist"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column
        label="联系电话"
        prop="contactPhone"
        align="center"
        width="200"
      >
        <template slot-scope="{ row }">
          <span>{{ row.contactPhone }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="联系人"
        prop="contacts"
        align="center"
        width="200"
      >
        <template slot-scope="{ row }">
          <span>{{ row.contacts }}</span>
        </template>
      </el-table-column>
      <el-table-column label="需求内容" prop="content" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.content }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建时间" prop="createdAt" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.createdAt }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="处理状态"
        prop="dealStatus"
        align="center"
        width="200"
      >
        <template slot-scope="{ row }">
          <span v-if="row.dealStatus === 0">待处理</span>
          <span v-else-if="row.dealStatus === 1">已完成</span>
          <span v-else-if="row.dealStatus === 2">已发榜</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="需求id" prop="id" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="企业名称" prop="name" align="center" width="200">
        <template slot-scope="{ row }">
          <span>{{ row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" prop="type" align="center" width="200">
        <template slot-scope="{ row }">
          <span v-if="row.type === 0">技术转移转化</span>
          <span v-else-if="row.type === 1">工业设计咨询</span>
          <span v-else-if="row.type === 2">科技金融建设</span>
          <span v-else-if="row.type === 3">政策项目咨询</span>
          <span v-else-if="row.type === 4">知识产权咨询</span>
          <span v-else-if="row.type === 5">创新体系建设</span>
          <span v-else-if="row.type === 6">创新创业咨询</span>
          <span v-else-if="row.type === 7">信息技术服务</span>
          <span v-else-if="row.type === 8">协同创新服务</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="修改时间" prop="updatedAt" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.updatedAt }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        width="260"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button type="primary" size="mini" @click="edit(row)">修改处理状态</el-button>
          <el-button size="mini" type="danger" @click="declare(row)">发榜</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(row.id)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 修改处理状态弹窗 -->
    <el-dialog title="修改处理状态" :visible.sync="dialogFormVisible">
      <el-form
        ref="dataForm"
        :model="temp"
        label-position="left"
        label-width="70px"
        style="width: 50%; margin-left: 50px"
      >
        <el-form-item label="ID" prop="id" style="width: 180%">
          <el-input v-model="temp.id" />
        </el-form-item>
        <el-form-item label="类型">
          <el-select
            v-model="temp.dealStatus"
            placeholder="请选类型"
            style="width: 50%"
          >
            <el-option label="未处理" value="0" />
            <el-option label="已处理 " value="1" />
            <el-option label="已发榜 " value="2" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false"> 取消 </el-button>
        <el-button type="primary" @click="editDeal()"> 提交 </el-button>
      </div>
    </el-dialog>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="data.pageNum"
      :limit.sync="data.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import * as api from '@/api/demand'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'Demand',
  components: { Pagination },
  data() {
    return {
      demandlist: [],
      data: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      listLoading: true,
      dialogFormVisible: false,
      temp: []
    }
  },
  computed: {
    ...mapGetters(['name'])
  },
  created() {
    this.getList()
  },
  methods: {

    async handleDelete(id) {
      await api.DemandDelete(id).then(res => {
        this.getList()
      })
      this.$message({
        message: '删除成功',
        duration: 1000,
        type: 'success'
      })
    },
    async getList() {
      const that = this
      await api.demandQuery(that.data).then(res => {
        that.demandlist = res.list
        that.total = res.total - 0
        setTimeout(() => {
          that.listLoading = false
        }, 1000)
      })
    },
    edit(row) {
      const that = this
      that.temp = Object.assign({}, row)
      that.dialogFormVisible = true
    },
    async editDeal() {
      const that = this
      await api.updateDemandStatus(that.temp).then(res => {})
      that.dialogFormVisible = false
      that.getList()
    },
    async declare(row) {
      const that = this
      console.log(row.id)
      that.temp = Object.assign({}, row)
      await api.demandPublishAdd(that.temp).then(res => {})
      this.$message({
        message: '发榜成功',
        duration: 1000,
        type: 'success'
      })
      this.getList()
    }
  }
}
</script>
<style scoped>
</style>
