<template>
  <div>
    <div class="mrg-b">
      <el-row>
        <el-col :span="21">
          <el-button v-auth="50100070105" type="primary" @click="handleClose">关闭订单</el-button>
        </el-col>
        <el-col :span="3">
          <el-col :span="24" class="mrg-l">
            <el-button v-auth="50100070102" type="primary" @click="handleMoreSearch">更多</el-button>
            <el-button
              v-auth="50100070101"
              icon="el-icon-refresh"
              class="query__item"
              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>
    <div class="inputBox">
      <el-form inline :model="query" ref="query" label-position="left">
        <el-form-item label="质检单号" prop="qcNo">
          <el-input
            v-model="query.qcNo"
            @keyup.enter.native="handleSearch"
            placeholder="快捷查询(质检单号)"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select multiple v-model="status" @change="handleStatus">
            <el-option label="创建" value="00"></el-option>
            <el-option label="部分质检" value="10"></el-option>
            <el-option label="完全质检" value="20"></el-option>
            <el-option label="关闭订单" value="99"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单时间">
          <el-date-picker
            v-model="date"
            type="datetimerange"
            format="yyyy-MM-dd HH:mm"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions2"
            @change="getTime"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="货主" prop="ownerCode">
          <PublicQuery
            title="货主"
            baseUrl="/crd_web/crdweb"
            cfgKey="crdWmsCustomer"
            :valueField.sync="query.ownerCode"
            @change="handleSearch"
          ></PublicQuery>
        </el-form-item>
      </el-form>
    </div>
    <more-query
      :moreQueryVisible="moreQueryVisible"
      @close="moreQueryVisible=false"
      @toGetList="getQueryList"
    ></more-query>
  </div>
</template>
<script>
import { today, yesterday, week, month, twoMonths, threeMonths } from '@/config/shortcuts'
import MoreQuery from './more-query'
export default {
  components: {
    MoreQuery
  },
  data () {
    return {
      query: {},
      moreQueryVisible: false,
      pickerOptions2: {
        shortcuts: [today, yesterday, week, month, twoMonths, threeMonths]
      },
      date: '',
      status: [],
      moreData: {}
    }
  },
  props: {
    ids: String
  },
  methods: {

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

    // 新增窗口打开
    handleOpenAddForm () {
      this.$emit('handleOpenAddForm', 'create')
    },

    getTime (val) {
      this.query.orderTimeFm = val ? val[0] : ''
      this.query.orderTimeTo = val ? val[1] : ''
      this.handleSearch()
    },
    handleStatus (val) {
      this.query.status = val.join(',')
      this.handleSearch()
    },

    handleRefresh () {
      this.date = ''
      this.status = []
      this.$refs.query.resetFields()
      this.$emit('getList')
    },
    // 搜索
    handleSearch () {
      const query = { ...this.query, qcNo: `%${this.query.qcNo || ''}%` }
      this.$emit('getList', query)
    },

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

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

    // 关闭订单
    handleClose () {
      if (!this.checkSelections()) return
      this.$confirm(`是否关闭订单 ?`)
        .then(() => {
          const url = this.$API.stockIn.Manage.colse
          const param = { qcNos: this.ids }
          this.$https.post(url, param).then(res => {
            if (res.success) {
              this.$emit('getList')
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消关闭订单'
          })
        })
    },
    handleExcel () {
      const url = this.$API.stockIn.Manage.getList
      const options = this.moreData
      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;
  }
}
// .inline{
//   width: 47%
// }
</style>
