《仿盒马》app开发技术分享-- 旧物回收页(提交云端)(42)

鸿蒙小林
• 阅读 3

技术栈

Appgallery connect

开发准备

上一节我们已经实现了地址,留言,取件时间的选择,以及静态的预估重量。现在我们需要把预估重量创建出来,从云端去获取,以应对后续的其他业务逻辑,以及回收订单的创建

功能分析

预估重量列表的实现首先需要创建对应的表和数据源,然后在页面打开的时候从云端查询出对应的数据,展示到我们创建的静态列表中,然后我们创建订单,把页面中的数据放置到创建的订单创建表中

代码实现

首先我们创建对应的表

{
  "objectTypeName": "weight_info",
  "fields": [
    {"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {"fieldName": "weight_id", "fieldType": "Integer"},
    {"fieldName": "weight", "fieldType": "String"},
    {"fieldName": "txt", "fieldType": "String"},
    {"fieldName": "integral", "fieldType": "Double"},
    {"fieldName": "money", "fieldType": "Double"}
  ],
  "indexes": [
    {"indexName": "field1IndexId", "indexList": [{"fieldName":"id","sortType":"ASC"}]}
  ],
  "permissions": [
    {"role": "World", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Authenticated", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Creator", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Administrator", "rights": ["Read", "Upsert", "Delete"]}
  ]
}

创建对应的实体和db类

import { cloudDatabase } from '@kit.CloudFoundationKit';

class weight_info extends cloudDatabase.DatabaseObject {
  public id: number;
  public weight_id: number;
  public weight: string;
  public txt: string;
  public integral: number;
  public money: number;

  public naturalbase_ClassName(): string {
    return 'weight_info';
  }
}

export { weight_info };




class WeightInfo {
    id: number;
    weight_id: number;
    weight: string;
    txt: string;
    integral: number;
    money: number;

    constructor() {
    }

    getFieldTypeMap():  Map<string, string> {
        let fieldTypeMap = new Map<string, string>();
        fieldTypeMap.set('id', 'Integer');
        fieldTypeMap.set('weight_id', 'Integer');
        fieldTypeMap.set('weight', 'String');
        fieldTypeMap.set('txt', 'String');
        fieldTypeMap.set('integral', 'Double');
        fieldTypeMap.set('money', 'Double');
        return fieldTypeMap;
    }

    getClassName(): string {
        return 'weight_info';
    }

    getPrimaryKeyList(): string[] {
        let primaryKeyList: string[] = [];
        primaryKeyList.push('id');
        return primaryKeyList;
    }

    getIndexList(): string[] {
        let indexList: string[] = [];
        indexList.push('id');
        return indexList;
    }

    getEncryptedFieldList(): string[] {
        let encryptedFieldList: string[] = [];
        return encryptedFieldList;
    }

    setId(id: number): void {
        this.id = id;
    }

    getId(): number  {
        return this.id;
    }

    setWeight_id(weight_id: number): void {
        this.weight_id = weight_id;
    }

    getWeight_id(): number  {
        return this.weight_id;
    }

    setWeight(weight: string): void {
        this.weight = weight;
    }

    getWeight(): string  {
        return this.weight;
    }

    setTxt(txt: string): void {
        this.txt = txt;
    }

    getTxt(): string  {
        return this.txt;
    }

    setIntegral(integral: number): void {
        this.integral = integral;
    }

    getIntegral(): number  {
        return this.integral;
    }

    setMoney(money: number): void {
        this.money = money;
    }

    getMoney(): number  {
        return this.money;
    }

    static parseFrom(inputObject: any): WeightInfo {
        let result = new WeightInfo();
        if (!inputObject) {
            return result;
        }
        if (inputObject.id) {
            result.id = inputObject.id;
        }
        if (inputObject.weight_id) {
            result.weight_id = inputObject.weight_id;
        }
        if (inputObject.weight) {
            result.weight = inputObject.weight;
        }
        if (inputObject.txt) {
            result.txt = inputObject.txt;
        }
        if (inputObject.integral) {
            result.integral = inputObject.integral;
        }
        if (inputObject.money) {
            result.money = inputObject.money;
        }
        return result;
    }
}

export { WeightInfo };

在页面打开后获取云端的数据

 @State weightList:WeightInfo[]=[]
  @State weightInfo:WeightInfo|null=null
async aboutToAppear(): Promise<void> {
    const value = await StorageUtils.getAll('user');
    if (value != "") {
      this.user = JSON.parse(value)
    }
    let condition = new cloudDatabase.DatabaseQuery(weight_info);
    let listData = await databaseZone.query(condition);
    let json = JSON.stringify(listData)
    let weightInfo:WeightInfo[]= JSON.parse(json)
    this.weightList=weightInfo
    hilog.info(0x0000, 'testTag', `Succeeded in querying data, result: ${weightInfo}`);
    this.flag=true
  }

添加对应的数据到提交信息表

Text("预约呼叫")
              .width('95%')
              .height(45)
              .fontSize(16)
              .fontWeight(FontWeight.Bold)
              .borderRadius(5)
              .backgroundColor("#fff84f4f")
              .textAlign(TextAlign.Center)
              .margin({top:15})
              .onClick(async ()=>{
                let recyclePushInfo=new recycle_info()
                recyclePushInfo.id=Math.floor(Math.random() * 1000000);
                recyclePushInfo.user_id=this.user!.user_id
                recyclePushInfo.nike_name=this.addressInfo!.nikeName
                recyclePushInfo.phone=this.addressInfo!.phone
                recyclePushInfo.address=this.addressInfo!.address
                recyclePushInfo.day=this.formatCurrent()
                recyclePushInfo.start_time=this.formatCurrentDate()
                recyclePushInfo.end_time=this.formatCurrentEndDate()
                recyclePushInfo.weight_id=String(this.weightInfo!.weight_id)
                if (this.remark!='') {
                  recyclePushInfo.msg=this.remark
                }
                recyclePushInfo.create_time=this.formatCurrentCreatTime()
                recyclePushInfo.express_code=this.generate16DigitRandom()
                recyclePushInfo.express_people="骑士阿三"
                recyclePushInfo.express_company="中国邮政(默认)"
                recyclePushInfo.order_type=0
                recyclePushInfo.logistics_id=10
                let num = await databaseZone.upsert(recyclePushInfo);
                hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${num}`);
                if (num>0) {
                  showToast("下单成功")
                }
              })

到这里我们就实现了提交云端数据的功能

点赞
收藏
评论区
推荐文章
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 确认订单页(业务逻辑)(30)
技术栈Appgalleryconnect开发准备上一节我们实现了确认订单页的页面绘制和价格计算优惠计算,订单列表展示等功能,这一节我们来实现确认订单页的整个业务逻辑。首先我们要实现的就是地址的选择,然后把我们计算的价格,商品列表等数据保存起来,然后我们开始
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 旧物回收页(静态)(40)
技术栈Appgalleryconnect开发准备上一节我们进行了购物车业务逻辑的优化,使我们的程序变得更加健壮,这一节我们将要开始电商业务以外的内容,旧物回收,这是一个全新的业务模块,我们将要在这里实现对应的,回收金,积分,回收业务相关内容功能分析要想实现
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 旧物回收页(业务逻辑)(41)
技术栈Appgalleryconnect开发准备上一节我们实现了旧物回收页的静态展示页,现在我们开始添加对应的模块逻辑,我们要实现的内容有,地址选择、留言、取件时间、重量选择这些模块功能分析1.地址选择要实现地址选择,我们首先要在跳转到地址列表选择页,传递
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 旧物回收订单列表(43)
技术栈Appgalleryconnect开发准备上一节我们实现了订单的创建,并且成功吧数据提交到云数据库中,这一节我们实现的内容是展示我们提交的订单列表功能分析要实现订单列表的展示,首先我们要查询对应用户下的订单列表,查询出对应的订单列表后,展示出对应的数
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 回收订单页功能完善(45)
技术栈Appgalleryconnect开发准备上一节我们实现了订单的待取件、已取消状态展示,并且成功实现了修改订单状态后的列表刷新,实现了云端数据的修改,这一节我们来实现订单页剩下的两个板块的业务逻辑,分别是运输中、已完成状态下的列表展示以及订单状态的修
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 回收金提现准备页(50)
技术栈Appgalleryconnect开发准备上一节我们实现了回收金的收入、支出记录查询,并且在订单完成后成功创建对应的收支记录,但是我们暂时只有收入记录,并没有支出记录,这一节我们将要实现账号的回收金提现功能,从商业角度实现app应用的正向循环功能分析
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 我的积分页(63)
技术栈Appgalleryconnect开发准备上一节我们实现了个人中心页面的业务逻辑优化,成功的在用户登陆退出状态下展示对应的组件内容,这一节我们来实现app中另外一个比较重要的模块积分模块。功能分析因为我们的回收订单是跟回收金积分是绑定的,我们在完成回
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 兑换订单提交(73)
技术栈Appgalleryconnect开发准备上一节我们实现了兑换提交前的准备页面,向用户展示了兑换相关的所有信息,这一节我们就可以实现兑换订单的提交了功能分析订单提交我们需要创建对应的兑换商品订单提交信息表,我们需要把地址,商品信息,积分,备注,订单状
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 兑换订单列表框架(75)
技术栈Appgalleryconnect开发准备上一节我们针对订单兑换的业务逻辑进行了完善,成功的在兑换物品之后修改了用户信息的修改,新增了积分消费的记录。这一节我们实现订单创建之后进入的列表展示页框架。功能分析兑换商品的订单列表框架我们选择使用tabs,
鸿蒙小林 鸿蒙小林
2小时前
《伴时匣》app开发技术分享--表单提交页(5)
技术栈Appgalleryconnect开发准备上一节我们已经实现了表单信息的创建,完成了首页跳转表单提交页的内容,这一节我们就要实现表单创建前的数据填充的页面。功能分析在表单提交前,我们要实现的静态内容有很多,分别有输入框,开关,时间选择器,表类型,是否