<!doctype html>
<html>
	<head>
		<meta charset="utf-8"><meta http-equiv="Expires" content="0"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-control" content="no-cache"><meta http-equiv="Cache" content="no-cache">
		<title>折扣方案</title>
		
		<script type="text/javascript">
			function loadJsCss(callback) {
				var jscss_urls = [];
				window.top.initJsCss(document, jscss_urls, callback);
			};
			
			function initVue() {
				new ListVue({
					el: "#vbody",
					data: {
						dataname: "fee_model_plan",
						title: "折扣方案",
						filterTxt: "",
						default_filterFields: [
							// {isshow: "T", field: "year", name: "年份", filteroperator: "=", type: "year"},
							{isshow: "T", field: "policyname", name: "方案名称", filteroperator: "like", type: ""},
							{isshow: "T", field: "zksq", name: "折扣申请", filteroperator: "=", type: "select", options: [{code: "0001",value: "二次议价申请"}, {code: "0002",value: "省标申请"}, {code: "0003",value: "征税变更"}]},
						],
						default_tableFields: [
							{isshow: "T", field: "policycode", name: "方案编码", width: "150"},
							{isshow: "T", field: "policyname", name: "方案名称", width: "200", align: "left", isminwidth: true},
							{isshow: "T", field: "version", name: "版本号", width: "100"},
							{isshow: "T", field: "state_name", name: "状态", width: "100"},
							{isshow: "T", field: "effdate", name: "生效日期", width: "180"},
							{isshow: "T", field: "expdate", name: "失效日期", width: "180"},
							{isshow: "T", field: "record_type", name: "准则来源", width: "200", align: "left", isminwidth: true},
							{isshow: "T", field: "flow_type", name: "流向来源", width: "200", align: "left", isminwidth: true},
							{isshow: "T", field: "createname", name: "创建人", width: "100"},
							{isshow: "T", field: "createtime", name: "创建时间", width: "180"}
						],
						default_tableData: [
							{"id": "P001", "policycode": "ZC_N001_2022","policyname": "二次议价","version": "V1","state_name": "启用", "effdate": "2022-01-01", "expdate": "2022-12-31", "record_type": "", "flow_type": "", "createname": "张三", "createtime": "2021-07-14"},
							{"id": "P002", "policycode": "ZC_P001_2022","policyname": "省标","version": "V1","state_name": "启用", "effdate": "2022-01-01", "expdate": "2022-12-31", "record_type": "", "flow_type": "", "createname": "张三", "createtime": "2021-07-14"},
							{"id": "P003", "policycode": "ZC_Y001_2022","policyname": "佣金","version": "V1","state_name": "启用", "effdate": "2022-01-01", "expdate": "2022-12-31", "record_type": "", "flow_type": "", "createname": "张三", "createtime": "2021-07-14"},
						],
						filterfieldClick: {},
						tablefieldClick: {},
						formfieldClick: {},
						initlized: false,
					},
					created() {
						
					},
					
					mounted() {
						this.initData();
						this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
							hideLoading();
						});
					},
					
					methods:{
						initData() {
							var me = this;
							this.onQuery(function(result,callback) {//查询后的回调,用于获取字段的
								if (result.meta && result.meta[me.dataname] && result.meta[me.dataname].fields) {
									var metas = clone(result.meta[me.dataname].fields);
									var filterFields_ = [];
									var tableFields_ = [];
									
									metas.map(f=>{
										f.isshow = "T";
										
										if (f.isfilter) {
											filterFields_.push(clone(f));
										}
										else {
											var filter_f = clone(f);
											filter_f.isshow = "F";
											filterFields_.push(filter_f);
										}
										
										tableFields_.push(clone(f));
									})
									if (!me.filterFields || (me.filterFields && me.filterFields.length == 0)) {
										me.filterFields = clone(filterFields_);
										me.tableFields = clone(tableFields_);
										
										// me.filterFields = clone(me.default_filterFields);
										// me.tableFields = clone(me.default_tableFields);
										//字段数组转字段obj
										me.fieldsToFieldsObj();
										
										//设置字段事件
										me.tableFieldClick();
									}
								}
								
								if(callback){
									callback();
								}
							});
						},
						
						tableFieldClick() {
							var me = this;
							//筛选字段事件设置
							this.filterfieldClick = {
							};
							//表格字段事件设置
							this.tablefieldClick = {
								name: {//字段事件设置
									val: {//有值时的点击事件
										notclick_val: "",//不可点击的值,1、是数组["11","22"];2、以“;”分隔的字符串"111;222"
										notclick_bindfield: [],//当该字段值等于指定字段值时不可点击["filterfield": "111"]
										onclick: function(obj) {//数据值点击事件
											me.showData(obj)
										},
									},
								},
								source_agreement_name: {//协议条款字段事件设置
									val: {//有值时的点击事件
										notclick_val: "",//不可点击的值,1、是数组["11","22"];2、以“;”分隔的字符串"111;222"
										notclick_bindfield: [],//当该字段值等于指定字段值时不可点击["filterfield": "111"]
										onclick: function(obj) {//数据值点击事件
											me.showData(obj)
										},
									},
								},
								source_flow_name: {//流向来源字段事件设置
									val: {//有值时的点击事件
										notclick_val: "",//不可点击的值,1、是数组["11","22"];2、以“;”分隔的字符串"111;222"
										notclick_bindfield: [],//当该字段值等于指定字段值时不可点击["filterfield": "111"]
										onclick: function(obj) {//数据值点击事件
											me.showData(obj)
										},
									},
								},
							};
						
							//表单字段事件设置
							this.formfieldClick = {
							};
						},
						
						showData(obj) {
							var me = this;
							var row = obj.row;
							
							var config = {
								totab: true, //true: 以Tab导航的方式打开
								width: "900px",
								height: "900px",
								icon: "icon-product",
								text: "方案定义",
								id: "settingPolicy_edit" + row.id, //totab: true时需设置,用于判断是否已打开此页面
								url: "module/performance/page/settingPolicy_edit_1.html",
								// url: "module/performance/page/designer/designer.html",
								data: row,
								delta: {},
								sceneCode: "edit", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						addData() {
							var me = this;
							
							var config = {
								totab: true, //true: 以Tab导航的方式打开
								width: "900px",
								height: "900px",
								icon: "icon-product",
								text: "方案定义",
								id: "settingPolicy_edit_add",//totab: true时需设置,用于判断是否已打开此页面
								url: "module/performance/page/settingPolicy_edit_1.html",
								// url: "module/performance/page/designer/designer.html",
								data: null,
								delta: {},
								sceneCode: "add", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						editData(scope) {
							var me = this;
							var row = scope.row;
							
							//1. empty row
							if (!row || !row.id) {
								Root.message({
									type: 'warning',
									message: '请选择要编辑的数据'
								});  
								return false;
							}
							
							//3. popup
							var config = {
								totab: true, //true: 以Tab导航的方式打开
								width: "900px",
								height: "900px",
								icon: "icon-product",
								text: "方案定义",
								id: "test_page",//totab: true时需设置,用于判断是否已打开此页面
								url: "module/performance/page/settingPolicy_edit_1.html",
								// url: "module/performance/page/designer/designer.html",
								data: row,
								delta: {},
								sceneCode: "edit", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						
						delData: function(scope) {
							let me = this;
							let row = scope.row;
							let index_ = scope.$index;
							let name_ = "该数据";
							
							if (!this.dataname) {
								Root.message({
									type: 'warning',
									message: '该事件需指定数据对象'
								});  
								return
							}
							if (!row.id) {
								Root.message({
									type: 'warning',
									message: '该事件需存在数据ID'
								});  
								return
							}
							if (row.name) {
								name_ = "_" + row.name + "_";
							}
							
							Root.confirm('确定删除' + name_ + '吗?', '删除提示', {
							  confirmButtonText: '删除',
							  cancelButtonText: '取消',
							  type: 'warning'
							}).then(() => {
								let param = {
									id: row.id,
									
									dataname: this.dataname,
								}
								// Server.call("rootfee/" + "root/data/deleteEntity", param, function(result) {
								// 	console.log(result);
								// 	Root.message({
								// 		type: 'success',
								// 		message: '删除成功!'
								// 	});
								// 	me.doQuery();
								// });
							}).catch(() => {
								Root.message({
									type: 'info',
									message: '已取消删除'
								});          
							});
						},
						
					}
				});
			};
			
			loadJsCss(function () {
				initVue();
			});
		</script>
	</head>
	
	<body style="margin: 0px;">
		<div v-cloak id="vbody">
			<div id="page_root">
				<div class="topbar">
					<span>{{title}}</span>
					<div style="float: right; margin-right: 18px;">
						<el-button-group style="margin-left: 3px">
							<el-button @click="addData":icon="buttonsconfig.add.icon">{{buttonsconfig.add.name}}</el-button>
							<el-button
								:disabled="!(selectedrow.id && (selectedrow.state_code == 'Input' || selectedrow.state_code == 'Rejected'))"
								@click="" :icon="buttonsconfig.edit.icon">{{buttonsconfig.edit.name}}
							</el-button>
							<el-button
								:disabled="!(selectedrow.id && (selectedrow.state_code == 'Input' || selectedrow.state_code == 'Rejected'))"
								type = "danger"
								@click="" :icon="buttonsconfig.delete.icon">{{buttonsconfig.delete.name}}
							</el-button>
						</el-button-group>
					</div>
				</div>
				
				<div class="topbar-line">
					<div class="query-icon">
						<i class="iconfont icon-query"></i>
					</div>
					<div class="query-bar">
						<h-form-filter ref="form1"
							:form-attr="filterAttr" 
							:table-fields="filterFields" 
							:table-field-click="filterfieldClick"
							:form-data="filterObj" 
							
							v-on:show-popup="showFilterPopup"
							v-on:on-query="onQuery"
							v-on:on-init-query="onInitFilter"
							v-on:on-edit-query="onEditFilter"
							>
						</h-form-filter>
					</div>
				</div>
				
				<div class="h_dialog__body">
					<h-table
						v-if="isRefresh"
						ref="table1"
						:table-fields="tableFields" 
						:table-data="tableData" 
						:is-edit-table-data="isEditTableData"
						:table-field-click="tablefieldClick"
						:pagesize="pagesize"
						:pagenum="pagenum"
						:total="total"
						:table-height="tableHeight"
						:is-highlight-row="true"
						
						v-on:get-data="getData"
						v-on:row-click="rowClick"
					>
					</h-table>
				</div>
			</div>
			
			
		</div>	
		<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 50vh;">
			<div class="spinner">
			  <div class="cube1"></div>
			  <div class="cube2"></div>
			</div>
		</div>
		<style>
			[v-cloak] {
				display: none !important;
			}
		</style>
		
	</body>
</html>