GiftApplicationPopup.vue 7.4 KB

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