addAddress.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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="submit">提交</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: '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. submit() {
  156. this.isShowAlert = true
  157. },
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .select-color {
  163. color: #C6CBD5;
  164. }
  165. .content {
  166. background: white;
  167. height: calc(100vh - 90rpx);
  168. }
  169. .content1 {
  170. padding: 40rpx;
  171. .top {
  172. font-size: 42rpx;
  173. font-weight: 700;
  174. color: rgba(0, 0, 0, 0.85);
  175. }
  176. }
  177. .submit {
  178. position: absolute;
  179. bottom: 40rpx;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. width: 80%;
  184. font-size: 36rpx;
  185. color: #FFFFFF;
  186. background: #2772FB;
  187. border-radius: 50rpx;
  188. padding: 20rpx 0;
  189. left: 0;
  190. right: 0;
  191. margin: auto;
  192. }
  193. /deep/input{
  194. word-break:break-all;
  195. }
  196. </style>