<!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 src="../../../jsnew/elementDefault.js?v=20220425"></script>
        <script src="../../../jsnew/vue/vue.js"></script>
		<script src="../../../jsnew/vue/element-ui/element-ui_15/index.js"></script>
		<script src="../../../jsnew/myelement.js?v=20220425"></script>
		<script src="../../../jsnew/page.js?v=20220425"></script>
		<!-- <script src="../../../setting.js"></script> -->
		
		<link href="../../../jsnew/vue/element-ui/element-ui_15/theme-chalk/index.css" rel="stylesheet">
		<link href="../../../jsnew/myelement.css?v=20220426" rel="stylesheet">
		<link href="../../../jsnew/theme.css?v=20220426" rel="stylesheet">
		<link href="../../../css/iconfont.css" rel="stylesheet">
		<link href="../../../jsnew/page.css?v=20220425" rel="stylesheet">
		<link href="//at.alicdn.com/t/font_2374495_13ltsxm2eor.css" rel="stylesheet">
	</head>

	<style>
        /*  在vue.js中 v-cloak 这个指令是防止页面加载时出现 vuejs 的变量名而设计的 */
        [v-cloak] {
            display: none !important;
        }
    </style>

	<body  style="margin: 0px;">
		<div v-cloak id="vbody">
			<div id="page_root">
				<div ref="popup_body" style="padding: 0 20px;">
					<div class="el-dialog__header">
						<div class="dialog-title">
						  <i class="iconfont icon-customermanagement"></i>
						  <span> {{title}}</span>
						</div>
					</div>

					<div :style="{height: t_height +'px', 'overflow-y': 'auto'}">
						<div class="el-dialog__body">
							<h-form
								ref="form1"
								:form-attr="formAttr"
								:table-fields="formFields"
								:form-data="formData"
								:table-field-click="formfieldClick"
							>
							</h-form>
						</div>
					</div>
					<div class="el-dialog__footer" v-if="isedit">
						<el-button size="small" type="default" @click="closeDialog">取 消</el-button>
						<el-button size="small" v-if="(isedit || isrefuseedit)" type="primary" @click="saveRowTable">保 存</el-button>
						<!-- <el-button size="small" v-if="isedit" type="success" @click="">提 交</el-button>
						<el-button size="small" v-if="isrefuseedit" type="success" @click="">再次提交</el-button> -->
					</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>
		
		<script type="text/javascript">
			function initVue() {
				new FormVue({
					el: "#vbody",
					data: {
						dataname: "price_manager_nation",
						title: "全国省中标价价格表",
						dataurl: "rootjemin/data/getEntitySet",
						filterTxt: "type='NationTag'",

						formAttr: {
							istitle: false,
							title: "表单名称",
							columnnumber: 2,
							labelwidth: "140px",
							labelposition: "left",//"left",// right//top
							size: "mini",
							border: "3px solid #c6c6c600"
						},
						dataRequest: [
							{
								name: "md_province",
								url: "rootjemin/data/getEntitySet",
								paramsobj: {dataname: "md_division", filter: "level = '1'"},
								isnotoption: false, //true:不是选项
								label: "name",
								code: "code"
							}
						],
						
						default_formFields: [
							{isshow: "T", field: "state", name: "是否有效", width: "100", type:'switch',},
							{isshow: "T", field: "area", name: "地区", width: "150", type: 'select',},
                            {isshow: "T", field: "program", name: "项目", width: "200", align: "left", type: 'input',},
                            {isshow: "T", field: "code", name: "药品编码", width: "150", type: 'popup',},
                            {isshow: "T", field: "name", name: "药品名称", width: "150", type: 'span',},
                            {isshow: "T", field: "spec", name: "药品规格", width: "100", type: 'span',},
                            {isshow: "T", field: "20", name: "20å¹´ä»·æ ¼", width: "100", formatter: "formatter_money", align: "right", type: "input"},
                            {isshow: "T", field: "21", name: "21å¹´ä»·æ ¼", width: "100", formatter: "formatter_money", align: "right", type: "input"},
							{isshow: "T", field: "22", name: "22å¹´ä»·æ ¼", width: "100", formatter: "formatter_money", align: "right", type: "input"},
							{isshow: "T", field: "23", name: "23å¹´ä»·æ ¼", width: "100", formatter: "formatter_money", align: "right", type: "input"},
							{isshow: "T", field: "unit_dose_price", name: "最小制剂单价", width: "100", formatter: "formatter_money", align: "right", type: "input"},
							{isshow: "T", field: "retail_price", name: "最小零售单价", width: "100", formatter: "formatter_money", align: "right", type: "input"},
							{isshow: "T", field: "unit", name: "价格单位", width: "100", type: "span"},
							{isshow: "T", field: "time", name: "执行时间", width: "100", formatter: "formatter_date", type: "date"},
							{isshow: "T", field: "remark", name: "备注", width: "150", align: "left", type: "textarea", colspan: 2},
						],
						formFields: [],
						newformData: {},
						formData: {},
						
						//字段设置
						tablefieldClick: {},
						formfieldClick: {},

						//按键权限设置
						isedit: false,//提交前编辑,保存/提交
						isrefuseedit: false,//拒绝后编辑,保存/再次提交
						isapproval: false,//审批,同意/拒绝/转办/退回
						isend: false,
						
						iscommit: false,//提交标记
						
						//弹窗参数
						popupParames: {},

						t_height:null,
						isRefresh: true,
					},
					created() {
						this.popupParames = clone(Root.popupParames);
						this.title = this.popupParames.title || this.popupParames.text;
						if (this.popupParames.data) {
							this.formData = clone(this.popupParames.data);
						}
						
						if (this.popupParames.sceneCode) {
							if (this.popupParames.sceneCode == "add") {//新增
								if (this.newformData) {
									let formData_ = clone(this.formData);
									
									for (var k in this.newformData) {
										formData_[k] = this.newformData[k];
									}
									this.formData = formData_;
								}
								
								this.isedit = true;
							}
							else if (this.popupParames.sceneCode == "browse") {//只读
								this.formAttr.disabled = true;
								this.formAttr2.disabled = true;
							}
							else if (this.popupParames.sceneCode == "edit") {//编辑
								this.isedit = true;
							}
							else if (this.popupParames.sceneCode == "approval") {//审批
								this.formAttr.disabled = true;
								this.formAttr2.disabled = true;
								this.isapproval = true;
							}
							else if (this.popupParames.sceneCode == "refuseedit") {//拒绝后的编辑
								this.isrefuseedit = true;
							}
						}
					},
					
					mounted() {
						var me = this;
						me.t_height = document.documentElement.clientHeight*1 - 91;

						//预加载数据
						if (this.dataRequest && this.dataRequest.length) {
							var result = {};
							this.loadRequestData(this.dataRequest, result, function(data) {
								me.dataRequestObj = data;
								//预加载数据后给哪些字段设置options或formatterjson
								
								me.initData();
							});
						}
						else {
							this.initData();
						}
						
						// 以服务的方式调用的 Loading 需要异步关闭
						this.$nextTick(() => { 
							hideLoading();
							
							//重新设置弹窗宽高
							this.$nextTick(function(){
								let w_ = this.$refs.popup_body.offsetWidth + "px";
								// let w_ = "900px";
								let h_ = this.$refs.popup_body.offsetHeight + "px";
								Root.setPopupWH(w_, h_);
							})
						});
					},
					
					methods:{
						//关闭弹窗
						closeDialog() {
							var me = this;
							if (me.popupParames.totab){
								Root.tab.removeItem(Root.tab.selected);
								Root.tab.open(me.popupParames.parentOption, false); 
							}
							else {
								Root.hidePopup();
							}
						},
						//关闭前调回调
						saveAfter() {
							var me = this;
							if(this.popupParames.callback) {
								let obj = {
									//row: this.formData
								}
								this.popupParames.callback(obj, function() {
									me.closeDialog();
								});
							}
							else {
								me.closeDialog();
							}
						},
						
						initData() {
							let me = this
							
							let id_ = ""
							if (this.formData.id) {
								id_ = this.formData.id;
							}
							this.getRowDataById(id_, function(result) {//查询后的回调,用于获取字段的
								if (result.meta && result.meta[me.dataname] && result.meta[me.dataname].fields) {
									var metas = clone(result.meta[me.dataname].fields);
									
									var formFields_ = [];
									metas.map(f=>{
										f.isshow = "T";
										
										if (f.field == 'province_name') {
											me.dataRequestObj.md_province.data.entityset.map(e => {
												e.value = e.name
											})
											f.options = me.dataRequestObj.md_province.data.entityset
										}
										
										let currentYear = parseInt(createDate().split('-')[0].substring(2, 4))
										// let currentYearField = "price_" + currentYear
										// let leftYear1 = "price_" + (currentYear - 1)
										// let leftYear2 = "price_" + (currentYear - 2)
										// let leftYear3 = "price_" + (currentYear - 3)
										
										if (f.field.indexOf('price_') != -1) {
											let fieldYear = parseInt(f.field.split('_')[1])
											
											if (fieldYear == currentYear) {
												formFields_.push(clone(f));
											}
										}
										else {
											formFields_.push(clone(f));
										}
									})
									
									
									if (!me.formFields || (me.formFields && me.formFields.length == 0)) {
										me.formFields = clone(formFields_);
										
										//字段数组转字段obj
										me.fieldsToFieldsObj();
										
										//设置字段事件
										me.tableFieldClick();
									}
								}
								
								if (me.rowData[me.dataname]) {
									me.formData = me.rowData[me.dataname];
								}
							})
						},

						newEndDeatil() {
							var me = this;
							
							var config = {
								totab: false, //true: 以Tab导航的方式打开
								width: "900px",
								height: "900px",
								icon: "icon-product",
								text: "请选择要终止的全国省中标价价格表明细数据",
								id: "popup_terminal_policy_info_list",//totab: true时需设置,用于判断是否已打开此页面
								url: "../agreement/policy/popup_terminal_policy_info_list.html",
								data: {},
								delta: {},
								sceneCode: "add",//"refuseedit",//"approval", //"add"//"browse",
								callback: function(obj, callback) {
									if (callback) {
										callback();
									}
								}
							};
							me.doPopupByPublic(config);
						},
						
						tableFieldClick() {
							var me = this;
							//表单字段事件设置
							this.formfieldClick = {
								product_name: {
									popup: {
										onclick: function(obj) {//弹窗点击事件
											var config = {
												totab: false, //true: 以Tab导航的方式打开
												width: "900px",
												height: "450px",
												icon: "icon-product",
												text: "选择药品",
												id: "popup_product_list",//totab: true时需设置,用于判断是否已打开此页面
												url: "../agreement/popup/popup_product_list.html",
												data: {},
												delta: {},
												dataname: "md_product",
												filter: "1 = 1",
												sceneCode: "add", //"add"//"browse",
												callback: function(popObj, callback) {
													let formData = clone(me.formData)
													
													formData['product_code'] = popObj.row.md_code
													formData['product_name'] = popObj.row.md_description
													formData['product_spec'] = popObj.row.specification
													formData['product_unit'] = popObj.row.unit
													
													me.formData = formData
													
													if (callback) {
														callback();
													}
												}
											};
											me.doPopupByPublic(config);
										}
									},
								},
								province_name: {
									select: {
										onchange: function(obj) {//下拉展开事件
											obj.data.province_code = obj.selectoption.code
											obj.data.province_name = obj.selectoption.name
										}
									},
								},
								files: {
									buttonarray: {
										onclick: function(obj) {
											var filenamefield = obj.obj.field;
											var fileidfield = "files";
											if(obj.buttonobj && obj.buttonobj.code == "showfilebyfile"){
												me.showFileImgByFileId(obj.buttonobj.fileobj);
											}else if (obj.buttonobj && obj.buttonobj.code == "uploadlist"){
												me.onPopupByUploadFile(filenamefield, fileidfield, me.dataname);
											}else if (obj.buttonobj && obj.buttonobj.code == "delfilebyfile"){
												me.deleteByFileId(filenamefield, obj.buttonobj.fileobj);
											}
										}
									}
								},

								oa_code: {
									val: {
										onclick: function(obj) {

										}
									}
								}
							};
							
							//表格字段事件设置
							this.tablefieldClick = {
							};
						
						},

						onPopupByUploadFile(filenamefield, fileidfield,dataname) {
							var me = this;
							var analysistype_ = "";
							var formData_ = clone(me.formData);
							var delta_ = {filetypelist: []}//".png", ".jpg", ".pdf"
							var config = {
								totab: false,
								width: "500px",
								icon: "icon-product",
								text: "附件上传",
								id: "popupByUploadFile",
								url: "../tool/popup_uploadFile.html",
								data: {
									dataName: dataname,
									fileidfieldName: fileidfield,
									id: me.formData.id,
									fileNamefieldName: filenamefield,
									max_size: "100MB",
								},
								delta: delta_,
								callback: function(obj, callback) {
									me.$message({
										showClose: true,
										message: '上传成功!',
										type: 'success'
									});
									
									var file_ = {
										id: obj.row[0].id,
										file_name: decodeURI(obj.row[0].name)
									}
									if (!formData_[filenamefield]) {
										formData_[filenamefield] = []
									}
									formData_[filenamefield].push(file_);
									
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							};
							this.doPopupByPublic(config);
						},

						deleteByFileId(filenamefield, fileobj){
							var me = this;
							var formData_ = clone(me.formData);
							Root.confirm('确定删除附件【' + fileobj.file_name + '】吗?', '删除提示', {
							  confirmButtonText: '删除',
							  cancelButtonText: '取消',
							  type: 'warning'
							}).then(() => {
								if (fileobj.id) {
									let param = {
										dataname: "file_index",
										id: fileobj.id
									}
									
									Server.call("root/data/deleteEntity", param, function(result) {
										console.log(result);
										if (result && result.data) {
											me.formData[filenamefield].remove(fileobj);
											// me.formData = formData_;
											Root.message({
												type: 'success',
												message: '删除成功!'
											});
										}
									});
								}
							}).catch(() => {
								Root.message({
									type: 'info',
									message: '已取消删除'
								});          
							});
							
						},
						
						showFileImgByFileId(fileobj) {
							let me = this;
							var file_id = fileobj.id;
							var file_name = fileobj.file_name;
							
							this.zzimg = {};
							this.zzimgList = [];
							this.file_txt = false;
							if(file_id) {
								var fileid = file_id;
								let fileName = clone(file_name);
								let index1 = fileName.lastIndexOf(".");
								let index2 = fileName.length;
								let suffix = fileName.substring(index1, index2).toLowerCase(); //后缀名
								if (suffix == ".png" || suffix == ".jpg" || suffix == ".pdf") {
									var row = {
										fileid: fileid,
										filename: fileName
									}
						
									var config = {
										totab: false,
										width: "1200px",
										height: 800,
										icon: "icon-product",
										text: "附件预览",
										id: "pdf_" + fileid,
										url: "module/tool/page/popup_file_pdf.html",
										data: row,
										delta: {},
										callback: function(obj, callback) {
											if (callback) {
												callback();
											}
										}
									};
									this.doPopupByPublic(config);
						
								}
								else {//只可下载,不可预览
									// handleDownloadUrl(fileid,false);
									handleDownload(fileid);
								}
							}
						},
						
						
						
						addTableData() {
							var table_row = clone(this.newTableData);
							this.rowChange(table_row, "add", this.table_dataname);
						},
						
						delData(scope) {
							let me = this;
							let row = scope.row;
							let index_ = scope.$index;
							
							Root.confirm('确定删除数据【' + JSON.stringify(row) + '】吗?', '删除提示', {
							  confirmButtonText: '删除',
							  cancelButtonText: '取消',
							  type: 'warning'
							}).then(() => {
								me.rowChange(row, "del", me.table_dataname);
							}).catch(() => {
								Root.message({
									type: 'info',
									message: '已取消删除'
								});          
							});
						},
						
						rowChange(row, type, tablename) {
							var me = this;
							if (type == "add") {
								this.tableData.unshift(row);
							}
							else if (type == "del") {
								if (row.id) {
									let param = {
										dataname: tablename,
										id: row.id
									}
									
									Server.call("root/data/deleteEntity", param, function(result) {
										console.log(result);
										if (result && result.data) {
											me.tableData.remove(row);
											
											Root.message({
												type: 'success',
												message: '删除成功!'
											});
										}
									});
								}
								else {
									this.tableData.remove(row);
								}
							}
							else {
							
							}
						},
						
						//提交
						submitRowTable() {
							this.iscommit = true;
							this.saveRowTable();
						},
						
						//保存
						saveRowTable() {
							var me = this;
							var operator_ = "save";//保存
							if(me.iscommit) {
								operator_ = "commit";//提交
							}
							
							var entity_ = clone(this.formData);
							var entity = {type: "NationTag", is_active: entity_.is_active? "T" : "F"};
							for (var r in entity_) {
								if (entity_[r] && r !== "is_active") {
									entity[r] = entity_[r];
								}
							}
							
							let param = {
								dataName: "price_manager_nation",
								data: {
									price_manager_nation: entity
								}
							}
							Server.call("rootjemin/data/saveEntity", param, function(result) {
								console.log(result);
								if (result.success) {
									Root.message({
										type: 'success',
										message: '保存成功'
									}); 
									me.saveAfter();
								}
							});
						},
						
					}
				});
			};

            initVue();
        </script>
		
		<style>
			.a:hover{
				background-color: #FFFFFF;
			}
			.el-input__inner{
				padding: 0 2px;
			}
			.header {
				height: 21px;
			}
			.el-dialog_header {
				padding: 10px 20px;
				border-bottom: 1px solid #ccc;
				right: 10px;
				left: 10px;
				top: 0px;
				position: fixed;
			}
			.el-dialog_body{
				padding: 20px;
				
				overflow-y: auto;
				right: 10px;
				left: 10px;
				top: 42px;
				bottom: 50px;	
				position: fixed;
			}
			.el-dialog_footer {
				padding: 10px 20px;
				border-top: 1px solid #ccc;
				right: 10px;
				left: 10px;
				bottom: 0px;
				position: fixed;
				background-color: #fff;
				z-index: 10;
				text-align: right;
			}
			html{
				overflow-y: hidden;
			}

			/* .el-button--mini {
				color: #FFF;
				background-color: #2984e2;
				border-color: #409EFF;
			} */
		</style>
		
	</body>
</html>