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

360 lines
9.2 KiB

  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="activityId" :customStyle="formItemStyle">
  18. <view class="form-item-label">
  19. <image class="icon" src="@/pages_order/static/icon-require.png" mode="widthFix"></image>
  20. 关联项目
  21. </view>
  22. <view class="form-item-content">
  23. <view class="flex row" @click="openRelatePojectPicker">
  24. <view v-if="form.activityId" class="text">{{ projectDesc }}</view>
  25. <view v-else class="text placeholder">请选择关联项目</view>
  26. <uv-icon name="arrow-right" color="#C6C6C6" size="32rpx"></uv-icon>
  27. </view>
  28. <reloateProjectPopup ref="reloateProjectPopup" :options="projects" @confirm="onRelateProjectChange"></reloateProjectPopup>
  29. </view>
  30. </uv-form-item>
  31. </view>
  32. <view class="form-item">
  33. <uv-form-item prop="area" :customStyle="formItemStyle">
  34. <view class="form-item-label">选择地址</view>
  35. <view class="form-item-content">
  36. <view class="flex row" @click="selectAddr">
  37. <view v-if="form.area" class="text">{{ form.area }}</view>
  38. <view v-else class="text placeholder">请选择地址</view>
  39. <uv-icon name="arrow-right" color="#C6C6C6" size="32rpx"></uv-icon>
  40. </view>
  41. </view>
  42. </uv-form-item>
  43. </view>
  44. <view class="form-item">
  45. <uv-form-item prop="images" :customStyle="formItemStyle">
  46. <view class="form-item-label">上传图片</view>
  47. <view class="form-item-content">
  48. <formUpload v-model="form.images"></formUpload>
  49. </view>
  50. </uv-form-item>
  51. </view>
  52. </uv-form>
  53. </view>
  54. <view class="footer">
  55. <button class="flex btn" @click="onPublish">发布</button>
  56. </view>
  57. </view>
  58. </uv-popup>
  59. </view>
  60. </template>
  61. <script>
  62. import Position from '@/utils/position.js'
  63. import reloateProjectPopup from '@/pages_order/components/reloateProjectPopup.vue'
  64. import formTextarea from '@/pages_order/components/formTextarea.vue'
  65. import formUpload from '@/pages_order/components/formUpload.vue'
  66. export default {
  67. components: {
  68. reloateProjectPopup,
  69. formTextarea,
  70. formUpload,
  71. },
  72. data() {
  73. return {
  74. form: {
  75. activityId: null,
  76. area: null,
  77. latitude: null,
  78. longitude: null,
  79. images: [],
  80. },
  81. rules: {
  82. 'activityId': {
  83. type: 'string',
  84. required: true,
  85. message: '请选择关联项目',
  86. },
  87. 'area': {
  88. type: 'string',
  89. required: true,
  90. message: '请选择地址',
  91. },
  92. 'images': {
  93. type: 'array',
  94. required: true,
  95. message: '请上传图片',
  96. },
  97. },
  98. projects: [],
  99. questions: [],
  100. }
  101. },
  102. computed: {
  103. projectDesc() {
  104. const { activityId } = this.form
  105. const target = this.projects?.find?.(item => item.id === activityId)
  106. return target?.name || ''
  107. },
  108. },
  109. methods: {
  110. getData() {
  111. // todo
  112. this.projects = [
  113. {
  114. id: '001',
  115. name: '亲子•坝上双草原6日 |乌兰布统+锡林郭勒+长城',
  116. },
  117. {
  118. id: '002',
  119. name: '青青草原•云中岭 |5-10公里AB线强度可选',
  120. },
  121. {
  122. id: '003',
  123. name: '新疆天山行7/9日丨醉美伊犁&吐鲁番双套餐',
  124. },
  125. {
  126. id: '004',
  127. name: '九色甘南|人间净土6日/7日深度游',
  128. },
  129. {
  130. id: '005',
  131. name: '北疆全景12日| 入疆首推!阿勒泰+伊犁+吐鲁番',
  132. },
  133. {
  134. id: '006',
  135. name: '塞上江南•神奇宁夏5日|穿越大漠与历史对话',
  136. },
  137. {
  138. id: '007',
  139. name: '尊享•天山环线9日| 伊犁全景+独库,头等舱大巴',
  140. },
  141. ]
  142. this.questions = [
  143. {
  144. id: '001',
  145. label: '这次研学之旅,整体给你留下了怎样的印象?用几个词或几句话简单概括一下',
  146. },
  147. {
  148. id: '002',
  149. label: '在整个行程中,你最喜欢的部分是哪里?为什么?',
  150. },
  151. {
  152. id: '003',
  153. label: '你觉得这次研学的行程安排是否合理?有没有哪些地方让你觉得特别满意或需要改进的?',
  154. },
  155. ]
  156. },
  157. async open(id) {
  158. // todo: auto bind activityId by id?
  159. await this.getData()
  160. this.form = {
  161. activityId: null,
  162. area: null,
  163. latitude: null,
  164. longitude: null,
  165. images: [],
  166. }
  167. this.$refs.popup.open()
  168. },
  169. close() {
  170. this.$refs.popup.close()
  171. },
  172. openRelatePojectPicker() {
  173. this.$refs.reloateProjectPopup.open(this.form.activityId?.id || null)
  174. },
  175. onRelateProjectChange(id) {
  176. this.form.activityId = id
  177. },
  178. //地图上选择地址
  179. selectAddr() {
  180. // Position.getLocation(res => {
  181. Position.selectAddress(0, 0, success => {
  182. this.setAddress(success)
  183. })
  184. // })
  185. },
  186. //提取用户选择的地址信息复制给表单数据
  187. setAddress(res) {
  188. //经纬度信息
  189. this.form.latitude = res.latitude
  190. this.form.longitude = res.longitude
  191. if (!res.address && res.name) { //用户直接选择城市的逻辑
  192. return this.form.area = res.name
  193. }
  194. if (res.address || res.name) {
  195. return this.form.area = res.address + res.name
  196. }
  197. this.form.area = '' //用户啥都没选就点击勾选
  198. },
  199. async onPublish() {
  200. try {
  201. await this.$refs.form.validate()
  202. const {
  203. activityId,
  204. area,
  205. images,
  206. } = this.form
  207. const params = {
  208. activityId,
  209. address: area,
  210. image: images.join(',')
  211. }
  212. await this.$fetch('addImage', params)
  213. uni.showToast({
  214. icon: 'success',
  215. title: '发布成功',
  216. });
  217. this.$emit('submitted')
  218. this.close()
  219. } catch (err) {
  220. console.log('onSave err', err)
  221. }
  222. },
  223. },
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .popup__view {
  228. width: 100vw;
  229. display: flex;
  230. flex-direction: column;
  231. box-sizing: border-box;
  232. background: #FFFFFF;
  233. border-top-left-radius: 32rpx;
  234. border-top-right-radius: 32rpx;
  235. }
  236. .header {
  237. position: relative;
  238. width: 100%;
  239. padding: 24rpx 0;
  240. box-sizing: border-box;
  241. border-bottom: 2rpx solid #EEEEEE;
  242. .title {
  243. font-family: PingFang SC;
  244. font-weight: 500;
  245. font-size: 34rpx;
  246. line-height: 1.4;
  247. color: #181818;
  248. }
  249. .btn {
  250. font-family: PingFang SC;
  251. font-weight: 500;
  252. font-size: 32rpx;
  253. line-height: 1.4;
  254. color: #8B8B8B;
  255. position: absolute;
  256. top: 26rpx;
  257. left: 40rpx;
  258. }
  259. }
  260. .form {
  261. max-height: 75vh;
  262. padding: 32rpx 40rpx;
  263. box-sizing: border-box;
  264. overflow-y: auto;
  265. &-item {
  266. padding: 8rpx 0 6rpx 0;
  267. & + & {
  268. padding-top: 24rpx;
  269. border-top: 2rpx solid #EEEEEE;
  270. }
  271. &-label {
  272. margin-bottom: 14rpx;
  273. display: flex;
  274. align-items: center;
  275. font-family: PingFang SC;
  276. font-weight: 400;
  277. font-size: 26rpx;
  278. line-height: 1.4;
  279. color: #181818;
  280. .icon {
  281. margin-right: 8rpx;
  282. width: 16rpx;
  283. height: auto;
  284. }
  285. }
  286. &-content {
  287. .text {
  288. padding: 2rpx 0;
  289. font-family: PingFang SC;
  290. font-weight: 400;
  291. font-size: 32rpx;
  292. line-height: 1.4;
  293. &.placeholder {
  294. color: #C6C6C6;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. .row {
  301. justify-content: space-between;
  302. .form-label {
  303. margin: 0;
  304. }
  305. }
  306. .footer {
  307. width: 100%;
  308. padding: 32rpx 40rpx;
  309. box-sizing: border-box;
  310. border-top: 2rpx solid #F1F1F1;
  311. .btn {
  312. width: 100%;
  313. padding: 14rpx 0;
  314. box-sizing: border-box;
  315. font-family: PingFang SC;
  316. font-weight: 500;
  317. font-size: 36rpx;
  318. line-height: 1.4;
  319. color: #FFFFFF;
  320. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  321. border: 2rpx solid #00A9FF;
  322. border-radius: 41rpx;
  323. }
  324. }
  325. </style>