123 lines
3.9 KiB
Plaintext
123 lines
3.9 KiB
Plaintext
import { BasicConstant } from '../constants/BasicConstant'
|
|
import { RequestDefaultModel } from '../models/RequestDefaultModel'
|
|
import { promptAction } from '@kit.ArkUI'
|
|
import HashMap from '@ohos.util.HashMap';
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { authStore } from '../utils/auth'
|
|
import { hdHttp, HdResponse } from '../utils/request'
|
|
|
|
interface DefaultData {
|
|
'name':string;
|
|
'uuid':string;
|
|
}
|
|
|
|
@CustomDialog
|
|
export struct PositionSelectedSheet {
|
|
controller: CustomDialogController;
|
|
@State officeNameArr:Array<string> = [];
|
|
private officeArr:Array<DefaultData> = [];
|
|
@Prop selectedOffice:object = new Object;
|
|
@State selectedModel:DefaultData = { name: '', uuid: '' };
|
|
|
|
@State selectedIndex:number = 0;
|
|
|
|
// 添加回调函数属性
|
|
private officeSelected: (name:string , uuid:string) => void = () => {};
|
|
|
|
// 修改构造函数
|
|
constructor(controller: CustomDialogController, officeSelected: (name: string,uuid:string) => void) {
|
|
super();
|
|
this.controller = controller;
|
|
this.officeSelected = officeSelected;
|
|
}
|
|
|
|
officeRequestUrl:string = BasicConstant.urlExpert+'positionList'
|
|
hashMap: HashMap<string, string> = new HashMap();
|
|
|
|
aboutToAppear(): void {
|
|
this.uploadOffice();
|
|
}
|
|
|
|
uploadOffice() {
|
|
hdHttp.httpReq<string>(this.officeRequestUrl,this.hashMap).then(async (res: HdResponse<string>) => {
|
|
let json:RequestDefaultModel = JSON.parse(res+'') as RequestDefaultModel;
|
|
if(json.code=='1') {
|
|
this.officeArr = json.data as DefaultData[];
|
|
this.officeNameArr = json.data.map(item => item.name);
|
|
for (let index = 0; index < this.officeNameArr.length; index++) {
|
|
const object = this.officeArr[index] as DefaultData;
|
|
const nameIndex = this.officeNameArr[index];
|
|
if (nameIndex == authStore.getUser().positionName) {
|
|
this.selectedIndex = index;
|
|
this.selectedModel = {name:nameIndex,uuid:object.uuid};
|
|
break;
|
|
} else {
|
|
const defaultModel = this.officeArr[0] as DefaultData;
|
|
this.selectedIndex = 0;
|
|
this.selectedModel = {name:defaultModel.name,uuid:defaultModel.uuid};
|
|
}
|
|
}
|
|
console.log('职称名称数组:', this.officeNameArr);
|
|
} else {
|
|
console.error('职称数据失败:'+json.message)
|
|
promptAction.showToast({ message: json.message, duration: 1000 })
|
|
}
|
|
}).catch((err: BusinessError) => {
|
|
console.info(`Response fail: ${err}`);
|
|
})
|
|
}
|
|
|
|
build() {
|
|
Column() {
|
|
// 操作按钮区域
|
|
Row({space:70}) {
|
|
Button('取消')
|
|
.layoutWeight(1)
|
|
.backgroundColor(Color.Transparent)
|
|
.fontColor($r('app.color.main_color'))
|
|
.backgroundColor(Color.White)
|
|
.width(80)
|
|
.onClick(() => {
|
|
this.controller.close()
|
|
})
|
|
|
|
Text('请选择职称')
|
|
.fontSize(15)
|
|
.fontColor('#666666')
|
|
|
|
Button('确定')
|
|
.layoutWeight(1)
|
|
.backgroundColor(Color.Transparent)
|
|
.fontColor($r('app.color.main_color'))
|
|
.backgroundColor(Color.White)
|
|
.width(80)
|
|
.onClick(() => {
|
|
this.controller.close()
|
|
this.officeSelected(this.selectedModel.name, this.selectedModel.uuid);
|
|
})
|
|
}
|
|
.height(40)
|
|
|
|
TextPicker({
|
|
range:this.officeNameArr,
|
|
selected:this.selectedIndex
|
|
})
|
|
.width('100%')
|
|
.canLoop(false)
|
|
.selectedTextStyle({
|
|
color: '#007AFF',
|
|
font: { size: 20, weight: FontWeight.Medium }
|
|
})
|
|
.onChange((name: string | string[], index: number | number[]) => {
|
|
// 处理单列选择场景
|
|
if (typeof index === "number" && this.officeArr[index]) {
|
|
this.selectedModel = this.officeArr[index];
|
|
}
|
|
})
|
|
}
|
|
.width('100%')
|
|
.height(240)
|
|
.backgroundColor(Color.White)
|
|
}
|
|
}
|