addAddress.vue 6.1 KB

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