<!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/myelement.js"></script>
		<script src="../../../js/vue/page.js"></script>
		<script src="../setting.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_13ltsxm2eor.css" rel="stylesheet">
	</head>
	
	<body>
		<div id="vbody">
			<div id="page_root">
				<div class="topbar">
					<span>{{title}}</span>
					
					<div style="float: right; margin-right: 24px;">
						<el-button-group style="margin-left: 3px;">
							<!-- 
							<el-button v-if="buttons.openanaccount" :disabled="buttons.openanaccount.disabled" @click="acct_mapping('add')">新增商业</el-button>
							<el-button v-if="buttons.openanaccount" :disabled="buttons.openanaccount.disabled" @click="acct_mapping('edit', 'acctstate', 'input')">开户</el-button>
							<el-button v-if="buttons.openanaccount" :disabled="buttons.openanaccount.disabled" @click="h_procedure_act('acctstate', 'input', 'working', 'md_description', '开户', '等待审批中', 'customeracct')">开户提交</el-button> 
							 -->
							<el-button v-if="buttons.openanaccountapproval" :disabled="buttons.openanaccountapproval.disabled" @click="">备案变更</el-button>
							<el-button v-if="buttons.openanaccountapproval" :disabled="buttons.openanaccountapproval.disabled" @click="approvalData('register_state')">资质申诉</el-button>
							<el-button v-if="buttons.openanaccountapproval" :disabled="buttons.openanaccountapproval.disabled" @click="">资质变更</el-button>
						</el-button-group>
					</div>
				</div>
			
				<div class="topbar-line">
					<div class="query-icon">
						<i class="iconfont icon-query"></i>
					</div>
					<div class="query-bar">
						<h-form-filter ref="form1" 
							:form-attr="filterAttr" 
							:table-fields="filterFields" 
							:form-data="filterObj" 
							
							v-on:show-popup="showFilterPopup"
							v-on:on-query="onQuery"
							v-on:on-init-query="onInitFilter"
							v-on:on-edit-query="onEditFilter"
							>
						</h-form-filter>
					</div>
				</div>
			
				<div class="versionNo">
					<h-table
						v-if="isRefresh"
						ref="table1"
						:table-fields="tableFields" 
						:table-data="tableData" 
						:is-edit-table-data="isEditTableData"
						:pagesize="pagesize"
						:pagenum="pagenum"
						:total="total"
						:table-height="tableHeight"
						:is-highlight-row="true"
						:is-show-index="true"
						
						v-on:get-data="getData"
						v-on:edit-data="editData"
						v-on:del-data="delData"
						v-on:cell-click="cellClick"
						v-on:row-click="rowClick"
					>
					</h-table>
				</div>
			</div>
			
			<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;">
				<div class="spinner">
				  <div class="cube1"></div>
				  <div class="cube2"></div>
				</div>
			</div>
		</div>	
		
		<script type="text/javascript">
			var setting = getSetting("customer_list");
			var initlized = false;
			
			new ListVue({
				el: "#vbody",
				data: {
					pageAttr: {
						heightType: "page"
					},
					dataname: "customerDelivery",
					tabaleFieldsName: "customer_factorylicence_approval",
					filterFieldsName: "customer_licence_approval",
					dataRequest: [
						{
							isClientMode: false,
							name: "hierarchy",
							filter: "long_code like '01!0101!010102!010102628!01010218!20210420-0001%'"
						},
						{
							isClientMode: false,
							name: "division_level1",
							filter: " level='1' and active='1'"
						},
						{
							isClientMode: false,
							name: "deliveryOrganizationOpen",
						}
					],
					dataRequestObj: {},
					
					filterAttr: {
						columnnumber: 3,
						labelwidth: "130px",
						labelposition: "right",
						size: "medium",
						border: "0px solid #c6c6c600",
					},
					
					title: "资质审批",
					page: setting.page,
					buttons: setting.buttons,
					
					provinces: [],
				},
				created() {
					
				},
				mounted() {
					this.initData();
					this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
						hideLoading();
					});
				},
				methods:{
					initData() {
						//1. run only
						if (initlized) { return; }
						initlized = true;
					  
						//2. query data
						this.onQuery();
					},
					
					onServerInitData(data) {
						var me = this.data;
						me.tableFields = data.tableFields;
						me.filterFields = data.filterFields;
						
						me.dataRequestObj = data;
						/* me.provinces = data.province;		 */	
						
						if(me.filterFields.length > 0) {
							me.filterFields.map(e=>{
								if(e.field == "dep_code") {
									e.options = me.dataRequestObj.hierarchy;
								}
								if(e.field == "record_province") {
									e.options = me.dataRequestObj.division_level1;
								}
								if(e.field == "delivery_part_name") {
									e.options = me.dataRequestObj.deliveryOrganizationOpen;
								}
								
								
								me.filterFieldsObj[e.field] = e;
							});
						}	
						if(me.tableFields.length > 0) {
							for(var i=0; i < me.tableFields.length; i++) {
								let fieldObj_ = me.tableFields[i];
								
								me.tableFieldsObj[fieldObj_.field] = fieldObj_;
							}
						}
					},
					
					onshowFilterPopup(filter) {
						var me = this;
						var fieldObj_ = filter.obj;
						var filterValue = clone(me.filterObj);
						var field_ = fieldObj_.field;
						
						if (field_ == "operator_name") {
							Root.showPopup({
								url: "../md/customer/popup/employee_list.html",
								
								width: 800,
								height: 550,
								callback: function(result, callback) {
									filterValue[field_] = result.row.md_description;
									filterValue.operator_code = result.row.md_code;
									me.filterObj = filterValue;
									if (callback) {
										callback();
									}
								}
							});
							
						}
					},
					
					onAddData(config) {
						var me = this;
						
						config.combine({
							url: "../md/customer/customer_edit.html",
							sceneCode: "add",
							data: {},
							delta: {},
							callback: function(obj) {
								me.saveRowTable_popup(obj);
							}
						});
						
						return true;
					},
					
					onEditData(config, scope) {
						var me = this;
						var row = scope.row;
						
						//1. empty row
						if (!row || !row.id) {
							Root.message({
								type: 'warning',
								message: '请选择要编辑的数据'
							});  
							return false;
						}
							
						//2. not input
						if (row.state != "input") {
							Root.message({
								type: 'warning',
								message: "当前数据不是输入状态"
							})
							return false;
						}
						
						//3. popup					
						config.combine({
							url: "../md/customer/customer_edit.html",
							sceneCode: "edit",
							data: row,
							delta: {},
							callback: function(obj) {
								me.saveRowTable_popup(obj);
							}
						});
						
						return true;
					},
					
					onApproveData(config, code) {
						var me = this;
						var row = this.selectedrow;
						
						//1. empty row
						if (!row || !row.id) {
							Root.message({
								type: 'warning',
								message: '请选择要审批的数据'
							});  
							return false;
						}
						
						//2 check state
						var field_, url_;
						if (code == "data_state") {
							field_ = "state";
							url_ = "../md/customer/customer_edit.html";
						}
						else if (code == "register_state") {
							field_ = "statecode";
							url_ = "../md/customer/account_open.html";
						}
							
						var state = row[field_];
						
						/* if ("working" != state) {
							Root.message({
								type: 'warning',
								message: "当前数据不是【审批中】状态"
							})
							return false;
						} */
						
						//3. popup
						config.combine({
							url: url_,
							sceneCode: "approval",
							data: row,
							delta: {},
							callback: function(obj) {
								me.saveRowTable_popup(obj);
							}
						})
						return true;
					},
					
					onCellClick(config, obj) {
						var clickContext = this.selectCellField.clickContext;
						
						if (clickContext && clickContext.type == "popup") {
							config.combine({
								url: clickContext.url,
								sceneCode: clickContext.sceneCode,
								data: obj.row,
								delta: clickContext.delta ? clickContext.delta : {},
							})
						}
						else {
							return false;
						}
						
						return true;
					},
					
					acct_mapping(type, field_, original_val) {
						let me = this;
						let row = {};
						var text_ = "资质审批";
						var id_ = "applicence";
						row = this.selectedrow;
						if (this.selectedrow[field_] && this.selectedrow[field_] != original_val) {
							Root.message({
								type: 'warning',
								message: "已开户"
							})
							return;
						}
						
						text_ = row.md_description;
						id_ = "licence" + row.id;
						
						var config = {
							totab: true,
							width: "1500px",
							icon: "icon-product",
							text: text_,
							id: id_,
							url: "../md/customer/customer_acct.html",
							data: row,
							delta: "",
							callback: function(obj, callback) {
								//me.uploadFileAfter(obj);
								if (callback) {
									callback();
								}
							}
						};
						this.doPopupByPublic(config);
					},
					
					consignee_mapping(){
						var row = this.selectedrow;
						var row_ ;
						let me = this;
						if (!row.id) {
							Root.message({
								type: 'warning',
								message: '请先选择一条数据'
							})
							return;
						}
						
						Root.popupParames = {
							width: "900px",
							//height: "580px",
							url: "../md/customer/consignee_mapping.html",
						 	callback: function(obj, callback) {
								if (callback) {
									callback();
								}
							} 
						};
						
						Root.popupParames.data = row; 
						Root.showPopup(Root.popupParames);
						
					},
					invoice_mapping(){
						var row = this.selectedrow;
						
						if (!row.id) {
							Root.message({
								type: 'warning',
								message: '请先选择一条数据'
							})
							return;
						}
						
					},
					licence_mapping(){
						var row = this.selectedrow;
						
						if (!row.id) {
							Root.message({
								type: 'warning',
								message: '请先选择一条数据'
							})
							return;
						}
						Root.popupParames = {
							width: "900px",
							//height: "580px",
							url: "../md/customer/licence_mapping.html",
						 	callback: function(obj, callback) {
								if (callback) {
									callback();
								}
							} 
						};
						
						Root.popupParames.data = row; 
						Root.showPopup(Root.popupParames);
						
						
					},
					//绑定审批流程的
					h_procedure_act(field_, original_val, new_val, confirm_field, confirm_type, success_val) {
						var row = this.selectedrow;
						
						if (!row.field1) {
							Root.message({
								type: 'warning',
								message: '请先选择一条数据'
							})
							return;
						}
						
						if (row && row[field_] != original_val) {
							Root.message({
								type: 'warning',
								message: row[field_]
							})
							return;
						}
						
						Root.confirm('确定' + confirm_type + '-' + row[confirm_field] + '-吗?', confirm_type + '提示', {
							confirmButtonText: confirm_type,
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							if (field_ == "field10") {//提交审批
								
							}
							else if (field_ == "field15") {//提交开户提交审批
								
							}
							
							this.selectedrow[field_] = new_val;
							window.top.setAlertNum();
							Root.message({
								type: 'success',
								message: success_val
							});
						}).catch(() => {
							Root.message({
								type: 'info',
								message: '已取消'
							});          
						});
					},
					
					approvalData() {
						let me = this;
						var row = this.selectedrow;
						var text_ = row.md_description + row.delivery_part_name;
						var id_ = "approval_licence" + row.id;
							/* this.getFormData(row); */
							
						var config = {
							totab: true,
							width: "1500px",
							icon: "icon-product",
							text: text_,
							id: id_,
							url: "../md/customer/customer_licence.html",
							//sceneCode: "approval",
							data: row,
							delta: this.formData,
							callback: function(obj, callback) {
								//me.uploadFileAfter(obj);
								if (callback) {
									callback();
								}
							}
						};
						this.doPopupByPublic(config);
					},
				}
			});

		</script>
		<style>
			
		</style>
	</body>
</html>