|
|
@@ -1,21 +1,38 @@
|
|
|
import { DiaLogSheetControl, YTAvoid, yTRouter } from 'basic';
|
|
|
import { AddressAddPageState } from '../model/EnumState';
|
|
|
+import { UserAddressStorage } from '../model/Storage';
|
|
|
import { CustomTextStyle } from '../style/CustomTextStyle';
|
|
|
import { AddressItemComp } from './AddressItemComp';
|
|
|
import { buttonComp } from './BuilderIndex';
|
|
|
+import { AppStorageV2 } from '@kit.ArkUI';
|
|
|
+import { Address } from '../model/Address';
|
|
|
|
|
|
|
|
|
@ComponentV2
|
|
|
export struct AddressComp{
|
|
|
- // @Param @Require param: BasicType
|
|
|
@Param @Require control: DiaLogSheetControl
|
|
|
+ @Param @Require addressId: string
|
|
|
|
|
|
- @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
|
|
|
@Local selectIndex: number = 0
|
|
|
+ @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
|
|
|
+
|
|
|
+ addressConnect: UserAddressStorage = AppStorageV2.connect(UserAddressStorage, () => new UserAddressStorage())!
|
|
|
+
|
|
|
+ aboutToAppear(): void {
|
|
|
+ this.selectIndex = this.addressConnect.getIndexById(this.addressId)
|
|
|
+ }
|
|
|
|
|
|
// 前往添加地址页面
|
|
|
IncreaseAddressPage(){
|
|
|
- yTRouter.router2IncreaseAddressPage(AddressAddPageState.ADD)
|
|
|
+ yTRouter.router2IncreaseAddressPage(undefined, (info) => {
|
|
|
+ let ans = info.result as Address
|
|
|
+ this.selectAddress(ans)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择地址
|
|
|
+ selectAddress(item: Address){
|
|
|
+ this.control._onBackPress({ item })
|
|
|
}
|
|
|
|
|
|
build() {
|
|
|
@@ -35,13 +52,17 @@ export struct AddressComp{
|
|
|
.borderRadius({topLeft: 12, topRight: 12})
|
|
|
.padding({left: 18, right: 18, top: 14, bottom: 14})
|
|
|
|
|
|
- Column({space: 18}){
|
|
|
- ForEach(new Array(3).fill(''), (item: string, index) => {
|
|
|
- this.addressItem(index)
|
|
|
- })
|
|
|
- }.width('100%')
|
|
|
- .backgroundColor('#F7F9FA')
|
|
|
- .padding({top: 18, bottom: 18, left: 15, right: 15})
|
|
|
+ Column(){
|
|
|
+ List({space: 18}){
|
|
|
+ ForEach(this.addressConnect.addressList, (item: Address, index) => {
|
|
|
+ ListItem(){
|
|
|
+ this.addressItem(item, index)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }.width('100%').height('100%')
|
|
|
+ .backgroundColor('#F7F9FA')
|
|
|
+ .padding({top: 18, bottom: 18, left: 15, right: 15})
|
|
|
+ }.height(Math.min(this.addressConnect.addressList.length*110, 400))
|
|
|
|
|
|
Row(){
|
|
|
buttonComp(
|
|
|
@@ -60,14 +81,15 @@ export struct AddressComp{
|
|
|
}
|
|
|
|
|
|
@Builder
|
|
|
- addressItem(index: number){
|
|
|
+ addressItem(item: Address, index: number){
|
|
|
RelativeContainer(){
|
|
|
- AddressItemComp({ selectIndex: this.selectIndex, index: index, type: 2, needBorder: false })
|
|
|
+ AddressItemComp({ selectIndex: this.selectIndex, index: index, type: 2, needBorder: false, address: item, click: () => { this.selectAddress(item) } })
|
|
|
.alignRules({
|
|
|
left: {anchor: '__container__', align: HorizontalAlign.Start},
|
|
|
top: {anchor: '__container__', align: VerticalAlign.Top}
|
|
|
})
|
|
|
|
|
|
+ // todo 是否保留默认地址
|
|
|
if(0 == index){
|
|
|
Text('默认')
|
|
|
.fontSize(12)
|
|
|
@@ -85,7 +107,6 @@ export struct AddressComp{
|
|
|
.height(100)
|
|
|
.borderRadius(16)
|
|
|
.backgroundColor(Color.White)
|
|
|
- .onClick(() => { this.selectIndex = index })
|
|
|
.border({width: 1, color: 0 == index ? '#FFFECF2F' : '#FF000000'})
|
|
|
}
|
|
|
}
|