import 'dart:convert'; import 'dart:io'; import 'package:bbyyy/beans/my_shop_bean_entity.dart'; import 'package:bbyyy/https/url.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/svg.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import '../../../beans/complain_bean_entity.dart'; import '../../../beans/upload_image_bean_entity.dart'; import '../../../https/MyDio.dart'; import '../../../https/my_request.dart'; import '../../../my_tools/dims.dart'; import '../../../my_tools/easy_loading/easy_loading.dart'; import '../../../my_tools/my_cookie.dart'; import '../../../my_tools/my_tools.dart'; import 'choose_a_store_page.dart'; class PunishPage extends StatefulWidget { @override _PunishPageState createState() => _PunishPageState(); } class _PunishPageState extends State { int selectedIndex = 0; TextEditingController _phoneNum = TextEditingController(); TextEditingController _content = TextEditingController(); List data = []; MyShopBeanDataData shop; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { MyTools().hideKeyboard(context); }, behavior: HitTestBehavior.translucent, child: Scaffold( backgroundColor: MyColors.cF7F7F7, body: Column( children: [ MyViews().myAppBar('投诉', context, []), Container( height: 40, color: Colors.white, child: Row( children: [ GestureDetector( onTap: () { setState(() { selectedIndex = 0; }); }, behavior: HitTestBehavior.translucent, child: Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Column( children: [ Text( '投诉', style: TextStyle( color: selectedIndex == 0 ? MyColors.cFF4233 : MyColors.c666666, fontSize: 15), ), Container( height: 10, child: Visibility( child: SvgPicture.asset('images/svg/tab.svg'), visible: selectedIndex == 0, ), ) ], mainAxisAlignment: MainAxisAlignment.end, ), ), ), GestureDetector( onTap: () { setState(() { selectedIndex = 1; }); }, behavior: HitTestBehavior.translucent, child: Padding( padding: EdgeInsets.only(left: 10, right: 10), child: Column( children: [ Text( '被投诉', style: TextStyle( color: selectedIndex == 1 ? MyColors.cFF4233 : MyColors.c666666, fontSize: 15), ), Container( height: 10, child: Visibility( child: SvgPicture.asset('images/svg/tab.svg'), visible: selectedIndex == 1, ), ) ], mainAxisAlignment: MainAxisAlignment.end, ), ), ) ], mainAxisAlignment: MainAxisAlignment.spaceAround, ), ), Expanded( child: selectedIndex == 0 ? complaintPage() : punishPage(), ) ], ), ), ); } complaintPage() { return SingleChildScrollView( child: Column( children: [ Container( color: Colors.white, margin: EdgeInsets.only(top: 10), child: Column( children: [ Container( padding: EdgeInsets.fromLTRB(16, 17, 14, 17), child: Row( children: [ MyViews().myText('投诉货帮', MyColors.c333333, 15), GestureDetector(child: shop == null ? MyViews().myText('请选择货帮', MyColors.c333333, 15) : Row( children: [ ClipRRect( borderRadius: BorderRadius.circular(10), child: MyViews() .netImg(imgURL(shop?.shopPic), 20, 20), ), Container(child: MyViews().myText(shop?.shopName, MyColors.c333333, 15),margin: EdgeInsets.only(left: 10),) ], ),onTap: (){ MyTools().toPage(context, ChooseAStorePage(), (then){ if(then is MyShopBeanDataData){ shop = then; setState(() { }); } }); }, behavior: HitTestBehavior.translucent,), ],mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), Container( color: MyColors.cF7F7F7, height: 0.5, margin: EdgeInsets.only(left: 16, right: 14), ), Container( padding: EdgeInsets.fromLTRB(16, 17, 14, 17), child: Row( children: [ MyViews().myText('个人电话', MyColors.c333333, 15), Expanded( child: TextField( inputFormatters: [ LengthLimitingTextInputFormatter(11) ], controller: _phoneNum, cursorColor: MyColors.cFF4233, cursorWidth: 1.0, textAlign: TextAlign.end, onTap: () {}, decoration: InputDecoration( border: InputBorder.none, disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, isDense: true, hintText: '请输入电话', hintStyle: TextStyle( color: MyColors.c999999, fontSize: 14), contentPadding: const EdgeInsets.fromLTRB(14, 4.5, 0, 4.5), ), style: TextStyle( color: MyColors.c333333, fontSize: 14, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.number, onChanged: (t) {}, ), ) ], ), ), ], ), ), Container( margin: EdgeInsets.only(top: 10), color: Colors.white, child: Column( children: [ Container( width: double.infinity, margin: EdgeInsets.only(left: 16, top: 17), child: Text( '投诉内容', style: TextStyle(color: MyColors.c333333, fontSize: 15), ), ), Container( margin: EdgeInsets.only(left: 15, right: 15, top: 17), constraints: BoxConstraints(minHeight: 86), decoration: BoxDecoration( border: Border.all(color: MyColors.cE7E7E7, width: 1), borderRadius: BorderRadius.all( Radius.circular(4), ), ), child: TextField( controller: _content, cursorColor: MyColors.cFF4233, cursorWidth: 1.0, maxLines: null, onTap: () {}, decoration: InputDecoration( border: InputBorder.none, disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, isDense: true, hintText: '请输入投诉内容…', hintStyle: TextStyle(color: MyColors.c999999, fontSize: 14), contentPadding: const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5), ), style: TextStyle( color: MyColors.c333333, fontSize: 14, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.text, onChanged: (t) {}, ), ), Container( width: double.infinity, margin: EdgeInsets.only(left: 16, top: 17), child: Text( '证据图片', style: TextStyle(color: MyColors.c333333, fontSize: 15), ), ), Container( margin: EdgeInsets.only(left: 15, right: 15, bottom: 17, top: 18), child: Row( children: [ GestureDetector( onTap: () async { pictures[0] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: pictures[0] == null ? Container( height: 102, width: 102, decoration: BoxDecoration( color: MyColors.cF0F0F0, borderRadius: BorderRadius.all(Radius.circular(4))), child: Icon( Icons.add, color: MyColors.cB6B6B6, size: 44, ), ) : ClipRRect( child: Image.file( pictures[0], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ), ), GestureDetector( onTap: () async { pictures[1] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: pictures[1] == null ? Container( height: 102, width: 102, decoration: BoxDecoration( color: MyColors.cF0F0F0, borderRadius: BorderRadius.all(Radius.circular(4))), child: Icon( Icons.add, color: MyColors.cB6B6B6, size: 44, ), ) : ClipRRect( child: Image.file( pictures[1], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ), ), GestureDetector( onTap: () async { pictures[2] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: pictures[2] == null ? Container( height: 102, width: 102, decoration: BoxDecoration( color: MyColors.cF0F0F0, borderRadius: BorderRadius.all(Radius.circular(4))), child: Icon( Icons.add, color: MyColors.cB6B6B6, size: 44, ), ) : ClipRRect( child: Image.file( pictures[2], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ], ), ), GestureDetector( onTap: () { uploadPictureOne(); }, behavior: HitTestBehavior.translucent, child: Container( color: Colors.white, margin: EdgeInsets.only(top: 10), height: 50, child: MyViews().myText('确 定', MyColors.cFF4233, 16), alignment: Alignment.center, ), ) ], ), ); } RefreshController controller = RefreshController(initialRefresh: true); punishPage() { return SmartRefresher( controller: controller, onRefresh: onRefresh, onLoading: onLoading, enablePullDown: true, enablePullUp: true, child: ListView.builder( itemBuilder: (c, index) { return MyViews().getPunishItem(context, data[index]); }, itemCount: data.length, padding: EdgeInsets.only(top: 10), ), ); } List pictures = [null, null, null]; String picturesPath = ''; void uploadPictureOne() { print('uploadPictureOne'); if (pictures[0] != null) { upload(pictures[0], (r, hE) { if (!hE) { UploadImageBeanEntity data = UploadImageBeanEntity.fromJson(json.decode(r.data.toString())); if (picturesPath == '') { picturesPath = data.data[0].path; } else { picturesPath = picturesPath + ',' + data.data[0].path; } uploadPictureTwo(); } else { EasyLoading.dismiss(); } }, (e) { EasyLoading.dismiss(); }); } else { uploadPictureTwo(); } } void uploadPictureTwo() { print('uploadPictureTwo'); if (pictures[1] != null) { upload(pictures[1], (r, hE) { if (!hE) { UploadImageBeanEntity data = UploadImageBeanEntity.fromJson(json.decode(r.data.toString())); if (picturesPath == '') { picturesPath = data.data[0].path; } else { picturesPath = picturesPath + ',' + data.data[0].path; } uploadPictureThree(); } else { EasyLoading.dismiss(); } }, (e) { EasyLoading.dismiss(); }); } else { uploadPictureThree(); } } void uploadPictureThree() { print('uploadPictureThree'); if (pictures[2] != null) { upload(pictures[2], (r, hE) { if (!hE) { UploadImageBeanEntity data = UploadImageBeanEntity.fromJson(json.decode(r.data.toString())); if (picturesPath == '') { picturesPath = data.data[0].path; } else { picturesPath = picturesPath + ',' + data.data[0].path; } submitAComplaint(); } else { EasyLoading.dismiss(); } }, (e) { EasyLoading.dismiss(); }); } else { submitAComplaint(); } } void submitAComplaint() { MyDio().save({ 'key': 'complain', 'object': { 'shop_uid': shop?.shopUid, 'user_uid': MyCookie().getUID(), 'content': _content.text.toString(), 'snapshots': picturesPath } }, (response, hasError) { if (!hasError) { showToast('提交成功'); Navigator.pop(context); // _content.clear(); // _phoneNum.clear(); // shop = null; // pictures.forEach((element) { // element = null; // }); // picturesPath = ''; // setState(() {}); } }, (error) {}); } int page = 1; inquiryAndComplaint() { MyDio().query({ "key": "complain", "filters": { "conditions": ["owner_uid==${MyCookie().getUID()}"] }, "dims": complainDims, "paging": [page, 20] }, (response, hasError) { if (!hasError) { ComplainBeanEntity entity = ComplainBeanEntity.fromJson(json.decode(response.data.toString())); if (page == 1) { data.clear(); } data.addAll(entity.data.data); setState(() {}); } endRe(controller); }, (error) { endRe(controller); }); } void onRefresh() { page = 1; inquiryAndComplaint(); } void onLoading() { page++; inquiryAndComplaint(); } }