backstageAdd.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="page-container">
  3. <!-- 信息描述区域 -->
  4. <view class="form-item">
  5. <text class="label">信息描述</text>
  6. <textarea class="textarea" placeholder="请在此输入新增承包方信息描述" v-model="infoDesc" maxlength="200"></textarea>
  7. </view>
  8. <!-- 图片信息区域 -->
  9. <view class="form-item">
  10. <text class="label">图片信息</text>
  11. <view class="sub-label">
  12. <text>证明材料</text>
  13. <text class="required">*</text>
  14. </view>
  15. <!-- 图片上传区域 -->
  16. <view class="upload-area" @click="chooseImage">
  17. </view>
  18. </view>
  19. <!-- 确认按钮 -->
  20. <button class="confirm-btn" @click="handleConfirm">确认</button>
  21. </view>
  22. </template>
  23. <script setup>
  24. import {
  25. ref
  26. } from 'vue';
  27. import {
  28. onLoad
  29. } from '@dcloudio/uni-app';
  30. // 信息描述内容
  31. const infoDesc = ref('');
  32. // 上传的图片地址
  33. const imageUrl = ref('');
  34. // 初始化数据,避免undefined
  35. const groupInfo = ref({});
  36. /**
  37. * 解析页面参数
  38. * @param {Object} options - 页面跳转参数
  39. * @returns {Object} 解析后的承包方数据
  40. */
  41. const parseOptions = (options) => {
  42. try {
  43. if (!options?.groupInfo) {
  44. console.warn('未传入groupInfo参数');
  45. return {};
  46. }
  47. // 解码并解析JSON
  48. const decodedData = decodeURIComponent(options.groupInfo);
  49. const parsedData = JSON.parse(decodedData);
  50. return parsedData;
  51. } catch (error) {
  52. console.error('解析groupInfo失败:', error);
  53. uni.showToast({
  54. title: '数据解析失败',
  55. icon: 'none'
  56. });
  57. return {};
  58. }
  59. };
  60. // 页面加载时解析参数
  61. onLoad((options) => {
  62. groupInfo.value = {
  63. ...groupInfo.value,
  64. ...parseOptions(options)
  65. };
  66. console.log('解析后的承包方数据:', groupInfo.value._value);
  67. });
  68. // 选择图片(uni-app上传API)
  69. const chooseImage = () => {
  70. uni.chooseImage({
  71. count: 1, // 仅允许选择1张
  72. sizeType: ['original', 'compressed'],
  73. sourceType: ['album', 'camera'],
  74. success: (res) => {
  75. // 临时文件路径,实际项目中需上传到服务器获取正式地址
  76. imageUrl.value = res.tempFilePaths[0];
  77. },
  78. fail: (err) => {
  79. uni.showToast({
  80. title: '选择图片失败',
  81. icon: 'none'
  82. });
  83. }
  84. });
  85. };
  86. // 确认按钮点击事件
  87. const handleConfirm = () => {
  88. // 表单校验
  89. if (!infoDesc.value.trim()) {
  90. return uni.showToast({
  91. title: '请填写信息描述',
  92. icon: 'none'
  93. });
  94. }
  95. if (!imageUrl.value) {
  96. return uni.showToast({
  97. title: '请上传证明材料',
  98. icon: 'none'
  99. });
  100. }
  101. // 实际项目中提交表单数据到接口
  102. console.log('提交数据:', {
  103. infoDesc: infoDesc.value,
  104. imageUrl: imageUrl.value
  105. });
  106. // uni.showToast({
  107. // title: '提交成功',
  108. // icon: 'success'
  109. // });
  110. // // 提交后返回上一页
  111. // setTimeout(() => {
  112. // uni.navigateBack();
  113. // }, 1500);
  114. };
  115. </script>
  116. <style scoped>
  117. .page-container {
  118. padding: 20rpx;
  119. background-color: #fff;
  120. min-height: 100vh;
  121. }
  122. .form-item {
  123. margin-bottom: 40rpx;
  124. }
  125. .label {
  126. font-size: 32rpx;
  127. color: #333;
  128. margin-bottom: 10rpx;
  129. display: block;
  130. }
  131. .sub-label {
  132. font-size: 28rpx;
  133. color: #666;
  134. margin-bottom: 15rpx;
  135. display: flex;
  136. align-items: center;
  137. }
  138. .required {
  139. color: #ff3333;
  140. margin-left: 5rpx;
  141. }
  142. .textarea {
  143. width: 100%;
  144. min-height: 150rpx;
  145. border: 1px solid #e5e5e5;
  146. border-radius: 8rpx;
  147. padding: 15rpx;
  148. font-size: 28rpx;
  149. color: #333;
  150. box-sizing: border-box;
  151. }
  152. .upload-area {
  153. width: 120rpx;
  154. height: 120rpx;
  155. border: 1px dashed #e5e5e5;
  156. border-radius: 8rpx;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. }
  161. .upload-img {
  162. width: 50rpx;
  163. height: 50rpx;
  164. }
  165. .confirm-btn {
  166. width: 100%;
  167. height: 80rpx;
  168. background-color: #2c83ff;
  169. color: #fff;
  170. font-size: 32rpx;
  171. border-radius: 8rpx;
  172. margin-top: 60rpx;
  173. }
  174. </style>