<!--
  @description: 项目信息列表清除redis
  @Modifier: haofengxian
  @routerPath: redisManagement/projectRedisList
  @date: 2020-7-17-16:37
-->
<template>
  <div>
    <!--标题-->
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />redis清除
    </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>
      <div :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
            label-position="left"
          >
            <!--招标编号-->
            <el-form-item ref="tenderNo" label="招标编号" prop="tenderNo">
              <el-input v-model="searchForm.tenderNo" placeholder="招标编号" style="width: 220px" @keyup.enter.native="onSearch" />
            </el-form-item>
            <!--项目名称-->
            <el-form-item ref="tenderName" label="项目名称" prop="tenderName">
              <el-input v-model="searchForm.tenderName" placeholder="项目名称" style="width: 220px" @keyup.enter.native="onSearch" />
            </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="handleCreateTime"
              />
            </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 auditStatusOptions"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </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>
      </div>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <div class="mb10">
        <el-button type="primary" @click="delAllRed">
          清空全部redis
        </el-button>
        <el-button type="primary" @click="likeSelectRedisKeys">
          模糊删除redis
        </el-button>
      </div>
      <div>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="tenderNo"
            align="center"
            label="招标项目编号"
            width="170"
          />
          <el-table-column
            header-align="center"
            prop="tenderName"
            label="招标项目名称"
            min-width="230"
          />
          <el-table-column
            header-align="center"
            prop="tenderMethod"
            label="招标方式"
            width="80"
            align="center"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in bidTypeList"
                v-if="scope.row.tenderMethod===item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="qualificationMethod"
            label="资格审查方式"
            width="120"
            align="center"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in phaseTypeList"
                v-if="scope.row.qualificationMethod===item.typecode"
                :key="index"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            prop="budgetTotalMoney"
            label="总概算（元）"
            width="110"
            align="right"
          />
          <el-table-column
            label="创建日期"
            align="center"
            width="130"
          >
            <template slot-scope="scope">
              {{ scope.row.createTime && $Moment(scope.row.createTime).format(momentDateTime) }}
            </template>
          </el-table-column>
          <el-table-column
            label="审核状态"
            prop="auditStatus"
            align="center"
            width="90"
          >
            <template slot-scope="scope">
              <span
                v-for="item in auditStatusOptions"
                v-if="scope.row.auditStatus === item.typecode"
                :key="item.typecode"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            width="160"
          >
            <template slot-scope="scope">
              <el-link type="primary" @click="packOpt(scope.row.tenderId)">
                [包组信息]
              </el-link>
              <el-link type="primary" @click="delRed(scope.row.tenderId)">
                [清除redis]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadTenderProjectRedisList" />
      </div>
    </section>
    <!--      &lt;!&ndash; 模糊查询redis弹框 &ndash;&gt;
<vagueSearchDialog :dialog-data="vagueSearchDialog" />
&lt;!&ndash; 清空全部redis弹框 &ndash;&gt;
<clearAllDialog :dialog-data="clearAllDialog"/>
&lt;!&ndash; 采购人名称弹框 &ndash;&gt;
<purchaserNameDialog :dialog-data="purchaserNameDialog"/>-->
    <redisLikeSelectDialog ref="redisLikeSelect" />
  </div>
</template>

<script>
import { delAllRedis, delRedisByTenderId } from '@/api/bidding/bid'
import { listTenderProjectRedisResetPages } from '@/api/bidding/biddingProject'

import { ListMixin } from '@/mixins/ListMixin'
// 组件
import pagination from '@comp/common/pagination/pagination'
import redisLikeSelectDialog from './redisLikeSelect-dialog'

// import vagueSearchDialog from './vagueSearch-dialog'
// import clearAllDialog from './clearAll-dialog'
// import purchaserNameDialog from './purchaserName-dialog'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
export default {
  name: 'BuildingProjectList',
  components: {
    pagination,
    redisLikeSelectDialog
    /*    vagueSearchDialog,
    clearAllDialog,
    purchaserNameDialog*/
  },
  mixins: [ListMixin],
  data() {
    return {
      /* 字典信息-start */
      bidTypeList: [], // 招标方式
      phaseTypeList: [], // 资格审查方式
      /* 字典信息-end */
      searchForm: {
        createTime: '',
        auditStatus: '', // 审核状态 00:待审核 01:审核通过 02:审核不通过
        buyersName: '', // 采购人名称
        createBeginTime: '', // 创建开始日期
        createEndTime: '', // 创建结束日期
        tenderName: '', // 项目名称
        tenderNo: '', // 项目编号
        userId: '' // 用户id
      },
      loading: true,
      tableData: []
    }
  },
  created() {
    this.initGroup() // 获取字典方法
    this.loadTenderProjectRedisList() // 根据查询条件获取项目信息列表
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = [
        'bidType', // 招标方式
        'phaseType' // 资格审查方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 清除redis模块-根据查询条件获取项目信息列表
    loadTenderProjectRedisList() {
      const params = this.getQueryParams()// 查询条件
      listTenderProjectRedisResetPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 包组信息
    packOpt(tenderId) {
      this.$router.push({
        name: 'packageRedis',
        params: {
          tenderId: tenderId
        }
      })
    },
    // 清除全部redis
    delAllRed() {
      this.$confirm('是否清空全部redis？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        delAllRedis().then(res => {
          this.$message.success(res.header.msg)
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 清空项目redis
    delRed(tenderId) {
      this.$confirm('是否清除该项目redis？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        delRedisByTenderId(tenderId).then(res => {
          this.$message.success(res.header.msg)
        }).catch(() => {
        })
      }).catch(() => {
      })
    },
    // 模糊删除redis
    likeSelectRedisKeys() {
      this.$refs.redisLikeSelect.openLikeRedisDialog()
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadTenderProjectRedisList()
    },
    // 重置
    resetForm(formName) {
      Object.keys(this.searchForm).forEach(val => {
        this.searchForm[val] = ''
      })
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      // 获取列表信息
      this.loadTenderProjectRedisList()
    },
    // 处理搜索时间格式
    handleCreateTime(val) {
      if (val) {
        this.searchForm.createBeginTime = this.$Moment(val[0]).format(this.momentDate)// 创建开始时间
        this.searchForm.createEndTime = this.$Moment(val[1]).format(this.momentDate)// 创建结束时间
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
