<template>
    <div>
        <div class="mrg-b">
            <el-row>
                <el-col :span="21">
                <el-button v-auth="50500020105" type="primary" @click="handleOpenAddForm">新增</el-button>
                <el-button v-auth="50500020106" type="primary" @click="handleDeleteRows">删除</el-button>
                <el-button v-auth="50500020108" type="primary" @click="handleAlloc">分配</el-button>
                <el-button v-auth="50500020107" type="primary" @click="handleAudit">审核</el-button>
                 <el-dropdown class="mrg-l" @command="toPrint">
                    <el-button v-auth="50500020316" type="primary">
                        打印<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item  command="18010050104">打印加工任务单</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <el-dropdown class="mrg-l" @command="toMore">
                    <el-button v-auth="50500020109" type="primary">
                        更多<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item v-auth="50500020118" command="copyOrder.shtml">复制</el-dropdown-item>
                        <el-dropdown-item v-auth="50500020111" needConfirm command="cancelAudit.shtml">取消审核</el-dropdown-item>
                        <el-dropdown-item v-auth="50500020112" needConfirm command="cancelAlloc.shtml">取消分配</el-dropdown-item>
                        <el-dropdown-item v-auth="50500020113" needConfirm command="closeOrder.shtml">关闭订单</el-dropdown-item>
                        <el-dropdown-item v-auth="50500020114" needConfirm command="cancelOrder.shtml">取消订单</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                </el-col>
                <el-col :span="3">
                <!-- <el-col :span="15"> -->
                    <!-- <el-input v-model="query.quickCondition" @keyup.enter.native="handleSearch" placeholder="快捷查询(加工单号)"></el-input> -->
                <!-- </el-col> -->
                <el-col class="mrg-l">
                    <el-button v-auth="50500020102" type="primary" @click="handleMoreSearch">更多</el-button>
                    <el-button v-auth="50500020101" icon="el-icon-refresh" class="query__item" type="primary" @click="handleSearch" 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="formData" ref="formData" label-position="left">
              <el-form-item
                label="加工单号"
                prop="kitNo">
                <el-input v-model="formData.kitNo" @keyup.enter.native="handelkitNo"></el-input>
              </el-form-item>
              <el-form-item
              label="组合件类型"
              prop="kitType">
              <el-select v-model="formData.kitType" @change="handelKitType">
                <el-option label="组合加工(A=B+C)" value="COM"></el-option>
                <el-option label="辅料加工(A=A+辅料)" value="ACC"></el-option>
                <el-option label="增值加工(A=A)" value="VA"></el-option>
              </el-select>
            </el-form-item>
             <el-form-item
              label="状态"
              prop="status">
              <el-select multiple v-model="status" @change="val => handleStatus(val)">
                <el-option label="创建" value="00"></el-option>
                <el-option label="部分加工" value="70"></el-option>
                <el-option label="完全加工" value="80"></el-option>
                <el-option label="取消订单" value="90"></el-option>
                <el-option label="关闭订单" value="99"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="货主编码"
              prop="ownerCode">
              <PublicQuery
              title="货主编码"
              baseUrl="/kit_web/kitweb"
              cfgKey="kitWmsCustomer"
              :valueField.sync="formData.ownerCode"
              @change="handelKitType">
              </PublicQuery>
            </el-form-item>
            </el-form>
        </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,
      formData: {},
      status: [],
      moreData: {}
    }
  },
  props: {
    selectedIds: Array
  },
  methods: {
    handleStatus (val) {
      this.formData.status = val.join(',')
      const formDate = { ...this.formData, kitNo: `%${this.formData.kitNo}%` }
      this.$emit('getList', formDate)
    },
    handelKitType () {
      const formDate = { ...this.formData, kitNo: `%${this.formData.kitNo}%` }
      this.$emit('getList', formDate)
    },
    handelkitNo () {
      const formDate = { ...this.formData, kitNo: `%${this.formData.kitNo}%` }
      this.$emit('getList', formDate)
    },
    // 检查是否选中行
    checkSelections () {
      if (!this.selectedIds.length) {
        this.$message.error('请选择记录')
        return false
      } else {
        return true
      }
    },

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

    // 搜索查询
    handleSearch () {
      this.$refs.formData.resetFields()
      this.status = []
      this.$emit('getList')
    },

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

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

    // 删除
    handleDeleteRows () {
      const url = this.$API.maintain.WmKitOrderList.delList
      const param = { kitNos: JSON.stringify(this.selectedIds) }

      if (!this.checkSelections()) return
      this.$confirm(`您已选中${this.selectedIds.length}条数据,是否删除？`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    getData (urlkey, text) {
      const url = this.$API.maintain.WmKitOrderList.more + urlkey
      const param = { kitNos: JSON.stringify(this.selectedIds) }
      this.$confirm(`是否执行${text}操作？`, `${text}`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList', {}, this.type)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: `已取消${text}`
        })
      })
    },

    // 更多操作
    toMore (command, vmNode) {
      const urlkey = command
      const text = vmNode.$el.innerText
      if (!this.checkSelections()) return
      this.getData(urlkey, text)
    },

    // 打印
    toPrint (command, vmNode) {
      if (this.checkSelections()) {
        const param = {
          title: vmNode.$el.innerHTML,
          qs: `_functionCode=${command}&kitNo=${this.selectedIds.join(';')}`
        }
        this.$print(param)
      }
    },
    // 分配
    handleAlloc () {
      const urlkey = 'alloc.shtml'
      const text = '分配'
      if (!this.checkSelections()) return
      this.getData(urlkey, text)
    },
    // 审核
    handleAudit () {
      const urlkey = 'audit.shtml'
      const text = '审核'
      if (!this.checkSelections()) return
      this.getData(urlkey, text)
    },
    handleExcel () {
      const url = this.$API.maintain.WmKitOrderList.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;
    }
  }
</style>
