newAddress.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="content">
  3. <button @tap="authVerification">请选择位置</button>
  4. <view style="margin-left: 20rpx;">地址信息</view>
  5. <view class="box_new_address">
  6. <u-form :model="model" :rules="rules" labelPosition="left" labelWidth="80" ref="uForm" :required="true">
  7. <u-form-item label="姓名" prop="userInfo.name" borderBottom>
  8. <u-input v-model="model.userInfo.name" border="none"></u-input>
  9. </u-form-item>
  10. <u-form-item label="手机号" prop="userInfo.phone" borderBottom>
  11. <u-input v-model="model.userInfo.phone" border="none"></u-input>
  12. </u-form-item>
  13. <u-form-item label="所在地区" prop="userInfo.region" borderBottom>
  14. <u-input v-model="model.userInfo.region" border="none">
  15. <template slot="suffix">
  16. <view class="same_row_in" @tap="authVerification">
  17. <u-icon name="map-fill" color="#909399" size="16"></u-icon>
  18. <view style="color: #909399;margin-left: 5rpx;">定位</view>
  19. </view>
  20. </template>
  21. </u-input>
  22. </u-form-item>
  23. <u-form-item label="详细地址" prop="userInfo.address" borderBottom>
  24. <u-input v-model="model.userInfo.address" border="none"></u-input>
  25. </u-form-item>
  26. <u-form-item label="地址标签" prop="userInfo.tag" borderBottom>
  27. <view>
  28. <view v-for="(item,index) in "></view>
  29. </view>
  30. </u-form-item>
  31. <u-form-item label="设为默认收货地址" prop="userInfo.tag" borderBottom>
  32. <view>
  33. <view v-for="(item,index) in "></view>
  34. </view>
  35. </u-form-item>
  36. </u-form>
  37. </view>
  38. <view class="box_new_address">
  39. <u-textarea v-model="value1" placeholder="请粘贴或输入文本,点击" ></u-textarea>
  40. </view>
  41. <x-bottomBtn title="保存地址" @buttonClick="buttonClick"></x-bottomBtn>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. currentLocation: {},
  49. model: {
  50. userInfo: {
  51. name: 'uView UI',
  52. phone: 'uView UI',
  53. region: '',
  54. address: '',
  55. tag: '',
  56. },
  57. },
  58. rules: {
  59. 'userInfo.name': {
  60. type: 'string',
  61. required: true,
  62. message: '请填写姓名',
  63. trigger: ['blur', 'change']
  64. },
  65. 'userInfo.phone': {
  66. type: 'string',
  67. required: true,
  68. message: '请填写手机号',
  69. trigger: ['blur', 'change']
  70. },
  71. },
  72. value1:'',
  73. }
  74. },
  75. onShow() {
  76. uni.getStorage({
  77. key: 'currentLocation',
  78. success: (res) => {
  79. this.currentLocation = res.data
  80. }
  81. })
  82. },
  83. methods: {
  84. authVerification() {
  85. uni.getSetting({
  86. success: (res) => {
  87. if (res.authSetting['scope.userLocation']) {
  88. /* 用户授权成功时走这里 */
  89. this.handerChooseLocation()
  90. } else if (res.authSetting['scope.userLocation'] === undefined) {
  91. /* 用户未授权时走这里 */
  92. console.log('没有授权')
  93. this.handleOpenSetting()
  94. } else {
  95. /* 用户拒绝了授权后走这里 */
  96. console.log('拒绝了授权 false')
  97. this.handleOpenSetting()
  98. }
  99. },
  100. })
  101. },
  102. handerChooseLocation(latitude, longitude) {
  103. uni.chooseLocation({
  104. latitude: latitude || '',
  105. longitude: longitude || '',
  106. success: (res) => {
  107. console.log('wx.chooseLocation res=', res)
  108. uni.setStorageSync('currentLocation', res)
  109. },
  110. fail: function(err) {
  111. console.log('取消按钮', err)
  112. }
  113. })
  114. },
  115. handleOpenSetting() {
  116. wx.openSetting({
  117. success: (res) => {
  118. console.log('定位 openSetting', res)
  119. if (res.authSetting["scope.userLocation"]) {
  120. this.handerChooseLocation()
  121. }
  122. }
  123. })
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss">
  129. .box_new_address {
  130. margin: 20rpx;
  131. background-color: #fff;
  132. border-radius: 10rpx;
  133. padding: 20rpx;
  134. }
  135. </style>