<!--
  @description:推荐邀请供应列表
  @Modifier:qk/xwl
  @routerPath:/supper/recommended-list
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />推荐/邀请供应商
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link
            :underline="false"
            :class="toggleSearchStatus?'arrow-is-active':''"
            type="primary"
            class="toggleSearchStatus icon el-icon-arrow-down"
          />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
          >
            <el-form-item ref="supplierName" label="供应商名称" prop="supplierName">
              <el-input v-model="searchForm.supplierName" placeholder="请输入供应商名称" style="width: 220px" />
            </el-form-item>
            <el-form-item ref="supplierType" label="类别" prop="supplierType">
              <el-select v-model="searchForm.supplierType" placeholder="请选择" style="width: 220px">
                <el-option
                  v-for="item in supplierTypeCodeGroup"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="linkerName" label="经办人" prop="linkerName">
              <el-input v-model="searchForm.linkerName" placeholder="请输入经办人" style="width: 220px" />
            </el-form-item>
            <el-form-item ref="linkerTel" label="联系电话" prop="linkerTel">
              <el-input v-model="searchForm.linkerTel" placeholder="请输入联系电话" style="width: 220px" />
            </el-form-item>
            <el-form-item ref="qualificationsType" label="类型" prop="qualificationsType">
              <el-select v-model="searchForm.qualificationsType" placeholder="请选择" style="width: 220px">
                <el-option
                  v-for="item in supplierQualificationsTypeGroup"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="auditStatus" label="审核状态" prop="auditStatus">
              <el-select v-model="searchForm.auditStatus" placeholder="请选择" style="width:220px">
                <el-option
                  v-for="item in auditStatusList"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="date" label="创建日期" prop="date">
              <el-date-picker
                v-model="searchForm.createTime"
                :value-format="elValueSaveFormat"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:220px"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <div class="mb10">
        <el-button type="primary" @click="supplierAdd">
          推荐/邀请供应商
        </el-button>
      </div>
      <section class="mt10">
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="supplierName"
            label="供应商名称"
            min-width="300"
          >
            <template slot-scope="scope">
              <el-link
                :underline="false"
                type="primary"
                @click="examineSupplierInfo(scope.row)"
              >
                {{ scope.row.supplierName }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="qualificationsType"
            label="类别"
            width="110"
          >
            <template slot-scope="scope">
              {{ filterDictText(supplierTypeCodeGroup,scope.row.qualificationsType) }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="linkName"
            label="经办人"
            min-width="75"
          />
          <el-table-column
            align="center"
            label="联系电话"
            prop="linkerTel"
            width="150"
          />
          <el-table-column
            label="类型"
            prop="qualificationsType"
            align="center"
            width="100"
          >
            <template slot-scope="scope">
              {{ filterDictText(supplierQualificationsTypeGroup,scope.row.qualificationsType) }}
            </template>
          </el-table-column>
          <el-table-column
            label="推荐至"
            prop="departName"
            align="center"
            min-width="300"
          />
          <el-table-column
            label="创建日期"
            prop="createTime"
            align="center"
            width="130"
          >
            <template slot-scope="scope">
              <span>
                {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDateTime) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="auditStatus"
            label="审核状态"
            min-width="75"
            align="center"
          >
            <template slot-scope="scope">
              {{ filterDictText(auditStatusList,scope.row.auditStatus) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            width="110"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.useStatus ==='02'"
                type="primary"
                @click="supplierAdd(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                v-if="scope.row.useStatus ==='01' && scope.row.auditStatus === '00' || scope.row.useStatus ==='01' && scope.row.auditStatus === '01'"
                type="primary"
                @click="supplierDetail(scope.row)"
              >
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.useStatus ==='01' && scope.row.auditStatus === '00'"
                type="primary"
                @click="intoWithdraw(scope.row)"
              >
                [撤回]
              </el-link>
              <el-link
                v-if="scope.row.useStatus ==='02'"
                type="primary"
                @click="intoDelete(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
    <!-- 添加/编辑 -->
    <recommendedAdd ref="recommendedAdd" @call-back="loadData" />
    <!-- 查看 -->
    <recommendeDetailDialog ref="recommendedDetail" />
    <!-- 供应商信息查看-弹框 -->
    <editorDeclarationDetailDialong ref="supplierInfo" />
  </div>
</template>
<script>
/* 接口*/
import {
  repealDeclaration,
  listDeclarationPages,
  removeDeclaration
} from '@/api/supplier/declaraTionrecord'
/* 组件*/
import recommendedAdd from './recommendedAdd-dialog'
import recommendeDetailDialog from './recommendeDetail-dialog'
/* 公用方法*/
import { filterObj, filterDictText } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperGroupMixin } from '../editorDeclaration/mixins/declareHegSupperGroupMixin'
import { supplierGroupMixin } from '../mixins/supplierGroupMixin'

/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import editorDeclarationDetailDialong from '@/views/supplier/editorDeclaration/editorDeclarationContent/editorDeclarationDetail-dialog'// 供应商信息查看
export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination, // 分页
    recommendedAdd, // 推荐邀请新增/编辑供应商
    recommendeDetailDialog, // 查看荐邀请新增/编辑供应商
    editorDeclarationDetailDialong // 供应商信息查看-弹框
  },
  mixins: [ListMixin, declareHegSupperGroupMixin, supplierGroupMixin],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        createTime: [], // 创建日期不传给后端
        auditStatus: '', // 审核状态:00审核中,01通过,02驳回,04暂存,05撤销
        createTimeBegin: '', // 创建时间开始
        createTimeEnd: '', // 创建时间结束
        supplierName: '', // 供应商名称
        supplierType: '', // 类别
        qualificationsType: '', // 类型
        linkerName: '', // 经办人
        linkerTel: '' // 联系电话
      },
      tableData: []
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
    // 获取字典
    this.getDeclarationDictionariesGroup()
  },
  methods: {
    filterDictText,
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listDeclarationPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 邀请/推荐/编辑
    supplierAdd(row) {
      this.$refs.recommendedAdd.openDialog(row && row.id || '')
    },
    // 查看
    supplierDetail(row) {
      this.$refs.recommendedDetail.openDialog(row.id)
    },
    // 撤回
    intoWithdraw(row) {
      this.$confirm('确定撤回本条记录么?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        repealDeclaration(row.id).then(res => {
          this.$message({
            message: '撤回成功',
            type: 'success'
          })
          this.loadData()
        })
      }).catch(() => {
      })
    },
    intoDelete(row) {
      // 删除
      this.$confirm('确定删除该记录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = [{
          id: row.id, // 项目id
          createUser: row.supplierId,
          departId: row.departId
        }]
        removeDeclaration(data).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 查询条件
    getQueryParams() {
      this.searchForm.createTimeBegin = this.searchForm.createTime[0] // 注册开始时间
      this.searchForm.createTimeEnd = this.searchForm.createTime[1] // 注册结束时间
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      // 删除不需要的参数
      delete param.createTime
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.searchForm.createTime = []// 时间
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.onSearch()
    },
    // 供应商信息-弹框
    examineSupplierInfo(row) {
      this.$refs.supplierInfo.open(row.supplierId)// 供应商主键id
    }
  }
}
</script>
<style lang="less" scoped>
</style>
