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

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