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

400 lines
9.3 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. <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 shopList = (await this.$fetch('queryShopList', { userId: this.userInfo.id }))?.records
  190. if (!shopList.length) {
  191. return
  192. }
  193. const {
  194. id,
  195. status,
  196. status_dictText,
  197. remark,
  198. image,
  199. shop,
  200. name,
  201. phone,
  202. area,
  203. latitude,
  204. longitude,
  205. address,
  206. } = shopList[0]
  207. this.form = {
  208. image,
  209. shop,
  210. name,
  211. phone,
  212. area,
  213. latitude,
  214. longitude,
  215. address,
  216. }
  217. this.id = id
  218. this.status = status
  219. this.statusDesc = status == '2' ? `${status_dictText}${remark}` : status_dictText
  220. } catch (err) {
  221. }
  222. },
  223. async updateStatus() {
  224. if (!this.id) {
  225. return
  226. }
  227. try {
  228. const { status, status_dictText, remark } = await this.$fetch('queryShopById', { id: this.id })
  229. this.status = status
  230. this.statusDesc = status == '2' ? `${status_dictText}${remark}` : status_dictText
  231. } catch (err) {
  232. console.log('--err', err)
  233. }
  234. uni.stopPullDownRefresh();
  235. },
  236. async onSubmit() {
  237. try {
  238. await this.$refs.form.validate()
  239. const {
  240. image,
  241. shop,
  242. name,
  243. phone,
  244. area,
  245. latitude,
  246. longitude,
  247. address,
  248. } = this.form
  249. const params = {
  250. image,
  251. shop,
  252. name,
  253. phone,
  254. area,
  255. latitude,
  256. longitude,
  257. address,
  258. }
  259. let api = this.id ? 'updateShop' : 'addShop'
  260. await this.$fetch(api, params)
  261. uni.showToast({
  262. title: '提交成功',
  263. icon: 'none'
  264. })
  265. setTimeout(uni.navigateBack, 1000, -1)
  266. } catch (err) {
  267. }
  268. },
  269. },
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. .page {
  274. background-color: $uni-bg-color;
  275. min-height: 100vh;
  276. /deep/ .nav-bar__view {
  277. background-image: linear-gradient(#84A73F, #D8FF8F);
  278. }
  279. }
  280. .tips {
  281. padding: 5rpx 0;
  282. font-weight: bold;
  283. font-size: 28rpx;
  284. color: $uni-color;
  285. background-color: rgba($color: #D8FF8F, $alpha: 0.3);
  286. }
  287. .content {
  288. padding: 28rpx 30rpx;
  289. }
  290. .form {
  291. & + & {
  292. margin-top: 44rpx;
  293. }
  294. &-title {
  295. color: #000000;
  296. font-size: 28rpx;
  297. margin-bottom: 15rpx;
  298. }
  299. &-item {
  300. padding-left: 8rpx;
  301. & + & {
  302. // margin-top: 20rpx;
  303. border-top: 1rpx solid rgba($color: #C7C7C7, $alpha: 0.69);
  304. }
  305. &-content {
  306. min-height: 60rpx;
  307. display: flex;
  308. align-items: center;
  309. justify-content: flex-end;
  310. font-size: 28rpx;;
  311. color: #999999;
  312. }
  313. }
  314. }
  315. .upload {
  316. padding: 37rpx 22rpx;
  317. &-img {
  318. width: 131rpx; height: 131rpx;
  319. }
  320. }
  321. .area {
  322. color: #000000;
  323. font-size: 28rpx;
  324. line-height: 40rpx;
  325. justify-content: flex-end;
  326. &-btn {
  327. border: none;
  328. padding: 7rpx 20rpx 7rpx 7rpx;
  329. &-icon {
  330. width: 30rpx;
  331. height: auto;
  332. }
  333. }
  334. }
  335. .address {
  336. padding: 0;
  337. /deep/ .uv-form-item__body__left__content {
  338. margin-top: 10rpx;
  339. padding-left: 8rpx;
  340. }
  341. }
  342. .tools {
  343. padding: 0 56rpx;
  344. margin-top: 126rpx;
  345. }
  346. .btn-submit {
  347. padding: 29rpx 0;
  348. border: none;
  349. font-size: 36rpx;
  350. border-radius: 45rpx;
  351. color: $uni-text-color-inverse;
  352. background-image: linear-gradient(to right, #84A73F, #D8FF8F);
  353. }
  354. </style>