<!--
  @description: 反馈管理---反馈人---发起反馈列表
  @Modifier: zcy/张慢慢
  @routerPath: complaintsSuggestions/complaintsSuggestions-list
  @date: 2021-11-18 15:02
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form.sync="searchForm"
      search-label-width="100px"
      @on-load="loadData"
    >
      <!--标题-->
      <template v-slot:header>
        <span>反馈列表</span>
      </template>
      <!--查询条件-->

      <template v-slot:search="search">
        <el-form-item ref="complaintsType" label="反馈类型" prop="complaintsType">
          <el-select v-model="searchForm.complaintsType" placeholder="--请选择--">
            <el-option
              v-for="item in complaintsTypeList"
              :key="item.typename"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!-- 反馈名称 -->
        <el-form-item ref="complaintsDepartmentName" label="反馈名称" prop="complaintsDepartmentName">
          <gx-input
            v-model.trim="searchForm.complaintsDepartmentName"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item ref="complaintsUserName" label="联系人" prop="complaintsUserName">
          <gx-input
            v-model.trim="searchForm.complaintsUserName"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item ref="complaintsState" label="状态" prop="complaintsState">
          <el-select v-model="searchForm.complaintsState" placeholder="--请选择--">
            <el-option
              v-for="item in complaintsStateList"
              :key="item.typename"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" @click="onAddFeed('')">
            新增反馈
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table ref="smallTable" v-loading="loading" :data="tableData">
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            prop="complaintsType"
            label="反馈类型"
            width="130"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              {{ filterDictText(complaintsTypeList,scope.row.complaintsType) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="supplierName"
            label="反馈名称"
            min-width="150"
            header-align="center"
            align="left"
          />
          <el-table-column
            prop="complaintsUserName"
            label="联系人"
            header-align="center"
            align="center"
            width="120"
          />
          <el-table-column
            prop="createTime"
            label="提交时间"
            header-align="center"
            align="center"
            width="130"
          >
            <template slot-scope="scope">
              {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDateTime) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="complaintsState"
            label="状态"
            header-align="center"
            align="center"
            width="120"
          >
            <template slot-scope="scope">
              {{ filterDictText(complaintsStateList,scope.row.complaintsState) }}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="150"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-link v-if="scope.row.complaintsState === '02'" type="primary" @click.stop="onAddFeed(scope.row)">
                编辑
              </el-link>
              <el-link v-if="scope.row.complaintsState === '02'" type="primary" @click.stop="onDelete(scope.row)">
                删除
              </el-link>
              <el-link v-if="scope.row.complaintsState !== '02'" type="primary" @click.stop="onLook(scope.row)">
                查看
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
  </div>
</template>

<script>
// api
import {
  queryList, // 获取列表
  delateComplaintsSuggestionsInfo // 删除
} from '@/api/procurement/procurementProject'
/* 公用方法*/
import { filterDictText } from '@/assets/js/utils' // 常用方法
import { compaintsSuggestionsGroupMixins } from '../mixins/complaintsSuggestionsGroupMixins' // 公共字典
export default {
  name: 'ComplainsSuggestionsList',
  mixins: [compaintsSuggestionsGroupMixins],
  data() {
    return {
      loading: true,
      tableData: [],
      searchForm: {
        complaintsState: '', // 筛选 00未回复(提交) 01已回复 02草稿
        complaintsType: '', // 筛选 00项目；01订单；02其他
        complaintsDepartmentName: '', // 反馈名称
        complaintsUserName: ''// 联系人
      }
    }
  },
  mounted() {
  },
  methods: {
    filterDictText,
    // 获取数据
    loadData(params, callback) {
      this.loading = true
      queryList(params).then(res => {
        this.loading = false
        this.tableData = res.data.records
        callback(res.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 删除
    onDelete(row) {
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          id: row.id
        }
        delateComplaintsSuggestionsInfo(data).then(res => {
          this.$message.success(`删除成功`)
          this.$refs.tableCrud.onSearchChange()
        })
      }).catch(() => {
      })
    },
    // 点击新增反馈 进入发起反馈页面
    onAddFeed(row) {
      this.$router.push({
        name: 'ComplaintsSuggestions-add',
        params: {
          id: row ? row.id : ''
        }
      })
    },
    // 查看
    onLook(row) {
      this.$router.push({
        name: 'ComplaintsSuggestions-detail',
        params: {
          id: row.id, // 主键id
          complaintsState: row.complaintsState // 状态
        }
      })
    }
  }
}
</script>

<style>
</style>
