<template>
    <div>
        <el-form ref="form" label-width="100px" :model="searchParam">
          <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="订单编号" prop="orderCode">
                    <el-input v-model="searchParam.orderCode" placeholder="订单编号" @keyup.enter.native="onSubmit('form')"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="物流单号" prop="invoiceNo">
                    <el-input v-model="searchParam.invoiceNo" placeholder="物流单号" @keyup.enter.native="onSubmit('form')"></el-input>
                </el-form-item>
              </el-col>
                <!-- <el-col :span="8">
                <el-form-item label="品牌" prop="brandId">
                    <el-select v-model="searchParam.brandId" placeholder="请选择品牌" filterable>
                       <el-option label="全部" value=""></el-option>
                      <el-option :label="item.brandName" :value="item.brandId"  v-for="(item,i) in brandsList" :key="i"></el-option>
                    </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                  <el-form-item label="收件人姓名" prop="receiver">
                    <el-input v-model="searchParam.receiver" placeholder="收件人姓名" @keyup.enter.native="onSubmit('form')"></el-input>
                </el-form-item>
              </el-col>
          </el-row>
          <el-row :gutter="20" v-if="source != 'saomafu'">
              
              <!-- <el-col :span="8" v-if="brandType == 2">
                  <el-form-item label="收件人手机" prop="deliverPhone">
                    <el-input v-model="searchParam.deliverPhone"></el-input>
                </el-form-item>
              </el-col> -->
              <el-col :span="8" v-show="source != 'brand'">
                <el-form-item label="订单类型" prop="actType">
                    <el-select v-model="searchParam.actType" placeholder="全部">
                      <el-option label="全部" value=""></el-option>
                      <el-option label="非活动期间订单" value="0"></el-option>
                      <el-option label="活动期间订单" value="1"></el-option>
                    </el-select>
                </el-form-item>
              </el-col>
                 <el-col :span="8" v-if="((brandType != 2) && (source != 'saomafu'))" v-show="source != 'brand'">
                <el-form-item label="交货期" prop="deliveryDateStatus">
                    <el-select v-model="searchParam.deliveryDateStatus" placeholder="全部">
                      <el-option label="全部" value=""></el-option>
                      <el-option label="现货" value="0"></el-option>
                      <el-option label="15天交期" value="1"></el-option>
                      <el-option label="30天交期" value="2"></el-option>
                      <el-option label="45天交期" value="3"></el-option>
                      <el-option label="45天交期以上" value="4"></el-option>
                    </el-select>
                </el-form-item>
              </el-col>
               <el-col :span="8" v-if="((brandType != 2) && (source != 'saomafu'))" v-show="source != 'brand'">
                <el-form-item label="商品名称" prop="goodsName">
                    <el-input v-model="searchParam.goodsName" placeholder="商品名称" @keyup.enter.native="onSubmit('form')"></el-input>
                </el-form-item>
              </el-col>

          </el-row>
          <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="下单时间段">
                   <el-date-picker
                    v-model="addDateVal"
                    type="daterange"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="订单完成时间">
                     <el-date-picker
                    v-model="cptDateVal"
                    type="daterange"
                    value-format="yyyy-MM-dd"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              
          </el-row>

          <el-row :gutter="0">
            <el-col :span="8" v-if="source != 'saomafu'">
                  <el-form-item label="物流公司" prop="logisticsName">
                    <el-input v-model="searchParam.logisticsName" placeholder="物流公司名称" @keyup.enter.native="onSubmit('form')"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="(source != 'saomafu'?16:24)">
                <el-form-item class="btn">
                  <el-button type="primary" @click="onSubmit('form')">搜索</el-button>
                  <el-button @click="reset('form')">重置</el-button>
                  <a :href="exportMain">
                    <el-button >导出订单主表</el-button>
                  </a>
                    <a :href="exportDetail" v-if="source != 'saomafu'" v-show="source != 'brand'">
                    <el-button>导出订单明细</el-button>
                    </a>
                </el-form-item>
              </el-col>
          </el-row>
      </el-form>
    </div>
</template>
<script>
import qs from 'qs'
export default {
    data(){
        return{
           brandsList:[],
           addDateVal:'',
           cptDateVal:''
            //  searchParam: {
            //     orderCode: '',//订单编号
            //     brandId: '', //品牌id
            //     actType: [], //订单类型
            //     invoiceNo: '',//物流单号
            //     receiver:'',//收货人
            //     deliveryDateStatus:'',//交货期
            //     addDateBegin:'',//下单开始时间
            //     addDateEnd:'',
            //     completionDateBegin:'',//订单完成时间
            //     completionDateEnd:'',
            // },
        }
    },
    props:{
      searchParam:{
        type:Object,
        default:{}
      },
      exportmainUrl:{
        type:String,
        default:''
      },
      exportdetailUrl:{
        type:String,
        default:''
      },
      brandType:{
        type:Number,
        default:1
      },
      source:{
        type:String,
        default:''
      },

    },
    mounted(){
      // this.getBrands()
    },
    methods:{
        // type 1-E淘  2-EDS 3-EDS2.0 4-家电馆 其他全部
        getBrands(){
          this.$axios.get(this.HOST +'/v1/select/brand',{
              params:{
                type:this.brandType
              }
            }).then((res) => {
              if(res.data.code==200){
                 this.brandsList = res.data.data;
              }else{
                this.$message.error(res.data.message);
              }
            }).catch(()=>{})
        },
     onSubmit(formName) {
         this.searchParam.pageNum =1;
        var params = this.searchParam;
        params.addDateBegin= this.addDateVal && this.addDateVal.length?this.addDateVal[0]:'';
        params.addDateEnd= this.addDateVal && this.addDateVal.length?this.addDateVal[1]:'';
        params.completionDateBegin= this.cptDateVal && this.cptDateVal.length?this.cptDateVal[0]:'';
        params.completionDateEnd= this.cptDateVal && this.cptDateVal.length?this.cptDateVal[1]:'';
        this.$emit('backData',params);
      },
      reset(formName){
        this.$refs[formName].resetFields();
        var params = this.searchParam;
        params.addDateBegin= '';
        params.addDateEnd= '';
        params.completionDateBegin= '';
        params.completionDateEnd= '';
        this.addDateVal ='';
        this.cptDateVal ='';
        this.$emit('backData',params);
      },
    },
    computed:{
        exportMain(){
          var info = localStorage.getItem('info') == "" ? "" : JSON.parse(localStorage.getItem('info'));
          var token = info && info.token ? info.token : '';
          var params = this.searchParam;
            params.token = token;
            params.brandId = info.brandId;
            let dataparams = qs.stringify(params);
            return this.exportmainUrl+'?' + dataparams;
        },
        exportDetail(){
          var info = localStorage.getItem('info') == "" ? "" : JSON.parse(localStorage.getItem('info'));
          var token = info && info.token ? info.token : '';
          var params = this.searchParam;
            params.token = token;
            params.brandId = info.brandId;
            let dataparams = qs.stringify(params);
            return this.exportdetailUrl +'?' + dataparams;
        }
    }
}
</script>
<style lang="scss" scoped>
.line{
  text-align: center;
}
.btn{text-align: right;}
.el-form-item{
  margin-bottom: 10px;
}
</style>

