推拿小程序前端代码仓库
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.

312 lines
7.4 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="商家合作" leftClick @leftClick="$utils.navigateBack" color="#fff" />
  5. <view class="content">
  6. <view class="form">
  7. <view class="form-title">门头照片</view>
  8. <view class="card upload">
  9. <formUpload v-model="form.image">
  10. <template v-slot="{ value }">
  11. <view class="flex">
  12. <image v-if="value"
  13. class="upload-img"
  14. :src="value"
  15. mode="aspectFill"
  16. />
  17. <image v-else
  18. class="upload-img"
  19. src="../static/cooperation/icon-upload.png"
  20. mode="aspectFill"
  21. />
  22. </view>
  23. </template>
  24. </formUpload>
  25. </view>
  26. </view>
  27. <view class="form">
  28. <view class="form-title">店铺信息</view>
  29. <view class="card info">
  30. <uv-form
  31. ref="form"
  32. :model="form"
  33. :rules="rules"
  34. labelPosition="left"
  35. labelWidth="150rpx"
  36. :labelStyle="{
  37. color: '#000000',
  38. fontSize: '28rpx',
  39. }"
  40. >
  41. <view class="form-item">
  42. <uv-form-item label="店铺名称" prop="shop">
  43. <view class="form-item-content">
  44. <formInput v-model="form.shop" placeholder="请输入店铺名称"></formInput>
  45. </view>
  46. </uv-form-item>
  47. </view>
  48. <view class="form-item">
  49. <uv-form-item label="您的姓名" prop="name">
  50. <view class="form-item-content">
  51. <formInput v-model="form.name" placeholder="请输入您的姓名"></formInput>
  52. </view>
  53. </uv-form-item>
  54. </view>
  55. <view class="form-item">
  56. <uv-form-item label="联系手机号" prop="phone">
  57. <view class="form-item-content">
  58. <formInput v-model="form.phone" placeholder="请输入您的手机号"></formInput>
  59. </view>
  60. </uv-form-item>
  61. </view>
  62. <view class="form-item">
  63. <uv-form-item label="所在地区" prop="area">
  64. <view class="form-item-content flex area">
  65. <text>{{ form.area ? form.area : '请选择' }}</text>
  66. <button plain class="btn area-btn" @click="selectAddr">
  67. <image class="area-btn-icon" src="../static/cooperation/icon-arrow.png" mode="widthFix"></image>
  68. </button>
  69. </view>
  70. </uv-form-item>
  71. </view>
  72. <view class="form-item address">
  73. <uv-form-item label="详细地址" prop="address" labelPosition="top" >
  74. <view style="margin-top: 22rpx;">
  75. <formTextarea
  76. v-model="form.address"
  77. placeholder="请输入详细地址"
  78. ></formTextarea>
  79. </view>
  80. </uv-form-item>
  81. </view>
  82. </uv-form>
  83. </view>
  84. </view>
  85. <view class="tools">
  86. <button plain class="btn btn-submit" @click="onSubmit">提交</button>
  87. </view>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import Position from '@/utils/position.js'
  93. import formInput from '../components/formInput.vue'
  94. import formUpload from '../components/formUpload.vue'
  95. import formTextarea from '../components/formTextarea.vue'
  96. export default {
  97. components: {
  98. formInput,
  99. formUpload,
  100. formTextarea,
  101. },
  102. data() {
  103. return {
  104. form: {
  105. image: null,
  106. shop: null,
  107. name: null,
  108. phone: null,
  109. area: null,
  110. latitude: null,
  111. longitude: null,
  112. address: null,
  113. },
  114. rules: {
  115. 'image': {
  116. type: 'string',
  117. required: true,
  118. message: '请选择门头照片',
  119. },
  120. 'shop': {
  121. type: 'string',
  122. required: true,
  123. message: '请输入店铺名称',
  124. },
  125. 'name': {
  126. type: 'string',
  127. required: true,
  128. message: '请输入您的姓名',
  129. },
  130. 'phone': {
  131. type: 'string',
  132. required: true,
  133. message: '请输入您的手机号',
  134. },
  135. 'area': {
  136. type: 'string',
  137. required: true,
  138. message: '请选择所在地区',
  139. },
  140. 'address': {
  141. type: 'string',
  142. required: true,
  143. message: '请输入详细地址',
  144. },
  145. },
  146. }
  147. },
  148. methods: {
  149. //地图上选择地址
  150. selectAddr() {
  151. // Position.getLocation(res => {
  152. Position.selectAddress(0, 0, success => {
  153. this.setAddress(success)
  154. })
  155. // })
  156. },
  157. //提取用户选择的地址信息复制给表单数据
  158. setAddress(res) {
  159. //经纬度信息
  160. this.form.latitude = res.latitude
  161. this.form.longitude = res.longitude
  162. if (!res.address && res.name) { //用户直接选择城市的逻辑
  163. return this.form.area = res.name
  164. }
  165. if (res.address || res.name) {
  166. return this.form.area = res.address + res.name
  167. }
  168. this.form.area = '' //用户啥都没选就点击勾选
  169. },
  170. async onSubmit() {
  171. try {
  172. await this.$refs.form.validate()
  173. const {
  174. image,
  175. shop,
  176. name,
  177. phone,
  178. area,
  179. latitude,
  180. longitude,
  181. address,
  182. } = this.form
  183. const params = {
  184. image,
  185. shop,
  186. name,
  187. phone,
  188. area,
  189. latitude,
  190. longitude,
  191. address,
  192. }
  193. await this.$fetch('addShop', params)
  194. uni.showToast({
  195. title: '提交成功',
  196. icon: 'none'
  197. })
  198. setTimeout(uni.navigateBack, 1000, -1)
  199. } catch (err) {
  200. }
  201. },
  202. },
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .page {
  207. background-color: $uni-bg-color;
  208. min-height: 100vh;
  209. /deep/ .nav-bar__view {
  210. background-image: linear-gradient(#84A73F, #D8FF8F);
  211. }
  212. }
  213. .content {
  214. padding: 28rpx 30rpx;
  215. }
  216. .form {
  217. & + & {
  218. margin-top: 44rpx;
  219. }
  220. &-title {
  221. color: #000000;
  222. font-size: 28rpx;
  223. margin-bottom: 15rpx;
  224. }
  225. &-item {
  226. padding-left: 8rpx;
  227. & + & {
  228. // margin-top: 20rpx;
  229. border-top: 1rpx solid rgba($color: #C7C7C7, $alpha: 0.69);
  230. }
  231. &-content {
  232. min-height: 60rpx;
  233. display: flex;
  234. align-items: center;
  235. justify-content: flex-end;
  236. font-size: 28rpx;;
  237. color: #999999;
  238. }
  239. }
  240. }
  241. .upload {
  242. padding: 37rpx 22rpx;
  243. &-img {
  244. width: 131rpx; height: 131rpx;
  245. }
  246. }
  247. .area {
  248. color: #000000;
  249. font-size: 28rpx;
  250. line-height: 40rpx;
  251. justify-content: flex-end;
  252. &-btn {
  253. border: none;
  254. padding: 7rpx 20rpx 7rpx 7rpx;
  255. &-icon {
  256. width: 30rpx;
  257. height: auto;
  258. }
  259. }
  260. }
  261. .address {
  262. padding: 0;
  263. /deep/ .uv-form-item__body__left__content {
  264. margin-top: 10rpx;
  265. padding-left: 8rpx;
  266. }
  267. }
  268. .tools {
  269. padding: 0 56rpx;
  270. margin-top: 126rpx;
  271. }
  272. .btn-submit {
  273. padding: 29rpx 0;
  274. border: none;
  275. font-size: 36rpx;
  276. border-radius: 45rpx;
  277. color: $uni-text-color-inverse;
  278. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  279. }
  280. </style>