<?php
/**
 * 视频课程分类一览
 * $Id: course_category_list.inc,v 1.1 2015/10/08 11:18:50 wanggb Exp $
 * @author lixq
 * @access public
 * @package manager.templates
 */


?>

<style type="text/css">
	.result_list{
		width: 701px;
	}
</style>
<div id="classSetting">
	<div class="list_title">
		视频课程分类管理<el-button type="primary" style="margin-right: 10px;" @click="addClass()">课程类添加</el-button>
	</div>
	<br/>
	一级分类名称:
	<el-select v-model="parent_id" size='medium' >
      <el-option
          v-for="item in parent_list"
          :key="item.id"
          :label="item.title"
          :value="item.id">
      </el-option>
  	</el-select>
	<br/>
	<div class="result_list">
		<el-table :data="tableData" border style="width: 100%">
		    <el-table-column
		      prop="parent_title"
		      label="一级分类名称"
		      width="300">
		    </el-table-column>
		    <el-table-column
		      prop="title"
		      label="分类名称"
		      width="300">
		    </el-table-column>
		     <el-table-column
		      label="操作"
		      width="100">
		      <template slot-scope="scope">
		        <el-button @click="handleChange(scope.row)" type="text" size="small">编辑</el-button>
		        <el-button type="text" size="small" @click.native.prevent="deleteRow(scope.row)">删除</el-button>
		      </template>
		    </el-table-column>
		</el-table>
	</div>
</div>

<script type="text/javascript">
	var list=[];
	<?
	foreach ($course_category_list as $tmp) {
	?>
		var data={
			id:<?=$tmp->id ?>,
			title:'<?=$tmp->title ?>',
			parent_id:<?=$tmp->parent_id?>,
			parent_title:'<?=CourseParentCategory::getTitleById($tmp->parent_id)?>'
		};
		list.push(data);
	<?
  }
	?>
	new Vue({
		el:'#classSetting',
		data:{
			tableData: list,
			parent_list:<?=json_encode($all_category_list)?>,
			parent_id:0,
			category_list:list,
			searchVal:''
		},
		methods:{
			handleChange(row) {
		        console.log(row);
		        window.location.href='course_category_edit_input.php?action_type=edit&id='+row.id;
		   },
		   deleteRow(rows) {
	        	this.$confirm('是否删除?', '提示', {
		          confirmButtonText: '确定',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		          this.$message({
		            type: 'success',
		            message: '删除成功!'
		          });
//	        		rows.splice(index, 1);
					window.location.href='course_category_delete_result.php?id='+rows.id;
		        }).catch(() => {
		          this.$message({
		            type: 'info',
		            message: '已取消删除'
		          });          
		        });
	      	},
	      	addClass(){
	      		window.open('course_category_edit_input.php?action_type=new','_self')
	      	}
		},
	  watch:{
	    parent_id(val,oldval){
		    if(val == 0){
		      this.tableData = this.category_list;
			  }else{
  	      var new_list = [];
  	      this.category_list.map(function(item) {
  	        if (item.parent_id == val) {
  	          new_list.push(item);
  	        }
  	       });
  	    	this.tableData = new_list;
			  }
      }
    }
	})
</script>
