|
@@ -2,10 +2,13 @@
|
|
|
import 'dart:async';
|
|
|
|
|
|
import 'package:cpt_community/modules/community/community_vm.dart';
|
|
|
+import 'package:cpt_community/modules/garage/garagesale_detail/garagesale_detail_vm.dart';
|
|
|
import 'package:cs_resources/generated/assets.dart';
|
|
|
+import 'package:domain/entity/garage_sale_rent_detail_entity.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:plugin_basic/constants/app_constant.dart';
|
|
|
import 'package:plugin_basic/provider/user_config/user_config_service.dart';
|
|
|
+import 'package:plugin_platform/engine/loading/loading_engine.dart';
|
|
|
import 'package:plugin_platform/engine/sp/sp_util.dart';
|
|
|
import 'package:plugin_platform/engine/toast/toast_engine.dart';
|
|
|
import 'package:plugin_platform/http/http_result.dart';
|
|
@@ -32,7 +35,8 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
List _resCategoryOptionsList = [];
|
|
|
int _initialSaleSelectIndex = 0;
|
|
|
String _initialSaleSelectedItem = '';
|
|
|
- int _type = 1; // 类型(1=Sale,2=Rent)
|
|
|
+ int _type = 1; // 类型(1=Sale,2=Rent, 3=mineForSale 4=mineForRent)
|
|
|
+ late GarageSaleRentDetailEntity _detailData;
|
|
|
|
|
|
GaragesalePostPageState initState() {
|
|
|
return GaragesalePostPageState(
|
|
@@ -92,7 +96,6 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
'obsecure': false,
|
|
|
},
|
|
|
},
|
|
|
- imgList: [],
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -120,16 +123,20 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
// 初始化回显 sale 分类
|
|
|
initSaleCategory();
|
|
|
this.getGarageCategoryList();
|
|
|
+ if(_type == 3 || _type == 4){
|
|
|
+ // mypost 页面进来的 是编辑 需要回显
|
|
|
+ this.initEchoData();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
initSaleCategory() {
|
|
|
state.saleOptionsList.asMap().forEach((index, item) => {
|
|
|
- if(_type == 1){
|
|
|
+ if(_type == 1 || _type == 3){
|
|
|
if(item == 'For Sale'){
|
|
|
_initialSaleSelectIndex = index,
|
|
|
_initialSaleSelectedItem = item
|
|
|
}
|
|
|
- }else if(_type == 2){
|
|
|
+ }else if(_type == 2 || _type == 4){
|
|
|
if(item == 'For Rent'){
|
|
|
_initialSaleSelectIndex = index,
|
|
|
_initialSaleSelectedItem = item
|
|
@@ -138,6 +145,102 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // mypost页面通过详情然后编辑 进入的 需要初始化回显数据
|
|
|
+ initEchoData() async{
|
|
|
+ LoadingEngine.show();
|
|
|
+ // 调取 详情接口
|
|
|
+ final garagesaleDetailVm = ref.read(garagesaleDetailVmProvider.notifier);
|
|
|
+ final _detailData = await garagesaleDetailVm.getDetailData();
|
|
|
+ if(_detailData != null){
|
|
|
+ // 回显 title
|
|
|
+ String title = _detailData.title??'';
|
|
|
+ String price = _detailData.price?.toString()??'0';
|
|
|
+ String description = _detailData.description??'';
|
|
|
+ String saleSelectedOption = _type==3? 'For Sale':'For Rent';
|
|
|
+ String contact = _detailData.contact??'';
|
|
|
+ String contactInformation = garagesaleDetailVm.getContactNumber(contact)??'';
|
|
|
+ String contactType = ''; // 联系方式 类型 Mobile Phone WhatsApp
|
|
|
+ // final category_id = result.category_id??'';
|
|
|
+ // final categorySelectedOption = result.category??'';
|
|
|
+ String categorySelectedOption = 'Kids';
|
|
|
+ // 根据 categorySelectedOption
|
|
|
+
|
|
|
+ List<String> imgList = _detailData.resources??[];
|
|
|
+ Log.d("imgList--------$imgList");
|
|
|
+
|
|
|
+ if(contact.isNotEmpty){
|
|
|
+ if(garagesaleDetailVm.isContactMobile(contact)){
|
|
|
+ // 是mobile
|
|
|
+ state.contactTypeSelectedOption = 'Mobile Phone';
|
|
|
+ contactType = 'Mobile Phone';
|
|
|
+ }else if(garagesaleDetailVm.isContactWhatsApp(contact)){
|
|
|
+ // 是whatsapp
|
|
|
+ state.contactTypeSelectedOption = 'WhatsApp';
|
|
|
+ contactType = 'WhatsApp';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // category_id
|
|
|
+
|
|
|
+ final newFormdata = {
|
|
|
+ 'sale': {
|
|
|
+ 'value': saleSelectedOption,
|
|
|
+ 'controller': TextEditingController(text: saleSelectedOption ?? ''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ 'category': {
|
|
|
+ 'value': categorySelectedOption??'',
|
|
|
+ 'controller': TextEditingController(text: categorySelectedOption??''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ 'title': {
|
|
|
+ 'value': title ?? '',
|
|
|
+ 'controller': TextEditingController(text: title ?? ''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ 'contactInfo': {
|
|
|
+ 'value': contactInformation ?? '',
|
|
|
+ 'controller': TextEditingController(text: contactInformation ?? ''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ 'price': {
|
|
|
+ 'value': price ?? '',
|
|
|
+ 'controller': TextEditingController(text: price != null? price.toString():''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ 'description': {
|
|
|
+ 'value': description??'',
|
|
|
+ 'controller': TextEditingController(text: description??''),
|
|
|
+ 'hintText': '',
|
|
|
+ 'focusNode': FocusNode(),
|
|
|
+ 'obsecure': false,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ state = state.copyWith(
|
|
|
+ title: title,
|
|
|
+ description: description,
|
|
|
+ price: price,
|
|
|
+ categorySelectedOption: categorySelectedOption,
|
|
|
+ contactTypeSelectedOption: contactType,
|
|
|
+ contactInformation: contactInformation,
|
|
|
+ imgList: imgList,
|
|
|
+ formData: {...state.formData, ...newFormdata}
|
|
|
+ );
|
|
|
+ }
|
|
|
+ LoadingEngine.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
Future<List<String>> getGarageCategoryList() async{
|
|
|
final communityVm = ref.read(communityVmProvider.notifier);
|
|
|
List<Map<String, dynamic>> garageCategoryList = await communityVm.getGarageSaleCategoryOptions();
|
|
@@ -252,9 +355,11 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
///提交反馈
|
|
|
Future submitGaragesalePost(BuildContext context, {VoidCallback? sCallback, VoidCallback? fCallback}) async{
|
|
|
Log.d("GaragesalePostPageState 提交表单");
|
|
|
+
|
|
|
state = state.copyWith(titleErrorText: null, descriptionErrorText: null);
|
|
|
_dismissKeyboard(keyStr: "");
|
|
|
|
|
@@ -336,28 +441,76 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
totalContactStr = 'email:$contactInfoValue';
|
|
|
}
|
|
|
|
|
|
- // 提交数据
|
|
|
- final resResult = await handlerSubmitPost(
|
|
|
- type: saleValue == 'For Sale'? 1:2,
|
|
|
- titleValue: titleValue,
|
|
|
- categoryId: categoryId!,
|
|
|
- priceValue: priceValue,
|
|
|
- descriptionValue: descriptionValue,
|
|
|
- contactValue: totalContactStr,
|
|
|
- imgList: state.imgList,
|
|
|
- );
|
|
|
-
|
|
|
- if(resResult.isSuccess){
|
|
|
- // 更新用户信息
|
|
|
- UserConfigService.getInstance().refreshUserInfo();
|
|
|
|
|
|
- final communitVm = ref.read(communityVmProvider.notifier);
|
|
|
- communitVm.getCurrentPageViewVm(null).initPageData();
|
|
|
- // Navigator.pop(context);
|
|
|
- appRouter.maybePop();
|
|
|
+ if(_type == 1 || _type == 2){
|
|
|
+ // 新增 提交数据
|
|
|
+ final resResult = await handlerSubmitPost(
|
|
|
+ type: saleValue == 'For Sale'? 1:2,
|
|
|
+ titleValue: titleValue,
|
|
|
+ categoryId: categoryId!,
|
|
|
+ priceValue: priceValue,
|
|
|
+ descriptionValue: descriptionValue,
|
|
|
+ contactValue: totalContactStr,
|
|
|
+ imgList: state.imgList??[],
|
|
|
+ );
|
|
|
+
|
|
|
+ if(resResult.isSuccess){
|
|
|
+ // 更新用户信息
|
|
|
+ UserConfigService.getInstance().refreshUserInfo();
|
|
|
+
|
|
|
+ final communitVm = ref.read(communityVmProvider.notifier);
|
|
|
+ communitVm.getCurrentPageViewVm(null).initPageData();
|
|
|
+ // Navigator.pop(context);
|
|
|
+ appRouter.maybePop();
|
|
|
+ }
|
|
|
+ }else if(_type == 3 || _type ==4){
|
|
|
+ // 调用编辑提交的接口
|
|
|
+ // mypost 入口进入的 编辑 提交数据
|
|
|
+ final resResult = await handlerSubmitEdit(
|
|
|
+ id: _detailData.id!,
|
|
|
+ titleValue: titleValue,
|
|
|
+ categoryId: categoryId!,
|
|
|
+ priceValue: priceValue,
|
|
|
+ descriptionValue: descriptionValue,
|
|
|
+ contactValue: totalContactStr,
|
|
|
+ imgList: state.imgList??[],
|
|
|
+ );
|
|
|
+ if(resResult.isSuccess){
|
|
|
+ // 更新用户信息
|
|
|
+ // UserConfigService.getInstance().refreshUserInfo();
|
|
|
+
|
|
|
+ final garagesaleDetailVm = ref.read(garagesaleDetailVmProvider.notifier);
|
|
|
+ final _detailData = await garagesaleDetailVm.getDetailData();
|
|
|
+ // Navigator.pop(context);
|
|
|
+ appRouter.maybePop();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 编辑
|
|
|
+ Future<HttpResult<Object>> handlerSubmitEdit({
|
|
|
+ required int id,
|
|
|
+ required String titleValue,
|
|
|
+ required int categoryId,
|
|
|
+ required String priceValue,
|
|
|
+ required String contactValue,
|
|
|
+ required String descriptionValue,
|
|
|
+ required List imgList,
|
|
|
+ }) async{
|
|
|
+ final params = <String, dynamic>{
|
|
|
+ "id": id,
|
|
|
+ "category_id": categoryId,
|
|
|
+ "title": titleValue,
|
|
|
+ "price": priceValue,
|
|
|
+ "description": descriptionValue,
|
|
|
+ "contact": contactValue, // string($例如:whatsapp:+8617671757687 或 mobile:+8617671757687)
|
|
|
+ "resources": imgList,
|
|
|
+ };
|
|
|
+ final result = await commonGarageRespositoryInstance.updateMyGarage(params);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增
|
|
|
Future<HttpResult<Object>> handlerSubmitPost({
|
|
|
required int type,
|
|
|
required String titleValue,
|
|
@@ -368,7 +521,7 @@ class GaragesalePostVm extends _$GaragesalePostVm {
|
|
|
required List imgList,
|
|
|
}) async{
|
|
|
final params = <String, dynamic>{
|
|
|
- "type": type, // 1 = Sale 2 = Rent
|
|
|
+ "type": type, // 1 = For Sale 2 = For Rent
|
|
|
"category_id": categoryId,
|
|
|
"title": titleValue,
|
|
|
"price": priceValue,
|