AgencyNeedNumberWidget.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import 'package:cs_resources/constants/color_constants.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:plugin_basic/basic_export.dart';
  6. import 'package:widgets/ext/ex_widget.dart';
  7. import 'package:widgets/my_load_image.dart';
  8. import 'package:widgets/my_text_view.dart';
  9. import 'package:widgets/picker/option_pick_util.dart';
  10. import 'package:widgets/shatter/round_my_text_field.dart';
  11. import 'package:domain/entity/agency_need_number.dart';
  12. /*
  13. * 代理商选择人数的控件封装
  14. * 选择性别限制的数量或者不限制性别限制的数量
  15. */
  16. class AgencyNeedNumberWidget extends StatefulWidget {
  17. final String? agencyId;
  18. final String? agencyName;
  19. AgencyNeedNumberWidget({
  20. this.agencyId,
  21. this.agencyName,
  22. Key? key,
  23. }) : super(key: key ?? GlobalKey<AgencyNeedNumberState>()); // 使用新的 GlobalKey
  24. @override
  25. State<AgencyNeedNumberWidget> createState() => AgencyNeedNumberState();
  26. }
  27. class AgencyNeedNumberState extends State<AgencyNeedNumberWidget> {
  28. int limitType = 0;
  29. List<String> limitTypeList = [
  30. "Gender Unlimited".tr,
  31. "Gender Limited".tr,
  32. ];
  33. final Map<String, Map<String, dynamic>> formData = {
  34. 'need_male': {
  35. 'value': '',
  36. 'controller': TextEditingController(),
  37. 'focusNode': FocusNode(),
  38. 'hintText': 'Male'.tr,
  39. 'obsecure': false,
  40. },
  41. 'need_female': {
  42. 'value': '',
  43. 'controller': TextEditingController(),
  44. 'focusNode': FocusNode(),
  45. 'hintText': 'Female'.tr,
  46. 'obsecure': false,
  47. },
  48. 'need_no': {
  49. 'value': '',
  50. 'controller': TextEditingController(),
  51. 'focusNode': FocusNode(),
  52. 'hintText': 'Needs Num'.tr,
  53. 'obsecure': false,
  54. },
  55. };
  56. @override
  57. void initState() {
  58. super.initState();
  59. limitType = 0;
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: [
  66. //中介性别
  67. MyTextView(
  68. widget.agencyName ?? "-",
  69. fontSize: 15,
  70. isFontRegular: true,
  71. marginBottom: 7,
  72. textColor: Colors.white,
  73. marginTop: 15,
  74. ),
  75. Row(
  76. children: [
  77. Container(
  78. padding: const EdgeInsets.only(left: 16, right: 10),
  79. margin: const EdgeInsets.only(right: 12),
  80. height: 45,
  81. decoration: BoxDecoration(
  82. color: const Color(0xFF4DCFF6).withOpacity(0.2),
  83. borderRadius: const BorderRadius.all(Radius.circular(5)),
  84. ),
  85. child: Row(
  86. mainAxisSize: MainAxisSize.max,
  87. crossAxisAlignment: CrossAxisAlignment.center,
  88. mainAxisAlignment: MainAxisAlignment.start,
  89. children: [
  90. MyTextView(
  91. limitTypeList[limitType],
  92. fontSize: 14,
  93. textHintColor: ColorConstants.textGrayAECAE5,
  94. isFontRegular: true,
  95. textColor: ColorConstants.white,
  96. ).expanded(),
  97. //下拉选图标
  98. const MyAssetImage(Assets.baseServiceTriangleDropDownIcon, width: 11.5, height: 6.28),
  99. ],
  100. ),
  101. ).onTap(() {
  102. FocusScope.of(context).unfocus();
  103. pickLimitType();
  104. }).expanded(flex: 45),
  105. //输入框-不限制性别
  106. Visibility(
  107. visible: limitType == 0,
  108. child: CustomTextField(
  109. formKey: "need_no",
  110. marginLeft: 0,
  111. marginRight: 0,
  112. paddingTop: 0,
  113. paddingBottom: 0,
  114. height: 45,
  115. fillBackgroundColor: const Color(0xFF4DCFF6).withOpacity(0.2),
  116. inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
  117. textInputType: TextInputType.number,
  118. formData: formData,
  119. textInputAction: TextInputAction.done,
  120. onSubmit: (key, value) {
  121. FocusScope.of(context).unfocus();
  122. },
  123. ).expanded(flex: 55),
  124. ),
  125. //输入框组-限制性别
  126. Visibility(
  127. visible: limitType != 0,
  128. child: Row(
  129. children: [
  130. Row(
  131. children: [
  132. MyTextView(
  133. "M",
  134. fontSize: 15,
  135. paddingLeft: 10,
  136. isFontRegular: true,
  137. textColor: ColorConstants.white,
  138. ),
  139. CustomTextField(
  140. formKey: "need_male",
  141. marginLeft: 0,
  142. marginRight: 0,
  143. paddingTop: 0,
  144. paddingBottom: 0,
  145. paddingLeft: 10,
  146. paddingRight: 10,
  147. height: 45,
  148. cornerRadius: 0,
  149. fillBackgroundColor: Colors.transparent,
  150. inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
  151. textInputType: TextInputType.number,
  152. formData: formData,
  153. textInputAction: TextInputAction.done,
  154. onSubmit: (key, value) {
  155. FocusScope.of(context).unfocus();
  156. },
  157. ).expanded(),
  158. ],
  159. )
  160. .decorated(
  161. color: const Color(0xFF4DCFF6).withOpacity(0.2),
  162. borderRadius: const BorderRadius.all(Radius.circular(5)),
  163. )
  164. .expanded(),
  165. const SizedBox(width: 12),
  166. Row(
  167. children: [
  168. MyTextView(
  169. "F",
  170. fontSize: 15,
  171. paddingLeft: 10,
  172. isFontRegular: true,
  173. textColor: ColorConstants.white,
  174. ),
  175. CustomTextField(
  176. formKey: "need_female",
  177. marginLeft: 0,
  178. marginRight: 0,
  179. paddingTop: 0,
  180. paddingBottom: 0,
  181. paddingLeft: 10,
  182. paddingRight: 10,
  183. height: 45,
  184. cornerRadius: 0,
  185. fillBackgroundColor: Colors.transparent,
  186. inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly],
  187. textInputType: TextInputType.number,
  188. formData: formData,
  189. textInputAction: TextInputAction.done,
  190. onSubmit: (key, value) {
  191. FocusScope.of(context).unfocus();
  192. },
  193. ).expanded(),
  194. ],
  195. )
  196. .decorated(
  197. color: const Color(0xFF4DCFF6).withOpacity(0.2),
  198. borderRadius: const BorderRadius.all(Radius.circular(5)),
  199. )
  200. .expanded(),
  201. ],
  202. ).expanded(flex: 55),
  203. ),
  204. ],
  205. ),
  206. ],
  207. );
  208. }
  209. //选择分类
  210. void pickLimitType() {
  211. OptionPickerUtil.showCupertinoOptionPicker(
  212. items: limitTypeList,
  213. initialSelectIndex: limitType,
  214. onPickerChanged: (_, index) {
  215. setState(() {
  216. limitType = index;
  217. });
  218. },
  219. );
  220. }
  221. // 返回 AgencyNeedNumberEntity 对象
  222. AgencyNeedNumberEntity getAgencyNeedNumberEntity() {
  223. AgencyNeedNumberEntity entity = AgencyNeedNumberEntity();
  224. entity.isInHouse = widget.agencyId != null && (widget.agencyId == "0");
  225. entity.agencyId = widget.agencyId;
  226. entity.agencyName = widget.agencyName;
  227. entity.sexLimit = limitType; // 设置性别限制
  228. if (limitType == 0) {
  229. // 不限制性别的总人数
  230. entity.needNum = int.tryParse(formData['need_no']!['controller']!.text) ?? 0;
  231. } else {
  232. // 限制性别
  233. entity.maleLimit = int.tryParse(formData['need_male']!['controller']!.text) ?? 0;
  234. entity.femaleLimit = int.tryParse(formData['need_female']!['controller']!.text) ?? 0;
  235. }
  236. return entity;
  237. }
  238. }