addAddress.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 @click='toMap' :class="addressInfo.area?'':'select-color'">
  18. {{addressInfo.area?(addressInfo.province+addressInfo.city+addressInfo.area):'选择所属区域 '}}
  19. </view>
  20. </u-form-item>
  21. <u-form-item label="详细地址" prop="addressInfo.detailedAddress" ref="item1" borderBottom>
  22. <u--input v-model="addressInfo.detailedAddress" border="none" placeholder="详细地址"></u--input>
  23. </u-form-item>
  24. <u-form-item label="联系人" prop="addressInfo.contacts" ref="item1" borderBottom>
  25. <u--input v-model="addressInfo.contacts" border="none" placeholder="联系人">></u--input>
  26. </u-form-item>
  27. <u-form-item label="联系电话" prop="addressInfo.contactPhone" ref="item1">
  28. <u--input v-model="addressInfo.contactPhone" border="none" placeholder="联系电话" maxlength="11">>
  29. </u--input>
  30. </u-form-item>
  31. </u--form>
  32. </view>
  33. </view>
  34. <u-modal :show="isShowAlert" :title="alertTitle" :closeOnClickOverlay='true' :showCancelButton='true'
  35. confirmColor='#2772FB' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
  36. <view class="submit" @click="submit">提交</view>
  37. <u-toast ref="uToast"></u-toast>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. mapState
  43. } from 'vuex';
  44. export default {
  45. data() {
  46. return {
  47. isShowAlert: false,
  48. alertTitle: '确定提交地址信息?',
  49. isShowMap: false,
  50. addressInfo: {
  51. commonId: "",
  52. province: "",
  53. city: "",
  54. area: "",
  55. detailedAddress: "",
  56. contacts: "",
  57. contactPhone: "",
  58. longitude: "",
  59. latitude: ""
  60. },
  61. // rules: {
  62. // // 'addressInfo.name': {
  63. // // type: 'string',
  64. // // required: true,
  65. // // message: '请填写姓名',
  66. // // trigger: ['blur', 'change']
  67. // // },
  68. // },
  69. };
  70. },
  71. onLoad(options) {
  72. console.log(options)
  73. this.$helper.formatLocation('辽宁省营口市鲅鱼圈区蝴蝶泉路红运小区')
  74. },
  75. computed: {
  76. ...mapState(['hasLogin', 'userInfo'])
  77. },
  78. methods: {
  79. confirmClick() {
  80. this.$request.baseRequest('post', '/cargoOwnerAddressInfo/api/addCargoOwnerAddress', this.addressInfo)
  81. .then(
  82. res => {
  83. if (res.code == 200) {
  84. this.$refs.uToast.show({
  85. type: 'success',
  86. message: "提交成功",
  87. complete() {
  88. // uni.$u.route('/pages/release/selectAddress');
  89. uni.navigateBack({
  90. delta: 1
  91. })
  92. }
  93. })
  94. }
  95. })
  96. .catch(res => {
  97. uni.showToast({
  98. title: res.message,
  99. icon: 'none',
  100. duration: 2000
  101. })
  102. });
  103. this.isShowAlert = false
  104. },
  105. cancelClick() {
  106. this.isShowAlert = false
  107. },
  108. radioChange(n) {
  109. console.log('radioChange', n);
  110. },
  111. toMap() {
  112. let that = this
  113. // this.isShowMap = true
  114. uni.getLocation({
  115. type: 'wgs84',
  116. success: function (res) {
  117. console.log('当前位置的经度:' + res.longitude);
  118. console.log('当前位置的纬度:' + res.latitude);
  119. uni.chooseLocation({
  120. latitude: res.latitude,
  121. longitude: res.longitude,
  122. success: function(res) {
  123. console.log(res);
  124. console.log('位置名称:' + res.name);
  125. console.log('详细地址:' + res.address);
  126. console.log('纬度:' + res.latitude);
  127. console.log('经度:' + res.longitude);
  128. let _address = that.$helper.formatLocation(res.address)
  129. console.log('----------------------------')
  130. console.log(_address)
  131. that.addressInfo.latitude = res.latitude
  132. that.addressInfo.longitude = res.longitude
  133. that.addressInfo.detailedAddress = _address.Village
  134. that.addressInfo.province = _address.Province
  135. that.addressInfo.city = _address.City
  136. that.addressInfo.area = _address.Country
  137. that.addressInfo.commonId = that.userInfo.id
  138. that.$forceUpdate()
  139. },
  140. fail(err) {
  141. console.log(err)
  142. },
  143. complete(res1) {
  144. console.log(res1)
  145. }
  146. });
  147. }
  148. })
  149. // console.log(123)
  150. // uni.$u.route('/pages/release/map', {
  151. // id: 1,
  152. // });
  153. },
  154. submit() {
  155. this.isShowAlert = true
  156. },
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .select-color {
  162. color: #C6CBD5;
  163. }
  164. .content {
  165. background: white;
  166. height: calc(100vh - 90rpx);
  167. }
  168. .content1 {
  169. padding: 40rpx;
  170. .top {
  171. font-size: 42rpx;
  172. font-weight: 700;
  173. color: rgba(0, 0, 0, 0.85);
  174. }
  175. }
  176. .submit {
  177. position: absolute;
  178. bottom: 40rpx;
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. width: 80%;
  183. font-size: 36rpx;
  184. color: #FFFFFF;
  185. background: #2772FB;
  186. border-radius: 50rpx;
  187. padding: 20rpx 0;
  188. left: 0;
  189. right: 0;
  190. margin: auto;
  191. }
  192. /deep/input{
  193. word-break:break-all;
  194. }
  195. </style>