|
|
|
@ -1,13 +1,14 @@ |
|
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
import {environment} from '../../../../environments/environment'; |
|
|
|
|
import {FormBuilder, FormGroup} from '@angular/forms'; |
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
|
|
|
import {CompanyService} from '../../../services/company.service'; |
|
|
|
|
import {ActivateService} from '../../../services/activate.service'; |
|
|
|
|
import {IconService} from '../../../services/icon.service'; |
|
|
|
|
import {NzMessageService} from 'ng-zorro-antd'; |
|
|
|
|
import {NzMessageService, NzModalService, NzUploadChangeParam} from 'ng-zorro-antd'; |
|
|
|
|
import {Router} from '@angular/router'; |
|
|
|
|
import {CommonsService} from '../../../services/commons.service'; |
|
|
|
|
import {DiscountPackageService} from '../../../services/discount-package.service'; |
|
|
|
|
import {ValidatorsService} from '../../../services/validators.service'; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-discount-package-list', |
|
|
|
@ -15,7 +16,7 @@ import {DiscountPackageService} from '../../../services/discount-package.service |
|
|
|
|
styleUrls: ['./discount-package-list.component.scss'] |
|
|
|
|
}) |
|
|
|
|
export class DiscountPackageListComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
BASE_URL = environment.baseUrl; |
|
|
|
|
WEB_SERVE_URL = environment.imageUrl; |
|
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
|
requestData = []; // 列表数据
|
|
|
|
@ -29,12 +30,33 @@ export class DiscountPackageListComponent implements OnInit { |
|
|
|
|
isVisibleInventory = false; |
|
|
|
|
id: number; |
|
|
|
|
num: number; |
|
|
|
|
|
|
|
|
|
deliverUserAddForm: FormGroup; |
|
|
|
|
deliverUserAddModal = false; |
|
|
|
|
userInterval; |
|
|
|
|
|
|
|
|
|
deliverUserSearchForm: FormGroup; |
|
|
|
|
deliverUserModal = false; |
|
|
|
|
deliverUserArray = []; |
|
|
|
|
deliverUserForm: FormGroup; |
|
|
|
|
serialNumber: string; |
|
|
|
|
|
|
|
|
|
excelUserModal = false; |
|
|
|
|
excelUploadBtn = true; |
|
|
|
|
excelUploadFile = []; |
|
|
|
|
|
|
|
|
|
spinObject = { |
|
|
|
|
title: '处理中', |
|
|
|
|
status: false |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private form: FormBuilder, |
|
|
|
|
private company: CompanyService, |
|
|
|
|
private activate: ActivateService, |
|
|
|
|
private iconService: IconService, |
|
|
|
|
private message: NzMessageService, |
|
|
|
|
private modal: NzModalService, |
|
|
|
|
private router: Router, |
|
|
|
|
private discountPackage: DiscountPackageService, |
|
|
|
|
private commonsService: CommonsService, |
|
|
|
@ -54,6 +76,23 @@ export class DiscountPackageListComponent implements OnInit { |
|
|
|
|
status: [null], |
|
|
|
|
phone: [null], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.deliverUserSearchForm = this.form.group({ |
|
|
|
|
phone: [null], |
|
|
|
|
registerStatus: [null], |
|
|
|
|
errorStatus: [null], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.deliverUserForm = this.form.group({ |
|
|
|
|
packageId: [null], |
|
|
|
|
packageName: [''], |
|
|
|
|
phoneArray: [null], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.deliverUserAddForm = this.form.group({ |
|
|
|
|
phone: [null, [Validators.required, ValidatorsService.mobile]], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
this.commonsService.getDictionary('USING_ATTRIBUTION ', data => { |
|
|
|
|
this.usingAttribution = data['return_data']; |
|
|
|
@ -185,5 +224,175 @@ export class DiscountPackageListComponent implements OnInit { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 打开 发送优惠券包给用户模态框
|
|
|
|
|
showDeliverUserModal(packageId: number, packageName: string) { |
|
|
|
|
this.discountPackage.getHandleByPackageId({ packageId: packageId}, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
if (data['return_data'] != null) { |
|
|
|
|
this.modal.confirm({ |
|
|
|
|
nzTitle: '提示', |
|
|
|
|
nzContent: '当前卷包有赠送任务进行中,是否查看赠送进度?', |
|
|
|
|
nzOnOk: () => this.processRate(data['return_data']['serialNumber']) |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.deliverUserForm.patchValue({ packageId: packageId, packageName: packageName}); |
|
|
|
|
this.deliverUserModal = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 关闭 发送优惠券包给用户模态框
|
|
|
|
|
closeDeliverUserModal() { |
|
|
|
|
this.deliverUserForm.reset(); |
|
|
|
|
this.deliverUserModal = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 删除赠送用户
|
|
|
|
|
delDeliverUser(serialNum: number) { |
|
|
|
|
this.deliverUserArray = this.deliverUserArray.filter(o => o.serialNum != serialNum); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 展示导入模态框
|
|
|
|
|
showExcelUserModal() { |
|
|
|
|
this.excelUserModal = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 关闭导入模态框
|
|
|
|
|
closeExcelUserModal() { |
|
|
|
|
this.spinObject.status = false; |
|
|
|
|
this.excelUploadBtn = true; |
|
|
|
|
this.excelUploadFile = []; |
|
|
|
|
this.excelUserModal = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 提交赠送数据
|
|
|
|
|
submitDeliverUser() { |
|
|
|
|
if (this.deliverUserArray.length == 0) { |
|
|
|
|
this.modal.warning({ nzTitle: '提示', nzContent: '没有需要赠送的用户'}); |
|
|
|
|
} |
|
|
|
|
this.deliverUserForm.patchValue({ phoneArray: this.deliverUserArray.filter(o => o.errorStatus == false)}); |
|
|
|
|
this.spinObject.status = true; |
|
|
|
|
this.spinObject.title = '处理中...'; |
|
|
|
|
const param = this.deliverUserForm.value; |
|
|
|
|
this.closeDeliverUserModal(); |
|
|
|
|
|
|
|
|
|
this.discountPackage.giveAway(param, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.serialNumber = data['return_data']; |
|
|
|
|
this.processRate(this.serialNumber); |
|
|
|
|
} else { |
|
|
|
|
this.showDeliverUserModal(this.deliverUserForm.controls.packageId.value, this.deliverUserForm.controls.packageName.value); |
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
this.spinObject.status = false; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理进度
|
|
|
|
|
processRate(serialNum: string) { |
|
|
|
|
this.spinObject.status = true; |
|
|
|
|
this.userInterval = setInterval(() => this.commonsService.getRedisValueByType(serialNum, data => { |
|
|
|
|
if (data['return_data'] != null) { |
|
|
|
|
this.spinObject.title = '已处理' + data['return_data'] + '条数据'; |
|
|
|
|
} else { |
|
|
|
|
this.spinObject.status = false; |
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
clearTimeout(this.userInterval); |
|
|
|
|
} |
|
|
|
|
}), 1000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 提交excel数据
|
|
|
|
|
submitExcelUser() { |
|
|
|
|
this.spinObject.title = '文件导入中... 数据太多会占用较长时间'; |
|
|
|
|
this.spinObject.status = true; |
|
|
|
|
this.discountPackage.getPhoneListByFileUrl({ fileUrl: this.excelUploadFile[0]['url']}, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.deliverUserArray = data['return_data']['data']; |
|
|
|
|
this.closeExcelUserModal(); |
|
|
|
|
} else { |
|
|
|
|
this.spinObject.status = false; |
|
|
|
|
this.message.error(data['return_msg']); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 上传excel回调
|
|
|
|
|
excelUserHandleChange(info: NzUploadChangeParam): void { |
|
|
|
|
if (info.file.status !== 'uploading') { |
|
|
|
|
this.excelUploadFile = []; |
|
|
|
|
} |
|
|
|
|
if (info.file.status === 'done') { |
|
|
|
|
this.excelUploadBtn = false; |
|
|
|
|
this.excelUploadFile.push( |
|
|
|
|
{ |
|
|
|
|
uid: '1', |
|
|
|
|
name: info.file.name, |
|
|
|
|
status: 'done', |
|
|
|
|
url: info.file['response']['return_data'][0], |
|
|
|
|
thumbUrl: this.WEB_SERVE_URL + info.file['response']['return_data'][0], |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} else if (info.file.status === 'error') { |
|
|
|
|
this.message.error('文件上传失败'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 打开 发送优惠券包给用户模态框
|
|
|
|
|
showDeliverUserAddModal() { |
|
|
|
|
this.deliverUserAddModal = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 关闭 发送优惠券包给用户模态框
|
|
|
|
|
closeDeliverUserAddModal() { |
|
|
|
|
this.deliverUserAddForm.reset(); |
|
|
|
|
this.deliverUserAddModal = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
submitDeliverUserAdd() { |
|
|
|
|
for (const i in this.deliverUserAddForm.controls) { |
|
|
|
|
this.deliverUserAddForm.controls[i].markAsDirty(); |
|
|
|
|
this.deliverUserAddForm.controls[i].updateValueAndValidity(); |
|
|
|
|
} |
|
|
|
|
if (this.deliverUserAddForm.status == null || this.deliverUserAddForm.status !== 'VALID') { |
|
|
|
|
this.modal.warning({ |
|
|
|
|
nzTitle: '提示', |
|
|
|
|
nzContent: '请规范填写所有的必填项信息', |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let phoneObject = this.deliverUserArray.find(o => o.phone == this.deliverUserAddForm.controls.phone.value); |
|
|
|
|
if (phoneObject != null) { |
|
|
|
|
this.modal.warning({ |
|
|
|
|
nzTitle: '提示', |
|
|
|
|
nzContent: '手机号在列表中已存在', |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.discountPackage.getPhoneRegisterStatus(this.deliverUserAddForm.value, data => { |
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
this.deliverUserArray.push({ |
|
|
|
|
serialNum: this.deliverUserArray.length + 1, |
|
|
|
|
phone: this.deliverUserAddForm.controls.phone.value, |
|
|
|
|
registerStatus: data['return_data'], |
|
|
|
|
errorStatus: false, |
|
|
|
|
errorMsg: null |
|
|
|
|
}); |
|
|
|
|
this.deliverUserArray = this.deliverUserArray.slice(); |
|
|
|
|
this.closeDeliverUserAddModal(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 下载模板
|
|
|
|
|
downloadTemp() { |
|
|
|
|
window.location.href = this.WEB_SERVE_URL + 'template/导入模板.xlsx'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|