GiftApplicationPopup.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <cwg-popup v-model:visible="visible" type="center" :mask-click="false" :showFooters="true" :showClose="false"
  3. :title="title">
  4. <view class="popup-content">
  5. <uni-forms ref="formRef" :model="giftForm" :rules="rules" label-position="top" validate-trigger="submit"
  6. :labelWidth="200">
  7. <view class="form-row">
  8. <view class="form-col-full">
  9. <uni-forms-item :label="t('UtaskList.item18')" name="giveCode">
  10. <cwg-combox v-model:value="giftForm.giveCode" :clearable="false" :options="giftOptions"
  11. :placeholder="t('UtaskList.item19')" @change="handleGiftChange" />
  12. </uni-forms-item>
  13. </view>
  14. </view>
  15. <view class="form-row">
  16. <view class="form-col-full">
  17. <uni-forms-item :label="t('UtaskList.item20')" name="giveAddress">
  18. <uni-easyinput v-model="giftForm.giveAddress" :placeholder="t('UtaskList.item21')" />
  19. </uni-forms-item>
  20. </view>
  21. </view>
  22. <view class="form-row">
  23. <view class="form-col-full">
  24. <uni-forms-item :label="t('UtaskList.item24')" name="giveAcceptName">
  25. <uni-easyinput v-model="giftForm.giveAcceptName" :placeholder="t('UtaskList.item25')" />
  26. </uni-forms-item>
  27. </view>
  28. </view>
  29. <view class="form-row">
  30. <view class="form-col-full">
  31. <uni-forms-item :label="t('UtaskList.item22')" name="givePhone">
  32. <uni-easyinput v-model="giftForm.givePhone" :placeholder="t('UtaskList.item23')" />
  33. </uni-forms-item>
  34. </view>
  35. </view>
  36. </uni-forms>
  37. </view>
  38. <template #footer>
  39. <button hover-class="" class="btn btn-dark btn-sm waves-effect waves-light btn-outline-dark1" @click="cancel">{{
  40. t('Btn.Cancel') }}</button>
  41. <button hover-class="" class="btn btn-danger btn-sm waves-effect waves-light" @click="submit"
  42. :loading="submitting">{{ t('Btn.Confirm') }}</button>
  43. </template>
  44. </cwg-popup>
  45. </template>
  46. <script setup>
  47. import { ref, computed, reactive, watch } from 'vue';
  48. import { useI18n } from 'vue-i18n';
  49. const props = defineProps({
  50. visible: { type: Boolean, default: false },
  51. title: { type: String, default: '' },
  52. giftList: { type: Array, default: () => [] },
  53. giftForm: { type: Object, default: () => ({}) }
  54. });
  55. const emit = defineEmits(['update:visible', 'confirm', 'cancel']);
  56. const { t, locale } = useI18n();
  57. const visible = computed({
  58. get: () => props.visible,
  59. set: (value) => emit('update:visible', value)
  60. });
  61. // 表单数据
  62. const giftForm = reactive({
  63. giveCode: props.giftForm.giveCode || '',
  64. giveAddress: props.giftForm.giveAddress || '',
  65. giveAcceptName: props.giftForm.giveAcceptName || '',
  66. givePhone: props.giftForm.givePhone || ''
  67. });
  68. // 表单引用
  69. const formRef = ref(null);
  70. // 提交状态
  71. const submitting = ref(false);
  72. // 礼物选项
  73. const giftOptions = computed(() => {
  74. return props.giftList.map(gift => ({
  75. text: `${gift.giveCode} - ${gift.giveName}`,
  76. value: gift.giveCode
  77. }));
  78. });
  79. // 表单验证规则
  80. const rules = computed(() => ({
  81. giveCode: {
  82. rules: [
  83. {
  84. required: true,
  85. errorMessage: t("UtaskList.item19")
  86. }
  87. ]
  88. },
  89. giveAddress: {
  90. rules: [
  91. {
  92. required: true,
  93. errorMessage: t("UtaskList.item21")
  94. }
  95. ]
  96. },
  97. giveAcceptName: {
  98. rules: [
  99. {
  100. required: true,
  101. errorMessage: t("UtaskList.item25")
  102. }
  103. ]
  104. },
  105. givePhone: {
  106. rules: [
  107. {
  108. required: true,
  109. errorMessage: t("UtaskList.item23")
  110. }
  111. ]
  112. }
  113. }));
  114. watch(locale, () => {
  115. formRef.value?.clearValidate()
  116. })
  117. const cancel = () => {
  118. visible.value = false;
  119. emit('cancel');
  120. };
  121. const handleGiftChange = (value) => {
  122. giftForm.giveCode = value;
  123. giftForm.giveName = props.giftList.find(item => item.giveCode === value)?.giveName || '';
  124. };
  125. const submit = async () => {
  126. if (submitting.value) return;
  127. submitting.value = true;
  128. try {
  129. // 表单验证
  130. await formRef.value?.validate();
  131. visible.value = false;
  132. emit('confirm', giftForm);
  133. } catch (error) {
  134. console.log('Form validation failed:', error);
  135. } finally {
  136. submitting.value = false;
  137. }
  138. };
  139. watch(() => props.visible, (newVal) => {
  140. if (newVal) {
  141. giftForm.giveCode = ''
  142. giftForm.giveAddress = ''
  143. giftForm.giveAcceptName = ''
  144. giftForm.givePhone = ''
  145. }
  146. })
  147. </script>
  148. <style lang="scss" scoped>
  149. @import "@/uni.scss";
  150. .popup-content {
  151. padding: px2rpx(20);
  152. .form-row {
  153. margin-bottom: px2rpx(20);
  154. &:last-child {
  155. margin-bottom: 0;
  156. }
  157. }
  158. .form-col-full {
  159. width: 100%;
  160. }
  161. :deep(.uni-forms) {
  162. width: 100%;
  163. :deep(.uni-forms-item) {
  164. margin-bottom: px2rpx(16);
  165. :deep(.uni-forms-item__label) {
  166. font-size: px2rpx(14);
  167. color: #606266;
  168. margin-bottom: px2rpx(8);
  169. }
  170. :deep(.uni-forms-item__error) {
  171. font-size: px2rpx(12);
  172. color: #f56c6c;
  173. margin-top: px2rpx(4);
  174. }
  175. :deep(.uni-easyinput) {
  176. width: 100%;
  177. :deep(input) {
  178. width: 100%;
  179. height: px2rpx(40);
  180. padding: 0 px2rpx(12);
  181. border: 1px solid #dcdfe6;
  182. border-radius: px2rpx(4);
  183. font-size: px2rpx(14);
  184. transition: border-color 0.3s;
  185. &:focus {
  186. outline: none;
  187. border-color: #409eff;
  188. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  189. }
  190. }
  191. }
  192. :deep(.cwg-combox) {
  193. width: 100%;
  194. :deep(.uni-select) {
  195. width: 100%;
  196. :deep(.uni-select-input) {
  197. width: 100%;
  198. height: px2rpx(40);
  199. padding: 0 px2rpx(12);
  200. border: 1px solid #dcdfe6;
  201. border-radius: px2rpx(4);
  202. font-size: px2rpx(14);
  203. transition: border-color 0.3s;
  204. &:focus {
  205. outline: none;
  206. border-color: #409eff;
  207. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. .tips {
  215. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  216. border-radius: px2rpx(8);
  217. padding: px2rpx(16);
  218. margin-bottom: px2rpx(20);
  219. .title {
  220. font-size: px2rpx(14);
  221. font-weight: 600;
  222. color: #303133;
  223. margin-bottom: px2rpx(8);
  224. }
  225. view {
  226. font-size: px2rpx(13);
  227. color: #606266;
  228. line-height: 1.5;
  229. margin-bottom: px2rpx(8);
  230. &:last-child {
  231. margin-bottom: 0;
  232. }
  233. }
  234. }
  235. button {
  236. width: 100%;
  237. height: px2rpx(44);
  238. border-radius: px2rpx(4);
  239. font-size: px2rpx(16);
  240. font-weight: 500;
  241. transition: all 0.3s;
  242. &.reselect {
  243. background-color: #409eff;
  244. color: #ffffff;
  245. border: none;
  246. &:hover {
  247. background-color: #66b1ff;
  248. }
  249. &:active {
  250. background-color: #3a8ee6;
  251. }
  252. &[disabled] {
  253. background-color: #c6e2ff;
  254. cursor: not-allowed;
  255. }
  256. }
  257. }
  258. }
  259. @media (max-width: 768px) {
  260. .popup-content {
  261. padding: px2rpx(16);
  262. .form-row {
  263. margin-bottom: px2rpx(16);
  264. }
  265. :deep(.uni-forms) {
  266. :deep(.uni-forms-item) {
  267. margin-bottom: px2rpx(12);
  268. :deep(.uni-easyinput) {
  269. :deep(input) {
  270. height: px2rpx(36);
  271. font-size: px2rpx(13);
  272. }
  273. }
  274. :deep(.cwg-combox) {
  275. :deep(.uni-select) {
  276. :deep(.uni-select-input) {
  277. height: px2rpx(36);
  278. font-size: px2rpx(13);
  279. }
  280. }
  281. }
  282. }
  283. }
  284. .tips {
  285. padding: px2rpx(12);
  286. .title {
  287. font-size: px2rpx(13);
  288. }
  289. view {
  290. font-size: px2rpx(12);
  291. }
  292. }
  293. button {
  294. height: px2rpx(40);
  295. font-size: px2rpx(15);
  296. }
  297. }
  298. }
  299. </style>