|
@@ -0,0 +1,208 @@
|
|
|
+import {Component, OnInit, ViewChild} from '@angular/core';
|
|
|
+import {DatePipe} from "@angular/common";
|
|
|
+import {ActivatedRoute, Router} from "@angular/router";
|
|
|
+import {ConfigService, RequsetData} from "../../../../../service/config.service";
|
|
|
+import {UserService} from "../../../../../service/user.service";
|
|
|
+import {AlertController, LoadingController, ModalController} from "@ionic/angular";
|
|
|
+import * as moment from 'moment';
|
|
|
+import {PhotoSwipeComponent} from "../../../../../comm/modal/photo-swipe/photo-swipe.component";
|
|
|
+import {PositionApi} from "../../../../../api/propagandawork/position";
|
|
|
+import {AlertModal} from "../../../../../comm/modal/alert";
|
|
|
+import {DictionaryApi} from "../../../../../api/system/dictionary";
|
|
|
+import {PanelApi} from "../../../../../api/propagandawork/position/panel";
|
|
|
+import {EditComponent as PanelEditComponent} from "../panel/edit/edit.component";
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-edit',
|
|
|
+ templateUrl: './edit.component.html',
|
|
|
+ styleUrls: ['./edit.component.scss'],
|
|
|
+})
|
|
|
+export class EditComponent implements OnInit {
|
|
|
+
|
|
|
+ @ViewChild(PhotoSwipeComponent)
|
|
|
+ photoSwipe: PhotoSwipeComponent;
|
|
|
+
|
|
|
+ op: number = 0;
|
|
|
+ dataModel: any = {};
|
|
|
+ positionTypeList: any = [];
|
|
|
+ positionLevelList: any = [];
|
|
|
+ positionStateList: any = [];
|
|
|
+ panelList: any = [];
|
|
|
+ detailOpen: boolean = false;
|
|
|
+ webServerHost: string = '';
|
|
|
+ maxDate: any = moment(new Date()).format("YYYY-MM-DD");
|
|
|
+ panelCycleList: any = [];
|
|
|
+
|
|
|
+ constructor(private datePipe: DatePipe, private router: Router, private routeInfo: ActivatedRoute, private configService: ConfigService, private userService: UserService, public alertController: AlertController,
|
|
|
+ public modalController: ModalController, public loadingController: LoadingController
|
|
|
+ , private positionApi: PositionApi, private alertModal: AlertModal, private dictionaryApi: DictionaryApi, private panelApi: PanelApi) {
|
|
|
+ }
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.routeInfo.queryParams.subscribe(params => {
|
|
|
+ this.dataModel.id = params['id'];
|
|
|
+ this.op = parseInt(params['op']);
|
|
|
+ this.getDictionList();
|
|
|
+ this.getData();
|
|
|
+ });
|
|
|
+
|
|
|
+ this.configService.GetConfig().subscribe((config) => {
|
|
|
+ this.webServerHost = config.webServerHost;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getData() {
|
|
|
+ this.positionApi.getData(this.dataModel.id, this.userService.GetUser().DZZDM).subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.dataModel = data.item;
|
|
|
+ this.getPanelList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getDictionList() {
|
|
|
+ this.dictionaryApi.getDictionaryList('positionType').subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.positionTypeList = data.item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.dictionaryApi.getDictionaryList('psiLevel').subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.positionLevelList = data.item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.dictionaryApi.getDictionaryList('positionState').subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.positionStateList = data.item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.dictionaryApi.getDictionaryList('panelCycle').subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ this.panelCycleList = data.item;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getPanelList() {
|
|
|
+ this.panelApi.getList({
|
|
|
+ pageIndex: 1, pageSize: 100, positionId: this.dataModel.publicitypositionid
|
|
|
+ }).subscribe((data: RequsetData) => {
|
|
|
+ if (data.success) {
|
|
|
+ data.item.list.forEach(e => {
|
|
|
+ this.panelList.push({
|
|
|
+ panelid: e.PANELID,
|
|
|
+ title: e.TITLE,
|
|
|
+ paneltime: e.PANELTIME,
|
|
|
+ panelimg: e.PANELIMG,
|
|
|
+ remark: e.REMARK
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ save() {
|
|
|
+ this.alertModal.loading("提交中...").then((loading) => {
|
|
|
+ this.positionApi.save(this.dataModel, this.panelList).subscribe((data: RequsetData) => {
|
|
|
+ loading.dismiss();
|
|
|
+ if (data.success) {
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ this.alertModal.alert(data.msg);
|
|
|
+ }, () => {
|
|
|
+ loading.dismiss();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ back() {
|
|
|
+ this.router.navigate(['../../position'], {relativeTo: this.routeInfo, queryParams: {random: Math.random()}});
|
|
|
+ }
|
|
|
+
|
|
|
+ editPanel(panel) {
|
|
|
+ this.panelModal(panel);
|
|
|
+ }
|
|
|
+
|
|
|
+ delete(id) {
|
|
|
+ /*this.alertModal.confirm("确认删除?", () => {
|
|
|
+ this.alertModal.loading("正在删除").then((loading) => {
|
|
|
+ this.positionApi.deletePlan(id).subscribe((fdata: RequsetData) => {
|
|
|
+ loading.dismiss();
|
|
|
+ if (fdata.success) {
|
|
|
+ this.getPanelList();
|
|
|
+ }
|
|
|
+ this.alertModal.alert(fdata.msg);
|
|
|
+ }, () => {
|
|
|
+ loading.dismiss();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });*/
|
|
|
+
|
|
|
+ this.panelList = this.panelList.filter(e => e.panelid != id);
|
|
|
+ }
|
|
|
+
|
|
|
+ async panelModal(panel) {
|
|
|
+ const modal = await this.modalController.create({
|
|
|
+ component: PanelEditComponent,
|
|
|
+ componentProps: {
|
|
|
+ panel: panel
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ await modal.present();
|
|
|
+
|
|
|
+ const {data} = await modal.onWillDismiss();
|
|
|
+ if (data.rtnData != null) {
|
|
|
+ let panel = this.panelList.filter(e => e.panelid === data.rtnData.panelid)[0];
|
|
|
+ if (panel == null) {
|
|
|
+ this.panelList.push(data.rtnData);
|
|
|
+ } else {
|
|
|
+ panel = data.rtnData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ showBigImage(id) {
|
|
|
+ try {
|
|
|
+ var items = [];
|
|
|
+ let url = this.webServerHost + "/appApi/home/showImg/" + id;
|
|
|
+ let img = this.getImageWidth(url) || {width: 500, height: 300};
|
|
|
+ items.push({
|
|
|
+ src: url,
|
|
|
+ w: img.width || 500,
|
|
|
+ h: img.height || 300
|
|
|
+ })
|
|
|
+
|
|
|
+ this.photoSwipe.open(items, {
|
|
|
+ index: 0,
|
|
|
+ tapToClose: true
|
|
|
+ }, "pswp" + (Math.random() * 100000).toFixed(0).toString());
|
|
|
+ } catch (e) {
|
|
|
+ this.alertModal.alert("图片查看异常:" + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getImageWidth(url) {
|
|
|
+ let obj = {width: 0, height: 0}
|
|
|
+ try {
|
|
|
+ var img = new Image();
|
|
|
+ img.src = url;
|
|
|
+ // 如果图片被缓存,则直接返回缓存数据
|
|
|
+ if (img.complete) {
|
|
|
+ obj.width = img.width;
|
|
|
+ obj.height = img.height;
|
|
|
+ return obj
|
|
|
+ } else {
|
|
|
+ img.onload = function () {
|
|
|
+ obj.width = img.width;
|
|
|
+ obj.height = img.height;
|
|
|
+ return obj
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ this.alertModal.alert("图片高宽获取异常:" + e);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|