index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view>
  3. <view class="hedtop">
  4. <view class="cs">
  5. {{citys}}
  6. <!-- <image src="../static/up.png" style="width:20rpx;height: 17rpx;margin-left: 5rpx;"></image> -->
  7. </view>
  8. <view class="seach">
  9. <!-- <u-search :disabled="true" placeholder="搜索地址" shape="square" :clearabled="false" :animation="true"
  10. bg-color="#F5F5F5" height="75" @click="openMap"></u-search> -->
  11. <view class="flex-sub margin-right-sm" @click="openMap">
  12. <u-icon name="search" color="#CCCCCC" size="32"></u-icon>
  13. <text class="margin-left-xs" style="color: #CCCCCC;font-size: 26rpx;">搜索地址</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="addlist">
  18. <view class="box" v-for="(item,index) in addlist" :key="index" @click="changetans(index,item)">
  19. <view class="" style="width: 85%;">
  20. <view class="flex">
  21. <image src="../static/addre.png" style="width:35rpx;height:35rpx;margin-right: 5rpx;"></image>
  22. <view class="text-lg " style="width: 480rpx;">{{item.address}}</view>
  23. </view>
  24. </view>
  25. <view class="flex justify-end" style="width: 130rpx;">
  26. <view class="btns" @click.stop='setadd(item)'>
  27. 保存</view>
  28. </view>
  29. </view>
  30. <view class="box" v-for="(item,index) in list" :key="index" :class="listIndex==index?'active':''"
  31. @click="changetan(index,item)">
  32. <image src="../static/addre.png" style="width:35rpx;height:35rpx;"></image>
  33. <view class="" style="width: 85%;">
  34. <view class="flex">
  35. <view class="text-lg " style="width: 480rpx;">{{item.address}}</view>
  36. </view>
  37. <!-- <view class="text-sm " style="color: #999999;margin-top:5rpx" v-if="!item.cityIsOpen">当前城市未开通
  38. </view> -->
  39. </view>
  40. <view class="flex">
  41. <view class="btnsa" @click.stop='deleteAddressList(item)'>
  42. 删除</view>
  43. <!-- <view style="font-size: 30upx;color: #999999;margin-left: 40rpx; "
  44. @click.stop='goAddress(item.addressId)'>编辑</view> -->
  45. </view>
  46. </view>
  47. <empty v-if="list.length==0&&addlist.length==0"></empty>
  48. </view>
  49. <view class="tabber">
  50. <!-- <view class="btn" @click="goadd()">添加地址</view> -->
  51. <view class="btn" @click="openMap()">添加地址</view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import empty from '@/components/empty.vue'
  57. export default {
  58. components: {
  59. empty
  60. },
  61. data() {
  62. return {
  63. city: '',
  64. keyword: '',
  65. page: 1,
  66. limit: 10,
  67. list: [],
  68. listIndex: '-1',
  69. index: 0,
  70. cityaddress: '',
  71. detailaddress: '',
  72. latitude: '',
  73. longitude: '',
  74. province: '',
  75. city: '',
  76. county: '',
  77. addlist: [],
  78. citys: ''
  79. }
  80. },
  81. onLoad(option) {
  82. if (option.index) {
  83. this.index = option.index
  84. }
  85. },
  86. onShow() {
  87. this.citys = uni.getStorageSync('city')
  88. this.getAddlist()
  89. },
  90. methods: {
  91. deleteAddressList(e) {
  92. let that = this
  93. uni.showModal({
  94. title: '温馨提示',
  95. content: '您确定要删除此地址信息吗?',
  96. showCancel: true,
  97. cancelText: '取消',
  98. confirmText: '确认',
  99. success: res => {
  100. if (res.confirm) {
  101. that.$Request.postT('/app/address/deleteAddress?addressId=' + e.addressId).then(
  102. res => {
  103. if (res.code == 0) {
  104. that.$queue.showToast("删除成功!");
  105. that.page = 1
  106. that.getAddlist();
  107. } else {
  108. that.$queue.showToast(res.msg);
  109. }
  110. });
  111. }
  112. }
  113. });
  114. },
  115. goAddress(addressId) {
  116. uni.navigateTo({
  117. url: '/my/address/add?addressId=' + addressId
  118. })
  119. },
  120. goadd() {
  121. uni.navigateTo({
  122. url: '/my/address/add'
  123. })
  124. },
  125. openMap() { //打开地图选择位置
  126. let that = this
  127. uni.chooseLocation({
  128. success: function(res) {
  129. console.log('位置名称:' + res.name);
  130. console.log('详细地址:' + res.address);
  131. console.log('纬度:' + res.latitude);
  132. console.log('经度:' + res.longitude);
  133. that.detailaddress = res.name
  134. that.latitude = res.latitude
  135. that.longitude = res.longitude
  136. that.shengcheng(res.longitude, res.latitude)
  137. // let data = {
  138. // address: res.name, //地址
  139. // addressDetail: res.address,
  140. // addressLongitude: res.longitude, //地址经度
  141. // addressLatitude: res.latitude, //地址维度
  142. // addressId: '',
  143. // addressDefault: '',
  144. // }
  145. // that.$Request.postJson('/app/indent/addUserAddress', data).then(res => {
  146. // if (res.code === 0) {
  147. // that.getAddlist()
  148. // }
  149. // });
  150. }
  151. });
  152. },
  153. shengcheng(longitude, latitude) {
  154. this.$Request.get('/app/Login/selectCity?lat=' + latitude + '&lng=' + longitude).then(res => {
  155. if (res.code === 0) {
  156. this.province = res.data.province
  157. this.city = res.data.city
  158. this.county = res.data.district
  159. this.cityaddress = res.data.province + res.data.city + res.data.district
  160. let userId = this.$queue.getData('userId');
  161. let data = {
  162. userName: '',
  163. userPhone: '',
  164. address: this.detailaddress,
  165. lat: this.latitude,
  166. lng: this.longitude,
  167. province: this.province,
  168. city: this.city,
  169. county: this.county,
  170. userId: userId,
  171. addressId: '',
  172. isDefault: '',
  173. addressId: '',
  174. cityIsOpen: true
  175. }
  176. // this.addlist.push(data)
  177. this.setadds(data)
  178. console.log(this.addlist)
  179. }
  180. });
  181. },
  182. setadds(){
  183. let userId = this.$queue.getData('userId');
  184. let data = {
  185. userName: '',
  186. userPhone: '',
  187. address: this.detailaddress,
  188. lat: this.latitude,
  189. lng: this.longitude,
  190. province: this.province,
  191. city: this.city,
  192. county: this.county,
  193. userId: userId,
  194. addressId: '',
  195. isDefault: '0',
  196. addressId: ''
  197. }
  198. this.$Request.postT('/app/address/saveAddress', data).then(res => {
  199. if (res.code == 0) {
  200. this.page = 1
  201. this.getAddlist()
  202. this.addlist = []
  203. } else {
  204. uni.hideLoading()
  205. this.$queue.showToast(res.msg);
  206. }
  207. });
  208. },
  209. setadd() {
  210. let that = this
  211. uni.showModal({
  212. title: '温馨提示',
  213. content: '您确定要保存此地址信息吗?',
  214. showCancel: true,
  215. cancelText: '取消',
  216. confirmText: '确认',
  217. success: res => {
  218. if (res.confirm) {
  219. let userId = this.$queue.getData('userId');
  220. let data = {
  221. userName: '',
  222. userPhone: '',
  223. address: this.detailaddress,
  224. lat: this.latitude,
  225. lng: this.longitude,
  226. province: this.province,
  227. city: this.city,
  228. county: this.county,
  229. userId: userId,
  230. addressId: '',
  231. isDefault: '0',
  232. addressId: ''
  233. }
  234. this.$Request.postT('/app/address/saveAddress', data).then(res => {
  235. if (res.code == 0) {
  236. uni.hideLoading()
  237. this.$queue.showToast("保存成功!");
  238. this.page = 1
  239. this.getAddlist()
  240. this.addlist = []
  241. } else {
  242. uni.hideLoading()
  243. this.$queue.showToast(res.msg);
  244. }
  245. });
  246. }
  247. }
  248. });
  249. },
  250. getAddlist() {
  251. let data = {
  252. page: this.page,
  253. limit: this.limit
  254. }
  255. this.$Request.getT('/app/address/getAddressList', data).then(res => {
  256. if (res.code === 0) {
  257. if (this.page == 1) {
  258. this.list = res.data.records;
  259. } else {
  260. this.list = [...this.list, ...res.data.records]
  261. }
  262. }
  263. });
  264. },
  265. changetans(index, item) {
  266. uni.showToast({
  267. title: '请先保存地址,然后下单',
  268. icon: 'none'
  269. })
  270. },
  271. changetan(index, item) {
  272. if (this.index == 1) {
  273. if (item.addressId) {
  274. uni.setStorageSync('addressId', item.addressId)
  275. } else {
  276. uni.setStorageSync('addlist', item)
  277. }
  278. // this.listIndex = index
  279. uni.navigateBack()
  280. } else if (this.index == 2) {
  281. uni.setStorageSync('addressIds', item.addressId)
  282. // this.listIndex = index
  283. uni.navigateBack()
  284. }
  285. }
  286. },
  287. onReachBottom: function() {
  288. this.page = this.page + 1;
  289. this.getAddlist();
  290. },
  291. onPullDownRefresh: function() {
  292. this.page = 1;
  293. this.getAddlist();
  294. }
  295. }
  296. </script>
  297. <style lang="less">
  298. page {
  299. background: #FFFFFF;
  300. }
  301. .hedtop {
  302. display: flex;
  303. align-items: center;
  304. padding: 0 30rpx;
  305. position: fixed;
  306. /* #ifdef H5 */
  307. top: 85rpx;
  308. /* #endif */
  309. /* #ifndef H5 */
  310. top: 0rpx;
  311. /* #endif */
  312. left: 0;
  313. right: 0;
  314. z-index: 99;
  315. background: #FFFFFF;
  316. .cs {
  317. width: 20%;
  318. }
  319. .seach {
  320. background: #F5F5F5;
  321. border-radius: 12rpx;
  322. padding: 20rpx;
  323. width: 80%;
  324. }
  325. }
  326. .addlist {
  327. /* #ifdef H5 */
  328. margin-top: 120rpx;
  329. /* #endif */
  330. /* #ifndef H5 */
  331. margin-top: 120rpx;
  332. /* #endif */
  333. .box {
  334. // width: 100%;
  335. margin: 20rpx 30rpx;
  336. background: #F7F7F7;
  337. border-radius: 18rpx;
  338. padding: 30rpx;
  339. font-family: PingFang SC;
  340. font-weight: bold;
  341. color: #333333;
  342. display: flex;
  343. justify-content: space-between;
  344. align-items: center;
  345. .add {
  346. // font-size: 26rpx;
  347. font-family: PingFang SC;
  348. font-weight: 500;
  349. color: #7c7c7c;
  350. margin-top: 10rpx;
  351. }
  352. }
  353. .active {
  354. border: 2rpx solid #346EF6;
  355. border-radius: 8rpx;
  356. background: #FFFFFF;
  357. }
  358. }
  359. .tabber {
  360. position: fixed;
  361. bottom: 0rpx;
  362. left: 0;
  363. right: 0;
  364. background: #FFFFFF;
  365. }
  366. .btn {
  367. background: #346EF6;
  368. border-radius: 24rpx;
  369. margin: 32rpx;
  370. padding: 20rpx 0;
  371. text-align: center;
  372. color: #FFFFFF;
  373. }
  374. .btns {
  375. font-size: 26upx;
  376. color: #FFFFFF;
  377. background: #346EF6;
  378. height: 50rpx;
  379. line-height: 50rpx;
  380. padding: 0rpx 20rpx;
  381. border-radius: 24rpx;
  382. letter-spacing: 2rpx;
  383. }
  384. .btnsa {
  385. width: 110rpx;
  386. font-size: 26upx;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. color: #FFFFFF;
  391. background: #cfcfcf;
  392. // height: 50rpx;
  393. // line-height: 50rpx;
  394. padding: 10rpx 20rpx;
  395. border-radius: 55rpx;
  396. letter-spacing: 2rpx;
  397. }
  398. </style>