addAddress.vue 6.5 KB

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