<!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="../../../js/vue/vue.js"></script>
		<script src="../../../js/vue/element-ui/lib/index.js"></script>
		<script src="../../../js/vue/axios/dist/axios.min.js"></script>
		<script src="../../../js/myelement.js?v=20220425"></script>
		<script src="../../../js/vue/page.js?v=20220425"></script>
		
		<link href="../../../js/vue/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
		<link href="../../../css/myelement.css?v=20220425" rel="stylesheet">
		<link href="../../../css/iconfont.css" rel="stylesheet">
		<link href="../../../css/page.css?v=20220425" rel="stylesheet">
		<link href="//at.alicdn.com/t/font_2374495_13ltsxm2eor.css" rel="stylesheet">
	</head>
	
	<body>
		<div id="vbody">
			<div id="page_root">
				<div class="topbar">
					<span>{{title}}</span>
					<div style="float: right; margin-right: 24px;">
						<el-button  @click="addData">新增发票</el-button>
						<el-button-group style="margin-left: 3px;">
							<el-button v-if="buttons.jsp_1" :disabled="buttons.jsp_1.disabled"  @click="getToJspByType(1)">开票申请</el-button>
						</el-button-group>
						<el-button-group style="margin-left: 3px;">	
							<el-button v-if="buttons.jsp_2" :disabled="buttons.jsp_2.disabled"  @click="getToJspByType(2)">开票待办</el-button>
						</el-button-group>
						<el-button-group style="margin-left: 3px;">	
							<el-button v-if="buttons.jsp_3" :disabled="buttons.jsp_3.disabled"  @click="getToJspByType(3)">开票已办</el-button>
						</el-button-group>
						<el-button-group style="margin-left: 3px;" v-if="buttons.nullify" >
							<el-button v-if="(selectedrow && !selectedrow.nullify) || !selectedrow" :disabled="!selectedrow.id"  @click="nullifyInvoicing(1)">作废</el-button>
						</el-button-group>
						<el-button-group style="margin-left: 3px;" v-if="buttons.nullify" >
							<el-button v-if="selectedrow && selectedrow.nullify" @click="nullifyInvoicing(0)">取消作废</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" style="width: 95%;" >
						<h-form-filter ref="form1" 
							:form-attr="filterAttr" 
							:table-fields="filterFields" 
							:form-data="filterObj" 
							:isbuttonquery="true"
							
							v-on:on-formchange="toOnQuery" 
							v-on:show-popup="showFilterPopup"
							v-on:on-query="toOnQuery"
							v-on:on-init-query="onInitFilter"
							v-on:on-edit-query="onEditFilter"
							>
						</h-form-filter>
					</div>
				</div>
			
				<div class="versionNo">
					<h-table
						v-if="isRefresh"
						ref="table1"
						:tableloading="tableloading"
						:table-fields="tableFields" 
						:table-data="tableData" 
						:is-edit-table-data="isEditTableData"
						:pagesize="pagesize"
						:pagenum="pagenum"
						:total="total"
						:table-height="tableHeight"
						:is-highlight-row="true"
						v-on:get-data="getData"
						v-on:edit-data="editData"
						v-on:del-data="delData"
						v-on:row-click="rowClick"
						v-on:cell-click="cellClick"
					>
					</h-table>
				</div>
			</div>
			
			<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;">
				<div class="spinner">
				  <div class="cube1"></div>
				  <div class="cube2"></div>
				</div>
			</div>
		</div>	
		
		<script type="text/javascript">
			var initlized = false;
			
			new ListVue({
				el: "#vbody",
				data: {
					dataname: "invoiceOrder",
					tabaleFieldsName: "invoice_",
					filterFieldsName: "invoice_",
					dataRequest: [
						"doInvoiceType",
						"invoiceStatus"
					],
					
					pageAttr: {
					   heightType: "page"
					},
					
					//jsp_ip: "http://oaqas01.jemincare.com:88",
					//jsp_ip: "http://oa.jemincare.com:88",
					
					
					/* tojsp_obj: {
						//待办链接地址:
						jsp_1: {
							name: "开票申请",
							url: "/workflow/request/RequestType.jsp"
						},
						jsp_2: {
							name: "大健康商业票折申请流程",
							url: "/workflow/search/wfTabFrame.jsp?offical=&officalType=-1&method=reqeustbywfidNode&workflowid=7303&nodeids=&complete=0&viewcondition=0&wftypes=&viewScope=doing&numberType=flowAll&flowAll=8&flowNew=0&flowResponse=0&flowOut=0&flowSup=0"
						},
						jsp_3: {
							name: "开票申请流程(E-Commerce)",
							url: "/workflow/search/wfTabFrame.jsp?offical=&officalType=-1&method=reqeustbywfidNode&workflowid=7304&nodeids=&complete=0&viewcondition=0&wftypes=&viewScope=doing&numberType=flowAll&flowAll=8&flowNew=0&flowResponse=0&flowOut=0&flowSup=0"
						},
						jsp_4: {
							name: "销售折让开票申请流程(E-Commerce)",
							url: "/workflow/search/wfTabFrame.jsp?offical=&officalType=-1&method=reqeustbywfidNode&workflowid=7302&nodeids=&complete=0&viewcondition=0&wftypes=&viewScope=doing&numberType=flowAll&flowAll=8&flowNew=0&flowResponse=0&flowOut=0&flowSup=0"
						},
						jsp_5: {
							name: "大健康商业票折申请流程",
							url: "/workflow/search/wfTabNewFrame.jsp?offical=&officalType=-1&method=reqeustbywfid&workflowid=7303&complete=2&viewcondition=0&date2during=0&viewType=2&wftypes=&viewScope=done&numberType=flowAll"
						},
						jsp_6: {
							name: "开票申请流程(E-Commerce)",
							url: "/workflow/search/wfTabNewFrame.jsp?offical=&officalType=-1&method=reqeustbywfid&workflowid=7304&complete=2&viewcondition=0&date2during=0&viewType=2&wftypes=&viewScope=done&numberType=flowAll"
						},
						jsp_7: {
							name: "销售折让开票申请流程(E-Commerce)",
							url: "/workflow/search/wfTabNewFrame.jsp?offical=&officalType=-1&method=reqeustbywfid&workflowid=7302&complete=2&viewcondition=0&date2during=0&viewType=2&wftypes=&viewScope=done&numberType=flowAll"
						},
					
					}, */
					tojsp_obj: {
						//待办链接地址:
						jsp_1: {
							name: "开票申请",
							url: "/workflow/request/RequestType.jsp"
						},
						jsp_2: {
							name: "大健康商业票折申请流程",
							url: "/workflow/search/wfTabFrame.jsp?offical=&officalType=-1&method=reqeustbywfidNode&nodeids=&complete=0&viewcondition=0&wftypes=&viewScope=doing&numberType=flowAll&flowAll=8&flowNew=0&flowResponse=0&flowOut=0&flowSup=0"
						},
						jsp_3: {
							name: "大健康商业票折申请流程",
							url: "/workflow/search/wfTabNewFrame.jsp?offical=&officalType=-1&method=reqeustbywfid&complete=2&viewcondition=0&date2during=0&viewType=2&wftypes=&viewScope=done&numberType=flowAll"
						},
					
					},
					
					filterAttr: {
						columnnumber: 3,
						labelwidth: "100px",
						labelposition: "right",
						size: "medium",
						border: "3px solid #c6c6c600"
					},
					
					title: "开票申请",
					orderby: "update_time desc",
					
					invoiceType: [],
					invoiceStatus: [],
				},
				created() {
					this.pageCode = "A6-1";
					     this.getResoures();
				},
				
				mounted() {
					this.initData();
					this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
						hideLoading();
					});
				},
				
				methods:{
					initData() {
						if (initlized) { return; }
						initlized = true;
						this.filterTxt = "";
						if (this.filterObj.factory_order_code) {
							this.filterTxt = " EXISTS (SELECT * from (SELECT * from invoice_order_detail where factory_order_code like '%" + this.filterObj.factory_order_code + "%') iod where iod.parent_id=io.id)";
						}
						this.onQuery();
					},
					
					toOnQuery() {
						this.filterTxt = "";
						if (this.filterObj.factory_order_code) {
							this.filterTxt = " EXISTS (SELECT * from (SELECT * from invoice_order_detail where factory_order_code like '%" + this.filterObj.factory_order_code + "%') iod where iod.parent_id=io.id)";
						}
						this.onQuery();
					},
					
					onInitFilter() {
						//清空
						this.filterObj = {};
						this.filterTxt = "";
						this.onQuery();
					},
					
					onServerInitData(data) {
						var me = this.data;
						
						me.tableFields = data.tableFields;
						me.filterFields = data.filterFields;
						me.invoiceType = data.doInvoiceType;			
						me.invoiceStatus = data.invoiceStatus;			
						
						if(me.filterFields.length > 0) {
							for(var i=0; i < me.filterFields.length; i++) {
								let fieldObj_ = me.filterFields[i];
								
								me.filterFieldsObj[fieldObj_.field] = fieldObj_;
							}
						}	
						if(me.tableFields.length > 0) {
							for(var i=0; i < me.tableFields.length; i++) {
								let fieldObj_ = me.tableFields[i];
								
								me.tableFieldsObj[fieldObj_.field] = fieldObj_;
							}
						}
					},
					
					getToJspByType(type) {
						var me = this;
						var url_ = this.tojsp_obj["jsp_" + type].url;
						
						if (url_) {
							this.url_ = window.top.RootSetting.url_jsp_ip + url_;
						}
						
						var param = {
							empCode: localStorage.getItem("emp_code")
						};
						Server.call("stock_post/token/create", param, function(result) {
							if (result.success) {
								var token_ = result.data;
								me.token = token_;
								if (token_) {
									me.doToJsp();
								}
							}
						});
					},
					
					doToJsp() {
						if (this.url_ && this.token) {
							var param_ = {
								ecToken: this.token
							};
							
							var url = SplicingGetUrlToStr(this.url_, param_);
							//this.src_url = url;
							window.open(url);
						}
					},
					
					onAddData(config) {
						var me = this;
						
						config.combine({
							totab: true,
							icon: "icon-product",
							text: "新增发票",
							id: "sinvoice_add",
							url: "../finance/sinvoice/sinvoice_edit.html",
							sceneCode: "add",
							data: {},
							delta: me.dataname,
						});
						
						return true;
					},
					
					onEditData(config, scope) {
						var me = this;
						var row = scope.row;
						
						//1. empty row
						if (!row || !row.id) {
							Root.message({
								type: 'warning',
								message: '请选择要编辑的数据'
							});  
							return false;
						}
							
						//2. not input
						if (row.statecode != "录入") {
							Root.message({
								type: 'warning',
								message: "当前数据不是输入状态"
							})
							return false;
						}
						
						//3. popup
						config.combine({
							totab: true,
							icon: "icon-product",
							text: "编辑发票",
							id: "sinvoice_edit",
							url: "../finance/sinvoice/sinvoice_edit.html",
							sceneCode: "edit",
							data: row,
							delta: me.dataname,
						});
						
						return true;
					},
					
					onDrawbill() {
						var me = this;
						var row = this.selectedrow;
						
						if (!row || !row.id) {
							Root.message({
								type: 'warning',
								message: '请选择要回填票号的数据'
							});  
							return false;
						}
							
						if (row.statecode != "working") {
							Root.message({
								type: 'warning',
								message: "当前数据不是可回填状态"
							})
							return false;
						}
						
						Root.popupParames = {
							width: "900px",
							height:"650px",
							sceneCode: "draw",
							url: "../finance/sinvoice/sinvoice_edit.html",
						};
						Root.popupParames.disabled = true;
						Root.showPopup(Root.popupParames);
					},
					
					makeCollection(scope) {
						var me = this;
						var row = this.selectedrow;
						
						if (!row || !row.id) {
							Root.message({
								type: 'warning',
								message: '请选择要生成收款单的数据'
							});  
							return false;
						}
							
						if (row.statecode != "working") {
							Root.message({
								type: 'warning',
								message: "当前数据不是可生成状态"
							})
							return false;
						}
						
						Root.popupParames = {
							width: "900px",
							height:"650px",
							sceneCode: "draw",
							url: "../finance/receipt/receipt_edit.html",
						};
						Root.popupParames.disabled = true;
						Root.showPopup(Root.popupParames);
						
					},
					nullifyInvoicing(nullify) {
						let me = this;
						document.getElementById('page_loading').style.display =  "block";
						
						let param = {
							id:this.selectedrow.id,
						}
						if(nullify == 1) {
							param.isNullify = true
						}else {
							param.isNullify = false
						}
						let url = window.top.RootSetting.url_stock + "order/recallInvoiceOrder?userId=" + window.top.userinfo.employee.id
						axios.post(url,param).then(data=>{
							if (data.data.success) {
								if(nullify) {
									Root.message({
										type:"success",
										message:"作废成功"
									})
								}else {
									Root.message({
										type:"success",
										message:"取消作废成功"
									})
								}
								me.doQuery();
								
							}else {
								Root.message({
									type:"warning",
									message:"操作失败"
								})
							}
							document.getElementById('page_loading').style.display =  "none";
						}).catch(error=>{
							console.log(error);
							document.getElementById('page_loading').style.display =  "none";
						})
					},
					onCellClick(config, obj) {
						var clickContext = this.selectCellField.clickContext;
						
						if (clickContext && clickContext.type == "popup") {
							config.combine({
								url: clickContext.url,
								width: clickContext.width,
								sceneCode: "browse",
								data: obj.row,
								delta: clickContext.delta ? clickContext.delta : {},
							})
						}
						else {
							return false;
						}
						
						return true;
					},
					
					onshowFilterPopup(filter) {
						var me = this;
						var fieldObj_ = filter.obj;
						var filterValue = clone(me.filterObj);
						var field_ = fieldObj_.field;
						
						if ("customer_name" == field_) {
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html",
								width: 800,
								height: 550,
								callback: function(result, callback) {
									filterValue[field_] = result.row.md_description;
									me.filterObj = filterValue;
									me.filterTxt = "";
									if (me.filterObj.factory_order_code) {
										me.filterTxt = " EXISTS (SELECT * from (SELECT * from invoice_order_detail where factory_order_code like '%" + me.filterObj.factory_order_code + "%') iod where iod.parent_id=io.id)";
									}
									me.onQuery();
									if (callback) {
										callback();
									}
								}
							});
						}
					}
				}
			});
		</script>
	</body>
</html>