<?php
/**
 * 领导机构-二维码管理
 * $Id: government_qr_list.inc,v 1.1 2020/01/03 11:18:46  Exp $
 * @author lixq
 * @access public
 * @package manager.templates
 */

global $government_qr_list;

?>

<div id="classSetting">
	<div class="list_title">
		领导机构-二维码管理<el-button type="primary" style="margin-right: 10px;" @click="addQR()">二维码添加</el-button>
	</div>
	<form id="form" action="government_qr_edit_input.php" method="post">
	<input type="hidden" name="government_id" value="<?=$government_mst->id?>"/>
	<input type="hidden" name="government_title" value="<?=$government_mst->title?>"/>
	<input type="hidden" name="action_type" value=""/>
	<input type="hidden" name="id" value=""/>
	</form>
  <br />
  <div class="result_list">
  	<el-table :data="tableData" border>
  		<el-table-column  prop="title" label="教育管局名称" width=""></el-table-column>
  		<el-table-column  prop="limit_date" label="截止使用时间" width=""></el-table-column>
  		<el-table-column  prop="max_count" label="最大使用次数" width=""></el-table-column>
  		<el-table-column  prop="use_count" label="已使用次数" width=""></el-table-column>
  		<el-table-column  label="二维码"  width="150">
  			<template slot-scope="scope">
  				<span  v-if="!scope.row.qr_image">未生成</span>
          <el-image style=" height: 50px" v-if="scope.row.qr_image" :src="scope.row.qr_image" :preview-src-list="scope.row.srcList"></el-image>     
  			</template>
  			</el-table-column>
  		<el-table-column  label="操作"  width="150">
  			<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>
<?
if ($government_qr_count > 0) {
?>
<!--page begin-->
<?
require_once("page_common.inc");
?>
<!--page end-->
<?
}
?>
<script type="text/javascript">
	var list=[];
	<?
	foreach ($government_qr_list as $tmp) {
	?>
		var data={
			id:<?=$tmp->id ?>,
			use_count:'<?=$tmp->use_count?>',
			max_count:'<?=$tmp->max_count?>',
			qr_image:'<?=$tmp->qr_image?>',
			srcList:['<?=$tmp->qr_image?>'],
			limit_date:'<?=!empty($tmp->limit_date)?$tmp->limit_date:"-"?>',
			title:'<?=$government_mst->title ?>'
		};
		list.push(data);
	<?
	}
	?>

	new Vue({
		el:'#classSetting',
		data:{
			tableData: list
		},
		methods:{
			handleChange(row) {
				$("input[name='id']").val(row.id);
				$("input[name='action_type']").val("edit");
				$("#form").submit();
		  },
		  deleteRow(rows) {
	    	this.$confirm('是否删除?', '提示', {
		    	confirmButtonText: '确定',
		    	cancelButtonText: '取消',
		    	type: 'warning'
		 		}).then(() => {
		    	this.$message({
		      	type: 'success',
		      	message: '删除成功!'
		     	});
//	        		rows.splice(index, 1);
					window.location.href='government_qr_delete_result.php?id='+rows.id;
		   	}).catch(() => {
		    	this.$message({
		      	type: 'info',
		      	message: '已取消删除'
		    	});          
		    });
	    },
	    showQr(row){
	      html_data = '<div style="width: 100%;text-align: center;"><img src="'+row.qr_image+'"/></div>';
	      doSelectPopup(html_data);
	    },
	    addQR(){
				$("input[name='action_type']").val("new");
				$("#form").submit();
	    }
		}
	})
</script>