modify.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. dist: '',
  56. address: '',
  57. floor: '',
  58. showAddress:''
  59. },
  60. region:{lat:'',long:''},
  61. regionData: {
  62. lat: 0,
  63. long: 0
  64. },
  65. cityPickerValueDefault: [0, 0],
  66. showRegion: false,
  67. hasMap: 0
  68. }
  69. },
  70. onLoad() {
  71. //返回上一页时不需要刷新
  72. let pages = getCurrentPages();
  73. let prevPage = pages[ pages.length - 2 ];
  74. //订单列表页修改客户地址,返回时不刷新
  75. prevPage.$vm.fromDetail = {status:1}
  76. //返回到客户详情页需要刷新
  77. prevPage.$vm.needRefresh = 1
  78. if(this.option.name){
  79. uni.setNavigationBarTitle({ title: this.option.name })
  80. }
  81. },
  82. methods: {
  83. init() {
  84. getHasMap().then(res=>{
  85. this.hasMap = res.data.hasMap
  86. })
  87. },
  88. //省市联动
  89. openAddres() {
  90. this.$refs.simpleAddress.open()
  91. },
  92. onCityConfirm(e) {
  93. this.form.province = e.provinceName
  94. this.form.city = e.cityName
  95. this.form.address = ''
  96. this.form.showAddress = ''
  97. this.region.lat = ''
  98. this.region.long = ''
  99. },
  100. selectRegion() {
  101. if (!this.form.city) {
  102. this.$msg('请先选择城市!')
  103. return false
  104. }
  105. this.showRegion = true
  106. },
  107. changeAreaFn(e) {
  108. let locationStr = e.location
  109. let fruits = locationStr.split(",").map(fruit => fruit.trim())
  110. this.region.lat = fruits[1]
  111. this.region.long = fruits[0]
  112. this.form.showAddress = e.address
  113. this.form.address = e.name
  114. // 提取地区信息,按遇到第一个"市"字后,把"市"后面的字符串作为地区
  115. const districtStr = e.district || '';
  116. const cityIndex = districtStr.indexOf('市');
  117. this.form.dist = cityIndex !== -1 ? districtStr.substring(cityIndex + 1) : districtStr;
  118. },
  119. confirmFn() {
  120. let that = this
  121. this.form.id = this.option.id ? this.option.id : 0
  122. this.form = {...this.form, ...this.region}
  123. uni.showLoading({mask:true})
  124. modifyAddress(this.form).then(res=>{
  125. if(res.code == 1){
  126. that.$msg('修改成功')
  127. setTimeout(() => {
  128. uni.navigateBack({})
  129. }, 1200)
  130. }
  131. })
  132. },
  133. formSubmit(e) {
  134. let rules = [
  135. {
  136. name: 'province',
  137. rule: ['required'],
  138. msg: ['请选择城市']
  139. },
  140. {
  141. name: 'address',
  142. rule: ['required'],
  143. msg: ['请填选地址']
  144. }
  145. ]
  146. let formData = e.detail.value
  147. let checkRes = form.validation(formData, rules)
  148. if (!checkRes) {
  149. this.confirmFn()
  150. } else {
  151. this.$msg(checkRes)
  152. }
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .app-content {
  159. min-height: calc(100vh - 20upx);
  160. padding-top: 20upx;
  161. }
  162. .prompt-text {
  163. color: $fontColor3;
  164. padding-left: 30upx;
  165. margin-bottom: 30upx;
  166. }
  167. .module-com {
  168. margin-bottom: 20upx;
  169. .member-wrap {
  170. .member-det {
  171. font-size: 24upx;
  172. margin-left: 20upx;
  173. }
  174. }
  175. .remark-wrap {
  176. align-items: flex-start;
  177. .remark {
  178. height: 180upx;
  179. }
  180. }
  181. }
  182. // 按钮
  183. .confirm-btn {
  184. width: calc(100% - 60upx);
  185. margin: 60upx 30upx 20upx;
  186. .admin-button-com {
  187. width: 100%;
  188. }
  189. }
  190. </style>