<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="userAccount">
                    <el-input v-model="searchParam.userAccount" 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="userName">
                    <el-input v-model="searchParam.userName" 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-row>

          <el-row :gutter="0">
              <el-col :span="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>

                </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.HOST + this.exportmainUrl+'?' + dataparams;
            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;
        //     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>

