<template>
  <!--
          作者：hah
          时间：2019-10-25
          描述：申请列表
      -->
  <div class="user">
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="企业名称"><el-input v-model="formInline.name" placeholder="请输入企业名称"></el-input></el-form-item>
        <el-form-item><el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button></el-form-item>
        <!-- <el-form-item style="float: right;"><el-button class="display" size="small" type="primary" icon="el-icon-plus" @click="addClick" v-auth="'/game/expert/add'">添加专家</el-button></el-form-item> -->
      </el-form>
      </div>
    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
          <!-- <el-table-column prop="id" label="ID" width="80"></el-table-column> -->
          <el-table-column prop="name" label="称呼" width="200"></el-table-column>
          <el-table-column prop="phone" label="联系方式" width="200"></el-table-column>
          <el-table-column prop="company" label="企业名称" width="280"></el-table-column>
          <!-- <el-table-column prop="company_type" label="企业类型" width="250"></el-table-column> -->
          <el-table-column prop="need" label="企业需求" width="400"></el-table-column>
         <!-- <el-table-column prop="status" label="状态" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.status.value == 1" class="green">正常</span>
              <span v-if="scope.row.status.value == 0" class="gray">禁用</span>
            </template>
          </el-table-column> -->
          <el-table-column prop="satisfaction" label="满意度" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.satisfaction === 5">非常满意</span>
              <span v-else-if="scope.row.satisfaction === 4">满意</span>
              <span v-else-if="scope.row.satisfaction === 3">良好</span>
              <span v-else-if="scope.row.satisfaction === 2">不满意</span>
              <span v-else-if="scope.row.satisfaction === 1">非常不满意</span>
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="申请时间" width="180"></el-table-column>
          <el-table-column prop="update_time" label="处理时间" width="140">
            <template slot-scope="scope">
              <span v-if="scope.row.update_time === scope.row.create_time">--</span>
              <span v-else>{{scope.row.update_time}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" >
            <template slot-scope="scope">
              <el-button @click="editClick(scope.row)" type="text" size="small" v-auth="'/game/applys/edit'">详情</el-button>
              <el-button @click="openProcessDialog(scope.row)" type="text" size="small" v-auth="'/game/apply/edit'" v-if="scope.row.status.value==0">处理</el-button>
              <el-button @click="deleteClick(scope.row)" type="text" size="small" v-auth="'/game/applys/delete'">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
    </div>

    <!-- 处理满意度弹窗 -->
    <el-dialog
      title="处理申请"
      :visible.sync="processDialogVisible"
      width="400px"
      :close-on-click-modal="false"
    >
      <el-form :model="processForm" label-width="80px">
        <el-form-item label="满意度" required>
          <el-select v-model="processForm.satisfaction" placeholder="请选择满意度" style="width: 100%;">
            <el-option label="非常满意" :value="5"></el-option>
            <el-option label="满意" :value="4"></el-option>
            <el-option label="良好" :value="3"></el-option>
            <el-option label="不满意" :value="2"></el-option>
            <el-option label="非常不满意" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="processDialogVisible = false">取 消</el-button>
        <el-button type="primary" :loading="processDialogLoading" @click="processSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import GameApi from '@/api/game.js';
export default {
  components: {},
  inject: ['reload'],
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        name: '',
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      /*处理弹窗相关*/
      processDialogVisible: false,
      processDialogLoading: false,
      processForm: {
        satisfaction: null
      },
      processRowId: null,
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      Params.apply_type = 1;
      GameApi.Applylists(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          // console.log(self.tableData, 222)
          self.totalDataNumber = data.data.list.total;
        })
        .catch(error => {});
    },

    /*打开添加*/
    addClick() {
      this.$router.push('/game/expert/add');
    },

    /*打开编辑*/
    editClick(row) {
      let params = row.id;
      this.$router.push({
        path: '/game/applys/edit',
        query: {
          id: params
        }
      });
    },

    /*删除*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          GameApi.deleteApplys(
            {
              id: row.id
            },
            true
          )
            .then(data => {
              self.$message({
                message: '恭喜你，删除成功',
                type: 'success'
              });
              self.getTableList();
            })
            .catch(error => {});
        })
        .catch(() => {});
    },

    /* 打开处理弹窗 */
    openProcessDialog(row) {
      this.processDialogVisible = true;
      this.processDialogLoading = false;
      this.processForm.satisfaction = null;
      this.processRowId = row.id;
    },

    /* 确认处理申请 */
    processSubmit() {
      if (!this.processForm.satisfaction) {
        this.$message({
          type: 'warning',
          message: '请选择满意度'
        });
        return;
      }
      this.processDialogLoading = true;
      GameApi.processApply({
        id: this.processRowId,
        satisfaction: this.processForm.satisfaction
      }, true)
        .then(() => {
          this.$message({
            type: 'success',
            message: '处理成功'
          });
          this.processDialogVisible = false;
          this.getTableList();
        })
        .catch(() => {})
        .finally(() => {
          this.processDialogLoading = false;
        });
    }
  }
};
</script>

<style></style>
