index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <script lang="ts" setup>
  2. import {
  3. useRequest
  4. } from 'alova/client'
  5. import {
  6. reactive,
  7. ref,
  8. computed
  9. } from 'vue'
  10. import {
  11. couponIssuerApplyByAdd,
  12. getCouponIssuerApplyById
  13. } from '@/api/me'
  14. import {
  15. useUserStore
  16. } from '@/store'
  17. definePage({
  18. style: {
  19. navigationBarTitleText: '发券人申请',
  20. },
  21. })
  22. const userStore = useUserStore()
  23. let model = reactive({
  24. name: '',
  25. phone: '',
  26. status: '0',
  27. auditRemark: '',
  28. })
  29. const rules = reactive({
  30. name: {
  31. type: 'string',
  32. required: true,
  33. message: '请填写姓名',
  34. trigger: ['blur', 'change'],
  35. },
  36. phone: {
  37. type: 'string',
  38. required: true,
  39. message: '请填写电话',
  40. pattern: /^1[3-9]\d{9}$/,
  41. trigger: ['blur', 'change'],
  42. },
  43. })
  44. // 发卷人查询审核状态
  45. const {
  46. send: getCouponIssuerApplyByIdRequest,
  47. data: couponIssuerApplyByIdData,
  48. } = useRequest(getCouponIssuerApplyById, {
  49. immediate: false,
  50. })
  51. const formResult = ref(null)
  52. onLoad(async (options) => {
  53. await getCouponIssuerApplyByIdRequest()
  54. console.log(999999, couponIssuerApplyByIdData.value?.status)
  55. if (couponIssuerApplyByIdData.value && couponIssuerApplyByIdData.value?.status && (couponIssuerApplyByIdData.value.status === '1' || couponIssuerApplyByIdData.value.status === '2')) {
  56. formResult.value = couponIssuerApplyByIdData.value
  57. model = couponIssuerApplyByIdData.value
  58. }
  59. })
  60. // 使用 ref 创建响应式引用
  61. const uFormRef = ref(null)
  62. // 发劵人审核-添加
  63. const {
  64. send: couponIssuerApplyByAddRequest,
  65. data: couponIssuerApplyByAddData,
  66. } = useRequest(couponIssuerApplyByAdd, {
  67. immediate: false,
  68. }).onSuccess(() => {
  69. // 返回上一页
  70. console.log('提交成功:', couponIssuerApplyByAddData)
  71. uni.showToast({
  72. title: '校验通过',
  73. icon: 'success',
  74. })
  75. uni.navigateBack()
  76. }).onError((error) => {
  77. console.log('校验失败:', error)
  78. uni.showToast({
  79. title: error.error.message,
  80. icon: 'error',
  81. })
  82. })
  83. function submitForm() {
  84. uFormRef.value.validate().then((valid) => {
  85. if (valid) {
  86. const couponIssuerApplyByAddForm = {
  87. name: model.name,
  88. phone: model.phone,
  89. }
  90. couponIssuerApplyByAddRequest(couponIssuerApplyByAddForm)
  91. }
  92. else {
  93. uni.showToast({
  94. title: '校验失败',
  95. icon: 'error',
  96. })
  97. }
  98. }).catch(() => {
  99. // 处理验证错误
  100. uni.showToast({
  101. title: '校验失败',
  102. icon: 'error',
  103. })
  104. })
  105. }
  106. const isShowBtn = computed(() => {
  107. return !formResult.value || (!!formResult.value && (formResult.value.status !== '1' && formResult.value.status !== '2'))
  108. })
  109. </script>
  110. <template>
  111. <view class="form-container">
  112. <view class="form-wrapper">
  113. <u-form ref="uFormRef" label-position="left" :model="model" :rules="rules">
  114. <u-form-item ref="item1" label="申请人姓名" prop="name" :border-bottom="true">
  115. <u-input v-model="model.name" border="none" :disabled="formResult" placeholder="请输入申请人姓名" />
  116. </u-form-item>
  117. <u-form-item ref="item2" label="电话" prop="phone" :border-bottom="true">
  118. <u-input v-model="model.phone" border="none" :disabled="formResult" placeholder="请输入小程序登录的手机号" />
  119. </u-form-item>
  120. <u-form-item v-if="formResult" ref="item3" label="申请结果" :border-bottom="true">
  121. <view v-if="formResult.status === '2'" class="form-item-result u-text-danger">
  122. 已拒绝
  123. </view>
  124. <view v-else class="form-item-result u-text-success">
  125. 已通过
  126. </view>
  127. </u-form-item>
  128. <view v-if="formResult && formResult.status === '2'" class="form-item-des">
  129. <u-form-item ref="item4" label="拒绝说明" :border-bottom="true">
  130. <u-textarea v-model="model.auditRemark" placeholder="此处显示拒绝说明" border="none" disabled />
  131. </u-form-item>
  132. </view>
  133. </u-form>
  134. <view v-if="isShowBtn" class="form-btn" @click="submitForm">
  135. 提交申请
  136. </view>
  137. </view>
  138. </view>
  139. </template>
  140. <style lang="scss" scoped>
  141. ::v-deep .u-form-item__body__left {
  142. width: 150rpx !important;
  143. font-weight: 400 !important;
  144. font-size: 26rpx !important;
  145. color: #333333 !important;
  146. }
  147. ::v-deep .u-input__content__field-wrapper__field {
  148. text-align: right !important;
  149. }
  150. ::v-deep .u-form-item__body__left__content__label {
  151. color: #333333 !important;
  152. font-size: 26rpx !important;
  153. font-weight: 400 !important;
  154. }
  155. ::v-deep .u-line {
  156. border-color: #eeeeee !important;
  157. }
  158. ::v-deep .u-form-item__body__right__content__slot {
  159. display: flex;
  160. justify-content: flex-end;
  161. }
  162. /* 为禁用状态的input添加白色背景 */
  163. ::v-deep .u-input__content__field-wrapper__field {
  164. background-color: #fff !important;
  165. }
  166. .form-container {
  167. background-color: #f5f5f5;
  168. min-height: 100vh;
  169. padding: 20rpx;
  170. }
  171. .form-wrapper {
  172. background-color: #fff;
  173. border-radius: 12rpx;
  174. padding: 0 32rpx;
  175. }
  176. .form-item-result {
  177. width: 112rpx;
  178. height: 44rpx;
  179. line-height: 44rpx;
  180. border-radius: 10rpx;
  181. text-align: center;
  182. &.u-text-danger {
  183. color: #ff3333;
  184. background: rgba(#ff7171, 0.2);
  185. }
  186. &.u-text-success {
  187. color: #64a6ff;
  188. background: rgba(#64a6ff, 0.2);
  189. }
  190. }
  191. .form-item-des {
  192. ::v-deep .u-form-item__body {
  193. flex-direction: column !important;
  194. gap: 32rpx !important;
  195. }
  196. }
  197. .form-btn {
  198. width: 600rpx;
  199. height: 80rpx;
  200. line-height: 80rpx;
  201. background: linear-gradient(90deg, #ee6b67 0%, #ff7d78 100%);
  202. border-radius: 10rpx;
  203. position: fixed;
  204. bottom: 62rpx;
  205. left: 50%;
  206. transform: translateX(-50%);
  207. font-weight: 400;
  208. font-size: 30rpx;
  209. color: #ffffff;
  210. text-align: center;
  211. }
  212. </style>