{extend name="main"}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right" class="flex py-3">

	  <el-form-item label="状态" prop="status" class="flex mb-0 pl-3">
	  	<el-select v-model="search.status" placeholder="请选择" class="w-100px">
		    <el-option label="全部"value="all"></el-option>
		    <el-option label="展示":value="1"></el-option>
		    <el-option label="隐藏":value="0"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item class="flex mb-0 pl-3">
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive">
		<el-table
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB">
	      <el-table-column
	        prop="id"
	        label="ID"
	        width="60">
	      </el-table-column>
	      <el-table-column
	        prop="cate"
	        label="分类"
	        width="100">
	      </el-table-column>
		  <el-table-column type="expand" width="20">
			  <template slot-scope="scope">
			  	<div>标题：{{scope.row.seo_title}}</div>
			  	<div>关键词：{{scope.row.seo_keywords}}</div>
			  	<div>描述：{{scope.row.seo_description}}</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="站点">
		      <template slot-scope="scope">
		      	<el-link :href="scope.row.url" target="_blank"
		      	:underline="false"
		      	title="在前台打开">{{scope.row.title}}</el-link>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="alias"
	        label="别名"
	        width="200">
	      </el-table-column>
	      <el-table-column
	        label="地区"
	        width="280">
		      <template slot-scope="scope">
		      	<div class="flex">
		      		<div class="mr-1">{{scope.row.province}}</div>
		      		<div class="mr-1">{{scope.row.city}}</div>
		      		<div class="mr-1">{{scope.row.area}}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="industry"
	        label="行业"
	        width="240">
	      </el-table-column>
	      <el-table-column
	        label="LOGO"
	        width="80">
		      <template slot-scope="scope">
				  <el-image
				  	v-if="scope.row.logo" 
				    style="max-width: 80px; height: 23px"
				    :src="scope.row.logo" 
				    :preview-src-list="[scope.row.logo]">
				  </el-image>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="状态"
	        width="80">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.status==1 || scope.row.status==2" 
		      		@click="setStatus(scope.row);" 
		      		:loading="scope.row.status==2">启用</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else="scope.row.status==0 || scope.row.status==2" 
		      		@click="setStatus(scope.row);" 
		      		:loading="scope.row.status==2">关闭</el-button>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="创建/更新时间"
	        width="200">
		      <template slot-scope="scope">
		      	<div class="small">
		          <div>{{ scope.row.create_time }}</div>
		          <div>{{ scope.row.update_time }}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="120">
		      <template slot-scope="scope">
		        <el-button
		            type="primary"
		            plain
		            round
		            size="minism"
		            @click="window.open('/city/website/edit/'+scope.row.id)">
		            编辑
		        </el-button>
		        <el-button
		            type="danger"
		            plain
		            round
		            size="minism"
		            @click="del(scope.row,scope.$index)">
		            删除
		        </el-button>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="cate"}
	var cate=[];
	{else/}
	var cate={:json_encode($cate,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			cate:cate,
			labelPosition:'right',
			pid:[],
	        defaultProps: {
	          	value: 'id',
	          	label: 'title',
	          	children: 'data'
	        },
			search:{
				status:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		    pid(val,oldVal){
				if (val.length>0) {
				this.search.cid=val[val.length-1];
				}
		    },
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	del(data,index){
	    		var _this=this;
		        _this.$confirm('此操作将永久删除【'+data.title+'】分站, 是否继续?', '提示', {
		          confirmButtonText: '确定',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		        	data.loading=1;
		        	$.getJSON('/city/website/del/'+data.id,function(ret){
		        		data.loading=0;
		        		if (ret) {
		        			if (ret.code == 0) {
		        				_this.tableData.splice(index,1);
		        			}else{
		        				XYBase.msg(ret.msg);
		        			}
		        		}else{
							XYBase.error(XYBase.config.system_network_error);
		        		}
		        	});
		        }).catch(() => {
    				XYBase.msg('已取消删除');
		        });
	    	},
	    	setStatus(data){
	    		if (data.status==2) return;
	    		var status=1,oldStatus=data.status;
	    		if (data.status) status=0;
	    		data.status=2;
	    		$.getJSON('/city/website/setStatus/'+data.id+'/'+status,function(ret){
	    			data.status=oldStatus;
	    			if (ret) {
	    				if (ret.code === 0) {
	    					data.status=status;
	    				}else{
	    					XYBase.msg(ret.msg);
	    				}
	    			}else{
						XYBase.error(XYBase.config.system_network_error);
	    			}
	    		});
	    	},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}