鸿宇研学生前端代码
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.

280 lines
6.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view>
  3. <uv-popup ref="popup" mode="bottom" bgColor="none" >
  4. <view class="popup__view">
  5. <view class="flex header">
  6. <view class="title">新增记录</view>
  7. <button class="btn" @click="close">关闭</button>
  8. </view>
  9. <view class="form">
  10. <uv-form
  11. ref="form"
  12. :model="form"
  13. :rules="rules"
  14. errorType="toast"
  15. >
  16. <view class="form-item">
  17. <uv-form-item prop="area" :customStyle="formItemStyle">
  18. <view class="form-item-label">选择地址</view>
  19. <view class="form-item-content">
  20. <view class="flex row" @click="selectAddr">
  21. <view v-if="form.area" class="text">{{ form.area }}</view>
  22. <view v-else class="text placeholder">请选择地址</view>
  23. <uv-icon name="arrow-right" color="#C6C6C6" size="32rpx"></uv-icon>
  24. </view>
  25. </view>
  26. </uv-form-item>
  27. </view>
  28. <view class="form-item">
  29. <uv-form-item prop="images" :customStyle="formItemStyle">
  30. <view class="form-item-label">上传图片</view>
  31. <view class="form-item-content">
  32. <formUpload v-model="form.images"></formUpload>
  33. </view>
  34. </uv-form-item>
  35. </view>
  36. </uv-form>
  37. </view>
  38. <view class="footer">
  39. <button class="flex btn" @click="onPublish">发布</button>
  40. </view>
  41. </view>
  42. </uv-popup>
  43. </view>
  44. </template>
  45. <script>
  46. import Position from '@/utils/position.js'
  47. import reloateProjectPopup from '@/pages_order/components/reloateProjectPopup.vue'
  48. import formTextarea from '@/pages_order/components/formTextarea.vue'
  49. import formUpload from '@/pages_order/components/formUpload.vue'
  50. export default {
  51. components: {
  52. reloateProjectPopup,
  53. formTextarea,
  54. formUpload,
  55. },
  56. data() {
  57. return {
  58. imageId: null,
  59. activityId: null,
  60. form: {
  61. area: null,
  62. latitude: null,
  63. longitude: null,
  64. images: [],
  65. },
  66. rules: {
  67. 'area': {
  68. type: 'string',
  69. required: true,
  70. message: '请选择地址',
  71. },
  72. 'images': {
  73. type: 'array',
  74. required: true,
  75. message: '请上传图片',
  76. },
  77. },
  78. projects: [],
  79. questions: [],
  80. }
  81. },
  82. computed: {
  83. },
  84. methods: {
  85. async open(imageId, activityId) {
  86. this.imageId = imageId
  87. this.activityId = activityId
  88. this.form = {
  89. area: null,
  90. latitude: null,
  91. longitude: null,
  92. images: [],
  93. }
  94. this.$refs.popup.open()
  95. },
  96. close() {
  97. this.$refs.popup.close()
  98. },
  99. //地图上选择地址
  100. selectAddr() {
  101. // Position.getLocation(res => {
  102. Position.selectAddress(0, 0, success => {
  103. this.setAddress(success)
  104. })
  105. // })
  106. },
  107. //提取用户选择的地址信息复制给表单数据
  108. setAddress(res) {
  109. //经纬度信息
  110. this.form.latitude = res.latitude
  111. this.form.longitude = res.longitude
  112. if (!res.address && res.name) { //用户直接选择城市的逻辑
  113. return this.form.area = res.name
  114. }
  115. if (res.address || res.name) {
  116. return this.form.area = res.address + res.name
  117. }
  118. this.form.area = '' //用户啥都没选就点击勾选
  119. },
  120. async onPublish() {
  121. try {
  122. await this.$refs.form.validate()
  123. const {
  124. area,
  125. images,
  126. } = this.form
  127. const params = {
  128. imageId: this.imageId,
  129. activityId: this.activityId,
  130. address: area,
  131. image: images.join(',')
  132. }
  133. await this.$fetch('addImageContent', params)
  134. uni.showToast({
  135. icon: 'success',
  136. title: '发布成功',
  137. });
  138. this.$emit('submitted')
  139. this.close()
  140. } catch (err) {
  141. console.log('onSave err', err)
  142. }
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .popup__view {
  149. width: 100vw;
  150. display: flex;
  151. flex-direction: column;
  152. box-sizing: border-box;
  153. background: #FFFFFF;
  154. border-top-left-radius: 32rpx;
  155. border-top-right-radius: 32rpx;
  156. }
  157. .header {
  158. position: relative;
  159. width: 100%;
  160. padding: 24rpx 0;
  161. box-sizing: border-box;
  162. border-bottom: 2rpx solid #EEEEEE;
  163. .title {
  164. font-family: PingFang SC;
  165. font-weight: 500;
  166. font-size: 34rpx;
  167. line-height: 1.4;
  168. color: #181818;
  169. }
  170. .btn {
  171. font-family: PingFang SC;
  172. font-weight: 500;
  173. font-size: 32rpx;
  174. line-height: 1.4;
  175. color: #8B8B8B;
  176. position: absolute;
  177. top: 26rpx;
  178. left: 40rpx;
  179. }
  180. }
  181. .form {
  182. max-height: 75vh;
  183. padding: 32rpx 40rpx;
  184. box-sizing: border-box;
  185. overflow-y: auto;
  186. &-item {
  187. padding: 8rpx 0 6rpx 0;
  188. & + & {
  189. padding-top: 24rpx;
  190. border-top: 2rpx solid #EEEEEE;
  191. }
  192. &-label {
  193. margin-bottom: 14rpx;
  194. display: flex;
  195. align-items: center;
  196. font-family: PingFang SC;
  197. font-weight: 400;
  198. font-size: 26rpx;
  199. line-height: 1.4;
  200. color: #181818;
  201. .icon {
  202. margin-right: 8rpx;
  203. width: 16rpx;
  204. height: auto;
  205. }
  206. }
  207. &-content {
  208. .text {
  209. padding: 2rpx 0;
  210. font-family: PingFang SC;
  211. font-weight: 400;
  212. font-size: 32rpx;
  213. line-height: 1.4;
  214. &.placeholder {
  215. color: #C6C6C6;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. .row {
  222. justify-content: space-between;
  223. .form-label {
  224. margin: 0;
  225. }
  226. }
  227. .footer {
  228. width: 100%;
  229. padding: 32rpx 40rpx;
  230. box-sizing: border-box;
  231. border-top: 2rpx solid #F1F1F1;
  232. .btn {
  233. width: 100%;
  234. padding: 14rpx 0;
  235. box-sizing: border-box;
  236. font-family: PingFang SC;
  237. font-weight: 500;
  238. font-size: 36rpx;
  239. line-height: 1.4;
  240. color: #FFFFFF;
  241. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  242. border: 2rpx solid #00A9FF;
  243. border-radius: 41rpx;
  244. }
  245. }
  246. </style>