add_address.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="addAddress">
  3. <view class="form">
  4. <view class="head">
  5. <span>地址信息</span>
  6. <view class="checked_box" @click="goExhibits">
  7. <!-- <view class="checked" v-if="item.type == 0"></view> -->
  8. <view class="select" v-if="type == 0">
  9. <image src="../../static/identify/round.png" mode=""></image>
  10. </view>
  11. <view class="select" v-else>
  12. <image src="../../static/identify/select.png" mode=""></image>
  13. </view>
  14. 默认地址
  15. </view>
  16. </view>
  17. <view class="item">
  18. <view class="title">
  19. 姓名
  20. </view>
  21. <view class="inp">
  22. <input class="weui-input" name="input" v-model="form.userName" placeholder="输入您的姓名" />
  23. </view>
  24. </view>
  25. <view class="item">
  26. <view class="title">
  27. 手机号
  28. </view>
  29. <view class="inp">
  30. <input class="weui-input" placeholder="手机号" v-model="form.phone" />
  31. </view>
  32. </view>
  33. <view class="item">
  34. <view class="title">
  35. 所在地区
  36. </view>
  37. <view class="inp" @click="getAddress" v-if="form.address !== ''">
  38. <!-- <input class="weui-input" name="input" v-model="form.userName" placeholder="姓名(必填)" /> -->
  39. {{form.address}}{{form.name}}
  40. </view>
  41. <view class="inp street" @click="getAddress" v-else>
  42. 省、市、区、街道
  43. </view>
  44. </view>
  45. <view class="item">
  46. <view class="title">
  47. 详细地址
  48. </view>
  49. <view class="inp">
  50. <input class="weui-input" name="input" v-model="form.atlasAdd" placeholder="列:1号楼一层101室" />
  51. </view>
  52. </view>
  53. </view>
  54. <view class="addbtn">
  55. <button type="primary" @click="save">{{btnName}}</button>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. addUpdate,
  62. addDetails,
  63. updateAdd,
  64. addList,
  65. defaultAdd
  66. } from '../../api/index'
  67. export default {
  68. data() {
  69. return {
  70. btnName: '保存',
  71. type: 0,
  72. form: {
  73. userName: '',
  74. phone: '',
  75. atlasAdd: '',
  76. openid: '',
  77. type: 0,
  78. latitude: '',
  79. longitude: '',
  80. name: '',
  81. address: '',
  82. },
  83. pos_name: '',
  84. latitude: '',
  85. longitude: '',
  86. requestBody: {},
  87. err: '',
  88. saveAddress: {
  89. latitude: '',
  90. longitude: '',
  91. name: '',
  92. address: '',
  93. },
  94. }
  95. },
  96. methods: { //设为默认地址
  97. goExhibits() {
  98. // this.checkedIndex = index
  99. var id = {
  100. id: this.id,
  101. openid: uni.getStorageSync('wx_copenid'),
  102. }
  103. defaultAdd(id).then(res => {
  104. if (res.data.code == 200) {
  105. this.getList()
  106. uni.showToast({
  107. title: '设置默认地址成功!',
  108. icon: 'none'
  109. })
  110. }
  111. })
  112. },
  113. getAddress() {
  114. uni.chooseLocation({
  115. success: res => {
  116. this.form.name = res.name;
  117. this.form.latitude = res.latitude;
  118. this.form.longitude = res.longitude;
  119. this.form.address = res.address
  120. }
  121. });
  122. },
  123. save() {
  124. this.form.openid = uni.getStorageSync('wx_copenid')
  125. // this.form.address = JSON.stringify(this.saveAddress)
  126. if (this.form.userName === '') {
  127. uni.showToast({
  128. title: '请输入姓名',
  129. icon: 'none'
  130. })
  131. return
  132. }
  133. if (!/^1[3456789]\d{9}$/.test(this.form.phone)) {
  134. uni.showToast({
  135. title: '请输入正确的手机号',
  136. icon: 'none'
  137. });
  138. return;
  139. }
  140. if (this.form.address == '') {
  141. uni.showToast({
  142. title: '请选择地址',
  143. icon: 'none'
  144. });
  145. return;
  146. }
  147. if (this.btnName == '修改地址') {
  148. // this.form.type =
  149. updateAdd(this.form).then(res => {
  150. if (res.data.code == 200) {
  151. uni.showToast({
  152. title: '修改成功',
  153. })
  154. setTimeout(function() {
  155. uni.navigateBack()
  156. }, 500)
  157. }
  158. })
  159. } else {
  160. this.form.type = this.type
  161. // this.requestBody = this.form
  162. addUpdate(this.form).then(res => {
  163. // console.log(res,"添加成功之后的数据")
  164. if (res.data.code == 200) {
  165. uni.showToast({
  166. title: '添加成功',
  167. })
  168. setTimeout(function() {
  169. uni.navigateBack()
  170. }, 500)
  171. } else {
  172. this.err = res.msg
  173. }
  174. })
  175. }
  176. }
  177. // onChooseLocation() {
  178. // uni.navigateTo({
  179. // url: './select_position'
  180. // })
  181. // },
  182. },
  183. mounted() {},
  184. onShow() {
  185. uni.getLocation({
  186. type: 'wgs84',
  187. success: function(res) {}
  188. });
  189. },
  190. onLoad(options) {
  191. this.type = options.type
  192. if (options.id) {
  193. addDetails({
  194. id: options.id
  195. }).then(res => {
  196. this.form = res.data.data,
  197. // this.saveAddress = JSON.parse(res.data.data.address),
  198. // this.address = JSON.parse(res.data.data.address),
  199. this.btnName = '修改地址',
  200. console.log(this.saveAddress)
  201. })
  202. } else {}
  203. },
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .addAddress {
  208. background-color: #f8f8f8;
  209. height: 100vh;
  210. padding: 40rpx 32rpx;
  211. box-sizing: border-box;
  212. }
  213. .head {
  214. width: 100%;
  215. display: flex;
  216. justify-content: space-between;
  217. margin-bottom: 20px;
  218. .checked_box {
  219. width: 128rpx;
  220. display: flex;
  221. align-items: center;
  222. font-size: 24rpx;
  223. .select {
  224. display: flex;
  225. align-items: center;
  226. image {
  227. width: 24rpx;
  228. height: 24rpx;
  229. margin-right: 8rpx;
  230. }
  231. }
  232. }
  233. }
  234. .form {
  235. background: #FFFFFF;
  236. box-shadow: 0px 4rpx 12rpx 0px rgba(88, 209, 187, 0.05);
  237. border-radius: 20rpx 20rpx 20rpx 20rpx;
  238. padding: 32rpx 24rpx;
  239. .item {
  240. width: 100%;
  241. display: flex;
  242. align-items: center;
  243. font-size: 26rpx;
  244. margin-bottom: 20rpx;
  245. .title {
  246. width: 104rpx;
  247. color: #333333;
  248. margin-right: 20rpx;
  249. }
  250. .inp {
  251. flex: 1;
  252. height: 64rpx;
  253. border-radius: 8rpx 8rpx 8rpx 8rpx;
  254. border: 2rpx solid #EEEEEE;
  255. padding-left: 24rpx;
  256. }
  257. .street {
  258. font-size: 26rpx;
  259. color: #999999;
  260. line-height: 64rpx;
  261. }
  262. }
  263. }
  264. .addbtn {
  265. position: fixed;
  266. bottom: 30px;
  267. width: 100%;
  268. // background-color: #fff;
  269. // border-top: 1px solid #ccc;
  270. padding-top: 15px;
  271. padding-bottom: 10px;
  272. button {
  273. margin: 0 50px;
  274. background: linear-gradient(90deg, #1AD7CE 0%, #21C9C1 100%);
  275. border-radius: 106rpx;
  276. }
  277. }
  278. ::v-deep.weui-input {
  279. height: 100%;
  280. font-size: 26rpx;
  281. }
  282. </style>