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

395 lines
8.1 KiB

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