<template>
<div>
<el-row class="query">
  <div class="query__operations">
    <el-button v-auth="50410010105" type="primary" @click="toAdd">新增</el-button>
    <el-button v-auth="50410010106" type="primary" @click="e => operate(e, 'delete')" needconfirm>删除</el-button>
  </div>
  <div class="query__retrieve">
    <!-- <el-input
      v-model="query.ruleCode"
      placeholder="快捷查询（规则编码）"
      @keyup.enter.native="toGetList(query)"
    ></el-input> -->
    <el-button v-auth="50410010102" class="query__item" type="primary" @click="moreQuery">更多</el-button>
    <el-button v-auth="50410010101" icon="el-icon-refresh" class="query__item" type="primary" @click="handelGetList(query)" plain circle></el-button>

    <MoreQuery
      :queryProp="query"
      :showMore="showMore"
      @close="showMore = false"
      @toGetList="toGetList"
    ></MoreQuery>
  </div>
</el-row>
<div class="inputBox">
    <el-form inline :model="formData" ref="formData" label-position="left">
      <el-form-item label="规则编码" prop="ruleCode">
        <el-input v-model="formData.ruleCode" @keyup.enter.native="toGetList(formData)">></el-input>
      </el-form-item>
      <el-form-item label="规则名称" prop="ruleName">
        <el-input v-model="formData.ruleName" @keyup.enter.native="toGetList(formData)">></el-input>
      </el-form-item>
      <el-form-item
          label="质检类型"
          prop="qcType"
        >
        <el-select multiple v-model="qcType" @change="val => handleReasonCode(val)">
          <el-option
            v-for="item in $keys.strategy.qcRules.qcType"
            :key="item.id"
            :label="item.name"
            :value="item.key"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="data">
          <el-date-picker
            v-model="data"
            type="datetimerange"
            :picker-options="pickerOptions"
            :default-time="['00:00:00', '23:59:59']"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="val => dateTimeChange(val)"
          ></el-date-picker>
        </el-form-item>
    </el-form>
</div>
</div>
</template>

<script>
import * as shortcuts from '@/config/shortcuts'
import MoreQuery from './MoreQuery'
export default {
  components: { MoreQuery },
  props: ['selectedIds'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
      pickerOptions: {
        shortcuts: { ...shortcuts }
      },
      qcType: [],
      data: '',
      formData: {},
      query: {
        ruleCode: '',
      }, // 查询条件
      showMore: false, // 显示更多查询
      fileList: [],
      file: [],
    }
  },
  methods: {
    handelGetList () {
      this.qcType = []
      this.data = []
      this.$refs.formData.resetFields()
      this.$emit('getList')
    },
    handleReasonCode (val) {
      this.formData.qcType = val.join(',')
      this.$emit('getList', this.formData)
    },
    dateTimeChange (val) {
      this.formData.tranTimeFrom = val ? val[0] : ''
      this.formData.tranTimeTo = val ? val[1] : ''
      this.$emit('getList', this.formData)
    },
    // 检查是否有勾选
    checkSelections () {
      if (!this.selectedIds) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },
    // 新增按钮
    toAdd () {
      this.$router.push({
        name: 'qcRulesCreator',
        params: {
          mode: 'create',
        }
      })
    },
    // 对质检规则任务进行操作, 更多按钮也在这里
    operateConfirm (type) {
      const url = this.$API.strategy.qcRules[type]
      const param = {
        ruleCodes: this.selectedIds
      }
      this.$https.post(url, param)
        .then(data => {
          console.log('操作成功', data)
          this.toGetList()
        })
    },
    // 查询
    toGetList (query) {
      this.$emit('getList', query)
    },
    // 点击更多查询
    moreQuery () {
      this.showMore = true
    },
  },
}
</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;
      }
  }
  .query {
    &__operations {
      float: left;
    }
    &__retrieve {
      float: right;
      .el-input {
        max-width: 180px;
      }
    }
    &__item {
      margin-left: 10px;
    }
  }
</style>
