GiftApplicationPopup.vue 7.7 KB

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