<template>
    <div>
        <el-dialog
          title="高级查询"
          :visible="moreQueryVisible"
          @close="close"
          width="66%">
          <el-form
            inline
            ref="queryForm"
            label-position="top"
            :model="formData">
            <el-form-item
              label="入库单号"
              prop="asnNo">
              <el-input v-model="formData.asnNo"></el-input>
            </el-form-item>
            <el-form-item
              label="采购计划单号"
              prop="poNo">
              <el-input v-model="formData.poNo"></el-input>
            </el-form-item>
            <el-form-item
              label="物流单号"
              prop="logisticNo">
              <el-input v-model="formData.logisticNo"></el-input>
            </el-form-item>
            <el-form-item label="车牌号" prop="vehicleNo">
              <el-input v-model="formData.vehicleNo"></el-input>
            </el-form-item>
            <el-form-item
              label="状态"
              prop="status">
              <el-select multiple v-model="formData.status">
                <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="90"></el-option>
                <el-option label="关闭订单" value="99"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="入库单类型"
              prop="asnType">
              <el-select multiple v-model="formData.asnType">
                <el-option label="普通入库" value="PI"></el-option>
                <el-option label="调拨入库" value="AI"></el-option>
                <el-option label="退货入库" value="RI"></el-option>
                <el-option label="换货入库" value="EI"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="审核状态"
              prop="auditStatus">
              <el-select multiple v-model="formData.auditStatus" >
                <el-option label="未审核" value="00"></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="EDI是否已发送"
              prop="isEdiSend">
              <el-select v-model="formData.isEdiSend">
                <el-option label="是" value="Y"></el-option>
                <el-option label="否" value="N"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="是否已预约月台"
              prop="isAppointDock">
              <el-select v-model="formData.isAppointDock">
                <el-option label="是" value="Y"></el-option>
                <el-option label="否" value="N"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              label="冻结状态"
              prop="holdStatus">
              <el-select multiple v-model="formData.holdStatus">
                <el-option label="无冻结" value="00"></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="getSTime">
              </el-date-picker>
            </el-form-item>
            <el-form-item
              label="货主"
              prop="ownerName">
              <PublicQuery
              title="货主"
              baseUrl="/inb_web/inbweb"
              cfgKey="inbWmsCustomer"
              :valueField.sync="formData.ownerCode"
              :textField.sync="formData.ownerName">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="供应商"
              prop="supplierName">
              <PublicQuery
              title="供应商"
              baseUrl="/inb_web/inbweb"
              cfgKey="LSP_SERVICE_SUPPLIER"
              :valueField.sync="formData.supplierCode"
              :textField.sync="formData.supplierName">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="商品"
              prop="skuName">
              <PublicQuery
              title="商品"
              baseUrl="/inb_web/inbweb"
              cfgKey="inbWmsSku"
              :valueField.sync="formData.skuCode"
              :textField.sync="formData.skuName">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="承运商"
              prop="carrierName">
              <PublicQuery
              title="承运商"
              baseUrl="/inb_web/inbweb"
              cfgKey="LSP_TRANSPORT_SUPPLIER"
              :valueField.sync="formData.carrierCode"
              :textField.sync="formData.carrierName">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="调出仓库"
              prop="allocateOutWhNames">
              <PublicQuery
              title="调出仓库"
              baseUrl="/inb_web/inbweb"
              cfgKey="inbWmsWareHouse"
              :valueField.sync="formData.allocateOutWhs"
              :textField.sync="formData.allocateOutWhNames">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="项目名称"
              prop="businessItemName">
              <PublicQuery
              title="项目名称"
              baseUrl="/inb_web/inbweb"
              cfgKey="customerBusinessItems"
              :valueField.sync="formData.businessItemCode"
              :textField.sync="formData.businessItemName">
              </PublicQuery>
            </el-form-item>
            <el-form-item
              label="调出仓库单号"
              prop="allocateSoNo">
              <el-input v-model="formData.allocateSoNo"></el-input>
            </el-form-item>
          </el-form>
          <div class="more-query-btn">
            <el-button v-auth="50100020103" type="primary" @click="submitForm">查询</el-button>
            <el-button v-auth="50100020104" @click="resetForm('queryForm')">重置</el-button>
          </div>
        </el-dialog>
    </div>
</template>
<script>
import { time } from 'apec-fe-utils'
import { today, yesterday, week, month, twoMonths, threeMonths } from '@/config/shortcuts'
export default {
  data () {
    return {
      formData: {
        asnNo: '',
        status: [],
        asnType: [],
        ownerName: '',
        ownerCode: '',
        supplierName: '',
        supplierCode: '',
        auditStatus: [],
        poNo: '',
        isEdiSend: '',
        skuName: '',
        skuCode: '',
        carrierName: '',
        carrierCode: '',
        isAppointDock: '',
        holdStatus: [],
        logisticNo: '',
        allocateOutWhNames: '',
        allocateOutWhs: '',
        businessItemName: '',
        businessItemCode: '',
        allocateSoNo: '',
        orderTimeFm: time.formatTime(new Date(new Date() - 3600 * 1000 * 24 * 7)),
        orderTimeTo: time.formatTime(new Date()),
      },
      pickerOptions2: {
        shortcuts: [today, yesterday, week, month, twoMonths, threeMonths]
      },
      date: '',

    }
  },
  mounted () {
  },
  props: {
    moreQueryVisible: Boolean,
  },
  methods: {

    // 获得时间
    getSTime (val) {
      this.formData.orderTimeFm = val ? val[0] : ''
      this.formData.orderTimeTo = val ? val[1] : ''
    },

    // 关闭弹窗
    close () {
      this.$emit('close')
    },

    // 提交表单
    submitForm () {
      this.format()
      this.$emit('toGetList', this.formData)
      this.$refs['queryForm'].resetFields()
    },

    // 重置表单
    resetForm () {
      this.$refs['queryForm'].resetFields()
    },

    // 格式化对象数据
    format () {
      for (const key in this.formData) {
        if (this.formData.hasOwnProperty(key)) {
          const element = this.formData[key]
          if (Array.isArray(element)) {
            this.formData[key] = element.join(',')
          }
        }
      }
      return this.formData
    }
  }
}
</script>
