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

358 lines
9.1 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="project" :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.project" 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. project: null,
  76. area: null,
  77. latitude: null,
  78. longitude: null,
  79. images: [],
  80. },
  81. rules: {
  82. 'project': {
  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 { project } = this.form
  105. const target = this.projects?.find?.(item => item.id === project)
  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 project by id?
  159. await this.getData()
  160. const texts = this.questions.map(() => '')
  161. this.form = {
  162. project: null,
  163. tripNum: null,
  164. spotNum: null,
  165. mentorNum: null,
  166. images: [],
  167. texts,
  168. }
  169. this.$refs.popup.open()
  170. },
  171. close() {
  172. this.$refs.popup.close()
  173. },
  174. openRelatePojectPicker() {
  175. this.$refs.reloateProjectPopup.open(this.form.project?.id || null)
  176. },
  177. onRelateProjectChange(id) {
  178. this.form.project = id
  179. },
  180. //地图上选择地址
  181. selectAddr() {
  182. // Position.getLocation(res => {
  183. Position.selectAddress(0, 0, success => {
  184. this.setAddress(success)
  185. })
  186. // })
  187. },
  188. //提取用户选择的地址信息复制给表单数据
  189. setAddress(res) {
  190. //经纬度信息
  191. this.form.latitude = res.latitude
  192. this.form.longitude = res.longitude
  193. if (!res.address && res.name) { //用户直接选择城市的逻辑
  194. return this.form.area = res.name
  195. }
  196. if (res.address || res.name) {
  197. return this.form.area = res.address + res.name
  198. }
  199. this.form.area = '' //用户啥都没选就点击勾选
  200. },
  201. async onPublish() {
  202. try {
  203. await this.$refs.form.validate()
  204. const {
  205. } = this.form
  206. const params = {
  207. }
  208. // todo: fetch
  209. // await this.$fetch('updateAddress', params)
  210. uni.showToast({
  211. icon: 'success',
  212. title: '发布成功',
  213. });
  214. this.$emit('submitted')
  215. this.close()
  216. } catch (err) {
  217. console.log('onSave err', err)
  218. }
  219. },
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .popup__view {
  225. width: 100vw;
  226. display: flex;
  227. flex-direction: column;
  228. box-sizing: border-box;
  229. background: #FFFFFF;
  230. border-top-left-radius: 32rpx;
  231. border-top-right-radius: 32rpx;
  232. }
  233. .header {
  234. position: relative;
  235. width: 100%;
  236. padding: 24rpx 0;
  237. box-sizing: border-box;
  238. border-bottom: 2rpx solid #EEEEEE;
  239. .title {
  240. font-family: PingFang SC;
  241. font-weight: 500;
  242. font-size: 34rpx;
  243. line-height: 1.4;
  244. color: #181818;
  245. }
  246. .btn {
  247. font-family: PingFang SC;
  248. font-weight: 500;
  249. font-size: 32rpx;
  250. line-height: 1.4;
  251. color: #8B8B8B;
  252. position: absolute;
  253. top: 26rpx;
  254. left: 40rpx;
  255. }
  256. }
  257. .form {
  258. max-height: 75vh;
  259. padding: 32rpx 40rpx;
  260. box-sizing: border-box;
  261. overflow-y: auto;
  262. &-item {
  263. padding: 8rpx 0 6rpx 0;
  264. & + & {
  265. padding-top: 24rpx;
  266. border-top: 2rpx solid #EEEEEE;
  267. }
  268. &-label {
  269. margin-bottom: 14rpx;
  270. display: flex;
  271. align-items: center;
  272. font-family: PingFang SC;
  273. font-weight: 400;
  274. font-size: 26rpx;
  275. line-height: 1.4;
  276. color: #181818;
  277. .icon {
  278. margin-right: 8rpx;
  279. width: 16rpx;
  280. height: auto;
  281. }
  282. }
  283. &-content {
  284. .text {
  285. padding: 2rpx 0;
  286. font-family: PingFang SC;
  287. font-weight: 400;
  288. font-size: 32rpx;
  289. line-height: 1.4;
  290. &.placeholder {
  291. color: #C6C6C6;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. .row {
  298. justify-content: space-between;
  299. .form-label {
  300. margin: 0;
  301. }
  302. }
  303. .footer {
  304. width: 100%;
  305. padding: 32rpx 40rpx;
  306. box-sizing: border-box;
  307. border-top: 2rpx solid #F1F1F1;
  308. .btn {
  309. width: 100%;
  310. padding: 14rpx 0;
  311. box-sizing: border-box;
  312. font-family: PingFang SC;
  313. font-weight: 500;
  314. font-size: 36rpx;
  315. line-height: 1.4;
  316. color: #FFFFFF;
  317. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  318. border: 2rpx solid #00A9FF;
  319. border-radius: 41rpx;
  320. }
  321. }
  322. </style>