<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>变更备案</title>
		<script src="../../../js/vue/vue.js"></script>
		<script src="../../../js/vue/element-ui/lib/index.js"></script>
		<script src="../../../js/vue/page.js"></script>
		<script src="../../../js/myelement.js"></script>
		
		<link href="../../../js/vue/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
		<link href="../../../css/myelement.css" rel="stylesheet">
		<link href="../../../css/iconfont.css" rel="stylesheet">
		<link href="../../../css/page.css" 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="width: 1300px; padding-right: 20px;" >
					<div class="el-dialog_header">
						<div class="dialog-title">
						  <i class="iconfont icon-customermanagement"></i>
						  <span> 变更备案 </span>
						</div>
					</div>	
					<div style="height: 550px; overflow-y: auto;">
						<div class="el-dialog_body">
							<h-form
								ref="form1"
								:form-attr="formAttr"
								:table-fields="formFields"
								:form-data="formData"
								v-on:show-popup="showPopup"
								v-on:form-change="formChange"
								v-on:select-change="formcellSelectChange"
							>
							</h-form>
							<h-form
								:form-attr="formAttr1"
								:table-fields="formFields1"
							>
							</h-form>
							<h-table
								v-if="isRefresh"
								ref="table2"
								:table-fields="tableFields" 
								:table-data="tableData2" 
								:is-edit-table-data="isEdittableData"
								:is-within-edit-table-data= "isWithinEdittableData"
								:table-height="tableHeight2"
								:is-pagination="false"
								v-on:cell-input-change="cellInputChange"
								v-on:edit-data="editData"
								
								v-on:cell-show-popup="cellShowPopup"
								v-on:cell-select-change="cellSelectChange"
							>
							</h-table>
						<!-- 	 -->
							
						</div>
						<el-dialog title="填写原因" :visible.sync="reasonvisible" height="50%">
							<el-input
							  type="textarea"
							  :autosize="{ minRows: 2, maxRows: 10}"
							  placeholder="请输入原因"
							  v-model="textarea2">
							</el-input>
							
							<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>
					</div>
					
					<div class="el-dialog_footer">
						<el-button-group v-if="approval" style="margin: 0px 20px;">
							<el-button type="success" @click="onpassApproval">通 过</el-button>
						</el-button-group>
						<el-button-group v-if="approval" style="margin: 0px 20px;">
							<el-button type="danger" @click="onrefuseApproval">拒 绝</el-button>
						</el-button-group>
						<!-- <el-button v-if="!approval" :disabled="formData.freeze" type="danger" @click="frozen">冻 结</el-button> -->
						<el-button v-if="!approval" type="danger" :loading="isLoading" @click="submitRowTable">提 交</el-button>
						<!-- <el-button v-if="!approval" type="primary" @click="saveRowTable">保 存</el-button> -->
					 	<el-button v-if="!fromDing" type="default" @click="closeDialog">取 消</el-button>
					 </div>
				</div>
			</div>
			<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;z-index:9999">
				<div class="spinner">
				  <div class="cube1"></div>
				  <div class="cube2"></div>
				</div>
			</div>
			
			<el-dialog :visible.sync="dingResult" width="40vw" height="50vh" :show-close="false" :close-on-click-modal="false" :close-on-press-escape="false">
				 <span>{{dingResultTxt}}</span>
				 <div style="min-height: 150px;"></div>
			</el-dialog>
		</div>	
		
		<script type="text/javascript">
			new ListVue({
				el: "#vbody",
				data: {
					formAttr: {
						columnnumber: 3,
						labelwidth: "150px",
						labelposition: "right",
						size: "medium",
						title: "基本信息",
						istitle: true,
						border: "0px solid #c6c6c6"
					},
					formAttr1: {
						columnnumber: 3,
						labelwidth: "150px",
						labelposition: "right",
						size: "medium",
						title: "产品政策",
						istitle: true,
						border: "0px solid #c6c6c6"
					},
					formFields: [],
					formFields1: [],
					formData: {},
					formData_old: {},
					approval:false,
					isLoading:false,
					reasonvisible:false,
					textarea2: '',
					tableData2: [],
					tableData2_old: [],
					tableHeight2: 240,
					isEdittableData:false,
					isWithinEdittableData:true,
					dataRequest: [
						 {
							isClientMode: false,
							code: "code",
							label: "value",
							name: "manager_part_name",
							dataname: "dictitem",
							filter: " parent_id='manager-part'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "cash_type",
							dataname: "dictitem",
							filter: " parent_id='cash_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "settle_type",
							dataname: "dictitem",
							filter: " parent_id='settle_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "business_type",
							dataname: "dictitem",
							filter: " parent_id='business_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "control_type",
							dataname: "dictitem",
							filter: " parent_id='control_type'"
						},
						{
							isClientMode: false,
							isinputoption: true,
							code: "code",
							label: "value",
							name: "tag_price_type",
							dataname: "dictitem",
							filter: " parent_id='tag_price_type'"
						},
						{
							isClientMode: false,
							code: "code",
							label: "value",
							name: "terminal_position",
							dataname: "dictitem",
							filter: " parent_id='terminal_position'"
						},
						
					],
					dataRequestObj: {},
					fromDing: false,
					dingResult: false,
					dingResultTxt: ""
				},
				
				created() {
					this.formFields = dataRootFields.formFields.changePolicyReportSummary_;
					this.tableFields = dataRootFields.tableFields.changePolicyReportSummary_;
					this.popupParames = clone(Root.popupParames);
					if (this.popupParames.sceneCode == "approval") {
						this.formAttr.disabled = true;
						this.approval = true;
						this.isWithinEdittableData = false;
					}
				},
				
				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_name") {
										e.options = me.dataRequestObj.manager_part_name;
										
										me.dataRequestObj.manager_part_name.map(e=>{
											if (!me.dataRequestObj.map) {
												me.dataRequestObj.map = {};
											}
											if (!me.dataRequestObj.map.manager_part_name) {
												me.dataRequestObj.map.manager_part_name = {};
											}
											me.dataRequestObj.map.manager_part_name[e.code] = e.value;
										})
									}
								
									
									else if(e.field == "business_type") {
										e.options = me.dataRequestObj.business_type;
										
										me.dataRequestObj.business_type.map(e=>{
											if (!me.dataRequestObj.map) {
												me.dataRequestObj.map = {};
											}
											if (!me.dataRequestObj.map.business_type) {
												me.dataRequestObj.map.business_type = {};
											}
											me.dataRequestObj.map.business_type[e.code] = e.value;
										})
									}
									else if(e.field == "control_type") {
										e.options = me.dataRequestObj.control_type;
										
										me.dataRequestObj.control_type.map(e=>{
											if (!me.dataRequestObj.map) {
												me.dataRequestObj.map = {};
											}
											if (!me.dataRequestObj.map.control_type) {
												me.dataRequestObj.map.control_type = {};
											}
											me.dataRequestObj.map.control_type[e.code] = e.value;
										})
									}
									else if(e.field == "terminal_position") {
										e.options = me.dataRequestObj.terminal_position;
										
										me.dataRequestObj.terminal_position.map(e=>{
											if (!me.dataRequestObj.map) {
												me.dataRequestObj.map = {};
											}
											if (!me.dataRequestObj.map.terminal_position) {
												me.dataRequestObj.map.terminal_position = {};
											}
											me.dataRequestObj.map.terminal_position[e.code] = e.value;
										})
									}
									
								});
							var tableFields_part_ = clone(me.tableFields);
							tableFields_part_.map(e=>{
								if(e.field == "settle_type") {
									e.options = me.dataRequestObj.settle_type;
								}
								if(e.field == "tag_price_type") {
									e.options = me.dataRequestObj.tag_price_type;
								}if(e.field == "cash_type") {
									e.options = me.dataRequestObj.cash_type;
								}
								if(e.field == "terminal_position") {
									e.options = me.dataRequestObj.terminal_position;
								}
							
							})
							me.tableFields  = tableFields_part_;
							me.formFields = formFields_part_;
							//me.initData();
						};
					});
					}
					
					
					
					if (this.popupParames.data) {
						me.formData = clone(me.popupParames.data);
						me.formData.old_end_date = me.formData.end_date
						me.formData.business_type = me.formData.business_type+""
						me.formData_old = clone(me.formData);
						var tableData_old = [];
						tableData_old[0] = clone(me.popupParames.data)
						tableData_old[0].settle_type = tableData_old[0].settle_type+"";
						me.tableData2 = tableData_old;
						me.tableData2_old = clone(me.tableData2)
						
					}
					if(me.formData.control_type == "1") {
						this.$set(me.formData,"days_payment",0);
						this.$set(me.formData,"peroid_payment",0);
						this.tableFields.map(e=>{
							if(e.field == "days_payment")
								e.type = "span"
						})
					}else{
						this.tableFields.map(e=>{
							me.formData.peroid_payment =parseFloat(me.formData.days_trans) || 0 +parseFloat(me.formData.days_payment) || 0 + "";
							if(e.field == "days_payment")
								e.type = "input"
						})
					}
					var urlParam = getGetParams(this.popupParames.url);
					
					for(let key in urlParam) {
						if(key == "fromDing") {
							this.fromDing = urlParam[key];
						}
					}
					
					this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
						document.getElementById('page_root').style.display =  "block";
						document.getElementById('page_loading').style.display =  "none";
						
						//重新设置弹窗宽高
						this.$nextTick(function(){
							document.getElementById('page_root').classList.add("z_popup-page");
							let w_ = this.$refs.popup_body.offsetWidth + "px";
							let h_ = this.$refs.popup_body.offsetHeight + "px";
							Root.setPopupWH(w_, h_);
						})
					});
				},
				
				methods:{
					closeDialog() {
						Root.hidePopup();
					},
					closeSubmit() {
						if(this.popupParames.callback) {
							this.popupParames.callback({},function(){
								Root.hidePopup();
							})
						}
					},
					saveAfter() {
						var me = this;
						if(this.popupParames.callback) {
							let obj = {
								//row: this.formData
							}
							this.popupParames.callback(obj, function() {
								if (me.popupParames.totab){
									Root.tab.removeItem(Root.tab.selected);
									Root.tab.open(me.popupParames.parentOption, false); 
								}
								else {
									Root.hidePopup();
								}
							});
						}
						else {
							alert("该按键事件缺失!")
						}
					},
					onServerInitData(data) {
						
					},
					frozen(){
						var me = this;
						this.formData;
						Root.confirm('确定冻结后此备案将不能在创建订单时使用,确定冻结吗?', '冻结提示', {
						  confirmButtonText: '冻结',
						  cancelButtonText: '取消',
						  type: 'warning'
						}).then(() => {
							var paramObj = {};
							paramObj.id = me.formData.id;
							paramObj.freeze = 1;
							var param_ = paramObj;
							//return
							Server.call("root/data/updateEntity/" + "agreement_record", param_, function(result) {
								console.log(result);
								Root.message({
									type: 'success',
									message: '冻结成功'
								}); 
								me.saveAfter();
							});
						}).catch(() => {
							Root.message({
								type: 'info',
								message: '已取消冻结'
							});          
						});
						
					},
					
					cellInputChange(scope) {
						 let row = scope.row;
						let field = scope.column.property;
						if(field == "days_trans" || field == "days_payment") {	//tag_price中标价
							if(this.formData.control_type != "1")
								row.peroid_payment = this.operatorNum(parseInt(row.days_payment || 0) , parseInt(row.days_trans || 0) , "+");
							else
								row.peroid_payment= 0;
						}
						if(field == "tag_price" || field == "supply_price") {	//tag_price中标价
							row.delivery_amt = this.operatorNum(parseFloat(row.tag_price||0),parseFloat(row.supply_price||0),"-") + "";
							if(!row.tag_price || !row.supply_price)
								row.delivery_amt = 0;
							row.delivery_rate = (this.operatorNumRate(parseFloat(row.delivery_amt||0),parseFloat(row.tag_price||0),"/")).toFixed(2) + " %";
							row.current_tick_rate = (this.operatorNumRate(parseFloat(row.current_tick_amt||0),parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.drained_rate = (this.operatorNumRate(parseFloat(row.drained_amt||0),parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.drained_arrest_rate = (this.operatorNumRate(parseFloat(row.drained_arrest_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.discount_common_rate = (this.operatorNumRate(parseFloat(row.discount_common_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.discount_business_rate = (this.operatorNumRate(parseFloat(row.discount_business_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.discount_trans_rate = (this.operatorNumRate(parseFloat(row.discount_trans_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.discount_annual_rate = (this.operatorNumRate(parseFloat(row.discount_annual_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.inventory_rate = (this.operatorNumRate(parseFloat(row.inventory_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.discount_flow_rate = (this.operatorNumRate(parseFloat(row.discount_flow_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.project_percentage = (this.operatorNumRate(parseFloat(row.project_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							row.pay_tax_rate = (this.operatorNumRate(parseFloat(row.pay_tax_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
							
						}
						else if(field == "days_payment" ) {
							row.peroid_payment =this.operatorNum(parseFloat(row.days_trans||0) , parseFloat(row.days_payment||0) , "+")  + "";
						}
						else if(field == "current_tick_amt" ) {
							row.current_tick_rate = (this.operatorNumRate(parseFloat(row.current_tick_amt||0),parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "drained_amt" ) {
							row.drained_rate = (this.operatorNumRate(parseFloat(row.drained_amt||0),parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "drained_arrest_amt" ) {
							row.drained_arrest_rate = (this.operatorNumRate(parseFloat(row.drained_arrest_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "discount_common_amt" ) {
							row.discount_common_rate = (this.operatorNumRate(parseFloat(row.discount_common_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "discount_business_amt" ) {
							row.discount_business_rate = (this.operatorNumRate(parseFloat(row.discount_business_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "discount_trans_amt" ) {
							row.discount_trans_rate = (this.operatorNumRate(parseFloat(row.discount_trans_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "discount_annual_amt" ) {
							row.discount_annual_rate = (this.operatorNumRate(parseFloat(row.discount_annual_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "inventory_amt" ) {
							row.inventory_rate = (this.operatorNumRate(parseFloat(row.inventory_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "discount_flow_amt" ) {
							row.discount_flow_rate = (this.operatorNumRate(parseFloat(row.discount_flow_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "project_amt" ) {
							row.project_percentage = (this.operatorNumRate(parseFloat(row.project_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						else if(field == "pay_tax_amt" ) {
							row.pay_tax_rate = (this.operatorNumRate(parseFloat(row.pay_tax_amt||0) , parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						}
						row.discount_total_amt = this.sumNumArray([parseFloat(row.current_tick_amt || 0) , parseFloat(row.drained_amt|| 0) , parseFloat(row.drained_arrest_amt|| 0) ,
													parseFloat(row.discount_common_amt|| 0) , parseFloat(row.discount_business_amt|| 0) , parseFloat(row.discount_trans_amt|| 0) ,
													parseFloat(row.discount_flow_amt|| 0) , parseFloat(row.discount_annual_amt|| 0) , parseFloat(row.project_amt|| 0),parseFloat(row.pay_tax_amt|| 0), parseFloat(row.inventory_amt|| 0)])
						row.discount_total_rate = (this.operatorNumRate(parseFloat(row.discount_total_amt||0),parseFloat(row.supply_price||0),"/")).toFixed(2) + " %";
						let a = this.operatorNum(parseFloat(row.delivery_amt||0) ,parseFloat(row.discount_total_amt||0),"+");
						if(!row.tag_price || !row.supply_price)
							a = 0;
						row.business_rate = this.operatorNumRate(parseFloat(a||0),parseFloat(row.tag_price||0),"/").toFixed(2) + " %";
					},
					operatorNum(num1,num2,type) {
						let max=6;
						let num1str,num2str;
						if(type == "*" || type == "/") {
							if(num1 === 0 || num2 === 0)
								return 0;
						}
						num1 = num1.toFixed(6)
						num2 = num2.toFixed(6)
						num1str = num1.toString().split(".")[0] + num1.toString().split(".")[1]
						num2str = num2.toString().split(".")[0] + num2.toString().split(".")[1]
						num1 = parseInt(num1str)
						num2 = parseInt(num2str)
						if(type == "+")
							return (num1 + num2)/Math.pow(10,max);
						else if(type == "-")
							return (num1 - num2)/Math.pow(10,max);
						else if(type == "*")
							return (num1 * num2)/(Math.pow(100,max));
						else if(type == "/")
							return (num1 / num2);
					},
					operatorNumRate(num1,num2,type) {
						let num3 = this.operatorNum(num1,num2,type);
						let str = this.operatorNum(num3,100,"*").toString()
						if(str.split(".").length > 1)
							return parseFloat(str.toString().split(".")[0] +"."+ str.toString().split(".")[1].substring(0,2));
						else
							return this.operatorNum(num3,100,"*");
						//return parseFloat(this.operatorNum(num3,100,"*"),2);
					},
					sumNumArray(array) {
						let max=0;
						let sum=0;
						if(!array || array.length == 0)
							return;
						for (var i = 0; i < array.length; i++) {
							let len;
							if(array[i] % 1 != 0) {
								len = array[i].toString().split(".")[1].length;
							}
							if(len > max) 
								max = len;
						}
						for (var i = 0; i < array.length; i++) {
							sum+=array[i]*Math.pow(10,max)
						}
						return sum/Math.pow(10,max)
					},
					submitRowTable() {
						this.formData.continueCommit = true;
						if(!this.formData.termination_date) {
							Root.message({
								type:"warning",
								message:"请设置终止日期"
							})
							return
						}
						this.saveRowTable();
					},
					saveRowTable() {
						let me = this;
						var row = this.tableData2[0];
						if(me.formData.continueCommit){
							let change = false;
							if(me.formData.control_type != me.formData_old.control_type)
								change = true;
							else {
								for(let i = 0;i<me.tableData2.length;i++) {
									let item = me.tableData2[i];
									let item_old = me.tableData2_old[i];
									for(key in item) {
										if(item[key] != item_old[key] && key != "remark") {
											if((item[key] == null && item_old[key] == 0) || (item_old[key] == null && item[key] == 0) || (key.indexOf("rate") > -1 && key != "actual_operate_id") )
												continue;
											change = true;
											break;
										}
									}
								}
							}
							if(!change) {
								Root.message({
									type:"warning",
									message:"没有检测到变更"
								})
								return;
							}
						}
						let date = new Date(this.formData.termination_date);
						date.setDate(date.getDate() + 1)
						date = dateFormat(date,'yyyy-MM-dd hh:mm:ss')
						let param = {
							nowAgreement:{
								startDate: date,
								endDate: this.formData.end_date,
								businessType: this.formData.business_type,
								customerId: this.formData.customer_id,
								productId: row.product_id,
								customerCode: this.formData.customer_code,
								managerPartCode: this.formData.manager_part_code,
								managerPartName: this.formData.manager_part_name,
								deliveryPartCode: this.formData.delivery_part_code,
								deliveryPartName: this.formData.delivery_part_name,
								businessDepartId: this.formData.business_depart_id,
								businessDepartCode: this.formData.business_depart_code,
								settleType: row.settle_type,
								settlePrice: row.settle_price,
								controlType: this.formData.control_type,
								daysPayment: row.days_payment,
								tagPriceType: row.tag_price_type,
								tagPrice: row.tag_price,
								invoiceLimitPrice: row.invoice_limit_price,
								supplyPrice: row.supply_price,
								distributionPrice: row.distribution_price,
								discountBusinessAmt: row.discount_business_amt,
								retailPrice: row.retail_price,
								deliveryAmt: row.delivery_amt,
								cashType: row.cash_type,
								rebateType: row.rebate_type,
								currentTickAmt: row.current_tick_amt,
								freeze:false,
								drainedAmt: row.drained_amt,
								drainedArrestAmt: row.drained_arrest_amt,
								discountCommonAmt: row.discount_common_amt,
								discountTransAmt: row.discount_trans_amt,
								annualCnt: row.annual_cnt,
								discountAnnualAmt: row.discount_annual_amt,
								inventoryAmt: row.inventory_amt,
								remark: row.remark,
								provinceCode: this.formData.province_code,
								discountFlowAmt: row.discount_flow_amt,
								daysTrans: this.formData.days_trans,
								peroidPayment: row.peroid_payment,
								businessOperateId: row.business_operate_id || "",
								businessOperateCode: row.business_operate_code || "",
								businessOperateName: row.business_operate_name || "",
								actualOperateId: this.formData.actual_operate_id || "",
								actualOperateCode: row.actual_operate_code || "",
								actualOperateName: row.actual_operate_name || "",
								customerPartName: row.customer_part_name || "",
								customerPartCode: row.customer_part_code || "",
								customerDeliveryId: this.formData.customer_delivery_id,
								customerName: row.customer_name || "",
								productName: row.product_name || "",
								productSpec: row.product_spec || "",
								customerEasCode : row.customer_eas_code || "",
								projectAmt : row.project_amt || "",
								payTaxAmt : row.pay_tax_amt || "",
								payTaxNum : row.pay_tax_num || "",
								terminalPosition : row.terminal_position,
								//projectPercentage : row.project_percentage || ""
							},
							preAgreementId:this.formData.id,
							terminationDate:this.formData.termination_date,
							type:"trans"
						}
						me.isLoading = true;
						document.getElementById("page_loading").style.display = "block"
						Server.call("root/agreement/modifyAgreement", param, function(result) {
							if(result.success){
								if(me.formData.continueCommit){
									let change = false;
									let param = {
										businessId:result.data.id,
										businessType:"agreement",
										variableMap:{
											province:me.formData.province_code,
											internationPart:false
										},
									}
									Server.call("root/api/startAct", param, function(result1) {
										if (result1.success){
											var paramObj = {};
											paramObj.id = result.data.id;
											paramObj.flow_id = result1.data.data.activitiId;
											var param_ = paramObj;
											Server.call("root/data/updateEntity/" + "agreementline", param_, function(result) {
												console.log(result);
												Root.message({
													type: 'success',
													message: '提交成功'
												}); 
												me.closeSubmit();
											});
										}else{
											Root.message({
												type: 'warning',
												message: result.message
											}); 
										}
									}) 
								}else
									me.closeSubmit();
							}
							document.getElementById("page_loading").style.display = "none"
							me.isLoading = false;
						},function(result) {
							Root.message({
								type:"warning",
								message:result.message
							})
							document.getElementById("page_loading").style.display = "none"
							me.isLoading = false;
						});
					},
					cellSelectChange(scope) {
					 	let row = scope.row;
						let field = scope.column.property;
						if(field == "manager_part_name") {
							let val = row[field];
							row.manager_part_code = val;
						}
					},
					formcellSelectChange(scope) {
						let row = scope.data;
						let field = scope.fieldobj.field;
						if(field == "control_type") {
							if(row.control_type == "1") {
								this.$set(this.tableData2[0],"days_payment",0);
								this.$set(this.tableData2[0],"peroid_payment",0);
								this.tableFields.map(e=>{
									if(e.field == "days_payment")
										e.type = "span"
								})
							}else{
								this.tableFields.map(e=>{
									this.tableData2[0].peroid_payment =parseFloat(row.days_trans) || 0 +parseFloat(row.days_payment) || 0 + "";
									if(e.field == "days_payment")
										e.type = "input"
								})
							}
						}
					},
					formChange(obj) {
						/* if(obj.fieldobj.field == "end_date") {
							let newEndDate = obj.data.end_date;
							let nowD = new Date();
							let year,month,day;
							year = nowD.getFullYear();
							month = nowD.getMonth();
							day = nowD.getDate()
							let starD = new Date(this.formData.old_end_date.replaceAll("-","/"));
							let endD = new Date(year,11,31);
							if(new Date(newEndDate.replaceAll("-","/")) < starD ) {
								Root.message({
									type:"warning",
									message:"有效期结束时间应大于原备案结束时间"
								})
								obj.data.end_date = obj.data.old_end_date
								return;
							}else if(new Date(newEndDate.replaceAll("-","/")) > endD) {
								Root.message({
									type:"warning",
									message:"有效期结束时间不能晚于当年12月31日"
								})
								obj.data.end_date = obj.data.old_end_date
								return;
							}
						}else */ if(obj.fieldobj.field == "termination_date") {
							let newEndDate = obj.data.termination_date;
							let nowD = new Date();
							let year,month,day;
							year = nowD.getFullYear();
							month = nowD.getMonth();
							day = nowD.getDate()
							let starD = new Date(year,month,day-1);
							let endD = new Date(year,11,31);
							if(new Date(newEndDate.replaceAll("-","/")) < starD || new Date(newEndDate.replaceAll("-","/")) > endD) {
								Root.message({
									type:"warning",
									message:"终止时间应介于" + starD.toLocaleDateString() + " - " + endD.toLocaleDateString() + "之间"
								})
								obj.data.termination_date = ''
								return;
							}
						}
					},
					cellShowPopup(scope){
						let me = this;
						let row = scope.row;
						let field = scope.column.property;
					
						if (field == "customer_name"){
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html",
								width: 1200,
								height: 550,
								tableFields:dataRootFields.tableFields.agreementchoosecustomer_,
								filterFields:dataRootFields.filterFields.agreementchoosecustomer_,
								dataname2:"vCustomerInfoAndvAgreementCustomerDelivery",
								filter:"v_agreement_customer_delivery.id IS NOT NULL and",
								callback: function(obj, callback) {
									row.customer_code = obj.row.md_code;
									row.customer_id = obj.row.id;
									row.customer_name = obj.row.md_description;
									row.province_name = obj.row.province_name;
									row.province_code = obj.row.province;
									row.days_trans = obj.row.trans_day;
									row.customer_uscc = obj.row.uscc;
									row.delivery_part_name = obj.row.delivery_part_name
									row.delivery_part_code = obj.row.delivery_part_code
									row.business_operate_id = obj.row.business_operate_id
									row.business_operate_code = obj.row.business_operate_code
									row.business_operate_name = obj.row.business_operate_name
									row.customer_part_name = obj.row.customer_part_name
									row.customer_part_code = obj.row.customer_part_code
									row.customer_delivery_id = obj.row.customer_delivery_id
									row.business_type = obj.row.business_type
								
									
									if (callback) {
										callback();
									}
								}
							});
						}
						
						else if (field == "product_name"){
							Root.showPopup({
								url: "../md/product/popup/product_list.html",
								width: 800,
								height: 550,
								type: "onlySimple",
								dataname:"md_product_act",
								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.product_spec
									row.product_pack = obj.row.product_pack
									if (callback) {
										callback();
									}
								}
							});
						}
						else if (field == "actual_operate_name"){
							let filter_ = "";
							/* if(row.delivery_part_code)
								filter_ = " and delivery_organization.code = '" + row.delivery_part_code + "'" */
							Root.showPopup({
								url: "../md/customer/popup/employee_list.html",
								width: 800,
								height: 550,
								callback: function(result, callback) {
									row.actual_operate_id = result.row.id;
									row.actual_operate_code = result.row.md_code;
									row.actual_operate_name = result.row.md_description;
									if (callback) {
										callback();
									}
								}
							});
							
						}
						else if (field == "business_depart_name"){
							Root.showPopup({
								url: "../org/department/popup/department_list.html",
								width: 800,
								height: 550,
								callback: function(obj, callback) {
									row.business_depart_name = obj.row.name
									row.business_depart_code = obj.row.code
									row.business_depart_id = obj.row.id
									if (callback) {
										callback();
									}
								}
							});
						}
					},
					//表单
					showPopup(obj) {
						let me = this;
						let list=this.customerList;
						this.selectFormField = obj.obj;
						if (this.selectFormField.field == "customer_name"){
							Root.showPopup({
								url: "../md/customer/popup/customer_list.html",
								width: 1200,
								height: 550,
								tableFields:dataRootFields.tableFields.agreementchoosecustomer_,
								filterFields:dataRootFields.filterFields.agreementchoosecustomer_,
								dataname2:"vCustomerInfoAndvAgreementCustomerDelivery",
								filter:"v_agreement_customer_delivery.id IS NOT NULL and",
								callback: function(obj, callback) {
									let formData_ = clone(me.formData);
									formData_.customer_code = obj.row.md_code;
									formData_.customer_id = obj.row.id;
									formData_.customer_name = obj.row.md_description;
									formData_.province_name = obj.row.province_name;
									formData_.province_code = obj.row.province;
									formData_.days_trans = obj.row.trans_day;
									me.tableData2[0].peroid_payment = me.tableData2[0].days_payment + obj.row.trans_day;
									formData_.customer_uscc = obj.row.uscc;
									formData_.delivery_part_name = obj.row.delivery_part_name
									formData_.delivery_part_code = obj.row.delivery_part_code
									formData_.business_operate_id = obj.row.business_operate_id
									formData_.business_operate_code = obj.row.business_operate_code
									formData_.business_operate_name = obj.row.business_operate_name
									formData_.customer_part_name = obj.row.customer_part_name
									formData_.customer_part_code = obj.row.customer_part_code
									formData_.customer_delivery_id = obj.row.customer_delivery_id
									formData_.business_type = obj.row.business_type
								
									me.formData = formData_;
									if (callback) {
										callback();
									}
								}
							});
						}
					},
					onpassApproval(){
						this.textarea2 = "";
						this.reasonvisible = true;
						this.passOrRefuse = true;
					},
					onrefuseApproval(){
						this.textarea2 = "";
						this.reasonvisible = true;
						this.passOrRefuse = false;
					},
					saveReason(){
						let me = this;
						if(this.passOrRefuse){
							let param = {
								flowId:this.formData.termination_flow_id,
								businessType:"agreementTrans",
								pass:true,
								variableMap:{ reason:this.textarea2}
							}
							Server.call("root/api/dealAct", param, function(result) {
								if (result.success){
									Root.message({
										type: 'success',
										message: '审批成功'
									}); 
									
									if(me.fromDing) {
										me.dingResult = true;
										me.dingResultTxt = "审批成功"
										return;
									}
									me.popupParames.callback(function() {
										Root.hidePopup();
									});
								}else{
									Root.message({
										type: 'warning',
										message: result.message
									}); 
								}
							}) 
						}else{
							if(this.textarea2 != ""){
								let param = {
									flowId:this.formData.termination_flow_id,
									businessType:"agreementTrans",
									pass:false,
									variableMap:{ reason:this.textarea2}
								}
								Server.call("root/api/dealAct", param, function(result) {
									if (result.success){
										Root.message({
											type: 'success',
											message: '拒绝审批成功'
										}); 
										if(me.fromDing) {
											me.dingResult = true;
											me.dingResultTxt = "拒绝审批成功"
											return;
										}
										me.popupParames.callback(function() {
											Root.hidePopup();
										});
									}else{
										Root.message({
											type: 'warning',
											message: result.message
										}); 
									}
								}) 
							}
							else{
								Root.message({
									type: 'warning',
									message: '请填写原因'
								});
							}
						}
					},
				}
			});
		</script>
		
		<style>
			.el-input__inner{
				padding: 0 2px;
			}
			.header {
				height: 21px;
			}
			.el-dialog__header {
			    border-bottom: 0;
			}
			.el-dialog__body {
			    text-align: center;
				/* height: 200px; */
			}
		</style>
		
	</body>
</html>