<!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">
			var pageVue = null;
			function loadJsCss(callback) {
				var jscss_urls = [];
				window.top.initJsCss(document, jscss_urls, callback);
			};
			
			function initVue() {
				new ListVue({
					el: "#vbody",
					data: {
						dataname: "sys_state_approve",
						title: "流程定义",
						
						isshowflowchart: true,
						flowchart: "workspace/process/instance/tabs",
						editflowchart: "admin/processdesign",
						flowchart_url: "",
					},
					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_);
		
										//字段数组转字段obj,目的为了筛选时获取字段属性
										me.fieldsToFieldsObj();
										
										//设置字段事件
										me.tableFieldClick();
									}
								}
								
								if (callback) {
									callback();
								}
							});
						},
						
						tableFieldClick() {
							var me = this;
							//筛选字段事件设置
							this.filterfieldClick = {
								product_code: {//字段事件设置
									popup: {
										onclick: function(obj) {//弹窗点击事件
											Root.message({
												type: 'success',
												message: '弹窗点击事件'
											});
										}
									},
									visible: {
										onchange: function(obj) {//下拉展开事件
											Root.message({
												type: 'success',
												message: '下拉展开事件'
											});
										}
									},
									select: {
										onchange: function(obj) {//下拉展开事件
											Root.message({
												type: 'success',
												message: '下拉更改事件'
											});
										}
									},
									input: {
										onchange: function(obj) {//下拉展开事件
											Root.message({
												type: 'success',
												message: '下拉更改事件'
											});
										}
									},
								},
							};
							//表格字段事件设置
							this.tablefieldClick = {
								product_code: {//字段事件设置
									val: {//有值时的点击事件
										notclick_val: "",//不可点击的值,1、是数组["11","22"];2、以“;”分隔的字符串"111;222"
										notclick_bindfield: [],//当该字段值等于指定字段值时不可点击["filterfield": "111"]
										onclick: function(obj) {//数据值点击事件
											Root.message({
												type: 'success',
												message: obj.val + '点击事件'
											}); 
										},
									},
									defaultval: {
										val: "查看",//空值时的显示值
										onclick: function(obj) {//默认值点击事件,此事件需要设置val才有效
											Root.message({
												type: 'success',
												message: '默认值点击事件'
											});
										}
									},
									suffixval: {
										// val: "详情",//有值时的后缀,此后缀和单位后缀不同,如:详情,更多,查看等
										// onclick: function(obj) {//有值时的后缀点击事件,此事件需要设置val才有效
										// 	//打开
										// 	me.opentest()
										// }
									},
									popup: {
										onclick: function(obj) {//弹窗点击事件
											Root.message({
												type: 'success',
												message: '弹窗点击事件'
											});
										}
									},
									visible: {
										onchange: function(obj) {//下拉展开事件
											Root.message({
												type: 'success',
												message: '下拉展开事件'
											});
										}
									},
									select: {
										onchange: function(obj) {//下拉更改事件
											Root.message({
												type: 'success',
												message: '下拉更改事件'
											});
										}
									},
									input: {
										onchange: function(obj) {//输入更改事件
											Root.message({
												type: 'success',
												message: '输入更改事件'
											});
										}
									},
									
									
								},
							};
						
							//表单字段事件设置
							this.formfieldClick = {
								product_code: {//字段事件设置
									val: {//有值时的点击事件
										onclick: function(obj) {//数据值点击事件
											Root.message({
												type: 'success',
												message: obj.val + '点击事件'
											}); 
										},
										onchange: function(obj) {//数据修改事件
											Root.message({
												type: 'success',
												message: '数据修改事件'
											});
										}
									},
									popup: {
										onclick: function(obj) {//弹窗点击事件
											Root.message({
												type: 'success',
												message: '弹窗点击事件'
											});
										}
									},
									visible: {
										onchange: function(fieldObj, row, callback) {//下拉展开事件
											Root.message({
												type: 'success',
												message: '下拉展开事件'
											});
											
											//重新设置选择项
											if (callback) {
												var obj_ = {
													options: []
												};
												callback(obj_);
											}
										}
									},
									select: {
										onchange: function(obj) {//下拉更改事件
											Root.message({
												type: 'success',
												message: '下拉更改事件'
											});
										}
									},
									input: {
										onchange: function(obj) {//输入更改事件
											Root.message({
												type: 'success',
												message: '输入更改事件'
											});
										}
									},
									button: {
										onclick: function(obj) {//按键点击事件
											Root.message({
												type: 'success',
												message: '按键点击事件'
											});
										}
									},
									buttonarray: {
										onclick: function(obj) {//按键组点击事件,需要根据按键的code来判断具体事件
											Root.message({
												type: 'success',
												message: '按键组点击事件'
											});
										}
									},
									
								},
							};
						},
						
						opentest() {
							var me = this;
							Root.message({
								type: 'success',
								message: '后缀点击事件'
							});
							
							var config = {
								totab: false, //true: 以Tab导航的方式打开
								width: "900px",
								height: "900px",
								icon: "icon-product",
								text: "表单样例页面",
								id: "test_page",//totab: true时需设置,用于判断是否已打开此页面
								//url: "module/system/page/coming.html",
								url: "module/system/page/sample/sample_form.html",
								data: {},
								delta: {},
								sceneCode: "edit", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						addData() {
							let me = this;
							var config = {
								totab: false, //true: 以Tab导航的方式打开
								width: "500px",
								height: "300px",
								icon: "icon-product",
								text: "产品信息",
								id: "product_edit",//totab: true时需设置,用于判断是否已打开此页面
								url: "module/md/page/product/page/product_edit.html",
								data: {},
								delta: {},
								sceneCode: "add",//"refuseedit",//"approval", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						onEditData(config, 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: false, //true: 以Tab导航的方式打开
								width: "500px",
								height: "300px",
								icon: "icon-product",
								text: "产品线信息",
								id: "product_edit" + row.id,//totab: true时需设置,用于判断是否已打开此页面
								url: "module/md/page/product/page/product_edit.html",
								data: row,
								delta: null,
								sceneCode: "edit",//"refuseedit",//"approval", //"add"//"browse",
								callback: function(obj, callback) {
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						onRowClick(obj) {
							// 查看流程图
							this.isshowflowchart = false;
							
							this.$nextTick(() => {
								var url_ = window.top.config.url_act + this.flowchart + "?flowChartId=" + obj.row.id;
								this.flowchart_url = clone(url_);
								this.isshowflowchart = true
							});
						},
						
						// 编辑流程图
						editFlowChart() {
							// this.isshowflowchart = false;
							// this.$nextTick(() => { 
							// 	this.flowchart_url = clone(url_);
							// 	this.isshowflowchart = true
							// });
							var url_ = window.top.config.url_act + this.editflowchart + "?flowChartId=" + this.selectedrow.id;
							this.doEditFlowChart(url_)
						},
						doEditFlowChart(acturl) {
							let me = this;
							var config = {
								totab: false, //true: 以Tab导航的方式打开
								width: "80vw",
								height: "95vh",
								icon: "icon-product",
								text: "编辑流程图",
								id: "approval_edit",//totab: true时需设置,用于判断是否已打开此页面
								url: "module/config/page/approval_edit.html",
								data: acturl,
								delta: {},
								// filter: "org_id='"+ me.selectedrow.org_id + "' and bu_id='" + me.selectedrow.bu_id + "'",
								// filter: filter_,
								callback: function(popupobj, popupcallback) {
									callback(popupobj);
									if (popupcallback) {
										popupcallback();
									}
								}
							}
							me.doPopupByPublic(config);
						},
						
						
						
					}
				});
			};
			
			loadJsCss(function () {
				initVue();
			});
		</script>
		
		<style>
			/*  在vue.js中 v-cloak 这个指令是防止页面加载时出现 vuejs 的变量名而设计的 */
			[v-cloak] {
				display: none !important;
			}
			.el-tabs__nav-scroll {
			    overflow: hidden;
			    position: relative;
			    padding-left: 20px;
			}
			
			.nodeLabel {
				max-width: 200px !important;
			}
			
		</style>
		
	</head>
	
	<body style="margin: 0px;">
		<div v-cloak id="vbody">
			<div id="page_root">
				<div class="topbar">
					<span>{{title}}</span>
				</div>
				
				<div class="h_dialog__body">
					<div style="position: absolute;left: 10px; top:45px;width: 220px; bottom: 10px;border: 1px solid #ccc;">
						<!-- <div style="height: 32px;line-height: 32px;border-bottom: 1px solid #ccc ;">
							<span style="font-size: 14px;margin-left: 20px;">{{title}}</span>
						</div> -->
						<div :style="{padding: '0px', height: tableHeight + 'px', overflow: 'auto'}">
							<h-table
								v-if="isRefresh && tableFields.length"
								ref="table1"
								:table-fields="tableFields" 
								:table-data="tableData" 
								:is-edit-table-data="isEditTableData"
								:table-height="tableHeight - 44"
								:table-field-click="tablefieldClick"
								:table-buttons-click="tablebuttonclick"
								:is-highlight-row="true"
								:tableloading="tableloading"
								:filtersobj="filterObj"
								:isdraggableorder="false"
								:is-pagination="false"
								:isfilterfield="false"
								:isbasicfilterfields="false"
								:istablebuttons="false"
								
								v-on:get-data="getData"
								v-on:row-click="rowClick"
							>
							</h-table>
							
						</div>
					</div>
					<div style="position: absolute;left: 240px; top:45px; right: 10px; bottom: 10px;border: 1px solid #ccc;">
						<div>
							<div style="height: 32px; border-bottom: 1px solid #ccc;">
								<div class="table_title" style="float: left;">
									<span>流程图</span>
								</div>
								
								<div style="margin-right: 18px;float: right;line-height: 30px;">
									<el-button-group style="margin-left: 3px">
										<el-button :disabled="!(selectedrow && selectedrow.id)" @click="editFlowChart" icon="el-icon-edit-outline">编辑</el-button>
									</el-button-group>
								</div>
							</div>
							<div :style="{height: (tableHeight - 40) + 'px', 'border': '1px dashed  #dfdfdf'}" v-if="selectedrow && selectedrow.id && isshowflowchart">
								<!--<div>
									 <table style="margin-top: 20px; margin-left: 20px;" cellpadding="0">
										<tr>
											<td ><div class="h_node_begin">开始</div></td>
											<template v-for="(s, k) in tableData_p">
												<td class="h_node_inbound"><div class="h_xian"></div></td><td><div class="h_sj"></div></td>
												<td class="h_main_node"><div >{{s.node_name}}</div></td>
											</template>
											<td class="h_node_inbound"><div class="h_xian"></div></td><td><div class="h_sj"></div></td>
											<td ><div class="h_node_end">完成</div></td>
										</tr>
									</table>
									
								</div> -->
								<iframe style="width: 100%; height: 100%;" frameborder="0" :src="flowchart_url"></iframe>
								
							</div>
						</div>
					</div>
				</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>
		
	</body>
</html>