敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

399 lines
11 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar :title="`${ !identity ? '团长申请' : '团长信息' }`" leftClick @leftClick="$utils.navigateBack" bgColor="#019245"
  5. color="#fff" />
  6. <!-- 顶部图片区域 -->
  7. <view class="banner" v-if="!identity">
  8. <image src="/static/image/红烧肉.webp" mode="aspectFill" class="banner-image"></image>
  9. </view>
  10. <view class="content-area">
  11. <!-- 送餐点照片上传区域 -->
  12. <view class="section-title">送餐点照片</view>
  13. <view class="section-block">
  14. <view class="upload-container">
  15. <view class="upload-area" @tap="chooseImage" v-if="!formData.spotImage">
  16. <view class="plus">+</view>
  17. <view class="upload-text">添加图片</view>
  18. </view>
  19. <image v-else :src="formData.spotImage" mode="aspectFill" class="upload-area"
  20. @tap="chooseImage" />
  21. </view>
  22. </view>
  23. <!-- 送餐点信息填写区域 -->
  24. <view class="section-title">送餐点信息</view>
  25. <view class="section-block">
  26. <view class="form-item">
  27. <text class="label">送餐点名称</text>
  28. <input class="input" type="text" v-model="formData.spotName" placeholder="请输入送餐点名称"
  29. placeholder-class="placeholder" />
  30. </view>
  31. <view class="form-item">
  32. <text class="label">您的姓名</text>
  33. <input class="input" type="nickname" v-model="formData.name" placeholder="请输入您的姓名"
  34. placeholder-class="placeholder" />
  35. </view>
  36. <view class="form-item">
  37. <text class="label">联系手机号</text>
  38. <input class="input" type="number" v-model="formData.phone" placeholder="请输入您的手机号"
  39. placeholder-class="placeholder" />
  40. </view>
  41. <view class="form-item region-item">
  42. <text class="label">所在地区</text>
  43. <picker mode="region" @change="regionSelect">
  44. <text style="font-size: 30rpx;">{{ formData.area || '请选择' }}</text>
  45. </picker>
  46. <uv-icon name="arrow-right" color="#000" style="margin-left: 2rpx;"/>
  47. </view>
  48. <view class="address-item">
  49. <text class="label">详细地址</text>
  50. <view class="address-box">
  51. <textarea class="address-input" v-model="formData.address" placeholder="请输入详细地址"
  52. placeholder-class="placeholder" />
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 提交按钮 -->
  57. <view v-if="!this.beModify" class="submit-btn" @tap="submitApplication">
  58. {{ !identity ? '提交申请' : '提交保存' }}
  59. </view>
  60. <view v-else class="submit-btn-container">
  61. <view class="submit-btn-modify" @tap="submitApplication">修改</view>
  62. <view class="submit-btn-save" @tap="submitApplication">保存</view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import navbar from '@/components/base/navbar.vue'
  69. import shareConfig from '@/mixins/configList.js'
  70. export default {
  71. components: {
  72. navbar
  73. },
  74. mixins: [shareConfig],
  75. data() {
  76. return {
  77. formData: {
  78. spotImage: '', // 上传的送餐点照片
  79. spotName: '', // 送餐点名称
  80. name: '', // 联系人姓名
  81. phone: '', // 联系电话
  82. area: '', // 所在地区
  83. address: '' // 详细地址
  84. },
  85. identity: uni.getStorageSync('identity'),
  86. beModify: false // 为团员并且可以修改的模式
  87. }
  88. },
  89. methods: {
  90. // 选择图片
  91. chooseImage() {
  92. uni.chooseImage({
  93. count: 1,
  94. sizeType: ['compressed'],
  95. sourceType: ['album', 'camera'],
  96. success: (res) => {
  97. // 这里可以添加图片上传到服务器的逻辑
  98. // 暂时只展示选择的图片
  99. this.formData.spotImage = res.tempFilePaths[0]
  100. }
  101. })
  102. },
  103. // 显示地区选择器(当前只是一个简单的点击反应)
  104. regionSelect(e) {
  105. this.formData.area = e.detail.value[1] + e.detail.value[2]
  106. },
  107. // 提交申请
  108. submitApplication() {
  109. // 表单验证
  110. if (!this.formData.spotImage) {
  111. return uni.showToast({
  112. title: '请上传送餐点照片',
  113. icon: 'none'
  114. })
  115. }
  116. if (!this.formData.spotName) {
  117. return uni.showToast({
  118. title: '请输入送餐点名称',
  119. icon: 'none'
  120. })
  121. }
  122. if (!this.formData.name) {
  123. return uni.showToast({
  124. title: '请输入您的姓名',
  125. icon: 'none'
  126. })
  127. }
  128. if (!this.formData.phone) {
  129. return uni.showToast({
  130. title: '请输入联系手机号',
  131. icon: 'none'
  132. })
  133. }
  134. if (!this.$utils.verificationPhone(this.formData.phone)) {
  135. return uni.showToast({
  136. title: '请输入正确的手机号',
  137. icon: 'none'
  138. })
  139. }
  140. if (!this.formData.area) {
  141. return uni.showToast({
  142. title: '请选择所在地区',
  143. icon: 'none'
  144. })
  145. }
  146. if (!this.formData.address) {
  147. return uni.showToast({
  148. title: '请输入详细地址',
  149. icon: 'none'
  150. })
  151. }
  152. // 显示提交中
  153. uni.showLoading({
  154. title: '提交中...'
  155. })
  156. // 模拟提交申请的过程
  157. setTimeout(() => {
  158. uni.hideLoading()
  159. if (this.identity) {
  160. // 如果是团长 保存表单信息 直接返回了
  161. this.saveInfo()
  162. return
  163. }
  164. console.log(this.formData);
  165. // 如果是团员 提交申请
  166. this.$api('addLeader', {
  167. ...this.formData,
  168. }, res => {
  169. if (res.code == 200) {
  170. uni.showModal({
  171. title: '提交成功!',
  172. content: '我们的工作人员会及时与您联系,\n请保持电话畅通!',
  173. showCancel: false,
  174. confirmColor: '#019245',
  175. success: (res) => {
  176. if (res.confirm) {
  177. // 如果是团员 延迟返回上一页
  178. setTimeout(() => {
  179. this.$utils.navigateBack()
  180. }, 500)
  181. }
  182. }
  183. })
  184. }
  185. })
  186. }, 1000)
  187. },
  188. // 保存信息 针对团长端
  189. saveInfo() {
  190. uni.setStorageSync('team_form_data', JSON.stringify(this.formData))
  191. uni.showToast({
  192. title: '保存成功!',
  193. icon: 'none',
  194. duration: 2000
  195. })
  196. }
  197. },
  198. onLoad() {
  199. if (this.identity) {
  200. // 如果是团员 才去获取团长信息
  201. const addData = uni.getStorageSync('team_form_data')
  202. if (addData) {
  203. this.beModify = true
  204. this.formData = JSON.parse(addData)
  205. }
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .page {
  212. background-color: #f5f5f5;
  213. min-height: 100vh;
  214. }
  215. .banner {
  216. width: 100%;
  217. height: 240rpx;
  218. background-color: #019245;
  219. .banner-image {
  220. width: 100%;
  221. height: 100%;
  222. display: block;
  223. }
  224. }
  225. .content-area {
  226. padding: 20rpx;
  227. }
  228. .section-block {
  229. margin-bottom: 20rpx;
  230. background-color: #fff;
  231. border-radius: 20rpx;
  232. padding: 10rpx 20rpx;
  233. overflow: hidden;
  234. }
  235. .section-title {
  236. font-size: 28rpx;
  237. color: #333;
  238. padding: 20rpx;
  239. // border-bottom: 1rpx solid #f5f5f5;
  240. }
  241. .upload-container {
  242. padding: 20rpx;
  243. min-height: 140rpx;
  244. }
  245. .upload-area {
  246. width: 150rpx;
  247. height: 150rpx;
  248. border: 3rpx dashed $uni-color;
  249. // border-radius: 8rpx;
  250. display: flex;
  251. flex-direction: column;
  252. justify-content: center;
  253. align-items: center;
  254. .plus {
  255. font-size: 80rpx;
  256. color: $uni-color;
  257. line-height: 1;
  258. // margin-bottom: 5rpx;
  259. font-weight: 100;
  260. }
  261. .upload-text {
  262. font-size: 24rpx;
  263. color: $uni-color-third;
  264. }
  265. }
  266. .form-item {
  267. padding: 24rpx 0;
  268. display: flex;
  269. align-items: center;
  270. border-bottom: 2rpx solid #C7C7C7;
  271. &:last-child {
  272. border-bottom: none;
  273. }
  274. }
  275. .label {
  276. flex: 3;
  277. font-size: 28rpx;
  278. color: #333;
  279. padding-left: 10rpx;
  280. }
  281. .input {
  282. flex: 2;
  283. font-size: 28rpx;
  284. // height: 60rpx;
  285. text-align: left;
  286. }
  287. .placeholder,
  288. .region-item text.placeholder {
  289. // height: 60rpx;
  290. color: #999;
  291. }
  292. .region-item {
  293. cursor: pointer;
  294. }
  295. .address-item {
  296. padding: 24rpx 0;
  297. display: flex;
  298. flex-direction: column;
  299. gap: 20rpx;
  300. .address-box {}
  301. .address-input {
  302. padding: 20rpx;
  303. background-color: #F5F5F5;
  304. border-radius: 10rpx;
  305. width: inherit;
  306. height: 60rpx;
  307. font-size: 28rpx;
  308. }
  309. }
  310. .submit-btn {
  311. width: 80%;
  312. margin: 40rpx auto 0;
  313. height: 100rpx;
  314. background-color: $uni-color;
  315. color: #fff;
  316. font-size: 32rpx;
  317. display: flex;
  318. justify-content: center;
  319. align-items: center;
  320. border-radius: 50rpx;
  321. }
  322. .submit-btn-container {
  323. display: flex;
  324. justify-content: space-between;
  325. align-items: center;
  326. margin: 40rpx auto 0;
  327. width: 74%;
  328. .submit-btn-modify {
  329. width: 45%;
  330. height: 90rpx;
  331. background-color: #fff;
  332. color: $uni-color;
  333. font-size: 32rpx;
  334. display: flex;
  335. justify-content: center;
  336. align-items: center;
  337. border-radius: 50rpx;
  338. border: 4rpx solid $uni-color;
  339. }
  340. .submit-btn-save {
  341. width: 45%;
  342. height: 90rpx;
  343. background-color: $uni-color;
  344. color: #fff;
  345. font-size: 32rpx;
  346. display: flex;
  347. justify-content: center;
  348. align-items: center;
  349. border-radius: 50rpx;
  350. }
  351. }
  352. </style>