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

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