ImportRecordsDialog.ets 4.6 KB
import { Row, QueryParams, RecordsList } from '../api/recordsType'
import { getRecordsList, importRecord } from '../api/originalRecords'
import { AxiosResponse } from '@ohos/axios'
import preferencesUtil from '../utils/preferences'
import { promptAction } from '@kit.ArkUI'

let companyId: number = preferencesUtil.get('XF_COMPANY_ID', 0) as number
@CustomDialog
export default struct ImportRecordsDialog{
  controller: CustomDialogController = new CustomDialogController({builder: ''})
  //回调函数
  onChange: () => void = () => {}
  @Prop applyCompanyName: string
  @Prop reportId: number
  @State recordsList: Row[] = []
  @State searchValue: string = ''
  async aboutToAppear() {
    let params: QueryParams = {
      pageNum: 1,
      pageSize: 20,
      applyCompanyName: this.applyCompanyName,
      companyId: companyId
    }
    const result: AxiosResponse<RecordsList> = await getRecordsList(params)
    this.recordsList = result.data.rows
  }
  build() {
    Column(){
      Row(){
        Search({ value: $$this.searchValue, placeholder: '请输入【记录编号】' })
          .searchButton('搜索', {
            fontSize: 12
          })
          .width('95%')
          .height(30)
          .backgroundColor('#fff')
          .placeholderColor(Color.Grey)
          .placeholderFont({ size: 12, weight: 400 })
          .textFont({ size: 12, weight: 400 })
          .layoutWeight(1)
          .onSubmit(async () => {
            this.recordsList = []
            let params: QueryParams = {
              pageNum: 1,
              pageSize: 10,
              applyCompanyName: this.applyCompanyName,
              companyId: companyId,
              reportType: '1',
              reportNo: this.searchValue
            }
            const result: AxiosResponse<RecordsList> = await getRecordsList(params)
            this.recordsList = result.data.rows
          })
      }.padding({left: 5, right: 5}).borderRadius(10)
      List({space: 10}){
        ForEach(this.recordsList, (item: Row) => {
          ListItem(){
            Row({space: 10}){
              Column({space: 10}){
                Row(){
                  Image($r('app.media.project')).width(16).margin({right: 10})
                  Text(item.reportName).fontSize(12).fontColor('#333').maxLines(2)
                    .textOverflow({overflow: TextOverflow.Ellipsis})
                }
                Row(){
                  Image($r('app.media.company')).width(16).margin({right: 10})
                  Text(item.applyCompanyName).fontSize(12).fontColor('#999')
                }
                Row(){
                  Image($r('app.media.numberNo')).width(16).margin({right: 10})
                  Text(item.reportNo).fontSize(12).fontColor('#999')
                }
                Row(){
                  Image($r('app.media.dateTime')).width(16).margin({right: 10})
                  Text(`${item.maintenanceTime}~${item.maintenanceEndTime || ''}`).fontSize(12).fontColor('#999')
                }
              }.alignItems(HorizontalAlign.Start).layoutWeight(1)
              Text('导入').fontSize(14).fontColor('#1890ff')
                .onClick(() => {
                  AlertDialog.show({
                    title: '',
                    message: '删除后无法找回,确认删除全部故障处理记录并提交?',
                    autoCancel: true,
                    alignment: DialogAlignment.Center,
                    gridCount: 4,
                    offset: { dx: 0, dy: -20 },
                    buttonDirection: DialogButtonDirection.HORIZONTAL,
                    buttons: [
                      {
                        value: '取消',
                        action: () => {
                          console.info('Callback when button1 is clicked')
                        }
                      },
                      {
                        value: '确认',
                        action: async () => {
                          await importRecord(item.reportId,this.reportId)
                          this.onChange()
                          this.controller.close()
                          promptAction.showToast({message: '更新成功'})
                        }
                      }
                    ],
                    cancel: () => {
                      console.info('Closed callbacks')
                    }
                  })
                })
            }.borderRadius(10).padding(10).backgroundColor('#fff').width('100%')
          }
        })
      }.padding({top: 10, bottom: 20, left: 10, right: 10})
    }.constraintSize({maxHeight: '60%'}).backgroundColor('#f2f3f7')
  }
}