editAddress.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="content">
  3. <view class="content1" v-if="!isShowMap">
  4. <view class="top">
  5. 编辑地址
  6. </view>
  7. <!-- <view class="row flex">
  8. <u-radio-group placement="row" class="select-type">
  9. <u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index"
  10. :label="item.name" :name="item.name" @change="radioChange">
  11. </u-radio>
  12. </u-radio-group>
  13. </view> -->
  14. <view class="">
  15. <u--form labelPosition="left" :model="addressInfo" :rules="rules" ref="form1" labelWidth='100'>
  16. <u-form-item label="所属区域" ref="item1" borderBottom>
  17. <view style='width:100%;flex-direction:row-reverse;' class='flex align-center' @click='toMap'>
  18. <image src="../../static/right.png" style="width: 22rpx;height: 22rpx;"></image>
  19. {{addressInfo.area?((addressInfo.province?addressInfo.province:'')+addressInfo.city+addressInfo.area):'选择所属区域 '}}
  20. </view>
  21. </u-form-item>
  22. <u-form-item label="详细地址" prop="addressInfo.detailedAddress" ref="item1" borderBottom>
  23. <u--textarea v-model="addressInfo.detailedAddress" border="none" placeholder="详细地址" autoHeight maxlength="30"></u--textarea>
  24. <!-- <u--input v-model="addressInfo.detailedAddress" border="none" placeholder="详细地址"></u--input> -->
  25. </u-form-item>
  26. <u-form-item label="联系人" prop="addressInfo.contacts" ref="item1" borderBottom>
  27. <u--input v-model="addressInfo.contacts" border="none" maxlength="10" inputAlign="right" placeholder="联系人">></u--input>
  28. </u-form-item>
  29. <u-form-item label="联系电话" prop="addressInfo.contactPhone" ref="item1">
  30. <u--input v-model="addressInfo.contactPhone" inputAlign="right" border="none" placeholder="联系电话" maxlength="11">></u--input>
  31. </u-form-item>
  32. </u--form>
  33. </view>
  34. </view>
  35. <u-modal :show="isShowAlert" :title="alertTitle" :closeOnClickOverlay='true' :showCancelButton='true'
  36. confirmColor='#2772FB' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
  37. <view class="submit" @click="$u.throttle(submit, 1000)">提交</view>
  38. <u-toast ref="uToast"></u-toast>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. mapState
  44. } from 'vuex';
  45. export default {
  46. data() {
  47. return {
  48. isShowAlert: false,
  49. alertTitle: '确定提交地址信息?',
  50. isShowMap: false,
  51. addressInfo: {
  52. commonId: "",
  53. province: "",
  54. city: "",
  55. area: "",
  56. detailedAddress: "",
  57. contacts: "",
  58. contactPhone: "",
  59. longitude: "",
  60. latitude: ""
  61. },
  62. rules: {
  63. // 'addressInfo.name': {
  64. // type: 'string',
  65. // required: true,
  66. // message: '请填写姓名',
  67. // trigger: ['blur', 'change']
  68. // },
  69. },
  70. };
  71. },
  72. onLoad(options) {
  73. console.log(options)
  74. this.addressInfo = options
  75. },
  76. computed: {
  77. ...mapState(['hasLogin', 'userInfo'])
  78. },
  79. methods: {
  80. confirmClick() {
  81. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/editCargoOwnerAddress', this.addressInfo)
  82. .then(
  83. res => {
  84. if (res.code == 200) {
  85. this.$refs.uToast.show({
  86. type: 'success',
  87. message: "提交成功",
  88. complete() {
  89. // uni.$u.route('/pages/release/selectAddress');
  90. uni.navigateBack({
  91. delta:1
  92. })
  93. }
  94. })
  95. }
  96. })
  97. .catch(res => {
  98. uni.showToast({
  99. title: res.message,
  100. icon: 'none',
  101. duration: 2000
  102. })
  103. });
  104. this.isShowAlert = false
  105. },
  106. cancelClick() {
  107. this.isShowAlert = false
  108. },
  109. radioChange(n) {
  110. console.log('radioChange', n);
  111. },
  112. toMap() {
  113. let that = this
  114. // this.isShowMap = true
  115. uni.getLocation({
  116. type: 'wgs84',
  117. success: function (res) {
  118. console.log('当前位置的经度:' + res.longitude);
  119. console.log('当前位置的纬度:' + res.latitude);
  120. uni.chooseLocation({
  121. latitude: res.latitude,
  122. longitude: res.longitude,
  123. success: function(res) {
  124. console.log(res);
  125. console.log('位置名称:' + res.name);
  126. console.log('详细地址:' + res.address);
  127. console.log('纬度:' + res.latitude);
  128. console.log('经度:' + res.longitude);
  129. let _address = that.$helper.formatLocation(res.address)
  130. console.log('----------------------------')
  131. console.log(_address)
  132. that.addressInfo.latitude = res.latitude
  133. that.addressInfo.longitude = res.longitude
  134. that.addressInfo.detailedAddress = _address.Village
  135. that.addressInfo.province = _address.Province
  136. that.addressInfo.city = _address.City
  137. that.addressInfo.area = _address.Country
  138. that.addressInfo.commonId = that.userInfo.id
  139. that.$forceUpdate()
  140. },
  141. fail(err) {
  142. console.log(err)
  143. },
  144. complete(res1) {
  145. console.log(res1)
  146. }
  147. });
  148. }
  149. })
  150. // console.log(123)
  151. // uni.$u.route('/pages/release/map', {
  152. // id: 1,
  153. // });
  154. },
  155. validate() {
  156. if (this.addressInfo.contacts.length<2||this.addressInfo.contacts.length>10) {
  157. this.$refs.uToast.show({
  158. type: 'error',
  159. message: "联系人姓名长度2-10个字符!",
  160. })
  161. return true
  162. }
  163. if (uni.$u.test.isEmpty(this.addressInfo.contactPhone)) {
  164. this.$refs.uToast.show({
  165. type: 'error',
  166. message: "联系电话不能为空!",
  167. })
  168. return true
  169. }
  170. if (this.addressInfo.detailedAddress.length<4||this.addressInfo.detailedAddress.length>15) {
  171. this.$refs.uToast.show({
  172. type: 'error',
  173. message: "详细地址4-15个字符!",
  174. })
  175. return true
  176. }
  177. },
  178. submit() {
  179. if (this.validate()) return
  180. this.isShowAlert = true
  181. },
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .select-color{
  187. color: #C6CBD5;
  188. }
  189. .content{
  190. background: white;
  191. height: calc(100vh - 90rpx);
  192. }
  193. .content1 {
  194. padding: 40rpx;
  195. .top {
  196. font-size: 42rpx;
  197. font-weight: 700;
  198. color: rgba(0, 0, 0, 0.85);
  199. }
  200. }
  201. .submit{
  202. position: absolute;
  203. bottom: 40rpx;
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. width: 80%;
  208. font-size: 36rpx;
  209. color: #FFFFFF;
  210. background: #2772FB;
  211. border-radius: 50rpx;
  212. padding: 20rpx 0;
  213. left: 0;
  214. right: 0;
  215. margin: auto;
  216. }
  217. /deep/.u-textarea{
  218. padding:9px 0;
  219. }
  220. /deep/.u-textarea__field{
  221. color:#000;
  222. text-align:right;
  223. }
  224. </style>