GiftApplicationPopup.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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" :labelWidth="200">
  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 class="btn btn-dark btn-sm waves-effect waves-light btn-outline-dark1" @click="cancel">{{ t('Btn.Cancel') }}</button>
  39. <button class="btn btn-danger btn-sm waves-effect waves-light" @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 = computed(() => ({
  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. watch(locale, () => {
  112. formRef.value?.clearValidate()
  113. })
  114. const cancel = () => {
  115. visible.value = false;
  116. emit('cancel');
  117. };
  118. const handleGiftChange = (value) => {
  119. giftForm.giveCode = value;
  120. };
  121. const submit = async () => {
  122. if (submitting.value) return;
  123. submitting.value = true;
  124. try {
  125. // 表单验证
  126. await formRef.value?.validate();
  127. visible.value = false;
  128. emit('confirm', giftForm);
  129. } catch (error) {
  130. console.log('Form validation failed:', error);
  131. } finally {
  132. submitting.value = false;
  133. }
  134. };
  135. watch(() => props.visible, (newVal) => {
  136. if (newVal) {
  137. giftForm.giveCode = ''
  138. giftForm.giveAddress = ''
  139. giftForm.giveAcceptName = ''
  140. giftForm.givePhone = ''
  141. }
  142. })
  143. </script>
  144. <style lang="scss" scoped>
  145. @import "@/uni.scss";
  146. .popup-content {
  147. padding: px2rpx(20);
  148. .form-row {
  149. margin-bottom: px2rpx(20);
  150. &:last-child {
  151. margin-bottom: 0;
  152. }
  153. }
  154. .form-col-full {
  155. width: 100%;
  156. }
  157. :deep(.uni-forms) {
  158. width: 100%;
  159. :deep(.uni-forms-item) {
  160. margin-bottom: px2rpx(16);
  161. :deep(.uni-forms-item__label) {
  162. font-size: px2rpx(14);
  163. color: #606266;
  164. margin-bottom: px2rpx(8);
  165. }
  166. :deep(.uni-forms-item__error) {
  167. font-size: px2rpx(12);
  168. color: #f56c6c;
  169. margin-top: px2rpx(4);
  170. }
  171. :deep(.uni-easyinput) {
  172. width: 100%;
  173. :deep(input) {
  174. width: 100%;
  175. height: px2rpx(40);
  176. padding: 0 px2rpx(12);
  177. border: 1px solid #dcdfe6;
  178. border-radius: px2rpx(4);
  179. font-size: px2rpx(14);
  180. transition: border-color 0.3s;
  181. &:focus {
  182. outline: none;
  183. border-color: #409eff;
  184. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  185. }
  186. }
  187. }
  188. :deep(.cwg-combox) {
  189. width: 100%;
  190. :deep(.uni-select) {
  191. width: 100%;
  192. :deep(.uni-select-input) {
  193. width: 100%;
  194. height: px2rpx(40);
  195. padding: 0 px2rpx(12);
  196. border: 1px solid #dcdfe6;
  197. border-radius: px2rpx(4);
  198. font-size: px2rpx(14);
  199. transition: border-color 0.3s;
  200. &:focus {
  201. outline: none;
  202. border-color: #409eff;
  203. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. .tips {
  211. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  212. border-radius: px2rpx(8);
  213. padding: px2rpx(16);
  214. margin-bottom: px2rpx(20);
  215. .title {
  216. font-size: px2rpx(14);
  217. font-weight: 600;
  218. color: #303133;
  219. margin-bottom: px2rpx(8);
  220. }
  221. view {
  222. font-size: px2rpx(13);
  223. color: #606266;
  224. line-height: 1.5;
  225. margin-bottom: px2rpx(8);
  226. &:last-child {
  227. margin-bottom: 0;
  228. }
  229. }
  230. }
  231. button {
  232. width: 100%;
  233. height: px2rpx(44);
  234. border-radius: px2rpx(4);
  235. font-size: px2rpx(16);
  236. font-weight: 500;
  237. transition: all 0.3s;
  238. &.reselect {
  239. background-color: #409eff;
  240. color: #ffffff;
  241. border: none;
  242. &:hover {
  243. background-color: #66b1ff;
  244. }
  245. &:active {
  246. background-color: #3a8ee6;
  247. }
  248. &[disabled] {
  249. background-color: #c6e2ff;
  250. cursor: not-allowed;
  251. }
  252. }
  253. }
  254. }
  255. @media (max-width: 768px) {
  256. .popup-content {
  257. padding: px2rpx(16);
  258. .form-row {
  259. margin-bottom: px2rpx(16);
  260. }
  261. :deep(.uni-forms) {
  262. :deep(.uni-forms-item) {
  263. margin-bottom: px2rpx(12);
  264. :deep(.uni-easyinput) {
  265. :deep(input) {
  266. height: px2rpx(36);
  267. font-size: px2rpx(13);
  268. }
  269. }
  270. :deep(.cwg-combox) {
  271. :deep(.uni-select) {
  272. :deep(.uni-select-input) {
  273. height: px2rpx(36);
  274. font-size: px2rpx(13);
  275. }
  276. }
  277. }
  278. }
  279. }
  280. .tips {
  281. padding: px2rpx(12);
  282. .title {
  283. font-size: px2rpx(13);
  284. }
  285. view {
  286. font-size: px2rpx(12);
  287. }
  288. }
  289. button {
  290. height: px2rpx(40);
  291. font-size: px2rpx(15);
  292. }
  293. }
  294. }
  295. </style>