modify.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="app-content">
  3. <form @submit="formSubmit">
  4. <view class="module-com input-line-wrap">
  5. <view style="background-color: white;font-size:36upx;font-weight:bold;padding:20upx 0 10upx 30upx;">修改本单客户地址:</view>
  6. <tui-list-cell class="line-cell" :hover="false" v-if="hasMap == 1">
  7. <view class="tui-title">地址类型</view>
  8. <button :class="[couldNavigation==1?'blue':'default']" class="admin-button-com middle" @click.stop="setStyle(1)" style="width:180upx;">支持导航</button>
  9. <button :class="[couldNavigation==0?'blue':'default']" class="admin-button-com middle" style="width:180upx;margin-left:60upx;" @click.stop="setStyle(0)">不用导航</button>
  10. </tui-list-cell>
  11. <tui-list-cell class="line-cell" :hover="false" :arrow="true" @click="openAddres">
  12. <view class="tui-title">城市</view>
  13. <view class="tui-input" v-if="form.province || form.city">{{ form.province + '-' + form.city }}</view>
  14. <view class="tui-placeholder" v-else>请选择</view>
  15. <input v-model="form.province" name="province" hidden />
  16. </tui-list-cell>
  17. <tui-list-cell v-if="couldNavigation == 1" class="line-cell" :hover="false" :arrow="true" @click="selectRegion">
  18. <view class="tui-title">地址</view>
  19. <view v-if="form.address" class="tui-input">{{ form.address }}</view>
  20. <view v-else class="tui-placeholder">请填写地址</view>
  21. <input v-model="form.address" name="address" hidden />
  22. </tui-list-cell>
  23. <tui-list-cell v-else class="line-cell" :hover="false">
  24. <view class="tui-title">地址</view>
  25. <input v-model="form.address" placeholder-class="phcolor" class="tui-input" name="address" placeholder="请填写地址" />
  26. </tui-list-cell>
  27. <tui-list-cell class="line-cell" :hover="false">
  28. <view class="tui-title ">门牌</view>
  29. <input v-model="form.floor" placeholder-class="phcolor" class="tui-input" name="floor" placeholder="楼号门牌号,建议填写,方便查找"/>
  30. </tui-list-cell>
  31. <tui-list-cell class="line-cell" :hover="false">
  32. <view class="tui-title">地址类型</view>
  33. <button :class="[syncDefaultAddress==1?'blue':'default']" class="admin-button-com middle" @click.stop="setDefaultAddress(1)" style="width:180upx;">设为默认</button>
  34. <button :class="[syncDefaultAddress==0?'blue':'default']" class="admin-button-com middle" style="width:180upx;margin-left:60upx;" @click.stop="setDefaultAddress(0)">临时使用</button>
  35. </tui-list-cell>
  36. </view>
  37. <view class="confirm-btn">
  38. <button class="admin-button-com big blue" formType="submit">提交</button>
  39. </view>
  40. </form>
  41. <!-- 省市联动 -->
  42. <simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onCityConfirm"></simple-address>
  43. <!-- 选择地区 -->
  44. <app-area-sel :show.sync="showRegion" :city="form.city" @change="changeAreaFn" />
  45. </view>
  46. </template>
  47. <script>
  48. import TuiListCell from '@/components/plugin/list-cell'
  49. import SimpleAddress from '@/components/plugin/simple-address'
  50. import AppAreaSel from '@/components/app-area-sel'
  51. const form = require('@/utils/formValidation.js')
  52. import { modifyAddress } from '@/api/order'
  53. import { getInfo } from '@/api/shop'
  54. import {getHasMap} from "@/api/express"
  55. export default {
  56. name: 'modify',
  57. components: {
  58. TuiListCell,
  59. SimpleAddress,
  60. AppAreaSel
  61. },
  62. data() {
  63. return {
  64. form: {
  65. province: '',
  66. city: '',
  67. dist: '',
  68. address: '',
  69. floor: '',
  70. showAddress:''
  71. },
  72. region:{lat:'',long:''},
  73. regionData: {
  74. lat: 0,
  75. long: 0
  76. },
  77. cityPickerValueDefault: [0, 0],
  78. showRegion: false,
  79. hasMap: 0,
  80. couldNavigation:1,
  81. syncDefaultAddress: 1
  82. }
  83. },
  84. onLoad() {
  85. },
  86. methods: {
  87. setStyle(flag){
  88. this.couldNavigation = flag
  89. this.form.address = ''
  90. },
  91. setDefaultAddress(flag){
  92. this.syncDefaultAddress = flag
  93. },
  94. onHere(){
  95. this.form.province = '云南省'
  96. this.form.city = '昆明市'
  97. },
  98. init() {
  99. getHasMap().then(res=>{
  100. this.hasMap = res.data.hasMap
  101. if(this.hasMap == 0){
  102. this.couldNavigation = 0
  103. }else{
  104. this.couldNavigation = 1
  105. }
  106. })
  107. getInfo().then(res=>{
  108. if(res.code == 1){
  109. let city = res.data.city ? res.data.city : ''
  110. let province = res.data.province?res.data.province:''
  111. this.form.province = province
  112. this.form.city = city
  113. }
  114. })
  115. },
  116. //省市联动
  117. openAddres() {
  118. this.$refs.simpleAddress.open()
  119. },
  120. onCityConfirm(e) {
  121. this.form.province = e.provinceName
  122. this.form.city = e.cityName
  123. this.form.address = ''
  124. this.form.showAddress = ''
  125. this.region.lat = ''
  126. this.region.long = ''
  127. },
  128. selectRegion() {
  129. if (!this.form.city) {
  130. this.$msg('请先选择城市!')
  131. return false
  132. }
  133. this.showRegion = true
  134. },
  135. changeAreaFn(e) {
  136. let locationStr = e.location
  137. let fruits = locationStr.split(",").map(fruit => fruit.trim())
  138. this.region.lat = fruits[1]
  139. this.region.long = fruits[0]
  140. this.form.showAddress = e.address
  141. this.form.address = e.name
  142. // 提取地区信息,按遇到第一个"市"字后,把"市"后面的字符串作为地区
  143. const districtStr = e.district || '';
  144. const cityIndex = districtStr.indexOf('市');
  145. this.form.dist = cityIndex !== -1 ? districtStr.substring(cityIndex + 1) : districtStr;
  146. },
  147. confirmFn() {
  148. let that = this
  149. this.form.id = this.option.id ? this.option.id : 0
  150. this.form = {...this.form, ...this.region, syncDefaultAddress: this.syncDefaultAddress}
  151. uni.showLoading()
  152. modifyAddress(this.form).then(res=>{
  153. if(res.code == 1){
  154. that.$msg('修改成功')
  155. setTimeout(() => {
  156. uni.navigateBack({})
  157. }, 1200)
  158. }
  159. })
  160. },
  161. formSubmit(e) {
  162. let rules = [
  163. {
  164. name: 'province',
  165. rule: ['required'],
  166. msg: ['请选择城市']
  167. },
  168. {
  169. name: 'address',
  170. rule: ['required'],
  171. msg: ['请填选地址']
  172. }
  173. ]
  174. let formData = e.detail.value
  175. let checkRes = form.validation(formData, rules)
  176. if (!checkRes) {
  177. this.confirmFn()
  178. } else {
  179. this.$msg(checkRes)
  180. }
  181. },
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .app-content {
  187. min-height: calc(100vh - 20upx);
  188. padding-top: 20upx;
  189. }
  190. .prompt-text {
  191. color: $fontColor3;
  192. padding-left: 30upx;
  193. margin-bottom: 30upx;
  194. }
  195. .module-com {
  196. margin-bottom: 20upx;
  197. .member-wrap {
  198. .member-det {
  199. font-size: 24upx;
  200. margin-left: 20upx;
  201. }
  202. }
  203. .remark-wrap {
  204. align-items: flex-start;
  205. .remark {
  206. height: 180upx;
  207. }
  208. }
  209. }
  210. // 按钮
  211. .confirm-btn {
  212. width: calc(100% - 60upx);
  213. margin: 60upx 30upx 20upx;
  214. .admin-button-com {
  215. width: 100%;
  216. }
  217. }
  218. // 复选框
  219. .checkbox-wrap {
  220. padding: 20upx 30upx;
  221. background-color: white;
  222. border-bottom: 1px solid #f0f0f0;
  223. display: flex;
  224. justify-content: flex-end;
  225. .checkbox-label {
  226. display: flex;
  227. align-items: center;
  228. font-size: 36upx;
  229. color: #333;
  230. }
  231. }
  232. </style>