<!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/jquery-3.5.1.min.js"></script>
		<script src="../../../js/vue/vue.js"></script>
		<script src="../../../data/data.js?v=2022052404"></script>
		<script src="../../../js/vue/element-ui/lib/index.js"></script>
		<script src="../../../js/vue/axios/dist/axios.min.js"></script>
		<script src="../../../js/foundation.js?v=20220524"></script>
		<script src="../../../js/control.js?v=20220425"></script>
		
		<script src="../../../js/myelement.js?v=20220615"></script>
		<script src="../../../js/vue/page.js?v=20220615"></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" align="center">
			<div id="page_root"  style="width: 276mm;">
				<div ref="popup_body" style="padding-right: 0px;">
					<div class="el-dialog_header">
						<div class="dialog-title">
							<span> {{formAttr.title}} </span>
						</div>
					</div>	
					<div id="page_body">
						
						<div class="el-dialog_body" >
							<h-form
								ref="form1"
								:form-attr="formAttr"
								:table-fields="formFields"
								:form-data="formData"
								:is-end-colspan="false"
								v-on:show-popup="showPopup"
								v-on:button-click="buttonClick"
								v-on:form-change="selectchange"
								v-on:visible-change="cellVisibleChange"
								v-on:formcallspan-click="formcallspanClick"
							>
							</h-form>
							<div v-if="!notdisabled" id="cell" class="h_stamp" style="margin-left: 20px;float: left;">
							</div>
							<div v-if="notdisabled" style="text-align: right;">
								<div id="cell" class="h_stamp" style="margin-left: 20px;float: left;">
								</div>
								<el-button-group >
									<el-button @click="clearData">清除内容</el-button>
								</el-button-group>
								<el-button-group >
									<el-button @click="showOrder">新增数据</el-button>
								</el-button-group>
							</div>
							<h-table
								v-if="isRefresh"
								ref="table1"
								:table-fields="tableFields" 
								:table-data="tableData2" 
								:is-edit-table-data="isEditTableData"
								:is-within-edit-table-data= "isWithinEditTableData"
								:is-pagination="false"
								:is-show-index="true"
								
								v-on:edit-data="editData"
								v-on:del-data="delData"
								v-on:cell-input-change="cellInputChange"
								v-on:cell-click="cellClick"
								v-on:visible-change="cellVisibleChange"
								v-on:cell-select-change="cellSelectChange"
							>
							</h-table>
							<!-- 
							 :table-height="tableHeight2"
							 -->
							<div v-if="acctObj.flow_id && popupParames.sceneCode == 'approval'" style="height: 350px; border-top: 1px solid #ccc;">
								<iframe :src="'../../approval/ApprovalList_page.html?flow_id=' + acctObj.flow_id" style="width: 100%; height: 100%; border: 0px;"></iframe>
							</div>
							<div v-else-if="acctObj.flow_id && popupParames.sceneCode == 'browsepdf'" style="border-top: 1px solid #ccc; padding-bottom: 20px;">
								<div class="topbar" align="left" style="font-weight: normal; font-size: 14px;">
									<span>审批记录 {{title}}</span>
								</div>
								<h-table
									:table-fields="tableFields_act" 
									:table-data="tableData_act" 
									:is-pagination="false"
									
								>
								</h-table>
							
							</div>
							
						</div>
						<div style="width: 100%; height: 60px;">
							
						</div>
					</div>
					<div class="el-dialog_footer">
						<el-button type="default" @click="toPDFPage">打印</el-button>
						<el-button v-if="!fromDing" type="default" @click="closeDialog">å…³ é—­</el-button>
					</div>
				</div>
			</div>
			
			<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;z-index:9999">
				<div class="spinner">
				  <div class="cube1"></div>
				  <div class="cube2"></div>
				</div>
			</div>
			
			<el-dialog :visible.sync="dingResult" width="40vw" height="50vh" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
				 <span>{{dingResultTxt}}</span>
				 <div style="min-height: 150px;"></div>
			</el-dialog>
		</div>	
		
		<script type="text/javascript">
			new ListVue({
				el: "#vbody",
				data: {
					table_dataname: "revocationOrderDetail",
					
					newRowDefault: {
						//id: uuid_short(),
						statecode: "input",
						biz_date: createDate(),
					},
					
					notdisabled: true,
					acctObj:{
						flow_id:""
					},
					attachment_name:"",
					formAttr: {
						istitle: false,
						title: "退货单信息",
						columnnumber: 2,
						labelwidth: "140px",
						labelposition: "right",
						size: "medium",
						border: "5px solid #c6c6c600"
					},
					formFields: [],
					tableFields: [],
					a2label:[],
					a1label:[],
					tableData2: [],
					tableDataChange: {},
					tableData: [],
					selectrow: {},
					
					tableHeight2: 240,
					isEditTableData:true,
					isWithinEditTableData:false,
					formData: {},
					isRefresh: true,
					selectFormField: {},
					popupByFieldsDialog: false,
					
					filterAttr: {
						columnnumber: 3,
						labelwidth: "100px",
						labelposition: "right",
						size: "medium",
						border: "3px solid #c6c6c600"
					},
					filterFields:[],
					filterFieldsObj: {},
					filterObj: {},
					filterList:[],
					returnreason: [],
					isLoading:false,
					treeDataObj: {},
					approval:false,
					reasonvisible:false,
					textarea2: '',
					fromDing: false,
					dingResult: false,
					dingResultTxt: "",
					isQGXD: false,
					isWLGLB: false,
					
					tableFields_act: [
						{isshow: "T", nottooltip: true, field: "node_name", name: "当前节点",  align: "center", formatterjson: "{\"商业盖章\": \"合同盖章\"}"},
						{isshow: "T", nottooltip: true, field: "end_time", name: "申请/审批时间", align: "center"},
						{isshow: "T", nottooltip: true, field: "pass", name: "审批情况", align: "center", formatter: "formatter_pass"},
						{isshow: "T", nottooltip: true, field: "reason", name: "原因", align: "center"},
						{isshow: "F", nottooltip: true, field: "user_code", name: "申请/审批人工号", align: "center"},
						{isshow: "T", nottooltip: true, field: "user_name", name: "申请/审批人", align: "center", formatter: "formatter_approvaluser",defaultval_isclick: true, defaultval: "查询", isassignment: true, defaultval_filter: [[{field: "act_task_id", type: "isnotnull"}]]},
						{isshow: "T", nottooltip: true, field: "attachment_name", name: "附件", align: "center", iscellclick: false},
					],
					tableData_act: [],
					
				},
				created() {
					//this.popupParames = clone(Root.popupParames);
					
					var url = window.location.href;
					var params = getGetParams(url);
					this.popupParames = clone(params);
					if (!window.top.userinfo) {
						window.top.userinfo = {
							user: {
								id: this.popupParames.userId
							}
						}
					}
					
				},
				
				mounted() {
					var me = this;
					this.initPageData(function() {
						me.initFields();
						me.getTree();
						if (me.popupParames.sceneCode && me.popupParames.sceneCode != "add") {
							me.initData();
						};
						
						if (me.popupParames.sceneCode == "browsepdf") {
							me.getApprovalList();
						}
						
						/* var urlParam = getGetParams(me.popupParames.url);
						
						for(let key in urlParam) {
							if(key == "fromDing") {
								me.fromDing = urlParam[key];
							}
						}
						 */
						me.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
							document.getElementById('page_root').style.display =  "block";
							document.getElementById('page_loading').style.display =  "none";
						});
					});
					
				},
				methods:{
					initPageData(callback) {
						var me = this;
						var url = window.location.href;
						var params = getGetParams(url);
						//标题
						if(params.id) {
							localStorage.setItem("id", params.userId)
							this.popupParames = {
								sceneCode: "browsepdf",
								data: {
									id: params.id
								}
							};
							this.formAttr.disabled = true;
							this.isWithinEditTableData = false;
							this.isEditTableData = false
							this.notdisabled = false;
							this.Approval = false;
						}
						
						var filter_ = "id='" + params.id + "'";
						var dataname_ = "revocationOrder";
						let param_ = {
							isClientMode: false,
							dataname: dataname_,
							filter: filter_,
						}
						
						Server.call("root/data/getEntitySet", param_, function(result) {
							console.log(result);
							if (result && result.data && result.data.entityset && result.data.entityset.length>0) {
								var data_ = result.data.entityset[0];
								me.popupParames.data = data_;
							}
							
							if (me.popupParames.data) {
								var formData_ = clone(me.popupParames.data);
								
								if (!formData_.customer_record_province_code) {
									let param = {
										dataname: "vCustomerInfo",
										filter: "md_code ='" + formData_.customer_code+"'",
									}
									Server.call("root/data/getEntitySet", param, function(result1) {
										console.log(result1);
										if (result1 && result1.data.entityset) {
											formData_.customer_record_province_code = result1.data.entityset[0].record_province
											formData_.customer_record_province_name = result1.data.entityset[0].province_name
										}
									});
								}
								me.acctObj.flow_id = formData_.flow_id;
								formData_.charge_user_old = formData_.charge_user;
								formData_.deo_id = formData_.sales_order_id
								if(me.popupParames.sceneCode != "add") 
									me.formAttr.title = me.formAttr.title + " " + formData_.code;
								if (formData_.file_id){
									let param = {
										dataname: "fileLog",
										filter: "id ='" + formData_.file_id+"'",
									}
									Server.call("root/data/getEntity", param, function(result1) {
										console.log(result1);
										if (result1 && result1.data.entity) {
											formData_.file_name = result1.data.entity.name
										}
									});
								}
								formData_.r_depart_type = formData_.business_depart_id;
								me.formData = formData_;
								
								if (callback) {
									callback();
								}
							}
							
						})
					},
					initFields() {
						let me = this;
						var returnDetail_= [
							{isshow: "T", nottooltip: true, field: "deo_raw_code", name: "工厂发货单号",width: "50"},
							{isshow: "T", nottooltip: true, field: "deo_factory_no", name: "工厂出库单号",width: "50"},
							{isshow: "T", nottooltip: true, field: "deo_biz_date", name: "原发货日期",width: "50"},
							{isshow: "T", nottooltip: true, field: "product_name", name: "药品名称",width: "50"},
							{isshow: "T", nottooltip: true, field: "product_code", name: "药品编号",width: "50"},
							{isshow: "T", nottooltip: true, field: "product_spec", name: "药品规格",min_width: "50"},
							{isshow: "F", nottooltip: true, field: "checkout_cnt", name: "已收货数量", required: true,width: "50"},
							{isshow: "F", nottooltip: true, field: "return_qty", name: "已退货数量", required: true,width: "50"},
							{isshow: "T", nottooltip: true, field: "revocation_delivery_cnt",defaultval:0, name: "已退货数量", type: "span",width: "50"},
							{isshow: "F", nottooltip: true, field: "qty_canReturn", name: "可退货数量", required: true,width: "50"},
							{isshow: "T", nottooltip: true, field: "qty_needreturn", name: "此次退货数量",isnumber:true, type: "input",width: "50"},
							
							{isshow: "T", nottooltip: true, field: "product_price", name: "单价", formatter: "formatter_money", align: "right",width: "50"},
							{isshow: "F", nottooltip: true, field: "pre_settle_type_name", name: "结算方式",width: "50",align: "right",formatter: "formatter_settleType"},
							{isshow: "T", nottooltip: true, field: "inventory_cnt", name: "库存量", type: "span",width: "50"},
							{isshow: "F", nottooltip: true, field: "a1_trans_price", name: "A1ä»·æ ¼",width: "50", formatter: "formatter_money",align: "right", type: "select", isrefresh:true, options: [], required: true, props:{value: "id", label: "supply_price", checkStrictly: true}},
							{isshow: "F", nottooltip: true, field: "trans_settle_type", name: "A1结算方式",width: "50",align: "right"},
							{isshow: "F", nottooltip: true, field: "a2_product_price", name: "A2ä»·æ ¼",width: "50", formatter: "formatter_money",align: "right", type: "select", isrefresh:true, options: [], required: true, props:{value: "id", label: "supply_price", checkStrictly: true}},
							{isshow: "F", nottooltip: true, field: "diff_date", name: "调价时间",width: "50",required:true ,formatter: "formatter_date", type: "date"},
							{isshow: "F", nottooltip: true, field: "old_discount_amt", name: "原折让小计",isnumber:true,width: "50",required:true ,formatter: "formatter_money",align: "right", type: "input"},
							{isshow: "F", nottooltip: true, field: "current_discount_amt", name: "现折让小计",isnumber:true,width: "50",required:true ,formatter: "formatter_money",align: "right", type: "input"},
							{isshow: "F", nottooltip: true, field: "diff_price", name: "补差单价",width: "50",required:true ,formatter: "formatter_money",align: "right", type: "span"},
							{isshow: "F", nottooltip: true, field: "diff_amt", name: "补差金额",width: "50",required:true, formatter: "formatter_money",align: "right", type: "span"},
							{isshow: "T", nottooltip: true, field: "price_return", name: "退货金额", formatter: "formatter_money", align: "right",width: "50"},
							{isshow: "T", nottooltip: true, field: "a1_delivery_amt", name: "A1发货金额",width: "50", formatter: "formatter_a1deliveryamt", align: "right"},
							{isshow: "F", nottooltip: true, field: "trans_price", name: "调货金额", formatter: "formatter_money", align: "right",width: "50"},
							{isshow: "F", nottooltip: true, field: "settle_type", name: "结算方式",width: "50"},
							
							{isshow: "F", nottooltip: true, field: "warehouse_name", name: "退货仓库",width: "50"},
							{isshow: "T", nottooltip: true, field: "detail_charge_user", name: "退货责任人", type:'input',width: "50",required:true},
							{isshow: "T", nottooltip: true, field: "deo_batch_no", name: "批号", width: "50"},
							{isshow: "F", nottooltip: true, field: "revo_remark" ,name: "退货原因",formatter: "formatter_returnType",width: "50",isallowcreate:true,isrefresh:true,type:"select",options:[],required:true,props:{value: "id", label: "name", checkStrictly: true}},
							{isshow: "F", nottooltip: true, field: "detail_remark" ,name: "明细备注",width: "50",type:'input'},
						];
						let tableFields_ = clone(returnDetail_);
						let formFields_ = clone(dataRootFields.formFields.returnBill_);
						let isDistributor = localStorage.isdistributor;
						if(isDistributor) {
							formFields_ = formFields_.filter(e=>{
								if(e.field == "customer_name" || e.field == "customer_code") {
									e.disabled = true;
								}
								return true;
							})
							tableFields_ = tableFields_.filter(e=>{
								if(e.field == "detail_charge_user")
									return false;
								else 
									return true;
							})
							me.formData.customer_name = localStorage.distributor_name;
							me.formData.customer_id = localStorage.distributor_id;
							me.formData.customer_code = localStorage.distributor_code;
						}
						
						let code = this.popupParames.sceneCode;
						let create_operate_code = me.formData.create_operate_code;
						if( code == "approval" && me.formData.act_node_name == '商务审核' && create_operate_code && create_operate_code.indexOf("CT") > -1) {
							tableFields_ = tableFields_.map((e)=>{
								e.type = 'span'
								if(e.field == "settle_type") {
									e.isshow = "T";
								}else if(e.field == "detail_charge_user") {
									e.isshow = "T";
									e.type = 'input'
								}
								return e;
							});
							this.isWithinEditTableData = true;
							this.isEditTableData = true;
						}
						if(code == 'approval' && me.formData.act_node_name == '数据服务部-流向及SD管理岗') {
							tableFields_ = tableFields_.map((e)=>{
								e.type = 'span'
								if(e.field == "inventory_cnt") {
									e.type = 'input';
								}
								return e;
							});
							this.isWithinEditTableData = true;
							this.isEditTableData = true;
						}
						let isshowT = "T";
						let isshowF = "T";
						if (this.formData.sub_type == 3){
							isshowT = "F"
							isshowF = "T"
						}
						else if (this.formData.sub_type == 2){
							isshowF = 'F';
							isshowT = 'T';
						}
						else if(this.formData.sub_type == "2-1" || this.formData.sub_type == "2-2"){
							isshowT = "T"
							isshowF = "F"
						}
						else{
							isshowT = "F"
							isshowF = "F"
						}
						
						formFields_ = formFields_.map((e)=>{
							if(e.field == "trans_customer_name") 
								e.isshow = isshowF;
							if (this.formData.sub_type == "2-2" && e.field == "ticket_discount_type") {
								e.isshow = 'T'
							}
							else if (e.field == "ticket_discount_type") {
								e.isshow = 'F'
							}
							return e;
						});
						
						tableFields_ = tableFields_.map((e)=>{
							let arr = ["diff_date","old_discount_amt","detail_remark","current_discount_amt","diff_amt","diff_price","a2_product_price"]
							if(arr.indexOf(e.field) != -1) 
								e.isshow = isshowT;
							if(e.field == "revo_remark" && isshowF == 'F' && isshowT == 'F') {
								e.isshow = "T";
								e.type = 'select'
								e.name = '退货原因'
							}else if(e.field == "revo_remark"){
								e.isshow = "F";
							}
							if(e.field == "a1_trans_price" || e.field == "a1_delivery_amt" || e.field == "trans_settle_type" || e.field == "pre_settle_type_name") {
								e.isshow = isshowF;
							}
							
							if(e.field == "inventory_cnt") {
								e.isshow = "F";
							}
							if(e.field == "checkout_cnt") {
								e.isshow = "T";
							}
							return e;
						});
						if(this.popupParames.sceneCode == "add") {
							tableFields_ = tableFields_.map((e)=>{
								if(e.field == "revocation_delivery_cnt" || e.field == "inventory_cnt") {
									e.isshow = "F";
								}
								if(e.field == "checkout_cnt" || e.field == "return_qty" || e.field == "qty_canReturn") {
									e.isshow = "T";
								}
								return e;
							});
						}
						me.tableFields = tableFields_;
						me.formFields = formFields_;
						//me.returnreason = dataRoot.database.returnreason;
						//me.getTree()
					},
					clearData() {
						this.formData = clone(this.newRowDefault)
						this.tableData2 = [];
					},
					onServerInitData(data) {
						
					},
					initData() {
						let me = this
						let filter_table = "1<>1";
						me.formData.so_id = me.formData.sales_order_id;
						if (this.formData.id) {
							filter_table = "revocation_order_detail.parent_id = '" + this.formData.id + "'";
						}
						let param_table = {
							isClientMode: false,
							dataname: this.table_dataname,
							filter: filter_table,
						}
						
						Server.call("root/data/getEntitySet", param_table, function(result) {
							if (result && result.data) {
								var tableData2_ = result.data.entityset;
								for(var i = 0 ;i<result.data.entityset.length;i++){//pre_settle_type_name
									tableData2_[i].deliveryOrderDetailId = tableData2_[i].delivery_detail_id;
									tableData2_[i].price_return = tableData2_[i].qty_needreturn * tableData2_[i].product_price;
									tableData2_[i].a2_product_price = tableData2_[i].trans_price;
									tableData2_[i].pre_settle_type_name = tableData2_[i].settle_type;
									tableData2_[i].checkout_cnt = tableData2_[i].deo_checkout_cnt;//已发货数量
								}
								me.tableData2= tableData2_
							}
						});
						
						if (me.formData.file_id) {
							let param = {
								dataname: "fileLog",
								filter: "id ='" + this.formData.file_id + "'",
							}
							Server.call("root/data/getEntity", param, function(result1) {
								console.log(result1);
								if (result1 && result1.data.entity) {
									let name = me.fileNameTrim(result1.data.entity.name)
									me.$set(me.formData,"file_name",name);
									me.$set(me.formData,"file_name_t",result1.data.entity.name);
									me.$set(me.formData,"file_id",result1.data.entity.id);
								}
							});
						}
						
					},
					
					getApprovalList() {
						var me = this;
						let param = {
							isClientMode: false,
							flowId: this.acctObj.flow_id
						}
						this.tableData_act = [];
						Server.call("root/order/getHistoryTask/", param, function(result) {
							console.log(result);
							if (result && result.data) {
								me.tableData_act = result.data.entityset;
							}
						}); 
					},
					
					fileNameTrim(str) {
						let name = str.substring(0,str.indexOf("."));
						let suffix = str.substring(str.indexOf(".")+1);
						if(name.length > 18)
							name = name.substring(0,18) + "...( " + suffix + " )"
						else
							name = str;
						return name;
					},
					closeDialog() {
						ClosePage();
						/* let me = this;
						if(this.popupParames.totab) {
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, false); 
						}else {
							Root.hidePopup();
						} */
					},
					
					toPDFPage() {
						//let newstr = document.getElementById("page_body").innerHTML;
						//let oldstr = document.body.innerHTML;
						//document.body.innerHTML = newstr;
						window.print();
						//document.body.innerHTML = oldstr;
						//return false;
					},
					
					ArrayToTree(array_, name, parentId, parId, disabled_field, isencode) {
						if(!parentId) {
							parentId = "parent_id";
						}
						
						if(!name) {
							name = "label";
						}
						
						if(!parId) {
							parId = "";
						}
						
						let obj = {};
						let result = [];
						let list = JSON.parse(JSON.stringify(array_));
						list.map(el => {
							obj[el.id] = el;
						})
						let openId = "";
						for (let i = 0, len = list.length; i < len; i++) {
							let parentId_ = list[i][parentId];
							//如果存在判断只读字段,并且该字段有值则设置该节点为只读
							if (disabled_field) {
								if(list[i][disabled_field]) {
									list[i].disabled = true;
								}
							}
							
							//设置显示字段
							if (isencode) {
								list[i].label = decodeURI(encodeURI(list[i][name]));//数据如果带“%”的需要编码再解码,否则会存在格式错误
								list[i].name = decodeURI(encodeURI(list[i][name]));
							}
							else {
								list[i].label = decodeURI(list[i][name]);
								list[i].name = decodeURI(list[i][name]);
							}
							if (parentId_ == parId || !parentId_ || parentId_ == "null") {
								if(!obj[list[i].id].children) {
								    obj[list[i].id].children = null;
								}
								result.push(list[i]);
								continue;
							} else if (obj[parentId_]) {
								if (!obj[parentId_].children) {
									obj[parentId_].children = [];
								}
								obj[parentId_].children.push(list[i]);
							}
						}
						return result;
					},
					getTree() {
						 let me = this;
						let param_table = {
							isClientMode: false,
							dataname: "revocationOrderType",
							filter:"parent_id <> '1' or parent_id is null"
						}
						Server.call("root/data/getEntitySet", param_table, function(result) {
							console.log(result); 
							me.defaultExpandedKeys = [];
							var formFields_ = clone(me.formFields);
							
							let treeDataList = result.data.entityset;//this.returnreason;//result.data.entityset;
							/* treeDataList.map(e=>{
								me.treeDataObj[e.id] = e;
							}); */
							let isDistributor = localStorage.isdistributor
							if(isDistributor) {
								treeDataList.map(e=>{
									if(e.id == "2" || e.id == "3")
										e.parent_id = "1111";
								})
							}
							
							let treeData_ = me.ArrayToTree(treeDataList, "name", "parent_id");
							if(!(me.formData.sub_type instanceof Array) && me.popupParames.sceneCode != "add") {
								let sub_id = me.formData.sub_type;
								let arr = [];
								arr.push(sub_id);
								for (var i = 0; i < treeDataList.length; i++) {
									let item = treeDataList[i];
									if(item.id == sub_id) {
										if(item.parent_id) {
											sub_id = item.parent_id;
											arr.unshift(item.parent_id);
											i = -1;
										}
										else {
											break;
										}
									}
								}
								me.$set(me.formData,"sub_type",arr);
							}
							
							treeData_.map(e=>{
								me.defaultExpandedKeys.push(e.id);
							});
							let treeDate = [];
							formFields_.map(e=>{
								if(e.field == "sub_type") {
									e.options = treeData_;
								}
							})
							me.formFields = formFields_;
							
							//me.formData.type = treeData_;
							//me.$refs.form1.refresh();
						});
						let param_table_1 = {
							isClientMode: false,
							dataname: "revocationOrderType",
							filter:"parent_id <> '2' and parent_id <> '' and id <> '15'"
						}
						Server.call("root/data/getEntitySet", param_table_1, function(result) {
							let treeDataList = result.data.entityset;//this.returnreason;//result.data.entityset;
							me.tableFields = me.tableFields.map(e=>{
								if(e.field == "revo_remark") {
									e.options = treeDataList;
								}
								return e;
							})
						});
					},
					checkCustomerAndDelivery(callback) {
						let m = document.getElementById("cell");
						m.innerHTML = "";
						if(this.popupParames.sceneCode == "approval")
							return;
						if (this.formData.delivery_part_name && this.formData.customer_name) {
							let me = this;
							let param_ = {
								isClientMode: false,
								dataname: "deliveryType",
								code: this.formData.delivery_part_code,
							}
							me.expiredLicense = false;
							Server.call("root/data/getEntity", param_, function(result) {
								//U8预留接口
								let url = window.top.RootSetting.url_stock + "order/checkLicence"
								axios.post(url, {
										customerId: me.formData.customer_id || "",
										bookNo: me.formData.book_no ? me.formData.book_no : "",
										deliveryPartCode:me.formData.delivery_part_code
									})
									.then(data => {
										console.log(data);
										if (data.data.success) {
											if(data.data.data.status != "0") {
												if(data.data.data.licenceList && data.data.data.licenceList.length > 0){
													let licenceList_ = data.data.data.licenceList;
													for (var i = 0; i < licenceList_.length; i++) {
														if((licenceList_[i].term && new Date(licenceList_[i].term) < new Date()) || !licenceList_[i].term) {
																let el = document.createElement('span');
																el.className = "cell";
																el.style.marginRight = "15px";
																el.style.paddingLeft = "5px";
																el.style.paddingRight = "5px";
																me.expiredMessage.push(licenceList_[i].type + "已过期")
																el.innerText = licenceList_[i].type + "已过期";
																m.appendChild(el);
																me.expiredLicense =true;
														}
													}
												}else{
													let el = document.createElement('span');
													el.className = "cell";
													el.style.marginRight = "15px";
													el.style.paddingLeft = "5px";
													el.style.paddingRight = "5px";
													me.expiredMessage.push("没有查询到证照信息")
													el.innerText = "没有查询到证照信息";
													m.appendChild(el);
													me.expiredLicense =true;
												}
											}
											if (callback) {
												callback();
											}
										} else {
											if (callback) {
												callback();
											}
											Root.message({
												type: 'warning',
												message: data.data.message
											});
										}
									})
									.catch((error) => {
										if (callback) {
											callback();
										}
										console.log(error);
									});
								//}
							});
						}else{
							if (callback) {
								callback();
							}
						}
						
					},
					cellVisibleChange(obj) {
						let options_ = [];
						let me= this;
						if (obj.field == "a2_product_price") {
							let filter = " business_type = '" + this.formData.business_type
								+ "' and control_type = '" + this.formData.control_type
								+ "' and operator_code = '" + this.formData.operate_emp_code
								//+ "' and tax_rate = '" + this.formData.tax_rate
								+ "' and delivery_part_code = '" + this.formData.delivery_part_code
								+ "' and province_code = '" + this.formData.province_code
								+ "' and manager_part_code = '" + this.formData.manager_part_code
								+ "' and business_depart_id = '" + this.formData.business_depart_id
								+ "' and settle_type = '" + this.formData.settle_type
								+ "' and product_code = '" + this.selectrow.product_code
								+ "' and customer_id = '" + this.formData.customer_id
								+ "' and supply_price <> '" + this.selectrow.product_price
								+ "'";
							let param_ = {
								isClientMode: false,
								filter: filter
							}
							Server.call("root/data/getEntitySet/A2Price", param_, function(result){
								options_ = result.data.entityset;
								obj.options = options_;
								me.a2label = clone(options_)
							});
						}else if(obj.field == "a1_trans_price") {
							if(!this.formData.trans_customer_code) {
								Root.message({
									type:"warning",
									message:"请选择A1客户"
								})
								return;
							}
							let param_ = {
								isClientMode: false,
								customer_code: this.formData.trans_customer_code,
								delivery_part_code: this.formData.delivery_part_code,
								product_code: this.selectrow.product_code,
								//product_code: this.selectedrow.product_code,
							}
							Server.call("root/data/getEntitySet/A1CustomerPrice", param_, function(result){
								options_ = result.data.entityset;
								obj.options = options_;
								me.a1label = clone(options_)
							});
						}
					 },
					 selectchange(obj){
					 	let field = obj.fieldobj.field;
						var formFields_ = clone(this.formFields);
						var tableFields_ = clone(this.tableFields);
					 	let row = obj.data;
					 	if (field == "sub_type") {
					 		let val = row[field];
							let isshowF ='T';
							let isshowT ='T';
							if (val[0] == 3){
								isshowF = 'T';
								isshowT = 'F';
							}
							else if(val[0] == 2){
								isshowF = 'F';
								isshowT = 'T';
							}
							else{
								isshowF = 'F';
								isshowT = 'F';
							}
							formFields_ = formFields_.map((e)=>{
								if(e.field == "trans_customer_name") 
									e.isshow = isshowF;
									
								if (val[0] == "2" && val[1] == "2-2" && e.field == "ticket_discount_type") {
									e.isshow = 'T'
								}
								else if (e.field == "ticket_discount_type") {
									e.isshow = 'F'
								}
								return e;
							});
							tableFields_ = tableFields_.map((e)=>{
								let arr = ["diff_date","old_discount_amt","detail_remark","current_discount_amt","diff_amt","diff_price","a2_product_price"]
								if(arr.indexOf(e.field) != -1) 
									e.isshow = isshowT;
								if(e.field == "revo_remark" && isshowF == 'F' && isshowT == 'F') {
									e.isshow = "T";
									e.type = 'select'
									e.name = '退货原因'
								}else if(e.field == "revo_remark"){
									e.isshow = "F";
								}
								if(e.field == "a1_trans_price" || e.field == "a1_delivery_amt" || e.field == "trans_settle_type" || e.field == "pre_settle_type_name") {
									e.isshow = isshowF;
								}
								
								return e;
							});
							let formData_ = clone(this.formData);
							formData_.trans_customer_code = "";
							formData_.trans_customer_name = "";
							formData_.trans_agreement_id = "";
							this.formData = formData_;
							this.formFields = formFields_;
							this.tableFields = tableFields_;
							//this.tableData2 = [];
							for (var i = 0; i < this.tableData2.length; i++) {
								this.tableData2[i].trans_agreement_record_id = "";
								this.tableData2[i].a2_product_price = "";
							}
					 	}
						/* this.$nextTick(e=>{
							let el = document.getElementsByClassName('el-table__body-wrapper',this.$refs.table1.$el)[0];
							let el_a = this.$refs.table1.$refs.table1.$el;
							el.style.height = (el_a.clientHeight - 40) + 'px'
						}) */
					 },
					 cellSelectChange(scope) {
						 let me = this;
					 	let row = scope.row;
					 		console.info(row)
					 	let field = scope.column.property;
					 		console.info(field)
						let val = row[field];
					 	if(field == "a2_product_price") {
					 		row.trans_agreement_record_id = val;
							this.a2label.map(e=>{
								if(e.id == val) {
									row.a2_product_price = e.supply_price
								}
							})
							let qty_needreturn_ = parseFloat(row.qty_needreturn);
							let old_discount_amt_ = parseFloat(row.old_discount_amt)
							let current_discount_amt_ = parseFloat(row.current_discount_amt)
							let a2_product_price_ = parseFloat(row.a2_product_price)
							if(!row.qty_needreturn)
								qty_needreturn_ = 0
							if(!row.old_discount_amt)
								old_discount_amt_ = 0
							if(!row.current_discount_amt)
								current_discount_amt_ = 0
							if(!row.a2_product_price)
								a2_product_price_ = 0
							let diff_price_ = 0;
							diff_price_ = parseFloat(row.product_price) - a2_product_price_ - old_discount_amt_ + current_discount_amt_
							me.$set(row,"diff_price",diff_price_)
							me.$set(row,"diff_amt",qty_needreturn_ * diff_price_)
					 	}
						else if(field == "a1_trans_price") {
							me.$set(this.formData,"trans_agreement_id",row[field])
							this.a1label.map(e=>{
								if(e.id == val) {
									row.a1_trans_price = e.supply_price
									//获取A1的结算方式
									row.trans_settle_type = e.settle_type_name
									//设置A1发货金额
									row.a1_delivery_amt = toMoney(row.a1_trans_price * 1 * row.qty_needreturn);
								}
							})
						}
					 },
					onpassApproval(){
						/* if(!this.formData.charge_user){
							Root.message({
								type: 'warning',
								message: '请填写退货责任人'
							})
							return;
						} */
						this.textarea2 = "";
						this.reasonvisible = true;
						this.passOrRefuse = true;
					},
					onrefuseApproval(){
						this.textarea2 = "";
						this.reasonvisible = true;
						this.passOrRefuse = false;
					},
					saveReason(){
						document.getElementById('page_loading').style.display = "block";
						if(this.passOrRefuse){
							this.isLoading = true;
							this.passApproval('revocation',this.textarea2)
						}else{
							if(this.textarea2 != ""){
								this.isLoading = true;
								this.refuseApproval('revocation',this.textarea2)
							}
							else{
								Root.message({
									type: 'warning',
									message: '请填写原因'
								});
								document.getElementById('page_loading').style.display = "none";
							}
						}
						
					},
					passApproval(dataType_,reason_) {
						let me = this;
						if(me.formData.act_node_name == '商务审核') {
							let arr = clone(this.tableData2);
							while(arr.length > 0) {
								let item = arr.pop();
								let param_table = {
									isClientMode: false,
									id:item.id,
									detail_charge_user:item.detail_charge_user,
									dataname: "revocation_order_detail",
								}
								Server.call("root/data/updateEntity", param_table, function(result) {
									if(arr.length == 0) {
										me.passApproval_(dataType_,reason_)
									}
								});
							}
							
						}else if(me.formData.act_node_name == '数据服务部-流向及SD管理岗') {
							let arr = clone(this.tableData2);
							while(arr.length > 0) {
								let item = arr.pop();
								let param_table = {
									isClientMode: false,
									id:item.id,
									inventory_cnt:item.inventory_cnt,
									dataname: "revocation_order_detail",
								}
								Server.call("root/data/updateEntity", param_table, function(result) {
									if(arr.length == 0) {
										me.passApproval_(dataType_,reason_)
									}
								});
							}
						}else {
							me.passApproval_(dataType_,reason_)
						}
					},
					passApproval_(dataType_,reason_) {
						var id = this.formData.id;
						let me = this;
						let subType = this.formData.sub_type;
						let dataType = ""
						if(subType instanceof Array) {
							subType = this.formData.sub_type[this.formData.sub_type.length-1];
							dataType = this.formData.sub_type[0];
						}else{
							subType = this.formData.sub_type;
							dataType = this.formData.sub_type;
						}
						let param = {
							orderId:id,
							eventType:"approvalSuccess",
							dataType:dataType_,
							extra:{
								variableMap:{ 
									reason:reason_,
									businessType:this.formData.business_type,
									businessDepartType:this.formData.r_depart_type||"",
									controlType:this.formData.control_type,
									managerPartCode:this.formData.manager_part_code,
									departRevoType:this.formData.depart_revo_type,
									deliveryPartCode:this.formData.delivery_part_code,
									isOverDue:true,
									dataType:dataType,
									subType:subType,
									attachment:this.attachment||"",
									flowId:this.formData.flow_id || ""
								}
								
							},
							isClientMode: false,
						}
						Server.call("root/order/onEvent", param, function(result) {
							console.log(result);
							if (result.success){
								Root.message({
									type: 'success',
									message: '审批成功'
								}); 
							}
							if(me.fromDing) {
								me.dingResult = true;
								me.dingResultTxt = "审批成功"
								return;
							}
							me.reasonvisible = false;
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, true); 
						}, function(result) {
							
								Root.message({
									type: 'warning',
									message: '审批失败'
								}); 
							this.reasonvisible = false;
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, true);
						});
					},
					//审批拒绝
					refuseApproval(dataType_,reason_) {
						let me = this;
						//var row = this.selectedrow;
						var id = this.formData.id;
						let subType = this.formData.sub_type;
						let dataType = ""
						if(subType instanceof Array) {
							subType = this.formData.sub_type[this.formData.sub_type.length-1];
							dataType = this.formData.sub_type[0];
						}else{
							subType = this.formData.sub_type;
							dataType = this.formData.sub_type;
						}
						let param = {
							orderId:id,
							eventType:"approvalFail",
							dataType:dataType_,
							extra:{
								variableMap:{ reason:reason_,
								businessType:this.formData.business_type,
								 businessDepartType:this.formData.r_depart_type||"",
								 controlType:this.formData.control_type,
								 managerPartCode:this.formData.manager_part_code,
								 departRevoType:this.formData.depart_revo_type||"",
								 deliveryPartCode:this.formData.delivery_part_code,
								 isOverDue:true,
								dataType:dataType,
								subType:subType,
								attachment:this.attachment||"",
								flowId:this.formData.flow_id || ""
								}
							},
							isClientMode: false,
						}
						Server.call("root/order/onEvent", param, function(result) {
							console.log(result);
							
							Root.message({
								type: 'success',
								message: '拒绝审批成功'
							}); 
							this.reasonvisible = false;
							
							if(me.fromDing) {
								me.dingResult = true;
								me.dingResultTxt = "拒绝审批成功"
								return;
							}
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, true);
						}, function(result) {
							
								Root.message({
									type: 'warning',
									message: '审批失败'
								}); 
							this.reasonvisible = false;
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, true);
						});
					},
					submitRowTable() {
						if(this.formData.has_gsp && this.expiredLicense) {
							Root.message({
								type: 'warning',
								message: '资质证照过期,无法提交'
							});
							return;
						}
						this.formData.continueCommit = true;
						this.saveRowTable();
					},
					
					saveRowTable() {
						let me = this;
						if (this.tableData2.length == 0 ) {
							Root.message({
								type: 'warning',
								message: '请选择退货明细'
							});
							return;
						}
						let isDistributor = localStorage.isdistributor;
						let typeReason = "";
						if(this.formData.sub_type instanceof Array) {
							if(this.formData.sub_type[0] == "2"){//A2
								typeReason = "2"
							}else if(this.formData.sub_type[0] == "3"){//A1
								typeReason = "3"
							}else(//退货
								typeReason = "1"
							)
							
							if (this.formData.sub_type[0] == "2" && this.formData.sub_type[1] == "2-2" && !this.formData.ticket_discount_type) {
								this.isLoading = false;
								Root.message({
									type: 'warning',
									message: '请选择票折类型'
								});
								return;
							}
						}
						if(typeReason == "3") {
							if(!this.formData.trans_agreement_id) {
								this.isLoading = false;
								Root.message({
									type: 'warning',
									message: '请选择A1客户或A1价格'
								});
								return;
							}
						}
						/* sensitiveWord(me,this.formData.remark, results => {
							if(!checkMenus) {
								return;
							}
						}); */
						
						
						/* var url = "stock/sensitiveWord/check";
						var param_ = {
							isClientMode: false,
							text:this.formData.remark
						}
						
						Server.call(url, param_, function(result) {
							if (data.data.check){
								
							}else{
								Root.message({
									type: 'warning',
									message:  data.data.data.msg
								});
								return
							}
							
						},function(errorresult) {
							
						}); */
						let url = window.top.RootSetting.url_stock +  "sensitiveWord/check";
						axios.post(url, {
							isClientMode: false,
							text:this.formData.remark
						})
						.then(data => {
							if (data.data.data.checked){
								
							}else{
								Root.message({
									type: 'warning',
									message:  data.data.message
								});
								return
							}
						})
						.catch( (error) => {
							console.log(error);
						});
						
						
						var array_ = [];
						for (var i = 0;i< this.tableData2.length;i++) {
							
							var row = this.tableData2[i];
							var row_ = {};
							if(!row.detail_charge_user && !isDistributor) {
								Root.message({
									type:"warning",
									message:'第 ' + (i+1) + '条明细: 请填写退货责任人'
								})
								return;
							}
							row_.detailChargeUser = row.detail_charge_user;
							row_.id = row.id?row.id:"";
							if(typeReason == '3'){
								row_.transAgreementRecordId = this.formData.trans_agreement_id?this.formData.trans_agreement_id:"";
							}else if(typeReason == '2') {
								if(!row.old_discount_amt && (row.old_discount_amt != 0 || row.old_discount_amt != "0")) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写原折让小计'
									});
									return;
								}
								if(!row.current_discount_amt && (row.current_discount_amt != 0 || row.current_discount_amt != "0")) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写现折让小计'
									});
									return;
								}
								
								if(!row.trans_agreement_record_id) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写调货价格'
									});
									return;
								}
								if(!row.diff_price) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写补差单价'
									});
									return;
								}
								if(!row.detail_remark) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写明细备注'
									});
									return;
								}
								row_.transAgreementRecordId = row.trans_agreement_record_id?row.trans_agreement_record_id:"";
								row_.diffAmt = row.diff_amt.toFixed(4)
								row_.diffDate = dateFormat(row.diff_date,'yyyy-MM-dd');
								row_.oldDiscountAmt = row.old_discount_amt
								row_.currentDiscountAmt = row.current_discount_amt
								row_.detailRemark = row.detail_remark
								row_.diffPrice = row.diff_price.toFixed(4)
							}else {
								if(!row.revo_remark) {
									me.isLoading = false;
									Root.message({
										type: 'warning',
										message: '第 ' + (i+1) + '条明细: 请填写退货原因'
									});
									return;
								}
							}
							if(row.revo_remark) {
								row_.revoRemark = row.revo_remark;
							}
							if(row.inventory_cnt) {
								row_.inventoryCnt = row.inventory_cnt;
							}
							row_.deliveryDetailId = row.deliveryOrderDetailId;
							let reg = /^[1-9][0-9]*$/
							if(!reg.test(row.qty_needreturn)) {
								me.isLoading = false;
								Root.message({
									type: 'warning',
									message: '请填写退货数量'
								});
								return;
							}
							//row_.transPrice = row.a2_product_price;
							row_.cnt = row.qty_needreturn;
							row_.warehouseCode = "1";
							row_.batchNO = row.deo_batch_no ? row.deo_batch_no:"";
							
							row_.a1TransPrice = row.a1_trans_price ? row.a1_trans_price: 0;
							row_.transSettleType = row.trans_settle_type ? row.trans_settle_type : "";
							
							array_.push(row_);
						}
						
						let subType = this.formData.sub_type;
						if(subType instanceof Array) {
							subType = this.formData.sub_type[this.formData.sub_type.length-1];
						}else
							subType = this.formData.sub_type;
						document.getElementById('page_loading').style.display =  "block";
						
						var remark_ = "";
						if (this.formData.remark) {
							remark_ = this.formData.remark;
							//去除两端的空格
							remark_ = remark_.replace(/(^\s*)|(\s*$)/g, "");
							
							//将所有空格改成中文逗号;
							remark_ = remark_.replace(/\s/g,",");
						}
						let param =
						{
							isClientMode: false,
							id: this.formData.id ? this.formData.id : "",
							salesOrderId:this.formData.deo_id || "",
							fileId:this.formData.file_id || "",
							deliveryDetailId:this.formData.deo_id || "",
							businessDepartId:this.formData.business_depart_id,
							businessType:this.formData.business_type || "",
							settleType:this.formData.settle_type || "",
							roProxy:this.formData.ro_proxy || false,
							controlType:this.formData.control_type || "",
							deliveryPartCode:this.formData.delivery_part_code,
							deliveryPartName:this.formData.delivery_part_name,
							
							managerPartCode:this.formData.manager_part_code,
							customerId:this.formData.customer_id,
							customerName:this.formData.customer_name,
							customerCode:this.formData.customer_code,
							transAgreementId:this.formData.trans_agreement_id || "",		//如果是调货
							dataType:typeReason,
							subType:subType,
							remark: remark_,
							bizDate:this.formData.biz_date,
							ticketDiscountType:this.formData.ticket_discount_type || "",
							customerRecordProvinceCode: this.formData.customer_record_province_code,
							customerRecordProvinceName: this.formData.customer_record_province_name,
							
							detailList:array_,
						}
						if(this.formData.withdraw) {
							param.status = "input"
						}
						this.isLoading = true;
						
						Server.call("root/order/saveRevocationOrder", param, function(result) {
							console.log(result);
							if(result.success){
								if(me.formData.continueCommit){
									let param = {
										orderId:result.data.id,
										eventType:"commit",
										dataType:"revocation",
										isClientMode: false,
										extra:{
											variableMap:{
												province:me.formData.province_code||"",
												businessType:me.formData.business_type|| "",
												departRevoType:me.formData.depart_revo_type,
												ticketDiscountType: me.formData.ticket_discount_type || "",
												subType:subType,
												subDataType:typeReason,
												dataType:typeReason,
												flowId:me.formData.flow_id || ""
											}
										},
									}
									Server.call("root/order/onEvent", param, function(result) {
										console.log(result);
										Root.message({
											type: 'success',
											message: '提交成功'
										}); 
										if(me.formData.withdraw && me.formData.id) {
											let param = {
												isClientMode:false,
												dataname:"revocation_order",
												id:me.formData.id,
												withdraw:0
											}
											Server.call("root/data/updateEntity",param,function(result) {
												
											})
										}
										Root.tab.removeItem(Root.tab.selected);
										Root.tab.open(me.popupParames.parentOption, true); 
									},function(result){
										document.getElementById('page_loading').style.display =  "none";
										me.isLoading = false;
										Root.message({
											type: 'warning',
											message: result.message
										}); 
									});
								}else{
									Root.message({
										type: 'success',
										message: '保存成功'
									});
									Root.tab.removeItem(Root.tab.selected);
									Root.tab.open(me.popupParames.parentOption, true); 
								}
								
							}else{
								document.getElementById('page_loading').style.display =  "none";
								me.isLoading = false;
								Root.message({
									type: 'warning',
									message: result.message
								}); 
							}
						},function(result){
							document.getElementById('page_loading').style.display =  "none";
							me.isLoading = false;
							Root.message({
								type: 'warning',
								message: result.message
							}); 
						});
					},
					rowChange(row, type) {
						//tc
						var id_ = row.id;
						if (this.tableDataChange[id_]) {
							this.tableDataChange[id_].data = row;
						}
						else {
							var changeRow_ = {
								type: type,
								data: row
							};
							this.tableDataChange[id_] = changeRow_;
						}
						
						//t2
						if (type == "add") {
							this.tableData2.unshift(row);
							this.selectrow = row;
						}
						else if (type == "del") {
							this.tableData2.remove(row);
						}
						
						/* var sum_noRate_ = 0 ;
						var formData_ = clone(this.formData);
						this.tableData2.map(e=>{
							sum_noRate_ += (e.price_return ? e.price_return : 0 ) * 1;
						})
						
						formData_.return_amt = sum_noRate_;
						
						this.formData = formData_; */
						this.isRefresh = true;
						//this.$refs.form1.refresh();
					},
					rowDBClick(scope) {
						this.editData(scope)
					},
					editData(scope) {
						if (this.selectrow != {} && this.selectrow.isWithinEdit) {
							this.selectrow.isWithinEdit = false;
						}
						if(this.selectrow == scope.row ){
							scope.row.isWithinEdit = false;
							this.selectrow = {};
						}else{
							this.selectrow = scope.row;
							this.selectedrow = clone(scope.row);
							scope.row.isWithinEdit = scope.row.isWithinEdit ? false : true;
						}
											
						this.isRefresh = false;
						this.$nextTick(function(){
							this.isRefresh = true;
						})
					},
					delData(scope) {
						let me = this;
						let row = scope.row;
						let index_ = scope.$index;
						
						Root.confirm('确定删除-' + row.product_name + '-吗?', '删除提示', {
						  confirmButtonText: '删除',
						  cancelButtonText: '取消',
						  type: 'warning'
						}).then(() => {
							if (row.id) {
								let param1 = {
									filter:{
										id: row.id
									},
									
									isClientMode: false,
									dataname: 'revocationOrderDetail',
								}
								Server.call("root/data/deleteEntitySet", param1, function(result) {
									
								});
							}
							me.rowChange(row, "del");
							
							Root.message({
								type: 'success',
								message: '删除成功!'
							});
						}).catch(() => {
							
							Root.message({
								type: 'info',
								message: '已取消删除'
							});          
						});
					},
					
					cellInputChange(scope) {
						let row = scope.row;
						let me = this;
						let field = scope.column.property;
						let qty_needreturn_ = parseFloat(row.qty_needreturn);
						let old_discount_amt_ = parseFloat(row.old_discount_amt)
						let current_discount_amt_ = parseFloat(row.current_discount_amt)
						let a2_product_price_ = parseFloat(row.a2_product_price)
						if(!row.qty_needreturn)
							qty_needreturn_ = 0
						if(!row.old_discount_amt)
							old_discount_amt_ = 0
						if(!row.current_discount_amt)
							current_discount_amt_ = 0
						if(!row.a2_product_price)
							a2_product_price_ = 0
						if(field == "qty_needreturn" || field == "old_discount_amt" || field == "current_discount_amt") {
							let diff_price_ = 0;
							diff_price_ = parseFloat(row.product_price) - a2_product_price_ - old_discount_amt_ + current_discount_amt_
							me.$set(row,"diff_price",diff_price_)
							me.$set(row,"diff_amt",qty_needreturn_ * diff_price_)
						}
						if(field == "qty_needreturn") {
							if(parseInt(row.qty_needreturn) > parseInt(row.qty_canReturn)) {
								Root.message({
									type:"warning",
									message:"退货数量大于收货数量"
								})
								me.$set(row,"qty_needreturn",0)
								row.qty_needreturn = 0;
								return;
							}
						}
						
						if (field == "qty_needreturn" && row.a1_trans_price) {
							//设置A1发货金额
							row.a1_delivery_amt = toMoney(row.a1_trans_price * 1 * row.qty_needreturn);
						}
						
						//this.isRefresh = true;
						this.rowChange(row, "up");
					},
					// cellClick(obj) {
					// 	/* if(obj.column.property == "product_name") {
					// 		this.selectrow = obj.row;
					// 		this.showPic("showPic", obj.row);
					// 	} */
					// },
					
					onCellClick(config, obj) {
						var row = obj.row ? obj.row : {};
						if(obj.tableField.field == "attachment_name" && obj.row.attachment){//
							var fileid = obj.row.attachment;
							let arr = obj.row.attachment_name.split(".");
							let flix = arr[arr.length-1];
							if(flix == 'pdf' || flix == 'png' || flix == 'jpg') {
								let url = "../tool/popup_file_pdf.html";
								let row = {
									filename:obj.row.attachment_name,
									fileid:fileid
								}
								var config = {
									totab: false,
									icon: "icon-product",
									text: "附件预览",
									url: url,
									data: row,
									width:1100,
									delta: null,
									callback: function(obj, callback) {
										if (callback) {
											callback();
										}
									}
								};
								this.doPopupByPublic(config);
							}else
								handleDownload(fileid);
						}
						
						return false;
					},
					onPopupByUploadFileAll() {
						var me = this;
						this.attachment = "";
						this.attachment_name = "";
						
						var config = {
							totab: false,
							width: "1500px",
							icon: "icon-product",
							text: "附件上传",
							id: "popupByUploadFile",
							url: "../tool/popup_uploadFile.html",
							data: {},
							delta: {filetypelist: []},
							callback: function(obj, callback) {
								var file_ = obj.row[0];
								me.attachment = file_.id;
								me.attachment_name = file_.name;
								
								if (callback) {
									callback();
								}
							}
						};
						this.doPopupByPublic(config);
					},
					showPic(code, row) {
						Root.popupParames = {
							url: "../md/product/sku/pic_list.html",
						};
						Root.showPopup(Root.popupParames);
					},
					
					showPopup(obj) {
						let list=this.customerList;
						this.selectFormField = obj.obj;
						if (this.selectFormField.field == "customer_code" || this.selectFormField.field == "customer_name") {
							let me = this;
							let filter_ = "1=1";
							if (this.isWLGLB) {
								filter_ = " sales_order.business_type = '2' and "
							}
							else {
								filter_ = "  sales_order.business_type = '1' and (sales_order.create_operate_code = '" + window.top.userinfo.employee.code + "' or sales_order.operate_emp_code = '" + window.top.userinfo.employee.code + "' or a1.link like '%" + window.top.userinfo.employee.code + "%') and checkout_status <> 0 and "
							}
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html?v=0517",
								width: 800,
								height: 550,
								dataname:"getDeliveryOrderDelivery",
								filter:filter_,
								delivery_part_code:this.formData.delivery_part_code,
								delivery_id:this.formData.deo_id?this.formData.deo_id:"",
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.customer_name = obj.row.customer_name;
									formData_.customer_code = obj.row.customer_code;
									formData_.customer_id = obj.row.customer_id;
									//formData_.trans_customer_code = '';
									//formData_.trans_customer_name = '';
									//formData_.trans_agreement_id = '';
									//formData_.delivery_part_name = '';
									//formData_.delivery_part_code = '';
									//formData_.revocation_address = '';
									me.tableData2 = [];
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						}
						if (this.selectFormField.field == "trans_customer_name") {
							if (!this.formData.delivery_part_name) {
								Root.message({
									type: 'warning',
									message: '请选择发货主体'
								});
								return;
							}
							if (this.tableData2.length <1) {
								Root.message({
									type: 'warning',
									message: '请选择发货单'
								});
								return;
							}
							let str = ''
							for (var i = 0; i < this.tableData2.length; i++) {
								if(str.indexOf("'" + this.tableData2[i].product_code + "'") == -1) {
									str += "'" + this.tableData2[i].product_code + "'" +","
								}
							}
							str = str.substring(0,str.length-1);
							let me = this;
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html?v=0517",
								width: 800,
								height: 550,
								customer_code:this.formData.customer_code,
								delivery_part_code:this.formData.delivery_part_code,
								product_codes:str,
								dataname:"A1CustomerSimple",
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.trans_customer_code = obj.row.md_code;
									formData_.trans_customer_name = obj.row.md_description;
									
									me.formData = formData_;
									//me.tableData2 = [];
									if (callback) {
										callback();
									}
								}
							});
						}
						if (this.selectFormField.field == "delivery_part_name") {
							let me = this;
							let filter_ = "delivery_order.withdraw <> 1 and ";
							if(this.formData.customer_code) {
								filter_ += " delivery_order.customer_code = '" + me.formData.customer_code + "' and "
							}
							if (this.isWLGLB) {
								filter_ = " sales_order.business_type = '2' and "
							}
							else {
								filter_ = " sales_order.business_type = '1' and (sales_order.create_operate_code = '" + window.top.userinfo.employee.code + "' or sales_order.operate_emp_code = '" + window.top.userinfo.employee.code + "'  or a1.link like '%" + window.top.userinfo.employee.code + "%') and checkout_status <> 0 and "
							}
							//filter_ += " (sales_order.create_operate_code = '" + window.top.userinfo.employee.code + "' or sales_order.operate_emp_code = '" + window.top.userinfo.employee.code + "') and "
							Root.showPopup({
								url: "../order/sorder/popup/sorder_deliverylist.html",
								width: 800,
								height: 550,
								type: "delivery",
								filter: filter_,
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.business_depart_id = obj.row.business_depart_id;
									formData_.delivery_part_name = obj.row.delivery_part_name;
									formData_.delivery_part_code = obj.row.delivery_part_code;
									formData_.revocation_address = obj.row.revocation_address;
									/* formData_.revocation_address = obj.row.revocation_address;
									formData_.customer_name = obj.row.customer_name;
									formData_.customer_code = obj.row.customer_code;
									formData_.business_type = obj.row.business_type;
									formData_.settle_type = obj.row.settle_type;
									formData_.control_type = obj.row.control_type;
									formData_.deo_raw_code = obj.row.deo_raw_code;
									formData_.deo_factory_no = obj.row.deo_factory_no;
									formData_.manager_part_code = obj.row.manager_part_code;
									formData_.customer_id = obj.row.customer_id;
									formData_.business_depart_id = obj.row.business_depart_id;
									formData_.province_code = obj.row.province_code;
									formData_.depart_revo_type = obj.row.depart_revo_type;
									formData_.deo_id = obj.row.deo_id;
									formData_.so_id = obj.row.id;
									formData_.book_no = obj.row.book_no;
									formData_.has_gsp = obj.row.has_gsp;
									formData_.operate_emp_code = obj.row.operate_emp_code;
									formData_.tax_rate = obj.row.tax_rate; */
									//formData_.trans_customer_code = '';
									//formData_.trans_customer_name = '';
									//formData_.trans_agreement_id = '';
									//me.tableData2 = [];
									me.formData = formData_;
									me.checkCustomerAndDelivery(callback)
								}
							});
						}
					},
					buttonClick(obj) {
						if (obj.obj.field == "file_name") { //合同
							let me = this;
							this.doPopup({
								totab: false,
								width: "1500px",
								icon: "icon-product",
								text: "附件上传",
								id: "popupByUploadFile",
								url: "../tool/popup_uploadFile.html",
								data: {},
								delta: {
									filetypelist: [".png", ".jpg", ".pdf"]
								},
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.file_id = obj.row[0].id
									formData_.file_name = obj.row[0].name
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						}
					},
					
					formcallspanClick(obj) {
						if (obj.obj.field == "file_name" && this.formData.file_id) {
							this.onDownloadFileByFileId(this.formData.file_id, this.formData.file_name);
						}
					},
					onDownloadFileByFileId(file_id, file_name) {
						var clickContext = {};
					
						var row_ = {};
						if (!file_id) {
							Root.message({
								type: 'warning',
								message: '没有附件文件'
							});
							return
						}
					
						////////////
						let fileid = clone(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") {
							var fileids_ = [];
							fileids_.push(fileid)
							row_ = {
								filetype: "img",
								fileids: fileids_
							};
							clickContext.url = "../tool/popup_file.html";
							var config = {
								icon: "icon-product",
								text: "附件预览",
								id: "img_" + fileid,
								url: "../tool/popup_file.html",
								data: row_,
								delta: {},
								callback: function(obj, callback) {
									if (callback) {
										callback();
									}
								}
							};
							this.doPopup(config);
							return
						} else if (suffix == ".pdf") {
							var row = {
								fileid: fileid,
								filename: fileName
							}
					
							var config = {
								icon: "icon-product",
								text: "附件预览",
								id: "pdf_" + fileid,
								url: "../tool/popup_file_pdf.html",
								data: row,
								delta: {},
								callback: function(obj, callback) {
									if (callback) {
										callback();
									}
								}
							};
							this.doPopupByPublic(config);
							return;
					
						} else { //只可下载,不可预览
							handleDownload(fileid);
						}
					},
					
					showOrder(obj) {
						let me = this;
						let formData_ = clone(me.formData);
						if(!formData_.delivery_part_name){
							Root.message({
								type: 'warning',
								message: '请选择发货主体'
							});  
							return;
						}else if(!formData_.customer_code ){
							Root.message({
								type: 'warning',
								message: '请选择客户'
							});  
							return;
						}else if(!formData_.sub_type || formData_.sub_type.length == 0){
							Root.message({
								type: 'warning',
								message: '请选择退货原因'
							});  
							return;
						}
						/* if(formData_.sub_type && formData_.sub_type.indexOf("3") > -1 && !formData_.trans_customer_name){
							Root.message({
								type: 'info',
								message: '请选择A1客户'
							});  
							return;
						} */
						let filter_order = " sales_order.delivery_part_code = '"+ formData_.delivery_part_code +"' and sales_order.customer_code = '" + formData_.customer_code + "'";
						
						if (this.isWLGLB) {
							filter_order += " and sales_order.business_type = '2'"
						}
						else {
							filter_order += " and (sales_order.create_operate_code = '" + window.top.userinfo.employee.code + "' or sales_order.operate_emp_code = '" + window.top.userinfo.employee.code + "'  or (a1.link like '%" + window.top.userinfo.employee.code + "%' and sales_order.business_type = '1'))  "
						}
						
						//filter_order += " and (sales_order.create_operate_code = '" + window.top.userinfo.employee.code + "' or sales_order.operate_emp_code = '" + window.top.userinfo.employee.code + "')"
						filter_order += " and delivery_order_detail.checkout_cnt > 0"
						
						if(this.tableData2.length > 0) {
							let str = " and delivery_order_detail.id not in ('";
							for (var i = 0; i < this.tableData2.length; i++) {
								if(i == this.tableData2.length-1)
									str += this.tableData2[i].deliveryOrderDetailId + "')"
								else
									str += this.tableData2[i].deliveryOrderDetailId + "','"
							}
							//str += " and delivery_order_detail.parent_id = '" + this.formData.deo_id + "'"
							filter_order += str;
						}
						let trans_customer_code = '%'
						if(this.formData.trans_customer_code) 
							trans_customer_code = this.formData.trans_customer_code
						Root.showPopup({
							url: "../order/sorder/popup/sorder_deliverylist.html",
							width: 900,
							height: 600,
							type: "return",
							filter: filter_order,
							//trans_customer_code:trans_customer_code,
							callback: function(array, callback) {
								if (array.length > 0) {
									for (var i = 0; i<array.length; i++) {
										if(array[i].qty_needReturn > 0){
											let row_ = {
												//id: array[i].deliveryorderdetailid,
												//parentid: formData_.id,
												code:array[i].code,
												product_name:array[i].product_name,
												deo_raw_code:array[i].deo_raw_code,
												deo_factory_no:array[i].deo_factory_no,
												product_code:array[i].product_code,
												product_spec:array[i].product_spec,
												deo_batch_no:array[i].batch_no,
												qty_needreturn:array[i].qty_needReturn,
												price_return:array[i].product_price * array[i].qty_needReturn,
												product_price:array[i].product_price,
												deliveryOrderDetailId :array[i].deliveryorderdetailid,
												settle_type:array[i].settle_type,
												checkout_cnt:array[i].checkout_cnt,
												qty_canReturn:array[i].qty_canReturn,
												revocation_delivery_cnt:array[i].return_qty,
												pre_settle_type_name: array[i].pre_settle_type_name,
												isWithinEdit:true
											};
											if(array[i].proxy_order) {
												formData_.ro_proxy = true;
											}
											me.selectedrow = row_;//selectedrow  selectrow
											me.rowChange(row_, "add");
										}else{
											Root.message({
												type: 'info',
												message: '可退货数量为0'
											});  
										}
									}
									formData_.revocation_address = array[0].revocation_address;
									formData_.customer_name = array[0].customer_name;
									formData_.customer_code = array[0].customer_code;
									formData_.business_type = array[0].business_type;
									formData_.settle_type = array[0].settle_type;
									formData_.control_type = array[0].control_type;
									formData_.deo_raw_code = array[0].deo_raw_code;
									formData_.deo_factory_no = array[0].deo_factory_no;
									formData_.manager_part_code = array[0].manager_part_code;
									formData_.customer_id = array[0].customer_id;
									formData_.business_depart_id = array[0].business_depart_id;
									formData_.province_code = array[0].province_code;
									formData_.business_depart_code = array[0].business_depart_code;
									formData_.depart_revo_type = array[0].depart_revo_type;
									formData_.deo_id = array[0].deo_id;
									formData_.so_id = array[0].id;
									formData_.book_no = array[0].book_no;
									formData_.has_gsp = array[0].has_gsp;
									formData_.operate_emp_code = array[0].operate_emp_code;
									formData_.tax_rate = array[0].tax_rate;
									//formData_.customercode = array[0].customercode;
									//formData_.customername = array[0].customername;
									formData_.orderid = array[0].orderid;
									formData_.trans_customer_code = "";
									formData_.trans_customer_name = "";
									formData_.trans_agreement_id = "";
								/* 	var sum_noRate_ = 0 ;
									me.tableData2.map(e=>{
										sum_noRate_ += (e.price_return ? e.price_return : 0 ) * 1;
									})
									formData_.return_amt = sum_noRate_; */
									me.formData = formData_;
									
									me.tableData2.map(t=>{
										t.a1_trans_price = 0;
										t.a1_delivery_amt = 0;
										t.trans_settle_type = "";
									});
									
									me.showCustomer();
								}
								if (callback) {
									callback();
								}
							}
						});
					},
					
					showCustomer() {
						if (this.formData.customername) {
							filter_customer = "name = '" + this.formData.customername + "'"
							var formData_ = clone(this.formData); 
							var me = this;
							let param_table = {
								isClientMode: false,
								dataname: "vCustomer",
								filter: filter_customer,
							}
							
							Server.call("root/data/getEntitySet", param_table, function(result) {
								var customerDetail = result.data.entityset[0];
								formData_.customerid = customerDetail.id;
								me.formData = formData_;
							});
						}
					}
					
				}
			});
		</script>
		<style>
			.header {
				height: 21px;
			}
			.el-dialog_header {
				padding: 10px 20px;
				border-bottom: 1px solid #ccc;
				height: 20px;
				/* right: 10px;
				left: 10px;
				top: 0px;
				position: fixed; */
			}
			.el-dialog_body{
				padding: 0px;
				
				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;
			}
			
			/* 纵向: */
			/* @page { size: portrait; } */
			/* 横向: */
			@page { size: landscape; }
			@media print{
				.el-dialog_footer{
					display:none
				}
				.popup-close{
					display:none
				}
				.approval_button{
					display:none
				}
				
			}
			@page {
			  margin-top: 0;
			  margin-bottom: 0
			}
			
		</style>
	</body>
</html>