addAddress.vue 7.4 KB

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