addAddress.vue 4.9 KB

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