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

404 lines
9.4 KiB

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