<!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=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_mkoo966o0uo.css" rel="stylesheet">
	</head>
	<body>
		<div id="vbody">
			<div id="page_root">
				<div ref="popup_body" style="padding-right: 20px;">
					<div class="el-dialog_header">
						<div class="dialog-title">
							<i class="iconfont icon-customermanagement"></i>
							<span> {{formAttr.title}} </span>
						</div>
					</div>
					<div style="height: 580px">
						<div ref="elbody" class="el-dialog_body" style="height: 530px">
							<div id="title1">
								<template slot="title">
									<i class="header-icon el-icon-info"></i>
									<span>
										订单信息
									</span>
								</template>
								<span style="font-weight:bold"> 一、选择客户名称 </span>
							</div>
							<h-form 
							ref="form1"
							 :form-attr="formAttr" 
							 :table-fields="formFields" 
							 :form-data="formData" 
							 v-on:button-click="buttonClick"
							 v-on:select-change="selectChange"
							 v-on:show-popup="showPopup"
							 v-on:form-change="formChange" 
							 v-on:visible-change="cellVisibleChange" 
							 :is-end-colspan="false"
							 v-on:formcall-click="formcallclick"
							 v-on:formcallspan-click="formcallspanClick">
							</h-form>
							<div id="title2">
								<el-tag
									v-if="isshowCell"
								    type="danger"
									style="margin-left: 60px;"
								   >
								    {{cellInnerText}}
								</el-tag>
								<div v-if="!notdisabled" id="cell" class="h_stamp" style="margin-left: 20px;float: left;">
								</div>
								<div v-if="notdisabled" style="overflow-y: auto;">
									<span style="font-weight:bold;float: left;text-align: left;"> 二、选择产品,填写数量等信息 </span>
									<div id="cell" class="h_stamp" style="margin-left: 20px;float: left;">
										
									</div>
									<div style="float:right;text-align: right;">
										<el-button @click="clearData">清空数据</el-button>
										<el-button-group style="margin-left: 40px;">
											<!-- <el-button style="margin-right: 10px;"@click="showCredit()">资信查询</el-button> -->
								
											<el-button @click="addTableData">新增数据</el-button>
										</el-button-group>
									</div>
								
								</div>
							</div>
							
							<h-table v-if="isRefresh" ref="table2"
								:table-fields="tableFields"
								:table-data="tableData2"
								:is-edit-table-data="isEditTableData"
								:is-within-edit-table-data="isWithinEditTableData"
								:show-summary="true"
								:is-pagination="false"
								:is-show-index="true"
							  
								:edit-table-button="editTableButton" 
								v-on:edit-data="editData"
								v-on:del-data="delData"
							 
								v-on:cell-input-change="cellInputChange" 
								v-on:row-click="rowClick" 
								v-on:cell-show-popup="cellShowPopup">
							</h-table>
							<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>
					</div>
					<div class="el-dialog_footer">
						<el-button-group v-if="seal" style="margin: 0px 20px;">
							<el-button type="success" @click="onseal">ç›– ç« </el-button>
						</el-button-group>
						<el-button-group v-if="approval && !isdistributor" style="margin: 0px 20px;">
							<el-button type="success" @click="onpassApproval">通 过</el-button>
						</el-button-group>
						<el-button-group v-if="approval && !isdistributor" style="margin: 0px 20px;">
							<el-button type="danger" @click="onrefuseApproval">拒 绝</el-button>
						</el-button-group>
						<el-button v-if="close && !fromDing" type="default" @click="closeDialog">取 消</el-button>
						<el-button v-if="!close && !fromDing" type="default" @click="closeDialog">å…³ é—­</el-button>
						<el-button v-if="notdisabled" type="primary" :loading="isLoading" @click="saveRowTable">保 存</el-button>
						<el-button v-if="notdisabled" type="primary" v-loading.fullscreen.lock="isLoading" :loading="isLoading" @click="submitRowTable">提 交</el-button>
					</div>
				</div>
				<div>
					<el-dialog title="填写原因" :visible.sync="reasonvisible" height="50%">
						<el-input
						  type="textarea"
						  :autosize="{ minRows: 2, maxRows: 10}"
						  placeholder="请输入原因"
						  v-model="textarea2">
						</el-input>
						<el-button type="primary" style="float: left;" size="small" @click="onPopupByUploadFileAll()">上传附件</el-button>
						<span  style="float: left;"> {{attachment_name}}</span>
						<div  class="dialog-footer" style="float: right;margin-top: 30px;">
						  <el-button type="default" @click="reasonvisible = false">取 消</el-button>
						  <el-button type="primary"  @click="saveReason">确 定</el-button>
						</div>
					</el-dialog>
					
					<el-dialog title="超账期数据" :visible.sync="isOverDue_dialog" width="800px">
						<div style="width: 100%; height: 310px;overflow: auto;">
							<el-table :data="overDueList" style="width: 100%" height="300">
							    <el-table-column prop="invCode" label="产品编号" width="100"></el-table-column>
							    <el-table-column prop="invName" label="产品名称" ></el-table-column>
							    <el-table-column prop="fhdCode" label="发货单号" width="140"></el-table-column>
							    <el-table-column prop="periodDays" label="超账期天数" width="180"></el-table-column>
							</el-table>
						</div>
						<div class="dialog-footer" style="float: right;margin-top: 30px;">
						  <el-button type="default" @click="isOverDue_dialog = false">å…³ é—­</el-button>
						</div>
					</el-dialog>
				</div>
				<!-- <div class="versionNo" style="width: 0px;height: 0px;">
				<iframe id="ifr1" :src="url" style="width: 100%;height: 100%; margin-top: 0px;"></iframe>
			</div> -->
			</div>
			<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 50vh;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 v-text="dingResultTxt"></span>
				 <div style="min-height: 150px;"></div>
			</el-dialog>
		</div>

		<script type="text/javascript">
			new ListVue({
				el: "#vbody",
				data: {
					disabled: false,
					notdisabled: true,
					approval: false,
					address: [],
					form_dataname: "salesOrder",
					dataname: "salesOrderDetail",
					rolecode: window.top.userinfo.user.rolecode,
					acctObj:{
						flow_id:""
					},
					attachment_name:"",
					formAttr: {
						title: "订单信息",
						istitle: false,
						columnnumber: 3,
						labelwidth: "130px",
						labelposition: "right",
						size: "medium",
						border: "0px solid #c6c6c600",
					},
					formFields: [],
					formData: {
						biz_date: createDate(),
						create_time: createDatetime(),
					},
					userPhone:{
						
					},
					expiredMessage:[],
					isLoading: false,
					isshowCell : false,
					newRowDefault: {
						//id: uuid_short(),
						code: createCode("S"),
						statecode: "input",
						biz_date: createDate(),
						create_time: createDatetime(),
						trans_type:"01",
						//operate_emp_name: window.top.userinfo.employee.name,
						sales_business_type: "1",
						sales_type: "07",
						tax_rate: "13",
					},

					tableFields: [],
					tableData2: [],
					tableDataChange: {},
					tableHeight2: 240,
					formData2: [],
					isEditTableData: true,
					isWithinEditTableData: false,
					isRefresh: true,
					selectFormField: {},
					selectrow: {},
					close: true,
					productDetail: [],
					hierarchy_name: "",
					expiredLicense:false,
					sum_noRate_: 0,
					updatetime: createDatetime(),
					reasonvisible: false,
					editTableButton: {
						edit: {
							isshow: true,
							txt: "编辑"
						},
						del: {
							isshow: true,
							txt: "删除"
						},
						save: {
							isshow: true,
							txt: "确认"
						}
					},
					roleList:[],
					cellInnerText:"应付账款余额:¥",
					textarea2: '',
					passOrRefuse: false,
					seal: false,
					dataRequest: [{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "manager_part_code",
							dataname: "dictitem",
							filter: " parent_id='manager-part'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "name",
							name: "trans_type",
							dataname: "md_trans_type",
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "settle_type",
							dataname: "dictitem",
							filter: " parent_id='settle_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "sales_type",
							dataname: "dictitem",
							filter: " parent_id='sales_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "business_type",
							dataname: "dictitem",
							filter: " parent_id='business_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "sales_business_type",
							dataname: "dictitem",
							filter: " parent_id='order-businesstype'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "tax_rate",
							dataname: "dictitem",
							filter: " parent_id='order-rate'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "control_type",
							dataname: "dictitem",
							filter: " parent_id='control_type'"
						},
					],
					dataRequestObj: {},
					fromDing: false,
					dingResult: false,
					dingResultTxt: "",
					
					isdistributor: false,
					
					isOverDue_dialog: false,
					overDueList: []
				},

				created() {
					let me = this;
					me.isdistributor = window.top.isdistributor;
					this.roleList = localStorage.getItem("roleid").split(";")
					this.popupParames = clone(Root.popupParames);
					this.initFields();
					if (this.popupParames.data) {
						let formData1 = clone(this.popupParames.data);
						this.acctObj.flow_id = formData1.flow_id;
						if (formData1.is_offline === "1" || formData1.is_offline === true) {
							formData1.offline = "线下合同";
						} else if (formData1.is_offline === "0" || formData1.is_offline === false) {
							formData1.offline = "线上合同";
						}
						formData1.sales_business_type = formData1.sales_business_type + "";
						formData1.business_type = formData1.business_type + "";
						formData1.control_type = formData1.control_type + "";
						formData1.r_depart_type = formData1.business_depart_id;
						me.formData = clone(formData1);
						me.isOverdueM(me.formData.id,me.formData.customer_code, me.formData.delivery_part_code);
						let finance_ = clone(dataRoot.pageSetting.finance);
						let isFiinance = false;
						for (var i = 0; i < finance_.length; i++) {
							if(this.roleList.indexOf(finance_[i]) > -1){
								isFiinance = true;
								break;
							}
						}
						if(isFiinance && this.popupParames.sceneCode == "approval") {
							me.getAccountsPayable(formData1.customer_code);
						}
					}
					if (this.popupParames.sceneCode) {
						if(this.popupParames.sceneCode != "add")
							this.formAttr.title = "订单信息 " + this.formData.code;
						if (me.formData.id) {
							if (me.formData.emp_depart_code == "202104200018")
								me.formData.emp_depart_name = "招商管理部";
						}
						if (this.popupParames.sceneCode == "browse") {
							this.formAttr.disabled = true;
							this.isWithinEditTableData = false;
							this.isEditTableData = false
							this.notdisabled = false;
							this.approval = false;
							this.close = false;
						} else if (this.popupParames.sceneCode == "main") {
							this.formAttr.disabled = true;
							this.isWithinEditTableData = false;
							this.isEditTableData = false
							this.notdisabled = false;
							this.approval = true;
							this.close = false;

							let param_ = {
								dataname: "salesOrder",
								filter: "id='" + this.popupParames.data.business_id + "'",

							}
							Server.call("root/data/getEntitySet", param_, function(result) {
								console.log(result);

								if (result && result.data) {
									let formData1 = clone(result.data.entityset[0]);

									//formData1.sales_business_type = formData1.sales_business_type+"";
									me.formData = formData1;
									me.initData();
								}
							});
						} else if (this.popupParames.sceneCode == "approval") {
							this.formAttr.disabled = true;
							this.isWithinEditTableData = false;
							this.isEditTableData = false;
							this.notdisabled = false;
							this.approval = true;
							this.close = false;
							if (me.popupParames.disabledone) {
								this.seal = true
							}
						} else if (this.popupParames.sceneCode == "add") {
							this.addTableData();
							if (this.newRowDefault) {
								let formData_ = clone(this.formData);

								for (var k in this.newRowDefault) {
									formData_[k] = this.newRowDefault[k];
								}
								this.formData = formData_;
							}

							this.formAttr.title = "订单信息";
						}
					}
				},

				mounted() {
					let me = this;
					if (this.dataRequest.length) {
						var result = {};
						this.loadRequestData(this.dataRequest, result, function(data) {
							me.dataRequestObj = data;
							if (me.formFields.length) {
								var formFields_part_ = clone(me.formFields);
								formFields_part_.map(e => {
									if (e.field == "manager_part_code") {
										e.options = me.dataRequestObj.manager_part_code;
									} else if (e.field == "sales_type") {
										e.options = me.dataRequestObj.sales_type;
									} else if (e.field == "settle_type") {
										e.options = me.dataRequestObj.settle_type;
									} else if (e.field == "business_type") {
										e.options = me.dataRequestObj.business_type;

									} else if (e.field == "sales_business_type") {
										e.options = me.dataRequestObj.sales_business_type;
									} else if (e.field == "tax_rate") {
										e.options = me.dataRequestObj.tax_rate;
									} else if (e.field == "control_type") {
										e.options = me.dataRequestObj.control_type;

									}else if(e.field == "trans_type") {
										e.options = me.dataRequestObj.trans_type;
									}

								});

								me.formFields = formFields_part_;
							}
							//me.initData();
						});
					}


					if (this.popupParames.sceneCode != "add") {
						this.initData();
					}
					
					var urlParam = getGetParams(this.popupParames.url);
					
					for(let key in urlParam) {
						if(key == "fromDing") {
							this.fromDing = urlParam[key];
						}
					}
					if(this.popupParames.sceneCode != "browse")
						this.checkCustomerAndDelivery();
					this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
						document.getElementById('page_root').style.display = "block";
						document.getElementById('page_loading').style.display = "none";
						
						//重新设置弹窗宽高
						this.$nextTick(function() {
							let w_ = this.$refs.popup_body.offsetWidth + "px";
							let h_ = this.$refs.popup_body.offsetHeight + "px";
							Root.setPopupWH(w_, h_);
						})
					});
				},

				methods: {
					initFields() {
						let me = this;
						me.tableFields = clone(dataRootFields.tableFields.orderDetail_);
						me.formFields = clone(dataRootFields.formFields.order_);
						
						if (window.top.isdistributor) {
							me.formFields.filter(fieldObj_=>{
								if (fieldObj_.field == "settle_type" 
								|| fieldObj_.field == "business_depart_name" 
								|| fieldObj_.field == "sales_business_type" 
								|| fieldObj_.field == "sales_type" 
								|| fieldObj_.field == "business_type") {
									fieldObj_.isshow = "F"
								}
								
								if (fieldObj_.field == "customer_name") {
									fieldObj_.type = "input";
									fieldObj_.disabled = true;
								}
							})
							me.newRowDefault.customer_name = me.formData.customer_name = window.top.distributorObj.md_description;
							me.newRowDefault.customer_id = me.formData.customer_id = window.top.distributorObj.id;
							me.newRowDefault.customer_code = me.formData.customer_code = window.top.distributorObj.md_code;
							me.newRowDefault.customer_eas_code = me.formData.customer_eas_code = window.top.distributorObj.old_code;
							
						}
						
						if(this.popupParames.sceneCode != "add" && this.popupParames.sceneCode != "edit" && this.popupParames.data.status == "open") {
							me.tableFields = me.tableFields.filter(e=>{
								if(e.field == "delivery_cnts")
									e.isshow = "T"
								return true;
							})
							me.formFields = me.formFields.filter(e=>{
								if(e.field == "delivery_status") 
									e.isshow = "T"
								return true;
							})
						}
						/* if(this.popupParames.sceneCode == "add") {
							me.formFields = me.formFields.filter(e=>{
								if(e.field == "customer_code" || e.field == "customer_eas_code")
									e.isshow = "T"
								return true;
							})
						} */
					},

					initData() {
						let me = this;
						if (me.formData.contract_file_id) {
							let param = {
								dataname: "fileLog",
								filter: "id ='" + this.formData.contract_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,"contract_file_name",name);
									me.$set(me.formData,"contract_file_name_t",result1.data.entity.name);
									me.$set(me.formData,"contract_file_id",result1.data.entity.id);
								}
							});
						}
						
						if (me.formData.attachment_file_id) {
							let param = {
								dataname: "fileLog",
								filter: "id ='" + this.formData.attachment_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,"attachment_file_name",name);
									me.$set(me.formData,"attachment_file_name_t",result1.data.entity.name);
									me.$set(me.formData,"attachment_file_id",result1.data.entity.id);
								}
							});
						}
						if(me.formData.customer_code) {
							let filter_ = "customer_code = '" + this.formData.customer_code + "'"
							
							let param_customer = {
								isClientMode:false,
								dataname:"sales_agreement",
								filter:filter_
							}
							Server.call("root/data/getEntity",param_customer,function(result) {
								if(result && result.success && result.data.entity) {
									if(!me.formData.customer_id)
										me.$set(me.formData,'customer_id',result.data.entity.customer_id)
									if(!me.formData.customer_name)
										me.$set(me.formData,'customer_name',result.data.entity.customer_name)
									if(!me.formData.customer_eas_code)
										me.$set(me.formData,'customer_eas_code',result.data.entity.customer_eas_code)
									if(!me.formData.province_code)
										me.$set(me.formData,'province_code',result.data.entity.province_code)
									if(!me.formData.province_name)
										me.$set(me.formData,'province_name',result.data.entity.province_name)
								}
							})
						}
						me.formData.updatetime = this.updatetime;
						let filter_table = "1<>1";

						if (this.formData.id) {
							filter_table = "sales_order_detail.parent_id = '" + this.formData.id + "'";
						}
						let param_table = {
							isClientMode: false,
							dataname: this.dataname,
							filter: filter_table,
						}
						Server.call("root/data/getEntitySet", param_table, function(result) {
							console.log(result);
							if (result && result.data.entityset) {
								me.tableData2 = clone(result.data.entityset);
								me.setTableHeight();
								if(result.data.entityset.length > 0) {
									if (!me.formData.sales_type) {
										me.$set(me.formData,"sales_type",result.data.entityset[0].sales_type + "");
									  }
									  if (!me.formData.tax_rate) {
										me.$set(me.formData,"tax_rate",result.data.entityset[0].tax_rate);
									  }
								}
								for (var i = 0; i < result.data.entityset.length; i++) {
									
									me.tableData2[i].supply_price = result.data.entityset[i].product_price
									me.tableData2[i].standrad_cnt = me.routnFixed(result.data.entityset[i].cnt / (result.data.entityset[i].product_conversion_rate || 1), 4);
									let item = i;
									let url = window.top.RootSetting.url_stock + "order/getInventoryByVo";
									axios.post(url, {
											deliveryPartCode:me.formData.delivery_part_code,
											productCodeList:[result.data.entityset[i].product_code],
									}).then(data => {
										if (data.data.data) {
											if(data.data.data.length == 0|| data.data.data[0].count === null || data.data.data[0].count === undefined)
												me.$set(me.tableData2[item],"stock","无库存");
											else
												me.$set(me.tableData2[item],"stock",data.data.data[0].count);
										} else if (data.data.message == "success") {
											me.$set(me.tableData2[item],"stock","无库存");
										}
									}).catch((error) => {
										console.log(error);
									});
								}
								
							}
						});
						

					},
					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;
					},
					onServerInitData(data) {

					},
					clearData() {
						Root.confirm('确定清空所有数据吗?', '提示', {
							confirmButtonText: "确认",
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							let m = document.getElementById("cell");
							m.innerHTML = "";
							this.formData = {};
							this.tableData2 = [];
							this.address = [];
							this.addTableData();
							if (this.newRowDefault) {
								let formData_ = clone(this.formData);

								for (var k in this.newRowDefault) {
									formData_[k] = this.newRowDefault[k];
								}
								this.formData = formData_;
							}
						}).catch(() => {
							Root.message({
								type: 'info',
								message: '已取消'
							});
						});
					},
					closeDialog() {
						let me = this;
						if(this.popupParames.totab) {
							Root.tab.removeItem(Root.tab.selected);
							Root.tab.open(me.popupParames.parentOption, false);
						}else {
							Root.hidePopup();
						}
					},
					
					submitRowTable() {
						let me = this;
						if (!this.formData.customer_id) {
							Root.message({
								type: 'warning',
								message: '请先选择客户'
							});
							return;
						}
						this.dosubmitRowTable();
						
					},

					dosubmitRowTable() {
						let me = this;
						if(this.formData.has_gsp && this.expiredLicense) {
							Root.message({
								type: 'warning',
								message: '资质证照过期,无法提交'
							});
							return;
						}
						this.formData.continueCommit = true;
						if(this.formData.control_type == "1" && !this.formData.attachment_file_id) {
							Root.confirm('未上传付款凭证,是否继续?', '提示', {
								confirmButtonText: "确定",
								cancelButtonText: '取消',
								type: 'warning'
							}).then(() => {
								this.checkConcat();
							}).catch(()=>{
								Root.message({
									type: 'info',
									message: '已取消'
								});
							})
						}else {
							this.checkConcat();
						}
					},
					checkConcat() {
						let me = this;
						let param = {
							dataname:'customer_contact_status',
							filter : "customer_code = '" + this.formData.customer_code + "' and contact_status = 1"
						}
						Server.call("root/data/getEntitySet",param,function(result) {
							if(result.data && result.data.entityset && result.data.entityset.length) {
								Root.confirm('您选择的商业有订单在期限内未上传合同附件,是否继续?', '提示', {
									confirmButtonText: "确定",
									cancelButtonText: '取消',
									type: 'warning'
								}).then(() => {
									me.saveRowTable();
								}).catch(()=>{
									Root.message({
										type: 'info',
										message: '已取消'
									});
								})
							}else {
								me.saveRowTable();
							}
						})
					},
					saveRowTable() {
						let me = this;
						
						if (this.popupParames.sceneCode == "add" || this.popupParames.sceneCode == "edit") {
							if (!this.formData.manager_part_code || !this.formData.trans_type || !this.formData.delivery_part_name ||
								!this.formData.customer_name || !this.formData.customer_consignee_address || !this.formData.customer_consignee_user_name ||
								!this.formData.customer_consignee_phone || !this.formData.sales_type) {
								Root.message({
									type: 'warning',
									message: '请填写必填项'
								});
								return;
							}
							for (var i = 0; i < this.tableData2.length; i++) {
								if (this.tableData2[i].cnt == 0) {
									Root.message({
										type: 'warning',
										message: '请填写订单数量'
									});
									return;
								}

							}
							
						}
						if (this.formData.is_offline && !this.formData.contract_no) {
							Root.message({
								type: 'warning',
								message: '请填写合同号'
							});
							return;
						}
						if(!this.formData.is_offline && this.popupParames.sceneCode == "edit") {
							this.formData.contract_no = this.formData.code;
						}
						/* if (this.formData.rebate_amt > this.formData.amt * 0.2) {
							Root.message({
								type: 'warning',
								message: '返利金额大于总金额的20%'
							});
						} */
						var array_ = [];
						for (var i = 0; i < this.tableData2.length; i++) {
							var row = this.tableData2[i];
							var row_ = {};
							row_.id = row.id ? row.id : "";
							row_.count = row.cnt; //ä»¶æ•°
							row_.product_id = row.product_id;
							row_.rebateAmt = row.rebate_amt;
							row_.salesType = this.formData.sales_type + "", //销售类型。。正常销售
							row_.taxRate = this.formData.tax_rate; //税率
							row_.agreementRecordId = row.agreement_record_id ? row.agreement_record_id : ""; //协议id  row.agreementRecordId
							
							var remark_ = "";
							if (row.remark) {
								remark_ = row.remark;
								//去除两端的空格
								remark_ = remark_.replace(/(^\s*)|(\s*$)/g, "");
								
								//将所有空格改成中文逗号;
								remark_ = remark_.replace(/\s/g,",");
							}
							row_.remark = remark_;
							
							if (row_.agreementRecordId != "") {
								array_.push(row_);
							}
						}
						let address = ""
						if(this.formData.customer_consignee_address) {
							if(this.formData.customer_consignee_address.indexOf("?:?") > -1) 
								address = this.formData.customer_consignee_address.substring(0,this.formData.customer_consignee_address.indexOf("?:?"));
							else
								address = this.formData.customer_consignee_address;
						}
						
						var formData_remark = ""
						if (this.formData.remark) {
							formData_remark = this.formData.remark;
							//去除两端的空格
							formData_remark = formData_remark.replace(/(^\s*)|(\s*$)/g, "");
							
							//将所有空格改成中文逗号;
							formData_remark = formData_remark.replace(/\s/g,",");
							
						}
						
						if (this.formData.continueCommit && (this.formData.status == "input" || !this.formData.status)) {
							if(this.formData.r_business_type == "2"){
								formData_remark = "【非直管】" + formData_remark
							}
							else {
								formData_remark = "【直管】" + formData_remark
							} 
							
						} 
						let param = {
							isClientMode: false,
							departSalesType: this.formData.depart_sales_type,
							departRevoType: this.formData.depart_revo_type,
							id: this.formData.id ? this.formData.id : "",
							code: this.formData.code || "",
							customerId: this.formData.customer_id,
							bizDate: this.formData.biz_date,
							salesType: this.formData.sales_type + "",
							transType: this.formData.trans_type,
							rBusinessType: this.formData.r_business_type, //商业属性:直管/非直管
							rDepartType: this.formData.r_depart_type,
							settleType: this.formData.settle_type,
							salesBusinessType: this.formData.sales_business_type,
							agreementRecordId: this.formData.agreementRecordId ? this.formData.agreementRecordId : "", //this.formData.agreementRecordId,	//协议id
							contractNo: this.formData.contract_no ? this.formData.contract_no : "",
							contractFileId: this.formData.contract_file_id || "",
							attachmentFileId: this.formData.attachment_file_id || "",
							empDepartId: this.formData.emp_depart_id || "",
							empDepartCode: this.formData.emp_depart_code || "",
							empDepartName: this.formData.emp_depart_name || "",
							taxRate: this.formData.tax_rate,
							isOffline: this.formData.is_offline,
							bookNo:this.formData.book_no || "",
							subSalesOrderList: array_,
							remark: formData_remark,
							oAgreementRecordId: this.tableData2[0].agreement_record_id,
							//customerEasCode:this.formData.customer_eas_code ||"",
							proxyOrder:false,
							customerConsignee: { //收货信息
								id: this.formData.customer_consignee_id, //this.formData.addressid,
								userName: this.formData.customer_consignee_user_name,
								address: address,
								phone: this.formData.customer_consignee_phone,
							},
						}
						if(this.formData.recall) {
							param.status = "input"
						}
						
						me.isLoading = true;
						//return
						Server.call("root/order/saveSalesOrder", param, function(result) {
							console.log(result);
							if (result.success) {
								//document.getElementById('page_loading').style.display = "block";
								if (me.formData.continueCommit) {
									me.formData.continueCommit = false;
									me.isOverdueM(result.data.id,me.formData.customer_code, me.formData.delivery_part_code,function(form_c, act_c){
										if (me.formData.is_offline === "1" || me.formData.is_offline === true) {
											if (!me.formData.contract_file_id) { //线下合同但没有上传合同的
												Root.confirm('该客户没有上传线下合同,确定直接提交吗?', '提示', {
													confirmButtonText: "提交",
													cancelButtonText: '取消',
													type: 'warning'
												}).then(() => {
													let param_ = {
														orderId: result.data.id,
														eventType: "commit",
														dataType: "sales",
														extra: {
															variableMap: {
																businessType: me.formData.business_type,
																businessDepartType: me.formData.depart_sales_type,
																controlType: me.formData.control_type,
																managerPartCode:me.formData.manager_part_code,
																isOverDue: act_c,
																offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
																agreementRecordId:me.tableData2[0].agreement_record_id,
																flowId:me.formData.flow_id || ""
															},
														},
													}
														
													Server.call("root/order/onEvent", param_, function(result_) {
														console.log(result_);
														if (result_.success) {
															Root.message({
																type: 'success',
																message: '提交成功'
															});
															//document.getElementById('page_loading').style.display = "none";
															Root.tab.removeItem(Root.tab.selected);
															Root.tab.open(me.popupParames.parentOption, true);
														}
													}, function(result_) {
														//document.getElementById('page_loading').style.display = "none";
														Root.confirm(result_.message + ',确定直接提交吗?', '提示', {
															confirmButtonText: "提交",
															cancelButtonText: '取消',
															type: 'warning'
														}).then(() => {
															//document.getElementById('page_loading').style.display = "block";
															let param = {
																orderId: result.data.id,
																eventType: "commit",
																dataType: 'sales',
																isClientMode: false,
																extra: {
																	mandatory: true,
																	variableMap: {
																		businessType: me.formData.business_type,
																		businessDepartType: me.formData.depart_sales_type,
																		controlType: me.formData.control_type,
																		managerPartCode: me.formData.manager_part_code,
																		agreementRecordId:me.tableData2[0].agreement_record_id,
																		isOverDue: act_c,
																		offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
																	},
																},
															}
															Server.call("root/order/onEvent", param, function(result) {
																console.log(result);
																if (result.success) {
																	Root.message({
																		type: 'success',
																		message: '提交成功'
																	});
																	//document.getElementById('page_loading').style.display = "none";
																	Root.tab.removeItem(Root.tab.selected);
																	Root.tab.open(me.popupParames.parentOption, true);
																}
															}, function(result) {
																Root.message({
																	type: 'warning',
																	message: '提交失败,请在销售订单页面重新提交'
																});
																document.getElementById('page_loading').style.display = "none";
																Root.tab.removeItem(Root.tab.selected);
																Root.tab.open(me.popupParames.parentOption, true);
															});
													
														}).catch(() => {
															me.isLoading = false;
															Root.message({
																type: 'info',
																message: '已取消'
															});
														});
													});
												}).catch(() => {
													me.isLoading = false;
													Root.message({
														type: 'info',
														message: '已取消'
													});
												});
											}
											else {
												let param_ = {
													orderId: result.data.id,
													eventType: "commit",
													dataType: "sales",
													extra: {
														variableMap: {
															businessType: me.formData.business_type,
															businessDepartType: me.formData.depart_sales_type,
															controlType: me.formData.control_type,
															managerPartCode: me.formData.manager_part_code,
															isOverDue: act_c,
															offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
															agreementRecordId:me.tableData2[0].agreement_record_id,
															flowId:me.formData.flow_id || ""
														},
													},
												}
												Server.call("root/order/onEvent", param_, function(result_) {
													console.log(result_);
													if (result_.success) {
														Root.message({
															type: 'success',
															message: '提交成功'
														});
														//document.getElementById('page_loading').style.display = "none";
														Root.tab.removeItem(Root.tab.selected);
														Root.tab.open(me.popupParames.parentOption, true);
													}
												}, function(result_) {
													//document.getElementById('page_loading').style.display = "none";
													Root.confirm(result_.message + ',确定直接提交吗?', '提示', {
														confirmButtonText: "提交",
														cancelButtonText: '取消',
														type: 'warning'
													}).then(() => {
														//document.getElementById('page_loading').style.display = "block";
														let param = {
															orderId: result.data.id,
															eventType: "commit",
															dataType: 'sales',
															isClientMode: false,
															extra: {
																mandatory: true,
																variableMap: {
																	businessType: me.formData.business_type,
																	businessDepartType: me.formData.depart_sales_type,
																	controlType: me.formData.control_type,
																	managerPartCode: me.formData.manager_part_code,
																	agreementRecordId:me.tableData2[0].agreement_record_id,
																	isOverDue: act_c,
																	offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
																},
															},
														}
														Server.call("root/order/onEvent", param, function(result) {
															console.log(result);
															if (result.success) {
																Root.message({
																	type: 'success',
																	message: '提交成功'
																});
																//document.getElementById('page_loading').style.display = "none";
																Root.tab.removeItem(Root.tab.selected);
																Root.tab.open(me.popupParames.parentOption, true);
															}
														}, function(result) {
															Root.message({
																type: 'warning',
																message: '提交失败,请在销售订单页面重新提交'
															});
															document.getElementById('page_loading').style.display = "none";
															Root.tab.removeItem(Root.tab.selected);
															Root.tab.open(me.popupParames.parentOption, true);
														});
													}).catch(() => {
														me.isLoading = false;
														Root.message({
															type: 'info',
															message: '已取消'
														});
													});
												});
											}
										} 
										//else if (me.formData.is_offline === "0" || me.formData.is_offline === false) {
										else {
											/* if (!me.formData.attachment_file_id) { //线上合同但没有上传预付款附件
												Root.confirm('该客户没有上传预付款附件,确定直接提交吗?', '提示', {
													confirmButtonText: "提交",
													cancelButtonText: '取消',
													type: 'warning'
												}).then(() => {}).catch(() => {
													me.isLoading = false;
													Root.message({
														type: 'info',
														message: '已取消'
													});
												});
											} */
											
											let param_ = {
												orderId: result.data.id,
												eventType: "commit",
												dataType: "sales",
												extra: {
													variableMap: {
														businessType: me.formData.business_type,
														businessDepartType: me.formData.depart_sales_type,
														controlType: me.formData.control_type,
														managerPartCode: me.formData.manager_part_code,
														isOverDue: act_c,
														offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
														agreementRecordId:me.tableData2[0].agreement_record_id,
														flowId:me.formData.flow_id || ""
													},
												},
											}
											Server.call("root/order/onEvent", param_, function(result_) {
												console.log(result_);
												if (result_.success) {
													Root.message({
														type: 'success',
														message: '提交成功'
													});
													//document.getElementById('page_loading').style.display = "none";
													Root.tab.removeItem(Root.tab.selected);
													Root.tab.open(me.popupParames.parentOption, true);
												}
											}, function(result_) {
												//document.getElementById('page_loading').style.display = "none";
												Root.confirm(result_.message + ',确定直接提交吗?', '提示', {
													confirmButtonText: "提交",
													cancelButtonText: '取消',
													type: 'warning'
												}).then(() => {
													//document.getElementById('page_loading').style.display = "block";
													let param = {
														orderId: result.data.id,
														eventType: "commit",
														dataType: 'sales',
														isClientMode: false,
														extra: {
															mandatory: true,
															variableMap: {
																businessType: me.formData.business_type,
																businessDepartType: me.formData.depart_sales_type,
																controlType: me.formData.control_type,
																managerPartCode: me.formData.manager_part_code,
																agreementRecordId:me.tableData2[0].agreement_record_id,
																isOverDue: act_c,
																offline: (me.formData.is_offline === "1" || me.formData.is_offline === true) ? "xianxia" : "xianshang",//xx:线下,xs:线上
															},
														},
													}
													Server.call("root/order/onEvent", param, function(result) {
														console.log(result);
														if (result.success) {
															Root.message({
																type: 'success',
																message: '提交成功'
															});
															//document.getElementById('page_loading').style.display = "none";
															Root.tab.removeItem(Root.tab.selected);
															Root.tab.open(me.popupParames.parentOption, true);
														}
													}, function(result) {
														Root.message({
															type: 'warning',
															message: '提交失败,请在销售订单页面重新提交'
														});
														document.getElementById('page_loading').style.display = "none";
														Root.tab.removeItem(Root.tab.selected);
														Root.tab.open(me.popupParames.parentOption, true);
													});
											
												}).catch(() => {
													me.isLoading = false;
													Root.message({
														type: 'info',
														message: '已取消'
													});
												});
											});
											
										}
										
										
									});//校验结束
								} else {
									if (me.popupParames.sceneCode != "approval") {
										Root.message({
											type: 'success',
											message: '保存成功'
										});
									}
									Root.tab.removeItem(Root.tab.selected);
									Root.tab.open(me.popupParames.parentOption, true);
								}

							} else {
								me.isLoading = false;
								Root.message({
									type: 'warning',
									message: result.message
								});
							}

						},function(result){
							me.isLoading = false;
							Root.message({
								type: 'warning',
								message: result.message
							}); 
						});
					},

					showCredit(code, row) {
						let me = this;
						if (me.formData.customername) {
							Root.popupParames = {
								url: "../tool/credit_status.html",
							};
							Root.showPopup(Root.popupParames);
						} else {
							Root.message({
								type: 'warning',
								message: '请先选择客户'
							});
						}
					},

					isOverdueM(so_id, customer_code, delivery_part_code, callback) {
						let me = this;
						
						if (!so_id || !customer_code || !delivery_part_code) {
							return
						}
						let param_1 = {
							isClientMode: false,
							ajaxtype: "get",
							
							// dataname: "getRemitOrderByCode",//超过90天
						 //    cus_code: "'" + customer_code + "'",
							// del_code: "'" + delivery_part_code + "'"
						}
						console.log("超账期校验开始:");
						// tps://csec.jemincare.com/japi/order/getRemitInfo/03838de65426441ca5b1101b79a835b2
						Server.call("stock/order/getRemitInfo/" + so_id, param_1, function(result) {
							console.log("超账期校验:", result);
							if (result.success) {
								if (result.data && result.data.length > 0) {
									var day0 = true;
									var day90 = false;
									var day45 = false;
									
									result.data.map(d=>{
										if (d.rows == 1) { //>90
											day90 = true;
										}
										else if (d.rows == 2) { //>45
											day45 = true;
										}
									})
									
									if (day90 || day45) {
										me.$set(me.formData,"overdue","超账期")
										me.$set(me.formData,"iscreditsuccess","0")
										me.$set(me.formData,"isOverDue",true)
										
										me.isOverDue_dialog = true;
										me.overDueList = result.data;
										if (callback) {
											callback(true, true);
										}
									}
									else {
										me.$set(me.formData,"overdue","超账期")
										me.$set(me.formData,"iscreditsuccess","0")
										me.$set(me.formData,"isOverDue",false)
										
										if (callback) {
											callback(true, false);
										}
										
									}
								}
								else{
									me.$set(me.formData,"overdue","未超账期")
									me.$set(me.formData,"iscreditsuccess","1")
									me.$set(me.formData,"isOverDue",false)
									if (callback) {
										callback(false, false);
									}
								}
							}
						});
					},

					isOverdueM2(so_id, customer_code, delivery_part_code, callback) {
						let me = this;
						
						if (!so_id || !customer_code || !delivery_part_code) {
							return
						}
						let param_1 = {
							isClientMode: false,
							dataname: "getRemitOrderByCode",//超过90天
						    cus_code: "'" + customer_code + "'",
							del_code: "'" + delivery_part_code + "'"
						}
						Server.call("root/data/getEntitySet", param_1, function(result) {
							if (result.success) {
								if (result.data && result.data.entityset && result.data.entityset.length > 0) {
									me.$set(me.formData,"overdue","超账期")
									me.$set(me.formData,"iscreditsuccess","0")
									me.$set(me.formData,"isOverDue",true)
									
									me.isOverDue_dialog = true;
									me.overDueList = result.data.entityset;
									if (callback) {
										callback(true, true);
									}
								} else {
									let param_2 = {
										isClientMode: false,
										dataname: "getRemitOrderById",//45-90天
										so_id: "'" + so_id + "'",
										dur_day: "v.dur_day > 44 and v.dur_day < 90"
									}
									Server.call("root/data/getEntitySet", param_2, function(result2) {
										if (result2.data.entityset.length > 0) {
											me.$set(me.formData,"overdue","超账期")
											me.$set(me.formData,"iscreditsuccess","0")
											me.$set(me.formData,"isOverDue",true)
											
											me.isOverDue_dialog = true;
											me.overDueList = result2.data.entityset;
											if (callback) {
												callback(true, true);
											}
										} 
										else {
											let param_3 = {
												isClientMode: false,
												dataname: "getRemitOrderById",//不超过45天(其余天数)
												so_id: "'" + so_id + "'",
												dur_day: "1=1"
											}
											Server.call("root/data/getEntitySet", param_3, function(result3) {
												if (result3.data.entityset.length > 0) {
													me.$set(me.formData,"overdue","超账期")
													me.$set(me.formData,"iscreditsuccess","0")
													me.$set(me.formData,"isOverDue",false)
													
													//me.isOverDue_dialog = true;
													//me.overDueList = result3.data.entityset;
													if (callback) {
														callback(true, false);
													}
												}
												else{
													me.$set(me.formData,"overdue","未超账期")
													me.$set(me.formData,"iscreditsuccess","1")
													me.$set(me.formData,"isOverDue",false)
													if (callback) {
														callback(false, false);
													}
												}
											})
										}
									});
								}
								
								
							}
						});
					},
					
					getIsOffline(customer_code, delivery_part_code){
						let me = this;
						if (!customer_code || !delivery_part_code) {
							return
						}
						let param_ = {
							isClientMode: false,
							dataname: "customerSignatureMapping",
							filter: "1 = 1 and (customer_code = '" + customer_code + "' or customer_name = '" + delivery_part_code + "')",
						}
						Server.call("root/data/getEntity", param_, function(result) {
							if (result && result.data.entity) {
								if (result.data.entity.has_signature && (!me.formData.business_type || me.formData.business_type == "1")) {
									me.$set(me.formData,"is_offline",false)
									me.$set(me.formData,"offline","线上合同")
								}
								else{
									me.$set(me.formData,"is_offline",true)
									me.$set(me.formData,"offline","线下合同")
								}
							} else {
								me.$set(me.formData,"is_offline",true)
								me.$set(me.formData,"offline","线下合同")
							}
							me.formFields = me.formFields.filter(e=>{
								if(e.field == "contract_no" || e.field == "contract_file_name") {
									if(me.formData.is_offline) {
										e.disabled = false;
									}else
										e.disabled = true;
								}
								return true;
							})
						});
					},
					
					getAccountsPayable(customerCode) {
						let me = this;
						let param = {
							isClientMode:false,
							filter: "customer_code = '" + customerCode + "'",
							dataname:"v_cope_order"
						}
						Server.call("root/data/getEntity", param, function(result) {
							
							if(result && result.data.entity && result.data.entity.dod_amt) {
								if(!result.data.entity.rod_amt) {
									me.cellInnerText = me.cellInnerText + result.data.entity.dod_amt;
								}else
									me.cellInnerText = me.cellInnerText + (result.data.entity.dod_amt - result.data.entity.rod_amt);
							}else
								me.cellInnerText = me.cellInnerText + 0;
							me.isshowCell = true;
						});
					},

					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.setTableHeight();
						} else if (type == "del") {
							
							this.tableData2.remove(row);
							if (this.tableData2.length == 0) {
								let formData_ = clone(this.formData);
								formData_.settle_type = "";
								formData_.operate_emp_name = "";
								formData_.control_type = "";
								formData_.business_type = "";
								formData_.emp_depart_name = "";
								this.formData = formData_;
							}
						}

						var sum_noRate_ = 0;
						var rebate_amt = 0;
						var formData_ = clone(this.formData);
						this.tableData2.map(e => {
							sum_noRate_ += (e.product_amt || 0) * 1;
							rebate_amt += (e.rebate_amt || 0) * 1;
						})

						formData_.rebate_amt = rebate_amt;
						formData_.amt = sum_noRate_ == 0 ? 0 : this.routnFixed(sum_noRate_ - rebate_amt, 2);

						this.formData = formData_;
						/* this.isRefresh = false;
						this.$nextTick(function(){ */
						this.isRefresh = true;
						//})
					},

					addTableData() {
						
						if (this.selectrow != {}) {
							this.selectrow.isWithinEdit = false;
						}


						var row_ = {
							isWithinEdit: true,
							rebate_amt: 0
						};

						for (var i = 0; i < this.tableFields.length; i++) {
							let field_ = this.tableFields[i].field;

							if (field_ == "parent_id") {
								row_[field_] = this.formData.id;
							} else {
								row_[field_] = "";
							}
						}
						this.selectrow = row_;
						this.rowChange(row_, "add");
					},

					rowClick(obj) {
						/* if (this.popupParames.sceneCode != "approval" && this.popupParames.sceneCode != "browse") {
							if (this.selectrow != {}) {
								this.selectrow.isWithinEdit = false;
							}
							this.selectrow = obj.row;
							obj.row.isWithinEdit = obj.row.isWithinEdit ? false : true;
						} */
					},
					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;
							scope.row.isWithinEdit = scope.row.isWithinEdit ? false : true;
						}

						this.isRefresh = false;
						this.$nextTick(function() {
							this.isRefresh = true;
						})
					},
					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);
					},
					cellShowPopup(scope) {
						/* var is_default_popup_filter = false;
						var default_popup_filter = {};
						if (this.tableData2.length == 1) {
							is_default_popup_filter = true;
						} */
						if (!this.formData.customer_name) {
							Root.message({
								message: '请选择客户'
							});
							return;
						}
						let me = this;
						let row = scope.row;
						let field = scope.column.property;
						if (field == "product_name") {
							this.getFormData(row, true);
						}
					},

					cellInputChange(scope) {
						let row = scope.row;
						let field = scope.column.property;
						if (field == "cnt") {
							if (row.cnt == 0) {
								Root.message({
									type: 'warning',
									message: '数量不能为0'
								});
								row.cnt = row.product_conversion_rate;
								return;
							}
							
							row.product_amt = this.routnFixed(((row.cnt ? row.cnt : 0) * (row.supply_price ? row.supply_price : 0)), 2);
							row.tax_amt = this.routnFixed(row.product_amt * 1, 2);
							//row.standrad_cnt = (row.cnt / (row.product_conversion_rate || 1)).toFixed(4);
							row.standrad_cnt = this.routnFixed(row.cnt / (row.product_conversion_rate || 1), 4);
							// if(row.standrad_cnt % 1 != 0){
							// 	Root.message({
							// 		type: 'warning',
							// 		message: '件数不为整数'
							// 	});
							// }
						}
						if (field == "rebate_amt") {
							if (row.rebate_amt > row.product_amt) {
								row.rebate_amt = "0";
								Root.message({
									type: 'warning',
									message: '返利金额大于金额'
								});
							}
							if(this.formData.business_depart_name.indexOf("OTC") == 0) {
								if (row.rebate_amt > this.formData.available_amt || (this.formData.rebate_amt + row.rebate_amt > this.formData.available_amt)) {
									Root.message({
										type: 'warning',
										message: '超过可用折扣'
									});
									row.rebate_amt = 0;
								}
							}
						}

						this.rowChange(row, "up");
					},

					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 == undefined || row.id == '') {
								me.rowChange(row, "del");
							} else {
								let param = {
									id: row.id
								}
								Server.call("root/data/deleteEntity" + "/" + me.dataname, param, function(result) {
									me.rowChange(row, "del");
								});
							}
							Root.message({
								type: 'success',
								message: '删除成功!'
							});
						}).catch(() => {

							Root.message({
								type: 'info',
								message: '已取消删除'
							});
						});
					},
					getFormData(row, is_default_popup_filter) {
						let me = this;
						var filterobj_ = {};

						let filter_ = "and agreement_record.customer_id is not null and flows.status = 'open'";
						//管理主体名称			
						if (me.formData.manager_part_code) {
							//filter_ += " and mdi.code = '" + me.formData.manager_part_code + "'";
							filterobj_.manager_part_code = me.formData.manager_part_code;
						}
						//发货主体
						if (me.formData.delivery_part_code) {
							//filter_ += " and agreement_record.delivery_part_code = '" + me.formData.delivery_part_code + "'"
							filterobj_.delivery_part_name = me.formData.delivery_part_name;
							filterobj_.delivery_part_code = me.formData.delivery_part_code;
							
						}
						//客户名称
						if (me.formData.customer_id) {
							filter_ += " and agreement_record.customer_id = '" + me.formData.customer_id + "'"
							//filterobj_.customer_id = me.formData.customer_id;
						}
						//区域
						if (me.formData.province_name) {
							//filter_ += " and agreement_record.province_code = '" + me.formData.province_code + "'"
							filterobj_.province_name = me.formData.province_name;
							filterobj_.province_code = me.formData.province_code;
						}
						//业务部门
						if (me.formData.business_depart_name) {
							//filter_ += " and agreement_record.business_depart_id = '" + me.formData.business_depart_id + "'"
							filterobj_.business_depart_name = me.formData.business_depart_name;
							filterobj_.business_depart_id = me.formData.business_depart_id;
						}
						//结算类型
						if (me.formData.settle_type) {
							//filter_ += " and agreement_record.settle_type = '" + me.formData.settle_type + "'"
							filterobj_.settle_type = me.formData.settle_type;
						}
						//商业类型
						if (me.formData.business_type) {
							//filter_ += " and agreement_record.business_type = '" + me.formData.business_type + "'"
							filterobj_.business_type = me.formData.business_type;
						}
						//业务员
						if (me.formData.operate_emp_name) {
							//filter_ += " and v_employee.md_description = '" + me.formData.operate_emp_name + "'"
							filterobj_.operate_emp_name = me.formData.operate_emp_name;
						}
						if (this.popupParames.sceneCode == "add") {
							//已选中的不可再次被选中
							var array_1 = "";
							for (var i = 0; i < this.tableData2.length; i++) {
								if (this.tableData2[i].agreement_record_id) {
									if (this.tableData2[i].agreement_record_id != this.selectrow.agreement_record_id)
										array_1 += "'" + this.tableData2[i].agreement_record_id + "',";
								}
							}
							if (array_1 != "") {
								array_1 = array_1.slice(0, array_1.length - 1)
								filter_ += " and agreement_record.id not in (" + array_1 + ")"
							}
						}
						//业务类型
						if (me.formData.sales_business_type) {
							filter_ += "";
						}
						Root.showPopup({
							url: "../md/product/popup/product_list.html",
							width: 1100,
							height: 550,
							filterobj: filterobj_,
							isdefaultfilter: is_default_popup_filter,
							filter: filter_,
							dataname: "salesAgreement", //salesAgreement
							type: "sorder",
							callback: function(obj, callback) {
								row.product_name = obj.row.product_name
								row.product_id = obj.row.id
								row.product_code = obj.row.product_code
								row.product_spec = obj.row.pack
								row.supply_price = obj.row.supply_price
								//row.standrad_cnt = row.trans_rate*obj.row.trans_rate
								row.product_unit = obj.row.product_unit
								
								row.settle_type = obj.row.settle_type
								row.taxrate = obj.row.taxrate
								row.product_conversion_rate = obj.row.product_conversion_rate
								row.agreement_record_id = obj.row.id
								row.cnt = 0;
								row.standrad_cnt = 0;
								let formData_ = clone(me.formData);
								formData_.tax_rate = obj.row.default_tax_rate?obj.row.default_tax_rate+"":"13"
								if(me.tableData2.length > 1) {
									if(formData_.control_type != obj.row.control_type + "") {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.settle_type != obj.row.settle_type) {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.province_code != obj.row.province_code) {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.delivery_part_code != obj.row.delivery_part_code) {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.delivery_part_code != obj.row.delivery_part_code) {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.business_depart_id != obj.row.business_depart_id) {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
									if(formData_.business_type != obj.row.business_type + "") {
										me.tableData2 = [];
										me.tableData2.push(row)
									}
										
								}
								formData_.control_type = obj.row.control_type + "";
								formData_.settle_type = obj.row.settle_type
								formData_.province_name = obj.row.province_name
								formData_.province_code = obj.row.province_code;
								formData_.has_gsp = obj.row.has_gsp;
								formData_.business_depart_name = obj.row.business_depart_name
								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_.business_type = obj.row.business_type + ""
								formData_.r_business_type = obj.row.business_type
								if(formData_.business_type == "2") {
									me.formFields = me.formFields.filter(e=>{
										formData_.is_offline=true
										formData_.offline="线下合同"
										if(e.field == "contract_no" || e.field == "contract_file_name") {
											if(formData_.is_offline) {
												e.disabled = false;
											}else
												e.disabled = true;
										}
										return true;
									})
								}else {
									me.getIsOffline(formData_.customer_code, formData_.delivery_part_code);
								}
								formData_.r_depart_type = obj.row.depart_type
								formData_.depart_sales_type = obj.row.s_depart_sales_type
								formData_.depart_revo_type = obj.row.s_depart_revo_type
								formData_.operate_emp_name = obj.row.operate_emp_name;
								formData_.tax_amt = 0;
								formData_.emp_depart_name = obj.row.emp_depart_name;
								
								let url = window.top.RootSetting.url_stock + "order/getInventoryByVo";
								axios.post(url, {
											deliveryPartCode:formData_.delivery_part_code,
											productCodeList:[row.product_code],
									}
									)
									.then(data => {
										if (data.data.data) {
											if(data.data.data.length == 0|| data.data.data[0].count === null || data.data.data[0].count === undefined)
												row.stock = "无库存";
											else
												row.stock = data.data.data[0].count;
										} else if (data.data.message == "success") {
											row.stock = "无库存";
										}
									})
									.catch((error) => {
										console.log(error);
									});
									
								let hierarchy_code = localStorage.getItem("hierarchy_code");
								if (hierarchy_code == "202104200018") {
									formData_.emp_depart_id = "40671f0a72e84d8c97aa385e4e07caea";
									formData_.emp_depart_code = "202009290552";
									formData_.emp_depart_name = "招商管理部";
								}
								if (obj.row.book_no) {
									formData_.book_no = obj.row.book_no;
									/* axios.post(window.top.RootSetting.url_stock + "order/checkLicence", {
											customerId: formData_.customer_id || "",
											bookNo: obj.row.book_no,
										})
										.then(data => {
											for (var i = 0; i < data.data.data.consigneeList; i++) {
												formData_.customer_consignee_address.push(data.data.data.consigneeList[i].address)
											} */
											/* formData_.customer_consignee_address = data.data.data.consigneeList[0].address;
											formData_.customer_consignee_user_name = data.data.data.consigneeList[0].empName;
											formData_.customer_consignee_phone = data.data.data.consigneeList[0].empTel; */
										/* })
										.catch((error) => {
											console.log(error);
										}); */
								}else{
									formData_.book_no = "";
								}
								formData_.manager_part_code = obj.row.manager_part_code;
								/* if(obj.row.manager_part_code == "CFY"){
									formData_.manager_part_code = "处方药"
								}else {
									formData_.manager_part_code = obj.row.manager_part_code
								} */
								me.formData = formData_;
								/* if(!obj.row.has_gsp) {
									me.$set(me.formData,"customer_consignee_address","")
									me.formFields = me.formFields.filter(e=>{
										if(e.field == "customer_consignee_address") {
											e.type = "input";
										}
										return true;
									})
									
									if(callback) 
										callback()
								}else {
									me.$set(me.formData,"customer_consignee_address","")
									me.formFields = me.formFields.filter(e=>{
										if(e.field == "customer_consignee_address") {
											e.type = "select";
										}
										return true;
									}) */
									me.checkCustomerAndDelivery(callback);
								//} 
								
								
							}
						});
					},

					Getfilter(filter_, filter) {

						let me = this;
						//管理主体名称			
						if (me.formData.manager_part_code) {

							filter_ += " and manager_part_code = '" + me.formData.manager_part_code + "'"
						}
						//发货主体
						if (me.formData.delivery_part_code && filter != "delivery_part_name") {
							filter_ += " and delivery_part_code = '" + me.formData.delivery_part_code + "'"
						}
						//客户名称
						if (me.formData.customer_id && filter != "customer_name") {
							filter_ += " and customer_id = '" + me.formData.customer_id + "'"
						}
						//区域
						if (me.formData.province_name && filter != "province_name") {
							filter_ += " and province_code = '" + me.formData.province_code + "'"
						}
						//业务部门
						if (me.formData.business_depart_name && filter != "business_depart_name") {
							filter_ += " and business_depart_id = '" + me.formData.business_depart_id + "'"
						}
						//商业属性
						if (me.formData.business_type) {
							filter_ += " and business_type = '" + me.formData.business_type + "'"
						}

						return filter_
					},
					onseal() {
						let me = this;
						let row = this.formData;
						//me.dataname: salesOrderDetail
						let url = "../sorder/signature.html?id=" + this.formData.id + "&delta=" + me.dataname + "&userid=" + window.top.userinfo.user.id;
						let post_url = window.top.RootSetting.url.slice(0,-8)
						let param = {
							data: row,
							delta: me.dataname,
						}
						let win1= window.open(url,'a')
						//win1.postMessage(param,"*");
					},
					
					/* onseal() {
						this.operationtype = "approval";

						//2. get config and go
						var config = new Config(),
						
							go = true;
						if (this.onApproveData) {
							go = this.onApproveData.call(this, config);
						}
						//3. popup
						if (go) {
							if (config.totab) {
								if (config.url) {
									if (config.text.length > 4) {
										config.text = config.text.substr(0, 4) + "...";
									}
								}
								var parames = {
									url: config.url,
									
									sceneCode: config.sceneCode,
									data: config.data,
									id:config.id,
									delta: config.delta,
									disabled: config.disabled,
									disabledone: config.disabledone,
									operationtype: "approval",
									parentOption: window.top.tab.selected.option
								};

								Root.popupParames = parames;
								window.top.tab.open(config,true);
							} else {
								this.doPopup(config);
							}
						}
					}, */
					/* onApproveData(config) {
						var me = this;
						var row = this.formData;

						//3. popup
						config.combine({

							totab: true,
							icon: "icon-product",
							text: "ç›–ç« ",
							id: "sorder_edit_approval1",
							url: "../order/sorder/signature.html",
							sceneCode: "approval",

							data: row,
							delta: me.dataname,

						});
						return true;

					}, */
					onpassApproval() {
						var me = this;
						this.textarea2 = "";
						
						if (this.seal) {//需盖章
							//校验盖章数量
							let param = {
								dataname:'order_signature_cnt',
								filter : "id = '" + this.formData.id + "' and type = 'sales'"
							}
							Server.call("root/data/getEntitySet",param,function(result) {
								var cnt = 0;
								if(result.data && result.data.entityset && result.data.entityset.length ) {
									cnt = result.data.entityset[0].cnt * 1;
									if (cnt == 2) {
										me.reasonvisible = true;
										me.passOrRefuse = true;
									}
									else if (cnt < 2) {
										Root.message({
											type: 'warning',
											message: '仅盖章' + result.data.entityset[0].cnt + '个' 
										});    
									}
									else if (cnt > 2) {
										Root.message({
											type: 'warning',
											message: '已盖章' + result.data.entityset[0].cnt + '个,超过2个' 
										});    
									}
								}else {
									Root.message({
										type: 'warning',
										message: '没有盖章'
									});     
								}
								/* 
								if (cnt > 0) {
									Root.confirm('检测已盖章数' + cnt + '个,确定已经盖章完成了吗?', '提示', {
									  confirmButtonText: "确定",
									  cancelButtonText: '取消',
									  type: 'warning'
									}).then(() => {
										me.reasonvisible = true;
										me.passOrRefuse = true;
									}).catch(() => {
										Root.message({
											type: 'info',
											message: '已取消'
										});          
									});
								}
								else {
									Root.confirm('未检测到盖章数,确定已经盖章完成了吗?', '提示', {
									  confirmButtonText: "确定",
									  cancelButtonText: '取消',
									  type: 'warning'
									}).then(() => {
										me.reasonvisible = true;
										me.passOrRefuse = true;
									}).catch(() => {
										Root.message({
											type: 'info',
											message: '已取消'
										});          
									});
								} */
							})
						}
						else {
							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) {
							let me = this;
							let param = {
								dataname:'customer_contact_status',
								filter : "customer_code = '" + this.formData.customer_code + "' and contact_status = 1"
							}
							Server.call("root/data/getEntitySet",param,function(result) {
								if(result.data && result.data.entityset && result.data.entityset.length) {
									me.passApproval('sales', me.textarea2,{},true);
								}else {
									me.passApproval('sales', me.textarea2,{},false);
								}
							})
							
						} else {
							if (this.textarea2 != "") {
								this.refuseApproval('sales', this.textarea2)
							} else {
								Root.message({
									type: 'warning',
									message: '请填写原因'
								});
								document.getElementById('page_loading').style.display = "none";
							}
						}

						//document.getElementById('page_loading').style.display =  "none";
					},
					passApproval(dataType_,reason_,param_,isCon) {
						let me = this;
						var id = this.formData.id;
						let isOverDue_ = true;
						if(typeof this.formData.isOverDue == "boolean")
							isOverDue_ = this.formData.isOverDue;
						if(!isOverDue_) {
							isOverDue_ = isCon;
						}
						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,
								 isOverDue:isOverDue_,
								 flowId:this.formData.flow_id || "",
								 attachment:this.attachment||""
								}
								
							},
							isClientMode: false,
						}
						if(dataType_ == 'sales') {
							param.extra.variableMap.agreementRecordId = me.formData.o_agreement_record_id ? me.formData.o_agreement_record_id: "";
						}
						if(param_) {
							let keyarr = Object.keys(param_);
							if(keyarr.length != 0) {
								keyarr.map(key=>{
									if(!param.extra.variableMap[key])
										param.extra.variableMap[key] = param_[key]
								})
							}
						}
						
						Server.call("root/order/onEvent", param, function(result) {
							console.log(result);
							if (result.success){
								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);
						});
					},
					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) {
								/* if (result.data.entity.sap) {
									let param_sap = {
										isClientMode: false,
										customerId: me.formData.customer_id
									}
									Server.call("root/order/checkCustomerLicence", param_sap, function(result) {
										if (result.success) {

											for (var i = 0; i < result.data.data.message.length; i++) {
												let el = document.createElement('span');
												el.className = "cell";
												el.style.marginRight = "15px";
												el.style.paddingLeft = "5px";
												el.style.paddingRight = "5px";
												el.innerText = result.data.data.message[i];
												m.appendChild(el);
											}
											Root.message({
												type: 'warning',
												message: result.data.data.message
											});
											//me.reason1 = result.data.data.message;
										}
									});
								} else { */
								//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.status == "1" && 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;
														}
													}
													if (callback) {
														callback();
													}
												 // return
												}else if (data.data.data.status == "2") {
													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();
													}
													//return
												}
											}
											if (data.data.data.status != 0 && !(data.data.data.status == "2" && data.data.data.status == "1")) {
											//if (data.data.data.licenceList.length == 0) {
												Root.message({
													type: 'warning',
													message: "未在工厂查询到该商业,请确认是否进行了工厂资质备案,以及工厂系统中该商业的总部编码与EAS编码一致"
												});
												me.address = [];
												if (callback) {
													callback();
												}
												return
											}
											if(me.popupParames.sceneCode == "add" || me.popupParames.sceneCode == "edit" || !me.formData.customer_consignee_address) {
												let addressArr = data.data.data.consigneeList;
												if (addressArr && addressArr.length > 0) {
													let arr = [];
													me.address = [];
													var address_ =[];
													if (addressArr.length == 1) {
														me.$set(me.formData,"customer_consignee_address",addressArr[0].address)
														if(!me.formData.customer_consignee_id) {
															me.$set(me.formData,"customer_consignee_id",addressArr[0].caddcode)
														}
														if(!me.formData.customer_consignee_user_name) {
															me.$set(me.formData,"customer_consignee_user_name",addressArr[0].empName)
														}
														if(!me.formData.customer_consignee_phone) {
															me.$set(me.formData,"customer_consignee_phone",addressArr[0].empTel)
														}
													}else {
														if(me.popupParames.sceneCode == "add") {
															if(me.formData.customer_consignee_address) {
																let clear = addressArr.some((e)=>{
																	if(e.address == me.formData.customer_consignee_address.replace(/\?:\?[0-9]+$/,""))
																		return true
																	else
																		return false;
																})
																if(!clear)
																	me.$set(me.formData,"customer_consignee_address","")
															}
														}
													}
													for (var i = 0; i < addressArr.length; i++) {
														address_.push({
															address: addressArr[i].address,
															address1: addressArr[i].address+"?:?"+i
														});
														me.userPhone[addressArr[i].address+"?:?"+i] = {caddcode:addressArr[i].caddcode, user:addressArr[i].empName,phone:addressArr[i].empTel}
													}
													me.address = address_;
												}else {
													Root.message({
														type: 'warning',
														message: "地址不存在"
													});
													me.userPhone = {}
													me.address = [];
													me.$set(me.formData,"customer_consignee_address","")
												}
											}
											
											if (callback) {
												callback();
											}
										} else {
											if (callback) {
												callback();
											}
											me.address = [];
											Root.message({
												type: 'warning',
												message: data.data.message
											});
										}
									})
									.catch((error) => {
										me.address = [];
										if (callback) {
											callback();
										}
										console.log(error);
									});
								//}
							});
						}else{
							if (callback) {
								callback();
							}
						}
						
					},
					checkDiscountAmount(customer_code) {
						let me = this;
						let param = {
							isClientMode:false,
							dataname:"v_customer_rebate_book",
							filter:"customer_code = '" + customer_code + "'"
						}
						Server.call("root/data/getEntity",param,function(result) {
							if(result && result.success) {
								if(result.data.entity && result.data.entity.amount) {
									me.$set(me.formData,"amount",Math.abs(result.data.entity.amount))
									me.$set(me.formData,"available_amt",Math.abs(result.data.entity.amount))
								}else{
									me.$set(me.formData,"amount",0)
									me.$set(me.formData,"available_amt",0)
								}
							}else{
								Root.message({
									type: 'warning',
									message: data.message
								});
							}
						})
					},
					showPopup(obj) {
						this.selectFormField = obj.obj;
						if (this.selectFormField.field == "customer_name") { //客户名称
							let me = this;
							let hierarchy_code = localStorage.hierarchy_code;
							let roleList = localStorage.roleid.split(";");
							let isAll = roleList.indexOf("7b84790f8649471c897d369bcde99623") > -1
							let arr = ["202012210001","202104200018"];
							var filter_ =" sales_agreement.operator_code = '" + localStorage.emp_code + "'"
							let roleids = localStorage.roleid.split(";");
              							let r_id = "";
              							roleids.map(r=>{
                							if (r == "sp023" || r == "sp016") {//OTC招商(sp023)和品控(sp016)
                  								r_id = r;
               	 							}
              							})
              							if (r_id) {
                							filter_ = " 1 = 1 and checked = 1 and vuoc.role_id='" + r_id + "'";
              							}
              
              							else if(arr.indexOf(hierarchy_code) > -1 || isAll)
								filter_ = "1=1"
							filter_ = this.Getfilter(filter_, "customer_name");
							filter_ += " and "
							//filter_ += " and sales_agreement.delivery_part_code = 'JMKX_YY' and "
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html",
								width: 900,
								height: 550,
								filter: filter_,
								dataname: "getCustomer_name",
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.customer_name = obj.row.md_description;
									/* formData_.customer_consignee_address = obj.row.address;
									me.address = [{address:obj.row.address}]; */
									//formData_.customer_consignee_user_name = obj.row.operator_name;
									formData_.customer_code = obj.row.customer_code;
									formData_.customer_eas_code = obj.row.customer_eas_code;
									formData_.customer_id = obj.row.customer_id;
									formData_.province_name = obj.row.province_name;
									formData_.province_code = obj.row.province_code;
									/* formData_.operate_emp_name = obj.row.business_operator_name;
									formData_.emp_depart_name = obj.row.emp_depart_name; */
									/* formData_.manager_part_code = "";
									formData_.delivery_part_name = "";
									formData_.settle_type = "";
									formData_.business_depart_name = ""; */
									me.formData = clone(formData_);
									me.getIsOffline(formData_.customer_code, me.formData.delivery_part_code);
									me.tableData2 = [];
									me.checkDiscountAmount(formData_.customer_code)
									me.addTableData();
									//if(me.formData.has_gsp) {
										me.checkCustomerAndDelivery(callback);
									/* }else {
										if (callback) {
											callback();
										}
									} */
								}
							});
						} else if (this.selectFormField.field == "delivery_part_name") { //发货主体
							let me = this;
							//var filter_ = " 1 = 1 and agreementRecord.delivery_part_code = 'JMKX_YY'";
							var filter_ = " 1 = 1";
							filter_ = this.Getfilter(filter_, "delivery_part_name");
							Root.showPopup({
								url: "../org/company/popup/managesubject_list.html",
								width: 800,
								height: 550,
								dataname: "getDelivery_part_name",
								type: "managesubjectname",
								filter: filter_,
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.delivery_part_name = obj.row.delivery_part_name;
									formData_.delivery_part_code = obj.row.delivery_part_code;
									formData_.has_gsp = obj.row.has_gsp;
									
									if (obj.row.book_no) {
										formData_.book_no = obj.row.book_no;
									}else{
										formData_.book_no = "";
									}
									me.formData = clone(formData_);
									me.confirmByTransType();
									me.getIsOffline(me.formData.customer_code, me.formData.delivery_part_code);
									//me.tableData2 = [];
									/* if(!obj.row.has_gsp) {
										me.$set(me.formData,"customer_consignee_address","")
										me.formFields = me.formFields.filter(e=>{
											if(e.field == "customer_consignee_address") {
												e.type = "input";
												
											}
											return true;
										})
										if(callback) 
											callback()
									}else {
										me.$set(me.formData,"customer_consignee_address","")
										me.formFields = me.formFields.filter(e=>{
											if(e.field == "customer_consignee_address") {
												e.type = "select";
											}
											return true;
										}) */
										me.checkCustomerAndDelivery(callback);
									//}
									
								}
							});
						} else if (this.selectFormField.field == "business_depart_name") { //业务部门
							let me = this;
							var filter_ = " 1 = 1 and name is not null ";
							filter_ = this.Getfilter(filter_, "business_depart_name");

							Root.showPopup({
								url: "../org/department/popup/department_list.html",
								width: 800,
								height: 550,
								dataname: "getBusiness_depart_name",
								filter: filter_,
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.business_depart_name = obj.row.name
									formData_.business_depart_id = obj.row.id
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						} else if (this.selectFormField.field == "province_name") {
							let me = this;
							var filter_ = " 1 = 1";
							filter_ = this.Getfilter(filter_, "province_name");

							Root.showPopup({
								url: "../org/department/popup/area_list.html",
								width: 800,
								height: 550,
								dataname: "getProvince_name",
								filter: filter_,
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.province_name = obj.row.province_name
									formData_.province_code = obj.row.province_code
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						}

					},
					formcallclick(obj) {
						this.click = obj.obj;
						if (this.selectFormField.field == "upload") {
							var url = baseUrl + "file/download?id=" + this.formData.file_id;
							dealExportByPath(url, this.formData.upload);
						} else if (this.click.field == "file_upload") {
							//"../../../js/web/viewer.html?file=" + encodeURIComponent(window.top.RootSetting.url + "root/file/download?id=" + this.popupParames.data.contract_file_id)
							var url = baseUrl + "file/download?id=" + this.formData.attachment_file_id;
							dealExportByPath(url, this.formData.file_upload);
							//getDownloadFileUrl(this.formData.attachment_file_id)
						}
					},
					buttonClick(obj) {
						if (obj.obj.field == "contract_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_.contract_file_id = obj.row[0].id
									let name = me.fileNameTrim(obj.row[0].name)
									formData_.contract_file_name_t = obj.row[0].name
									formData_.contract_file_name = name
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						} else if (obj.obj.field == "attachment_file_name") { //附件
							let me = this;
							Root.showPopup({
								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_.attachment_file_id = obj.row[0].id
									let name = me.fileNameTrim(obj.row[0].name)
									formData_.attachment_file_name = name
									formData_.attachment_file_name_t = obj.row[0].name
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						}
					},
					setTableHeight(){
						//if(this.tableData2.length < 2){
						//	this.tableHeight2 = 165;
						//}
							
						//else
						//	this.tableHeight2 = this.tableData2.length * 40 + 100;
						//let body = document.getElementsByClassName("el-table__body-wrapper")[0];
						//if(body)
						//	body.style.height = (this.tableHeight2  - 80) + "px";
					},
					formcallspanClick(obj) {
						if (obj.obj.field == "contract_file_name" && this.formData.contract_file_id) {//合同
						//let url = "../sorder/signature.html?id=" + this.formData.id + "&delta=" + me.dataname ;
							this.onDownloadFileByFileId(this.formData.contract_file_id, this.formData.contract_file_name_t, true);
						}else if(obj.obj.field == "attachment_file_name" && this.formData.attachment_file_id) {
							this.onDownloadFileByFileId(this.formData.attachment_file_id, this.formData.attachment_file_name_t);
						}
					},
					onDownloadFileByFileId(file_id, file_name, isseal) {//isseal: 是否盖章
						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 == ".pdf" || suffix == ".png" || suffix == ".jpg") {
							var row = {
								fileid: fileid,
								filename: fileName
							}
							
							if (isseal) {
								row.isseal = isseal;
								row.id = this.formData.id;
								row.dataname = this.dataname;
							}

							var config = {
								icon: "icon-product",
								text: "附件预览",
								id: "pdf_" + fileid,
								url: "../tool/popup_file_pdf.html?fileid=" + fileid + "&filename=" + fileName,
								data: row,
								width:1200,
								delta: {},
								callback: function(obj, callback) {
									if (callback) {
										callback();
									}
								}
							};
							this.doPopupByPublic(config);
							return;

						} else { //只可下载,不可预览
							handleDownload(fileid);
						}
					},
					cellVisibleChange(obj) {
						let options_ = [];

						/* if (obj.field == "manager_part_code") {
							let param_ = {
								isClientMode: false,
								filter: "1 = 1 and parent_id = 'manager-part'",
							}
							Server.call("root/data/getEntitySet/dictitem", param_, function(result){
								options_ = result.data.entityset;
								obj.options = options_;
							});
						} 
						else if (obj.field == "sales_type") {
							let param_ = {
								isClientMode: false,
								filter: "parent_id = 'sales_type'",
							}
							Server.call("root/data/getEntitySet/dictitem", param_, function(result){
								options_ = result.data.entityset;
								obj.options = options_;
							});
						}
						
						else*/
						if (obj.field == "customer_consignee_address") {
							/* 	let param_ = {
									isClientMode: false,
									filter: "1 = 1 and customer_id = '" + this.formData.customer_id +"'",
								}
								Server.call("root/data/getEntitySet/customerConsigneeMapping", param_, function(result){
									options_ = result.data.entityset;
									obj.options = options_;
								}); */
							/* if(this.address.length == 1) {
								let index = this.formData.customer_consignee_address.indexOf("?:?");
								if(index == -1)
									this.$set(this.formData,"customer_consignee_address",this.formData.customer_consignee_address + "?:?0")
							} */
							options_ = this.address;
							obj.options = options_;
						}
					},
					selectChange(obj){
						if(obj.fieldobj.field == "customer_consignee_address") {
							let formData_ = clone(this.formData);
							formData_.customer_consignee_id = this.userPhone[this.formData.customer_consignee_address].caddcode;
							formData_.customer_consignee_user_name = this.userPhone[this.formData.customer_consignee_address].user;
							formData_.customer_consignee_phone = this.userPhone[this.formData.customer_consignee_address].phone;
							this.formData = formData_;
						}
						else if (obj.fieldobj.field == "trans_type") {
							this.confirmByTransType();
						}
					},
					formChange(obj) {
						this.selectFormField = obj.fieldobj;
						
						
						if (this.selectFormField.field == "amt_rebate") {
							if (!this.formData.customer_name) {
								Root.message({
									type: 'warning',
									message: '请选择客户'
								});
								return;
							}
							var data_ = obj.data;
							if (data_.amt_rebate > data_.rebate_available) {
								Root.message({
									type: 'warning',
									message: '超出可用返利'
								});
								data_.amt_rebate = data_.rebate_available
								return;
							}
						}
						
					},
					routnFixed(val, num) {
						return Math.round(Math.pow(10, num) * val) / Math.pow(10, num);
					},
					
					confirmByTransType() {
						if (this.formData.trans_type && this.formData.delivery_part_code) {
							this.$confirm('请与发货主体确认此发运方式可用', '提示', {
							  confirmButtonText: '已确认',
							  cancelButtonText: '未确认',
							  type: 'warning',
							  customClass: "cssTransType"
							}).then(() => {
							
							
							}).catch(() => {
								this.formData.trans_type = "";
							});
						}
					}
					
				}
			});
		</script>
		<style>
		.header {
			height: 21px;
		}
		.el-dialog__header {
		    border-bottom: 0;
		}
		.el-dialog__body {
		    text-align: center;
			/* height: 200px; */
		}
		.cssTransType .el-message-box__content{
			color: red;
		}
		</style>
	</body>
</html>