addAddress.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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" ref="form1" labelWidth='100'>
  16. <u-form-item label="所属区域" ref="item1" borderBottom>
  17. <view style='width:100%;' class='flex flex-space-between' @click='toMap' :class="addressInfo.area?'':'select-color'">
  18. <view>{{addressInfo.area?(addressInfo.province+addressInfo.city+addressInfo.area):'选择所属区域 '}}</view>
  19. <image src="../../static/right.png" style="width: 22rpx;height: 22rpx;"></image>
  20. </view>
  21. </u-form-item>
  22. <u-form-item label="详细地址" prop="addressInfo.detailedAddress" ref="item1" borderBottom>
  23. <u--input v-model="addressInfo.detailedAddress" border="none" placeholder="详细地址"></u--input>
  24. </u-form-item>
  25. <u-form-item label="联系人" prop="addressInfo.contacts" ref="item1" borderBottom>
  26. <u--input v-model="addressInfo.contacts" border="none" placeholder="联系人">></u--input>
  27. </u-form-item>
  28. <u-form-item label="联系电话" prop="addressInfo.contactPhone" ref="item1">
  29. <u--input v-model="addressInfo.contactPhone" border="none" placeholder="联系电话" maxlength="11">>
  30. </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, 5000)">提交</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.$helper.formatLocation('辽宁省营口市鲅鱼圈区蝴蝶泉路红运小区')
  75. },
  76. computed: {
  77. ...mapState(['hasLogin', 'userInfo'])
  78. },
  79. methods: {
  80. confirmClick() {
  81. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/addCargoOwnerAddress', 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: 'gcj02',
  117. geocode:true,
  118. altitude:true,
  119. isHighAccuracy:true,
  120. success: function (res) {
  121. console.log('当前位置的经度:' + res.longitude);
  122. console.log('当前位置的纬度:' + res.latitude);
  123. uni.chooseLocation({
  124. latitude: res.latitude,
  125. longitude: res.longitude,
  126. success: function(res) {
  127. console.log(res);
  128. console.log('位置名称:' + res.name);
  129. console.log('详细地址:' + res.address);
  130. console.log('纬度:' + res.latitude);
  131. console.log('经度:' + res.longitude);
  132. let _address = that.$helper.formatLocation(res.address)
  133. console.log('----------------------------')
  134. console.log(_address)
  135. that.addressInfo.latitude = res.latitude
  136. that.addressInfo.longitude = res.longitude
  137. that.addressInfo.detailedAddress = _address.Village
  138. that.addressInfo.province = _address.Province
  139. that.addressInfo.city = _address.City
  140. that.addressInfo.area = _address.Country
  141. that.addressInfo.commonId = that.userInfo.id
  142. that.$forceUpdate()
  143. },
  144. fail(err) {
  145. console.log(err)
  146. },
  147. complete(res1) {
  148. console.log(res1)
  149. }
  150. });
  151. }
  152. })
  153. // console.log(123)
  154. // uni.$u.route('/pages/release/map', {
  155. // id: 1,
  156. // });
  157. },
  158. submit() {
  159. this.isShowAlert = true
  160. },
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .select-color {
  166. color: #C6CBD5;
  167. }
  168. .content {
  169. background: white;
  170. height: calc(100vh - 90rpx);
  171. }
  172. .content1 {
  173. padding: 40rpx;
  174. .top {
  175. font-size: 42rpx;
  176. font-weight: 700;
  177. color: rgba(0, 0, 0, 0.85);
  178. }
  179. }
  180. .submit {
  181. position: absolute;
  182. bottom: 40rpx;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. width: 80%;
  187. font-size: 36rpx;
  188. color: #FFFFFF;
  189. background: #2772FB;
  190. border-radius: 50rpx;
  191. padding: 20rpx 0;
  192. left: 0;
  193. right: 0;
  194. margin: auto;
  195. }
  196. /deep/input{
  197. word-break:break-all;
  198. }
  199. </style>