<template>
  <div>
	  <div class="content">
	  	<div class="content_item">
	  	    <div class="label">项目名称</div>
	  	    <div class="content_right">
	  	        <el-input class="ename_input" 
	  			placeholder="请输入项目名称关键字" v-model="jskBidPlanDto.projectName" ></el-input>
	  	    </div>
	  	</div>
		<div class="content_item">
		    <div class="label">招标单位</div>
		    <div class="content_right">
		        <el-input class="ename_input" 
				placeholder="请输入招标单位关键字" v-model="jskBidPlanDto.tenderee" ></el-input>
		    </div>
		</div>
		<div class="content_item">
		    <div class="label">工程规模</div>
		    <div class="content_right">
		        <el-input class="ename_input" 
				placeholder="请输入工程规模关键字" v-model="jskBidPlanDto.projectScale" ></el-input>
		    </div>
		</div>
		<div class="content_item">
		    <div class="label">更多筛选</div>
		    <div class="content_right">
		       <div class="select-popper" >
		         <span :class="{color_text:jskBidPlanDto.province.length ||jskBidPlanDto.city.length ||jskBidPlanDto.area.length,}">
					 项目属地{{jskBidPlanDto.province.length ||jskBidPlanDto.city.length ||jskBidPlanDto.area.length? jskBidPlanDto.province.length + jskBidPlanDto.city.length +jskBidPlanDto.area.length +"项": ""}}
		           <i class="el-icon-caret-bottom"></i>
		         </span>
		         <el-cascader
		           ref="address"
		           class="cascader-region"
		           v-model="addressType"
		           :options="addressList"
		           :props="props"
		           @change="domicileChange"
		           collapse-tags
		           clearable
		         ></el-cascader>
		       </div>
			   <div class="select-popper">
			     <span :class="{ color_text: jskBidPlanDto.objectType.length }">
			       标的物类型{{jskBidPlanDto.objectType.length? jskBidPlanDto.objectType.length + "项": ""}}
			       <i class="el-icon-caret-bottom"></i>
			     </span>
			     <el-select v-model="jskBidPlanDto.objectType" class="select-multiple" multiple placeholder="请选择">
			       <el-option v-for="(item, i) in bidPlanObjectTypeList" :key="i":label="item" :value="item">
			       </el-option>
			     </el-select>
			   </div>
			   <div class="select-popper">
			     <span :class="{ color_text: jskBidPlanDto.projectType.length }">
			       项目类型{{jskBidPlanDto.projectType.length? jskBidPlanDto.projectType.length + "项": ""}}
			       <i class="el-icon-caret-bottom"></i>
			     </span>
			     <el-select v-model="jskBidPlanDto.projectType" class="select-multiple" multiple placeholder="请选择">
			       <el-option v-for="(item, i) in projectTypeList" :key="i":label="item" :value="item">
			       </el-option>
			     </el-select>
			   </div>
			   <div class="select-popper">
			     <span :class="{ color_text: jskBidPlanDto.tenderWay.length }">
			       招标方式{{jskBidPlanDto.tenderWay.length? jskBidPlanDto.tenderWay.length + "项": ""}}
			       <i class="el-icon-caret-bottom"></i>
			     </span>
			     <el-select v-model="jskBidPlanDto.tenderWay" class="select-multiple" multiple placeholder="请选择">
			       <el-option v-for="(item, i) in tenderWayList" :key="i":label="item" :value="item">
			       </el-option>
			     </el-select>
			   </div>
			   <el-dropdown @command="planTenderAmounthandleCommand" class="el-dropdown-land" trigger="click" ref="planTenderAmountShowPopper" :hide-on-click="false">
			   	<span class="el-dropdown-link" :class="jskBidPlanDto.startPlanTenderAmount ||jskBidPlanDto.endPlanTenderAmount ? 'color_text': ''">
			   		成交金额{{jskBidPlanDto.startPlanTenderAmount ||jskBidPlanDto.endPlanTenderAmount? " 1项": ""}}<i class="el-icon-caret-bottom"></i>
			   	</span>
			   	<el-dropdown-menu slot="dropdown">
			   		<el-dropdown-item v-for="(item, i) in planTenderAmount" :class="jskBidPlanDto.startPlanTenderAmount == item.value[0] &&jskBidPlanDto.endPlanTenderAmount == item.value[1] &&
			                      !startPlanTenderAmount &&!endPlanTenderAmount? 'color_text': '' " :key="i" :command="item.value">{{ item.label }}</el-dropdown-item>
			   			<el-dropdown-item command="" style="padding: 0; text-indent: 20px">
			   				<div @mouseenter="planTenderAmountShowPopper = true" @mouseleave="planTenderAmountShowPopper = false">
			   					<span :class="(startPlanTenderAmount || endPlanTenderAmount) &&jskBidPlanDto.startPlanTenderAmount ==startPlanTenderAmount &&
			                               jskBidPlanDto.endPlanTenderAmount == endPlanTenderAmount? 'color_text': '' ">
			   						自定义<i class="el-icon-arrow-right"></i>
			   					</span>
			   					<div class="jabph_popper_box" style="position: absolute"v-if="planTenderAmountShowPopper">
			   						<div class="jabph_popper_wrap">
			   							从
			   							<el-input class="jabph_popper_input" v-limit-num clearable v-model="startPlanTenderAmount"></el-input>
			   							万
			   						</div>
			   						<div class="jabph_popper_wrap">
			   							到
			   							<el-input class="jabph_popper_input" v-limit-num clearable v-model="endPlanTenderAmount"></el-input>
			   							万
			   						</div>
			   						<div style="">
			   							<el-button size="mini" @click="planTenderAmountCancel">取消</el-button>
			   							<el-button type="primary" size="mini" @click="planTenderAmountPopperConfirm">确定</el-button>
			   						</div>
			   					</div>
			   				</div>
			   			</el-dropdown-item>
			   	</el-dropdown-menu>
			   </el-dropdown>
			   
			   <div class="select-popper">
			     <span :class="{ color_text: jskBidPlanDto.projectCapitalSource.length }">
			       资金来源{{jskBidPlanDto.projectCapitalSource.length? jskBidPlanDto.projectCapitalSource.length + "项": ""}}
			       <i class="el-icon-caret-bottom"></i>
			     </span>
			     <el-select v-model="jskBidPlanDto.projectCapitalSource" class="select-multiple" multiple placeholder="请选择">
			       <el-option v-for="(item, i) in projectCapitalSourceList" :key="i":label="item" :value="item">
			       </el-option>
			     </el-select>
			   </div>
			   
			 
			   
			   
			   
		    </div>
		</div>
		<div class="content_item content_item_padding0">
		    <div class="geduan">
		       
		    </div>
		</div>
		<div class="content_item content_item_padding0">
			
			<div class="search-new">
				<span @click="search()">查询</span>
				<span @click="reset">重置</span>
			</div>
		</div>
		
		
	  </div>
	  <div class="bottomlist">
	  	<div class="bottomlist-title">
	  		<div></div>
	  		<div class="title-right">
	  			<p>共有{{total}}条</p>
	  			<p>
	  				<img src="@/assets/images/EXCEL.png" alt="">
	  				<span>导出EXCEL</span>
	  			</p>
	  		</div>
	  		  
	  	</div>
	  	<ul class="bottomlist-content" v-if="tableData.length>0">
	  		<li class="bottomlist-list" v-for="item in tableData">
	  			<p class="list-titel">
	  				 <router-link  :to="'/radar/Bidding/details/'+ item.id" tag="a" class="list-titel-a" v-html="item.projectName"  ></router-link>
	  				 <!-- <div  v-else-if="item.projectName" v-html="item.projectName"></div> -->
	  			</p>
	  			<div class="content-label">
	  				<span class="list-label" v-if="item.projectType">{{item.projectType}}</span>
					<span class="list-label list-label-wl" v-if="item.objectType">{{item.objectType}}</span>
					<span class="list-label list-label-lx" v-if="item.projectType">{{item.projectType}}</span>
	  			</div>
	  			
	  			<div  class="list-content">
	  				<p class="list-content-text">
	  					<span>招采单位：</span>
						<router-link v-if="item.tendereeId" :to="'/company/' + encodeStr(item.tendereeId)  + '/?index=true'" tag="a" class="list-titel-a blue" v-html="item.tenderee"></router-link>
						<span v-else>{{item.tenderee||'--'}}</span>
	  				</p>
	  				<p class="list-content-text">
	  					<span>合同预估金额（万元）：</span>
	  					<span>{{item.planTenderAmount||'--'}}</span>
	  				</p>
	  				<p class="list-content-text">
	  					<span>资金来源：</span>
	  					<span>{{item.projectCapitalSource||'--'}}</span>
	  				</p>
	  				
	  				
	  			</div>
				<div  class="list-content">
					<p class="list-content-text">
						<span>发布时间：</span>
						<span >{{item.issueTimestamp||'--'}}</span>
					</p>
					<p class="list-content-text">
						<span>预计招标时间：</span>
						<span>{{item.issueTimestamp||'--'}}</span>
					</p>
					<p class="list-content-text">
						<span>来源网站：</span>
						<span  >{{item.issueTimestamp||'--'}}</span>
					</p>
					
					
				</div>
				<div  class="list-content list-addree">
					<p class="list-content-text">
						<span class="content-text-gc">工程规模：</span>
						<span class="content-text-p">{{item.projectScale||'--'}}</span>
					</p>
					
				</div>
	  			
	  		</li>
	  	</ul>
	  	<div class="pagination clearfix"  v-show="total>0">
	  		  <el-pagination
	  		    background
	  		    :page-size="limit"
	  		    :current-page="page"
	  		    @current-change="handleCurrentChange"
	  		    layout="prev, pager, next"
	  		    :total="total">
	  		  </el-pagination>
	  	</div>
	  	
	  </div>
  </div>
</template>

<script>
import jsk_data from '../../../../../public/jsk.json';
import {encodeStr} from "@/assets/js/common.js"
import api from '@/api/radar/radar.js';
export default {
  name: 'Bidding',
  data() {
    return {
	  encodeStr,
      addressList: [],
      addressType: [],
      props: {
        multiple: true,
        expandTrigger: "hover",
        value: "id",
      },
	  bidPlanObjectTypeList: [],//标的物类型
	  projectTypeList: [],//项目类型
	  tenderWayList: [],//招标方式
	  projectCapitalSourceList: [],//资金来源
	  planTenderAmount: [{
	  		value: "不限",
	  		label: "不限",
	  	},
	  	{
	  		value: [0, 100],
	  		label: "100万元以下",
	  	},
	  	{
	  		value: [100, 1000],
	  		label: "100万-1000万元",
	  	},
	  	{
	  		value: [1000, 5000],
	  		label: "1000万-5000万元",
	  	},
	  	{
	  		value: [5000, 20000],
	  		label: "5000万-2亿元",
	  	},
	  	{
	  		value: [20000, ""],
	  		label: "2亿元以上",
	  	},
	  ],

      jskBidPlanDto: {
	    projectName:'',
		tenderee:'',
		projectScale:'',
        province: [],
        city: [],
        area: [],
		objectType:[],
		projectType:[],
		tenderWay:[],
		startPlanTenderAmount:'',
		endPlanTenderAmount:'',
		projectCapitalSource:[],
      },
	  planTenderAmountShowPopper:false,
	  startPlanTenderAmount:'',
	  endPlanTenderAmount:'',
	  
      domicile: [],
      pageFlag: true,
	  conditionsArr: [],
	  
	  tableData:[],
	  total:0,
	  page:1,
	  limit:20
    };
  },
  computed: {
    checkJskBidQueryDto() {
        let arr = [];
		let data = {};
      if(this.jskBidPlanDto.projectName){
        data = {
				title: "项目名称:",
				keyid: "projectName",
				value: this.jskBidPlanDto.projectName,
				key: "projectName"
					}
		arr.push(data)
      }
     
      if(this.jskBidPlanDto.tenderee){
        data = {
				title: "招标单位:",
				keyid: "tenderee",
				value: this.jskBidPlanDto.tenderee,
				key: "tenderee"
					}
		arr.push(data)
      }
	  if(this.jskBidPlanDto.projectScale){
	    data = {
				title: "工程规模:",
				keyid: "projectScale",
				value: this.jskBidPlanDto.projectScale,
				key: "projectScale"
	  					}
	  	arr.push(data)
	  }
      if (this.domicile.length > 0) {
        data = {
          title: "项目属地:",
          keyid: "domicile",
          value: this.domicile.join(","),
          key: "domicile"
        }
        arr.push(data)
      }
	  if (this.jskBidPlanDto.objectType.length > 0) {
	    data = {
	      title: "标的物类型:",
	      keyid: "objectType",
	      value: this.jskBidPlanDto.objectType,
	      key: "objectType"
	    }
	    arr.push(data)
	  }
	  if (this.jskBidPlanDto.projectType.length > 0) {
	    data = {
	      title: "项目类型:",
	      keyid: "projectType",
	      value: this.jskBidPlanDto.projectType,
	      key: "projectType"
	    }
	    arr.push(data)
	  }
	  if (this.jskBidPlanDto.tenderWay.length > 0) {
	    data = {
	      title: "招标方式:",
	      keyid: "tenderWay",
	      value: this.jskBidPlanDto.tenderWay,
	      key: "tenderWay"
	    }
	    arr.push(data)
	  }
	  if (this.jskBidPlanDto.projectCapitalSource.length > 0) {
	    data = {
	      title: "资金来源:",
	      keyid: "projectCapitalSource",
	      value: this.jskBidPlanDto.projectCapitalSource,
	      key: "projectCapitalSource"
	    }
	    arr.push(data)
	  }
	  
	  
      this.conditionsArr = arr
    },
  },
  mounted() {
   this.init();
      
  },
  methods: {
	getCapitalSourceSelect(){
	  	api.getCapitalSourceSelect().then(res=>{
	  		this.projectCapitalSourceList = res.data;
	  	}).catch(error=>{
	  	});
	},
	searchDic(){
	  	api.searchDic().then(res=>{
	  		this.bidPlanObjectTypeList= res.bidPlanObjectType,//标的物类型
	  		this.projectTypeList= res.projectType,//项目类型
	  		this.tenderWayList= res.tenderWay;//招标方式
	  	}).catch(error=>{
	  	});
	},
    keywordClick(val) {
      this.projectName = val
    },
	 
    search(page, limit,exportFlag) {
      if (!page) {
        this.page = 1;
      }
      if (!limit) {
        this.limit = 20;
      }
      if (!page && !limit) {
        this.reloadPage();
      }
      var data = JSON.parse(JSON.stringify(this.jskBidPlanDto));
      data.province = data.province.join(",");
      data.city = data.city.join(",");
      data.area = data.area.join(",");
	  data.objectType=data.objectType.join(",");
	  data.projectCapitalSource=data.projectCapitalSource.join(",");
	  data.projectType=data.projectType.join(",");
	  data.tenderWay=data.tenderWay.join(",");
      let params = {
        page: {
          page: this.page,
          limit: this.limit,
          field: this.field,
        },
        jskBidPlanDto: data,
      };
      if(this.projectName){
        params.projectName = this.projectName
      }else{
        delete params.projectName
      }
      if(this.keywordNot){
        params.keywordNot = this.keywordNot
      }else{
        delete params.keywordNot
      }
	  api.jskBidPlanPage(params).then(res=>{
		  console.log(res);
	  	if (res.code==200) {
	  		this.tableData=res.data.list;
	  		this.total=res.data.total;
	  	}
	  }).catch(error=>{
	  	
	  });
      
      
    },
    reloadPage() {
      this.pageFlag = false;
      this.$nextTick(() => {
        this.pageFlag = true;
      });
    },
    handleCurrentChange(page) {
      this.page = page;
      this.search(page, this.limit);
    },
    handleSizeChange(limit) {
      this.limit = limit;
      this.search(this.page, limit);
    },
    deleteDomicile() {
      this.$refs.address.handleClear();
    },
    domicileChange() {
      let arr = this.$refs.address.getCheckedNodes();
      let province = [],
        city = [],
        area = [];
      this.domicile = [];
      for (var i in arr) {
        if (arr[i].parent) {
          if (!arr[i].parent.checked) {
            arr[i].hasChildren && city.push(arr[i].value);
            arr[i].hasChildren && this.domicile.push(arr[i].label);
            !arr[i].hasChildren && area.push(arr[i].value);
            !arr[i].hasChildren && this.domicile.push(arr[i].label);
          }
        } else {
          province.push(arr[i].value);
          this.domicile.push(arr[i].label);
        }
      }
      var obj = JSON.parse(JSON.stringify(this.jskBidPlanDto));
      obj.province = province;
      obj.city = city;
      obj.area = area;
      this.jskBidPlanDto = obj;
    },
    addressListfn() {
      var str = [];
      for (let x = 0; x < 3; x++) {
        for (let i = 0; i < jsk_data.length; i++) {
          if (jsk_data[i].regionLevel == x + 1 && x + 1 == 1) {
            str.push({
              id: jsk_data[i].id,
              label: jsk_data[i].regionName,
              short: jsk_data[i].short,
              value: jsk_data[i].parentId,
              children:jsk_data[i].id==900000?undefined:[],
            });
          } else if (jsk_data[i].regionLevel == x + 1 && x + 1 == 2&&str) {
            for (let j = 0; j < str.length; j++) {
              if (str[j].id == jsk_data[i].parentId) {
                str[j].children.push({
                  id: jsk_data[i].id,
                  label: jsk_data[i].regionName,
                  short: jsk_data[i].short,
                  value: jsk_data[i].parentId,
                  children: [],
                });
              }
            }
          } else if (jsk_data[i].regionLevel == x + 1 && x + 1 == 3) {
            for (let j = 0; j < str.length; j++) {
              if(str[j].children){
                for (let k = 0; k < str[j].children.length; k++) {
                  if (str[j].children[k].id == jsk_data[i].parentId) {
                    str[j].children[k].children.push({
                      id: jsk_data[i].id,
                      label: jsk_data[i].regionName,
                      short: jsk_data[i].short,
                      value: jsk_data[i].parentId,
                    });
                  }
                }
              }
            }
          }
        }
      }
      this.addressList = str;
    },
	planTenderAmountPopperConfirm() {
		if (
			this.startPlanTenderAmount &&
			this.endPlanTenderAmount &&
			!(Number(this.endPlanTenderAmount) > Number(this.startPlanTenderAmount))
		) {
			return this.$message.warning("最小值必须小于最大值,请重新输入！");
		}
		this.planTenderAmountShowPopper = false;
		var obj = JSON.parse(JSON.stringify(this.jskBidPlanDto));
		obj.startPlanTenderAmount = this.startPlanTenderAmount;
		obj.endPlanTenderAmount = this.endPlanTenderAmount;
		this.jskBidPlanDto = obj;
		this.$refs.planTenderAmountShowPopper.hide();
	},
	planTenderAmountCancel() {
		this.planTenderAmountShowPopper = false;
		this.$refs.planTenderAmountShowPopper.hide();
	},
	planTenderAmounthandleCommand(command) {
		if (command) {
			this.$refs.planTenderAmountShowPopper.hide();
			var obj = JSON.parse(JSON.stringify(this.jskBidPlanDto));
			this.startPlanTenderAmount = "";
			this.endPlanTenderAmount = "";
			if (command == "不限") {
				obj.startPlanTenderAmount = "";
				obj.endPlanTenderAmount = "";
			} else {
				obj.startPlanTenderAmount = command[0];
				obj.endPlanTenderAmount = command[1];
			}
			this.jskBidPlanDto = obj;
		}
	},
    reset() {
      Object.assign(this.$data, this.$options.data.call(this)); //重置data
      this.init();
      this.$emit("reset");
    },
    init(){
      this.search();
      this.addressListfn();
	  this.searchDic();
      this.getCapitalSourceSelect();
    },
   
  },
};
</script>
<style lang="scss" scoped>
	.content{
	  padding: 0px 16px;
	  border-radius: 4px 4px 4px 4px;
	   background: #FFFFFF;
	   .content_item{
		   padding-top: 12px;
		   display: flex;
		   align-items: center;
	       .label{
	           width: 84px;
			   font-size: 14px;
			   font-weight: 400;
			   color: rgba(35,35,35,0.8);
	       }
	       .content_right{
	           
	           .ename_input{
	               width: 640px;
	               margin-right: 20px;
	           }
			   .land_ipt_470 {
			   	width: 640px;
			   }
	       }
		   
		 .item_ckquery_list {
			display: flex;
		
		}
		
		 .item_ckquery_list .el-input__icon {
			position: relative;
			top: 1px;
		}
		.ckquery_list_right {
			width: 640px;
		}
		.register_count_ipt{
			margin-left: 0px;
			
		}
		.register_count_ipt .el-input__inner{
			width: 174px;
		}
		::v-deep .el-input-group__prepend{
			padding: 0 8px;
		}
		.content-projecttype{
			display: flex;
			align-items: center;
			justify-content: center;
			.projecttype{
				font-weight: 400;
				color: #232323;
				padding: 1px 5px;
				margin-right: 4px;
				cursor: pointer;
				border-radius: 3px 3px 3px 3px;
				font-size: 14px;
			}
			.projecttype:first-child{
				padding-left: 0px;
			}
			.projecttype:hover{
				background: #F3F4F5;
				padding: 1px 5px;
			}
			.activetype{
				background: #F3F4F5;
				padding: 1px 5px !important;
			}
		}
		
		
	   
	   }
	   .content_item_padding0{
		   padding: 0;
	   }
		
	}
	.bottomlist{
		width: 100%;
		background-color: #FFFFFF;
		
	     border-radius: 4px 4px 4px 4px;
		.bottomlist-title{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 12px;
			padding: 16px ;
			border-bottom: 1px solid #EFEFEF;
			 
			.title-right{
				display: flex;
				align-items: center;
				p:first-child{
					font-size: 12px;
					font-weight: 400;
					color: #3D3D3D;
					margin-right: 10px;
				}
				p:last-child{
					display: flex;
					align-items: center;
					font-size: 14px;
					font-weight: 400;
					color: rgba(35,35,35,0.8);
				}
				img{
					width: 18px;
					height: 18px;
				}
			}
			
		}
		.bottomlist-content{
			
			padding-bottom: 0px;
		}
		.bottomlist-list{
			padding: 16px;
			font-size: 14px;
			border-bottom: 1px solid #EFEFEF;
			padding-bottom: 14px;
			.list-titel{
				font-size: 16px;
				font-weight: 700;
				color: #3D3D3D;
				line-height: 19px;
				.list-titel-a{
					text-decoration: none;
					color:#3D3D3D;
				}
				a:hover, a:visited, a:link, a:active{
					color:#3D3D3D;
				}
			}
			.content-label{
				margin-top: 12px;
				.list-label{
					background: #F3F3FF;
					color: #8491E8;
					border-radius: 1px 1px 1px 1px;
					padding: 3px 7px;
					font-size: 12px;
					margin-right: 16px;
					
				}
				.list-label-wl{
					background: #e8f7f0;
					color: #38c8bf;
					
				}
				.list-label-lx{
					background: #e4f3fd;
					color: #41a1fd;
				}
			}
			
			
			.list-content{
				margin-top: 8px;
				display: flex;
				justify-content: start;
				align-items: center;
				
				.list-content-text{
					margin-top: 7px;
					display: flex;
					justify-content: start;
					align-items:flex-start ;
					margin-right: 27px;
					font-size: 14px;
					
					span:first-child{
						font-weight: 400;
						color: rgba(35,35,35,0.4);
						line-height: 15px
					}
					span:last-child{
						font-weight: 400;
						color: rgba(35,35,35,0.8);
						line-height: 15px
					}
					.content-text-gc{
						width: 72px;
					}
					.content-text-p{
						width: 1200px;
					}
					.blue{
						color: #0081FF !important;
						cursor: pointer;
						
					}
					
				}
				
				
			}
			.list-addree{
				width: auto;
				background: #F3F4F5;
				display: inline-flex;
				margin-top: 7px;
				.list-content-text{
					margin-top: 0px;
					span{
						line-height: 30px!important;
					}
				}
				img{
					width: 14px;
					margin: 0  8px;
					
				}
			}
			
			
		}
		.bottomlist-list:hover{
			background: #F6F9FC;
			cursor: pointer;
		}
		.pagination{
			padding: 14px ;
		   .el-pagination{
			   float: right;
		   }
		}
	}
	
	
</style>

