<!--
  @description:不合格供应商管理
  @Modifier:qk/haofengxian/肖文龙
  @routerPath:/supperManagement/supplierUnqualified
  @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.trim="searchForm.supplierName" placeholder="请输入供应商名称" style="width: 220px" />
            </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="supplyScope" label="供货范围" prop="supplyScope">
              <el-input v-model.trim="searchForm.supplyScope" style="width: 228px" @focus="dialogData.dialog=true" />
            </el-form-item>
            <el-form-item ref="punishIdea" label="类别" prop="punishIdea">
              <el-select v-model="searchForm.punishIdea" placeholder="请选择" style="width:220px">
                <el-option
                  v-for="item in supplierPunishIdeaGroup"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="createUserName" label="申请人" prop="createUserName">
              <el-input v-model.trim="searchForm.createUserName" placeholder="请输入申请人" style="width: 220px" />
            </el-form-item>
            <el-form-item ref="createTime" label="创建日期" prop="createTime">
              <el-date-picker
                v-model="searchForm.createTime"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:220px"
                @change="createTimeChange"
              />
            </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="editAdd(null)">
          新增不合格供应商
        </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="160"
          >
            <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

            header-align="center"
            prop="supplyScope"
            label="供货范围"
            min-width="110"
          />
          <el-table-column
            header-align="center"
            label="类型"
            width="120"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.blacklistType === '01'? '加入': '取消' }}{{ scope.row.punishIdea === '01'? '不合格供应商': '黑名单' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="申请人"
            prop="createUserName"
            align="left"
            width="110"
          />
          <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
            label="状态"
            align="center"
            width="90"
          >
            <template slot-scope="scope">
              {{ filterDictText(auditStatusList,scope.row.auditStatus) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            width="240"
          >
            <template slot-scope="scope">
              <el-link v-if="scope.row.useStatus ==='01' && scope.row.auditStatus === '02' || scope.row.useStatus ==='02'" type="primary" @click="editAdd(scope.row.id)">
                [编辑]
              </el-link>
              <el-link type="primary" @click="see(scope.row.id)">
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.useStatus ==='01' && scope.row.auditStatus === '00'"
                type="primary"
                @click="withdraw(scope.row)"
              >
                [撤回]
              </el-link>
              <el-link
                v-if="scope.row.useStatus ==='01' && scope.row.auditStatus === '02' || scope.row.useStatus ==='02'"
                type="primary"
                @click="intoDelete(scope.row)"
              >
                [删除]
              </el-link>
              <el-link
                v-if="scope.row.useStatus!=='01'"
                type="primary"
                @click="removBlacklist(scope.row)"
              >
                [移除黑名单]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
    <!--查看不合格供应商-->
    <supplierUnqualifiedDetail ref="supplierUnqualifiedDetail" />
    <!-- 添加/编辑 -->
    <supplierUnqualifieded ref="supplierUnqualifieded" @call-back="loadData" />
    <!-- 移除黑名单 -->
    <supplierUnqualifiedRemove ref="supplierUnqualifiedRemove" @call-back="loadData" />
    <!-- 供货范围 -->
    <category-tree-dialog :dialog-data="dialogData" @categoryTreeInfo="categoryTreeInfo" />
    <!-- 供应商信息查看-弹框 -->
    <editorDeclarationDetailDialong ref="supplierInfo" />
  </div>
</template>
<script>
/* 接口*/
import { listBlacklistPages, removeBlacklist, repealBlacklist } from '@/api/supplier/supplierUnqualified'
/* 公用方法*/
import { filterObj, restoreInitialValue, filterDictText } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { supplierGroupMixin } from '@/views/supplier/mixins/supplierGroupMixin'

/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import supplierUnqualifieded from './supplierUnqualifieded-dialog'
import supplierUnqualifiedDetail from './supplierUnqualifiedDetail-dialog'// 不合格供应商查看详情-弹框
import supplierUnqualifiedRemove from './supplierUnqualifiedRemove-dialog'// 移除不合格供应商-弹框
import categoryTreeDialog from '@/views/common/tools/categoryTree-dialog'// 供货范围
import editorDeclarationDetailDialong from '@/views/supplier/editorDeclaration/editorDeclarationContent/editorDeclarationDetail-dialog'// 供应商信息查看
export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination, // 分页
    categoryTreeDialog, // 供货范围
    supplierUnqualifieded, // 添加
    supplierUnqualifiedRemove, // 移除不合格供应商-弹框
    supplierUnqualifiedDetail, // 不合格供应商查看详情-弹框
    editorDeclarationDetailDialong // 供应商信息查看-弹框
  },
  mixins: [ListMixin, supplierGroupMixin],
  data() {
    return {
      loading: true, // 表格loading
      // 弹窗-展示/隐藏状态 true 展示/false 隐藏
      dialogData: {
        title: '供货范围',
        dialog: false, // 产品分类
        selectCodes: [] // 当前选中的供货范围Code
      },
      // 搜索
      searchForm: {
        createTime: [], // 创建日期
        auditStatus: '', // 审核状态:00审核中,01通过,02驳回,03暂存
        blacklistType: '', // 类型 01:淘汰 02:取消淘汰
        createTimeBegin: '', // 创建时间开始
        createTimeEnd: '', // 创建时间结束
        createUserName: '', // 申请人
        departId: '', // 归属机构id
        nameStatus: '', // 名单状态 01:已取消 02:已列入 03:审核中
        punishIdea: '', // 处罚意见 01:暂停合格供应商资格 02:取消合格供应商资格
        supplierId: '', // 供应商id
        supplierName: '', // 供应商名称
        supplierType: '', // 供应商类别名称. 01:物质代理商 02:物质制造商 03:设备代理商 04:设备制造商
        supplyScope: '', // 供应范围
        useStatus: '' // 有效状态 00:临时(草稿) 01:有效 02:作废
      },
      tableData: [] // 不合格供应商列表
    }
  },
  created() {
    this.initGetBlacklistDictionaries() // 字典
    // 获取列表信息
    this.loadData()
  },
  methods: {
    filterDictText,
    // 创建日期
    createTimeChange(val) {
      if (val) {
        this.searchForm.createTimeBegin = this.$Moment(val[0]).format(this.momentSaveFormat)// 创建开始时间
        this.searchForm.createTimeEnd = this.$Moment(val[1]).format(this.momentSaveFormat)// 创建结束时间
      }
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listBlacklistPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      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.dialogData.selectCodes = []
      restoreInitialValue(this.searchForm)
      // 搜索
      this.onSearch()
    },
    // 供货范围选择/清空
    categoryTreeInfo(data) {
      this.searchForm.supplyScope = data.labels
      this.dialogData.selectCodes = data.keys.split(',')
    },
    // 不合格供应商新增/编辑
    editAdd(id) {
      // 触发子组件方法
      this.$refs.supplierUnqualifieded.open(id)
    },
    // 撤回
    withdraw(row) {
      this.$confirm('确定撤回本条记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        repealBlacklist(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 removeList = [{
          id: row.id
        }]
        removeBlacklist(removeList).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 移除黑名单
    removBlacklist(row) {
      this.$refs.supplierUnqualifiedRemove.open(row.id)
    },
    // 查看 id 主键id
    see(id) {
      this.$refs.supplierUnqualifiedDetail.open(id) // 获取详情
    },
    // 供应商信息-弹框
    examineSupplierInfo(row) {
      this.$refs.supplierInfo.open(row.supplierId)// 供应商主键id
    }
  }
}
</script>
<style lang="less" scoped>
</style>
