modify.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="app-content">
  3. <form @submit="formSubmit">
  4. <view class="module-com input-line-wrap">
  5. <tui-list-cell class="line-cell" :hover="false" :arrow="true" @click="openAddres">
  6. <view class="tui-title">城市</view>
  7. <view class="tui-input" v-if="form.province || form.city">{{ form.province + '-' + form.city }}</view>
  8. <view class="tui-placeholder" v-else>请选择</view>
  9. <input v-model="form.province" name="province" hidden />
  10. </tui-list-cell>
  11. <tui-list-cell v-if="hasMap == 0" class="line-cell" :hover="false">
  12. <view class="tui-title">地址</view>
  13. <input v-model="form.address" placeholder-class="phcolor" class="tui-input" name="address" placeholder="请填写地址" />
  14. </tui-list-cell>
  15. <tui-list-cell v-else class="line-cell" :hover="false" :arrow="true" @click="selectRegion">
  16. <view class="tui-title">地址</view>
  17. <view v-if="form.address" class="tui-input">{{ form.address }}</view>
  18. <view v-else class="tui-placeholder">请填写地址</view>
  19. <input v-model="form.address" name="address" hidden />
  20. </tui-list-cell>
  21. <tui-list-cell class="line-cell" :hover="false">
  22. <view class="tui-title ">门牌</view>
  23. <input v-model="form.floor" placeholder-class="phcolor" class="tui-input" name="floor" placeholder="楼号门牌号" />
  24. </tui-list-cell>
  25. </view>
  26. <view class="confirm-btn">
  27. <button class="admin-button-com big blue" formType="submit">提交</button>
  28. </view>
  29. </form>
  30. <!-- 省市联动 -->
  31. <simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onCityConfirm"></simple-address>
  32. <!-- 选择地区 -->
  33. <app-area-sel :show.sync="showRegion" :city="form.city" @change="changeAreaFn" />
  34. </view>
  35. </template>
  36. <script>
  37. import TuiListCell from '@/components/plugin/list-cell'
  38. import SimpleAddress from '@/components/plugin/simple-address'
  39. import AppAreaSel from '@/components/app-area-sel'
  40. const form = require('@/utils/formValidation.js')
  41. import { modifyAddress } from '@/api/custom'
  42. import {getHasMap} from "@/api/express"
  43. export default {
  44. name: 'modify',
  45. components: {
  46. TuiListCell,
  47. SimpleAddress,
  48. AppAreaSel
  49. },
  50. data() {
  51. return {
  52. form: {
  53. province: '',
  54. city: '',
  55. address: '',
  56. floor: '',
  57. showAddress:''
  58. },
  59. showRegion: false,
  60. region: {
  61. lat: 0,
  62. long: 0
  63. },
  64. cityPickerValueDefault: [0, 0],
  65. hasMap: 0
  66. }
  67. },
  68. onLoad() {
  69. if(this.option.name){
  70. uni.setNavigationBarTitle({ title: this.option.name })
  71. }
  72. },
  73. methods: {
  74. init() {
  75. getHasMap().then(res=>{
  76. this.hasMap = res.data.hasMap
  77. })
  78. },
  79. openAddres() {
  80. this.$refs.simpleAddress.open()
  81. },
  82. onCityConfirm(e) {
  83. this.form.province = e.provinceName
  84. this.form.city = e.cityName
  85. this.form.address = ''
  86. this.region.lat = 0
  87. this.region.long = 0
  88. },
  89. selectRegion() {
  90. if (!this.form.city) {
  91. this.$msg('请选择城市')
  92. return false
  93. }
  94. this.showRegion = true
  95. },
  96. changeAreaFn(e) {
  97. this.form.address = e.name
  98. let locationStr = e.location
  99. let fruits = locationStr.split(",").map(fruit => fruit.trim())
  100. this.region.lat = fruits[1]||''
  101. this.region.long = fruits[0]||''
  102. this.form.showAddress = e.address||''
  103. // 提取地区信息,按遇到第一个"市"字后,把"市"后面的字符串作为地区
  104. const districtStr = e.district || '';
  105. const cityIndex = districtStr.indexOf('市');
  106. this.form.dist = cityIndex !== -1 ? districtStr.substring(cityIndex + 1) : districtStr;
  107. },
  108. confirmFn() {
  109. let that = this
  110. this.form.id = this.option.id ? this.option.id : 0
  111. this.form = {...this.form,...this.region}
  112. uni.showLoading({mask:true})
  113. modifyAddress(this.form).then(res=>{
  114. if(res.code == 1){
  115. that.$msg('修改成功')
  116. setTimeout(() => {
  117. uni.navigateBack({})
  118. }, 1200)
  119. }
  120. })
  121. },
  122. formSubmit(e) {
  123. let rules = [
  124. {
  125. name: 'province',
  126. rule: ['required'],
  127. msg: ['请选择城市']
  128. },
  129. {
  130. name: 'address',
  131. rule: ['required'],
  132. msg: ['请填选地址']
  133. }
  134. ]
  135. let formData = e.detail.value
  136. let checkRes = form.validation(formData, rules)
  137. if (!checkRes) {
  138. this.confirmFn()
  139. } else {
  140. this.$msg(checkRes)
  141. }
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .app-content {
  148. min-height: calc(100vh - 20upx);
  149. padding-top: 20upx;
  150. }
  151. .prompt-text {
  152. color: $fontColor3;
  153. padding-left: 30upx;
  154. margin-bottom: 30upx;
  155. }
  156. .module-com {
  157. margin-bottom: 20upx;
  158. .member-wrap {
  159. .member-det {
  160. font-size: 24upx;
  161. margin-left: 20upx;
  162. }
  163. }
  164. .remark-wrap {
  165. align-items: flex-start;
  166. .remark {
  167. height: 180upx;
  168. }
  169. }
  170. }
  171. // 按钮
  172. .confirm-btn {
  173. width: calc(100% - 60upx);
  174. margin: 60upx 30upx 20upx;
  175. .admin-button-com {
  176. width: 100%;
  177. }
  178. }
  179. </style>