addAddress.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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="联系电话">></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. }
  89. })
  90. }
  91. })
  92. .catch(res => {
  93. uni.showToast({
  94. title: res.message,
  95. icon: 'none',
  96. duration: 2000
  97. })
  98. });
  99. this.isShowAlert = false
  100. },
  101. cancelClick() {
  102. this.isShowAlert = false
  103. },
  104. radioChange(n) {
  105. console.log('radioChange', n);
  106. },
  107. toMap() {
  108. let that = this
  109. // this.isShowMap = true
  110. uni.chooseLocation({
  111. success: function(res) {
  112. console.log(res);
  113. // console.log('位置名称:' + res.name);
  114. // console.log('详细地址:' + res.address);
  115. // console.log('纬度:' + res.latitude);
  116. // console.log('经度:' + res.longitude);
  117. let _address = that.$helper.formatLocation(res.address)
  118. console.log('----------------------------')
  119. console.log(_address)
  120. that.addressInfo.latitude = res.latitude
  121. that.addressInfo.longitude = res.longitude
  122. that.addressInfo.detailedAddress = _address.Village
  123. that.addressInfo.province = _address.Province
  124. that.addressInfo.city = _address.City
  125. that.addressInfo.area = _address.Country
  126. that.addressInfo.commonId = that.userInfo.id
  127. that.$forceUpdate()
  128. }
  129. });
  130. // console.log(123)
  131. // uni.$u.route('/pages/release/map', {
  132. // id: 1,
  133. // });
  134. },
  135. submit() {
  136. this.isShowAlert = true
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .select-color{
  143. color: #C6CBD5;
  144. }
  145. .content{
  146. background: white;
  147. height: calc(100vh - 90rpx);
  148. }
  149. .content1 {
  150. padding: 40rpx;
  151. .top {
  152. font-size: 42rpx;
  153. font-weight: 700;
  154. color: rgba(0, 0, 0, 0.85);
  155. }
  156. }
  157. .submit{
  158. position: absolute;
  159. bottom: 40rpx;
  160. display: flex;
  161. justify-content: center;
  162. align-items: center;
  163. width: 80%;
  164. font-size: 36rpx;
  165. color: #FFFFFF;
  166. background: #2772FB;
  167. border-radius: 50rpx;
  168. padding: 20rpx 0;
  169. left: 0;
  170. right: 0;
  171. margin: auto;
  172. }
  173. </style>