import { IPSDEFormDetail, PSDEFormDetail } from '@ibizstudio/api';
import { VueLifeCycleProcessing } from '../../../decorators';
import { Component, Prop } from 'vue-property-decorator';
import { DragDesignItemBase } from '../drag-design-item-base';
import './design-page.less';
import { generateOrderValue } from 'qx-util';
/**
* 表单分页
*
* @export
* @class DesignPage
* @extends {DragDesignItemBase}
*/
@Component({})
@VueLifeCycleProcessing()
export class DesignPage extends DragDesignItemBase {
@Prop({ default: 'FORMPAGE' })
itemType!: string;
/**
* 当前激活表单分页
*
* @type {IPSDEFormDetail}
* @memberof DesignPage
*/
activateData: any = null;
/**
* 激活数据变更
*
* @param {T} data
* @memberof DesignItemBase
*/
activeChange(data: IPSDEFormDetail): void {
if (data.itemtype === this.itemType) {
this.activateData = data;
}
}
accCrated(data: IPSDEFormDetail): void {
if (data.itemtype === this.itemType) {
this.load();
}
}
accRemove(data: IPSDEFormDetail): void {
if (data.itemtype === this.itemType) {
this.load();
}
}
async load() {
this.loadChild({
itemtype: this.itemType,
psdeformid: this.ctx.context.psdeform,
});
}
async addPage() {
const data = await this.getDraft(new PSDEFormDetail({ itemtype: this.itemType }));
const newIndex = this.list.length;
await this.updateOrderValue(newIndex + 1);
this.list.splice(newIndex, 1);
data.ordervalue = generateOrderValue(newIndex);
data.srfordervalue = data.ordervalue;
await this.create(data);
}
removePage(item: PSDEFormDetail) {
this.remove(item.srfkey);
}
change(evt: any) {
if (evt?.moved) {
this.move(evt.moved);
}
}
render() {
if(this.ctx.isPreview && this.list.length === 1){
return (
)
}
return (
this.setSelect(item)}
on-remove-page={(item: any) => this.removePage(item)}
on-add-page={() => this.addPage()}
on-change={(e: any) => this.change(e)}
renderTabItemContent={(_h: any, item: any) => {
return (
);
}}
/>
);
}
}