<template>
  <div>
    <div class="mrg-b">
      <el-row>
        <el-col :span="21">
          <el-button v-auth="50600010105" type="primary" @click="handleAdd">新增</el-button>
          <el-button v-auth="50600010106" type="primary" @click="handleDeleteRows">删除</el-button>
        </el-col>
        <el-col :span="3">
          <el-col :span="24" class="mrg-l">
            <!-- <el-button v-auth="50600010102" type="primary" @click="handleMoreSearch">更多</el-button> -->
            <el-button
              v-auth="50600010101"
              icon="el-icon-refresh"
              type="primary"
              @click="handleRefresh"
              plain
              circle
            ></el-button>
            <el-button
            v-if="false"
              icon="el-icon-download"
              type="primary"
              @click="handleExcel"
              plain
              circle
            ></el-button>
          </el-col>
        </el-col>
      </el-row>
      <div class="inputBox">
        <el-form inline :model="query" ref="query" label-position="left">
          <el-form-item label="费率组编码" prop="rateCode">
            <el-input v-model="query.rateCode" @keyup.enter.native="handleSearch" placeholder="快捷查询(费率组编码)"></el-input>
          </el-form-item>
          <el-form-item label="费率组名称" prop="rateName">
            <el-input v-model="query.rateName" @keyup.enter.native="handleSearch"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="query.remark" @keyup.enter.native="handleSearch"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <more-query
      :moreQueryVisible="moreQueryVisible"
      @close="moreQueryVisible=false"
      @toGetList="getQueryList"
    ></more-query>
  </div>
</template>
<script>
import MoreQuery from './more-query'
export default {
  components: {
    MoreQuery
  },
  data () {
    return {
      query: {},
      moreQueryVisible: false,
      moreData: {}
    }
  },
  props: {
    selectIds: Array
  },
  methods: {

    // 检查是否选中行
    checkSelections () {
      if (!this.selectIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },

    // 新增
    handleAdd () {
      this.$emit('handleOpenForm', 'create')
    },

    handleRefresh () {
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, rateCode: `%${this.query.rateCode || ''}%`, rateName: `%${this.query.rateName || ''}%`, remark: `%${this.query.remark || ''}%` }
      this.$emit('getList', query)
    },

    // 更多查询数据
    getQueryList (query) {
      this.moreQueryVisible = false
      this.$emit('getList', query)
    },

    // 更多搜索查询
    handleMoreSearch () {
      this.moreQueryVisible = true
    },

    // 删除
    handleDeleteRows () {
      const url = this.$API.charging.costGroup.delList
      const param = { removeCodes: JSON.stringify(this.selectIds) }
      if (!this.checkSelections()) return
      this.$confirm(`您已选中${this.selectIds.length}条数据,是否删除？`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleExcel () {
      const url = this.$API.charging.costGroup.getList
      const options = this.query
      this.$exportExcel(url, options)
    },
  }
}
</script>
<style lang="scss" scoped>
.inputBox {
  width: 100%;
  border: 1px solid #d1d5db;
  margin-top: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  padding-bottom: 10px;
  padding-left: 10px;
  .el-form-item {
    margin-bottom: 0px;
    margin-top: 10px;
  }
}
.mrg-b {
  margin-bottom: 20px;
}
.mrg-l {
  margin-left: 10px;
}
.query {
  &__operations {
    float: left;
  }
  &__retrieve {
    float: right;
    .el-input {
      max-width: 180px;
    }
  }
  &__item {
    margin-left: 10px;
  }
}
</style>
