|
|
|
@ -2,9 +2,13 @@ import { Component, OnInit } from '@angular/core'; |
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
|
import {environment} from '../../../../environments/environment'; |
|
|
|
|
import {MerchantService} from '../../../services/merchant.service'; |
|
|
|
|
import {NzMessageService, NzUploadFile} from 'ng-zorro-antd'; |
|
|
|
|
import {NzMessageService} from 'ng-zorro-antd'; |
|
|
|
|
import {ActivatedRoute} from '@angular/router'; |
|
|
|
|
import {ValidatorsService} from '../../../services/validators.service'; |
|
|
|
|
import {MerchantStoreService} from '../../../services/merchant-store.service'; |
|
|
|
|
|
|
|
|
|
declare var AMap: any; // 一定要声明AMap,要不然报错找不到AMap
|
|
|
|
|
declare var AMapUI: any; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-store-edit', |
|
|
|
@ -20,12 +24,10 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
passwordVisible = false; |
|
|
|
|
logoFile = []; |
|
|
|
|
WEB_SERVE_URL = environment.baseUrl; |
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
previewVisible = false; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
private merchant: MerchantService, |
|
|
|
|
private merchantStore: MerchantStoreService, |
|
|
|
|
private message: NzMessageService, // 信息提示
|
|
|
|
|
private activatedRoute: ActivatedRoute, |
|
|
|
|
) { |
|
|
|
@ -33,25 +35,29 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.activatedRoute.queryParams.subscribe(queryParams => { |
|
|
|
|
if (queryParams.merchantId != null) { |
|
|
|
|
if (queryParams.storeId != null) { |
|
|
|
|
this.editFlag = true; |
|
|
|
|
this.id = queryParams.merchantId; |
|
|
|
|
this.getDetails(queryParams.merchantId); |
|
|
|
|
this.id = queryParams.storeId; |
|
|
|
|
this.getDetails(queryParams.storeId); |
|
|
|
|
} else { |
|
|
|
|
this.getMap (); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
loginTelephone: [null, [Validators.required, ValidatorsService.mobile]], |
|
|
|
|
telephone: [null, [Validators.required, ValidatorsService.mobile]], |
|
|
|
|
password: [null, [Validators.required, ValidatorsService.minLength(6)]], |
|
|
|
|
storeKey: [null, [Validators.required, ValidatorsService.maxLength(10)]], |
|
|
|
|
storeKeyName: [null, [Validators.required, ValidatorsService.pwdLength(2, 12)]], |
|
|
|
|
telephone: [null, [Validators.required]], |
|
|
|
|
storeName: [null, [Validators.required]], |
|
|
|
|
address: [null, [Validators.required]], |
|
|
|
|
latitude: [null, [Validators.required]], |
|
|
|
|
longitude: [null, [Validators.required]], |
|
|
|
|
latitude: [29.553134, [Validators.required]], |
|
|
|
|
longitude: [106.565428, [Validators.required]], |
|
|
|
|
status: [null], |
|
|
|
|
companyId: [null], |
|
|
|
|
merchantId: [null], |
|
|
|
|
createTime: [null], |
|
|
|
|
secUser: {}, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 返回
|
|
|
|
@ -75,8 +81,8 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.validateForm.value['secUser']['telephone'] = this.validateForm.value.loginTelephone; |
|
|
|
|
console.log(this.validateForm.value); |
|
|
|
|
this.validateForm.value['secUser']['telephone'] = this.validateForm.value.telephone; |
|
|
|
|
this.validateForm.value['secUser']['password'] = this.validateForm.value.password; |
|
|
|
|
if (this.logoFile.length !== 0) { |
|
|
|
|
if (this.logoFile[0]['response'] != null) { |
|
|
|
@ -85,10 +91,9 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
this.validateForm.value.merchantLogo = this.logoFile[0].name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
console.log(this.validateForm.value); |
|
|
|
|
if (this.editFlag) { |
|
|
|
|
this.validateForm.value.id = this.id; |
|
|
|
|
this.merchant.updateMerchant(this.validateForm.value, data => { |
|
|
|
|
this.merchantStore.updateMerchantStore(this.validateForm.value, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.getBack(); |
|
|
|
|
this.message.success('修改成功'); |
|
|
|
@ -98,8 +103,7 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
this.merchant.insertMerchant(this.validateForm.value, data => { |
|
|
|
|
console.log(data); |
|
|
|
|
this.merchantStore.insertMerchantStore(this.validateForm.value, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.getBack(); |
|
|
|
|
this.message.success('添加成功'); |
|
|
|
@ -111,26 +115,66 @@ export class StoreEditComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public getDetails(id) { |
|
|
|
|
this.merchant.getMerchantById(id, data => { |
|
|
|
|
this.merchantStore.getMerchantStoreById(id, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
data['return_data'].loginTelephone = data['return_data'].secUser.loginName; |
|
|
|
|
data['return_data'].telephone = data['return_data'].secUser.loginName; |
|
|
|
|
data['return_data'].password = data['return_data'].secUser.password; |
|
|
|
|
if (data['return_data']['merchantLogo'] != null && data['return_data']['merchantLogo'] !== '') { |
|
|
|
|
const logo = String(data['return_data']['merchantLogo']); |
|
|
|
|
const logoArray = []; |
|
|
|
|
logoArray.push( |
|
|
|
|
{ |
|
|
|
|
uid: 1, |
|
|
|
|
name: logo, |
|
|
|
|
status: 'done', |
|
|
|
|
url: environment.imageUrl + logo |
|
|
|
|
}); |
|
|
|
|
this.logoFile = logoArray; |
|
|
|
|
} |
|
|
|
|
this.validateForm.patchValue(data['return_data']); |
|
|
|
|
this.getMap (); |
|
|
|
|
} else { |
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 地图要放到函数里。
|
|
|
|
|
getMap() { |
|
|
|
|
// tslint:disable-next-line:variable-name
|
|
|
|
|
AMapUI.loadUI(['misc/PositionPicker'], PositionPicker => { |
|
|
|
|
console.log(this.validateForm.value); |
|
|
|
|
const map = new AMap.Map('container', { |
|
|
|
|
resizeEnable: true, |
|
|
|
|
scrollWheel: false, |
|
|
|
|
center: [this.validateForm.value.longitude, this.validateForm.value.latitude], // 初始化中心点坐标
|
|
|
|
|
zoom: 13, |
|
|
|
|
}); |
|
|
|
|
AMap.plugin(['AMap.ToolBar', 'AMap.Autocomplete'], () => { |
|
|
|
|
const toolbar = new AMap.ToolBar(); |
|
|
|
|
map.addControl(toolbar); |
|
|
|
|
}); |
|
|
|
|
const autoOptions = { |
|
|
|
|
// input 为绑定输入提示功能的input的DOM ID
|
|
|
|
|
input: 'input' |
|
|
|
|
}; |
|
|
|
|
const autoComplete = new AMap.Autocomplete(autoOptions); |
|
|
|
|
const placeSearch = new AMap.PlaceSearch({ |
|
|
|
|
map: map |
|
|
|
|
}); // 构造地点查询类
|
|
|
|
|
AMap.event.addListener(autoComplete, 'select', select); // 注册监听,当选中某条记录时会触发
|
|
|
|
|
function select(e) { |
|
|
|
|
placeSearch.setCity(e.poi.adcode); |
|
|
|
|
placeSearch.search(e.poi.name); // 关键字查询查询
|
|
|
|
|
} |
|
|
|
|
const positionPicker = new PositionPicker({ |
|
|
|
|
mode: 'dragMap', |
|
|
|
|
map: map |
|
|
|
|
}); |
|
|
|
|
positionPicker.on('success', positionResult => { |
|
|
|
|
positionResult['latitude'] = positionResult.position.lat; |
|
|
|
|
positionResult['longitude'] = positionResult.position.lng; |
|
|
|
|
this.validateForm.patchValue(positionResult); |
|
|
|
|
}); |
|
|
|
|
positionPicker.on('fail', positionResult => { |
|
|
|
|
console.log(positionResult); |
|
|
|
|
}); |
|
|
|
|
positionPicker.setMode('dragMap'); |
|
|
|
|
positionPicker.start(); |
|
|
|
|
map.panBy(0, 1); |
|
|
|
|
|
|
|
|
|
map.addControl(new AMap.ToolBar({ |
|
|
|
|
liteStyle: true |
|
|
|
|
})); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|