酒店桌布为微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
11 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <template>
  2. <view class="address">
  3. <navbar title="地址管理" leftClick @leftClick="leftClick" />
  4. <view v-if="addressList.length > 0" class="address-list">
  5. <!-- <uv-radio-group v-model="selectAddress">
  6. <view v-for="item in addressList" :key="item.id" class="address-item">
  7. <view class="address-item-top">
  8. <view class="img-box">
  9. <image src="../static/address/icon.png" mode="aspectFill"></image>
  10. </view>
  11. <view class="address-info">
  12. <view class="user-info">
  13. <text class="user-name">{{ item.name }}</text>
  14. <text class="user-phone">{{ item.phone }}</text>
  15. <text v-if="item.defaultId == '1'" class="is-default">默认</text>
  16. </view>
  17. <view class="address-detail">
  18. {{ item.address + " " + item.addressDetail }}
  19. </view>
  20. </view>
  21. </view>
  22. <view class="controls">
  23. <view class="default-checkbox">
  24. <uv-radio @click="addDefault(item)"
  25. :name="item.id"
  26. label-disabled
  27. size="30rpx"
  28. icon-size="30rpx">
  29. 默认地址
  30. </uv-radio>
  31. </view>
  32. <view class="edit-btn">
  33. <uv-icon name="edit-pen"></uv-icon>
  34. <text @click="getAddressDetail(item.id)" class="control-title">编辑</text>
  35. </view>
  36. <view class="del-btn">
  37. <uv-icon name="trash"></uv-icon>
  38. <text class="control-title" @click="deleteAddress(item.id)">删除</text>
  39. </view>
  40. </view>
  41. </view>
  42. </uv-radio-group> -->
  43. <addressList
  44. controls
  45. @deleteAddress="deleteAddress"
  46. @editAddress="getAddressDetail"
  47. @editDefault="addDefault"
  48. :addressList="addressList"/>
  49. </view>
  50. <view
  51. style="padding: 100rpx 0;"
  52. v-else>
  53. <uv-empty
  54. mode="history"
  55. textSize="28rpx"
  56. iconSize="100rpx"/>
  57. </view>
  58. <uv-popup
  59. round="40rpx"
  60. ref="addressPopup"
  61. :customStyle="{ height: 'auto' , width : '100%' , padding : '20rpx'}">
  62. <redactAddress :addressDetail="addressDetail" @saveOrUpdate="saveOrUpdate" :title="title"
  63. @clickAddressIcon="selectAddr"></redactAddress>
  64. </uv-popup>
  65. <view class="add-btn">
  66. <view @click="addBtn" class="btn">
  67. 新增地址
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import redactAddress from '../components/address/redactAddress.vue'
  74. import addressList from '../components/address/addressList.vue'
  75. import Position from '@/utils/position.js'
  76. export default {
  77. components: {
  78. redactAddress,
  79. addressList
  80. },
  81. data() {
  82. return {
  83. selectAddress: 0, //单选框选中的地址
  84. queryParams: {
  85. pageNo: 1,
  86. pageSize: 10
  87. },
  88. addressList: [
  89. {
  90. id : 1,
  91. name : 'xx',
  92. phone : '1305xxxx802',
  93. address : '广东省广州市越秀区',
  94. addressDetail : '城南故事C3栋2802',
  95. },
  96. {
  97. id : 2,
  98. name : 'xx',
  99. phone : '1305xxxx802',
  100. address : '广东省广州市越秀区',
  101. addressDetail : '城南故事C3栋2802',
  102. },
  103. {
  104. id : 3,
  105. name : 'xx',
  106. phone : '1305xxxx802',
  107. address : '广东省广州市越秀区',
  108. addressDetail : '城南故事C3栋2802',
  109. },
  110. ],
  111. addressDetail: {},
  112. title: '新增地址'
  113. }
  114. },
  115. onShow() {
  116. // if (this.$route.query.current == 'payOrder') {
  117. // this.$refs.addressPopup.open('bottom')
  118. // }
  119. // this.getAddressList()
  120. },
  121. methods: {
  122. //list列表滑动到底部自动新增数据列表
  123. onLoad() {
  124. this.queryParams.pageSize += 10
  125. this.getAddressList()
  126. },
  127. //获取地址列表
  128. getAddressList() {
  129. this.$api('getAddressList', this.queryParams, res => {
  130. if (res.code == 200) {
  131. this.addressList = res.result.records || [];
  132. this.addressList.forEach(n => { //筛选默认地址
  133. if (n.defaultId == '1') {
  134. this.selectAddress = n.id
  135. }
  136. })
  137. if (this.queryParams.pageSize > res.result.total) {
  138. this.finished = true
  139. }
  140. }
  141. this.loading = false
  142. })
  143. },
  144. //获取地址详情
  145. getAddressDetail(id) {
  146. this.title = '修改地址'
  147. this.$api('getAddressDetail', {
  148. id
  149. }, res => {
  150. if (res.code == 200) {
  151. this.addressDetail = res.result;
  152. this.$refs.addressPopup.open('bottom')
  153. }
  154. })
  155. },
  156. //返回个人中心
  157. leftClick() {
  158. uni.navigateBack(-1)
  159. },
  160. //添加和修改地址
  161. saveOrUpdate() {
  162. let isOk = this.parameterVerification()
  163. if (isOk && !isOk.auth) {
  164. return showNotify({
  165. type: 'warning',
  166. message: isOk.title,
  167. 'z-index': 10000
  168. });
  169. }
  170. let data = {
  171. name: this.addressDetail.name,
  172. phone: this.addressDetail.phone,
  173. address: this.addressDetail.address,
  174. addressDetail: this.addressDetail.addressDetail,
  175. defaultId: this.addressDetail.defaultId || '0',
  176. latitude: this.addressDetail.latitude,
  177. longitude: this.addressDetail.longitude
  178. }
  179. if (this.addressDetail.id) {
  180. data.id = this.addressDetail.id
  181. }
  182. this.$api('addOrUpdateAddress', data, res => {
  183. if (res.code == 200) {
  184. this.$refs.addressPopup.close()
  185. this.getAddressList()
  186. uni.showToast({
  187. title: '操作成功',
  188. icon: 'none'
  189. })
  190. if (this.$route.query.current == 'payOrder') { //如果是从订单支付过来添加地址的就再调回去
  191. uni.navigateTo({
  192. url: `/pages/order/payOrder?orderId=${this.$route.query.orderId}`
  193. })
  194. }
  195. }
  196. })
  197. },
  198. //新增默认地址
  199. addDefault(item) {
  200. this.selectAddress = item.id
  201. this.$api('addOrUpdateAddress', {
  202. id: item.id,
  203. defaultId: '1',
  204. }, res => {
  205. if (res.code == 200) {
  206. this.$refs.addressPopup.close()
  207. uni.showToast({
  208. title: '操作成功',
  209. icon: 'none'
  210. })
  211. this.getAddressList()
  212. }
  213. })
  214. },
  215. //删除地址
  216. deleteAddress(id) {
  217. let self = this
  218. uni.showModal({
  219. title: '删除地址',
  220. content: '确认删除此地址?删除后数据不可恢复',
  221. success(e) {
  222. if(e.confirm){
  223. self.$api('deleteAddress', {
  224. id
  225. }, res => {
  226. if (res.code == 200) {
  227. uni.showToast({
  228. title: '删除成功',
  229. icon: 'none'
  230. })
  231. self.getAddressList()
  232. }
  233. })
  234. }
  235. }
  236. })
  237. },
  238. //点击新增按钮
  239. addBtn() {
  240. this.title = '新增地址'
  241. this.addressDetail = { //初始化数据
  242. name: '',
  243. phone: '',
  244. address: '',
  245. addressDetail: '',
  246. defaultId: '',
  247. latitude: '',
  248. longitude: ''
  249. }
  250. this.$refs.addressPopup.open('bottom')
  251. },
  252. //验证用户参数合法性
  253. parameterVerification() {
  254. let {
  255. name,
  256. phone,
  257. address,
  258. addressDetail
  259. } = this.addressDetail
  260. if (name.trim() == '') {
  261. return {
  262. title: '请填写联系人',
  263. auth: false
  264. }
  265. } else if (phone.trim() == '') {
  266. return {
  267. title: '请填写手机号',
  268. auth: false
  269. }
  270. } else if (address.trim() == '') {
  271. return {
  272. title: '请填写所在地区',
  273. auth: false
  274. }
  275. } else if (addressDetail.trim() == '') {
  276. return {
  277. title: '请填写详细地址',
  278. auth: false
  279. }
  280. } else if (phone.trim() != '') {
  281. if (!this.$utils.verificationPhone(phone)) {
  282. return {
  283. title: '手机号格式不合法',
  284. auth: false
  285. }
  286. }
  287. }
  288. return {
  289. title: '验证通过',
  290. auth: true
  291. }
  292. },
  293. //地图上选择地址
  294. selectAddr() {
  295. Position.getLocation(res => {
  296. Position.selectAddress(res.longitude, res.latitude, success => {
  297. this.setAddress(success)
  298. })
  299. })
  300. },
  301. //提取用户选择的地址信息复制给表单数据
  302. setAddress(res) {
  303. //经纬度信息
  304. this.addressDetail.latitude = res.latitude
  305. this.addressDetail.longitude = res.longitude
  306. if (!res.address && res.name) { //用户直接选择城市的逻辑
  307. return this.addressDetail.address = res.name
  308. }
  309. if (res.address || res.name) {
  310. return this.addressDetail.address = res.address + res.name
  311. }
  312. this.addressDetail.address = '' //用户啥都没选就点击勾选
  313. }
  314. }
  315. }
  316. </script>
  317. <style lang="scss" scoped>
  318. .address {
  319. width: 750rpx;
  320. margin: 0rpx auto;
  321. background: #F5F5F5;
  322. box-sizing: border-box;
  323. min-height: 100vh;
  324. .address-list {
  325. padding: 40rpx 20rpx 120rpx 20rpx;
  326. // .address-item {
  327. // background: white;
  328. // border-radius: 20rpx;
  329. // overflow: hidden;
  330. // margin-bottom: 20rpx;
  331. // padding: 15rpx 15rpx 0rpx 15rpx;
  332. // width: 680rpx;
  333. // .address-item-top {
  334. // border-bottom: 1px dashed #D3D1D1;
  335. // display: flex;
  336. // align-items: center;
  337. // padding: 0rpx 0rpx 15rpx 0rpx;
  338. // .img-box {
  339. // width: 120rpx;
  340. // height: 120rpx;
  341. // image {
  342. // width: 75%;
  343. // height: 75%;
  344. // display: block;
  345. // margin: 12.5% auto;
  346. // }
  347. // }
  348. // .address-info {
  349. // width: calc(100% - 120rpx);
  350. // height: 100%;
  351. // display: flex;
  352. // flex-direction: column;
  353. // justify-content: space-between;
  354. // .user-info {
  355. // display: flex;
  356. // align-items: center;
  357. // text {
  358. // display: block;
  359. // line-height: 40rpx;
  360. // margin-right: 20rpx;
  361. // }
  362. // .user-name,
  363. // .user-phone {
  364. // font-size: 30rpx;
  365. // }
  366. // .is-default {
  367. // display: flex;
  368. // align-items: center;
  369. // justify-content: center;
  370. // background: #FEB773;
  371. // color: white;
  372. // width: 80rpx;
  373. // height: 35rpx;
  374. // border-radius: 20rpx;
  375. // font-size: 22rpx;
  376. // }
  377. // }
  378. // .address-detail {
  379. // color: #4a4a4a;
  380. // font-size: 26rpx;
  381. // overflow: hidden;
  382. // display: -webkit-box;
  383. // -webkit-box-orient: vertical;
  384. // -webkit-line-clamp: 2;
  385. // text-overflow: ellipsis;
  386. // }
  387. // }
  388. // }
  389. // .controls {
  390. // display: flex;
  391. // align-items: center;
  392. // justify-content: space-between;
  393. // align-items: center;
  394. // font-size: 26rpx;
  395. // padding: 15rpx 15rpx 25rpx 15rpx;
  396. // .default-checkbox {
  397. // display: flex;
  398. // text {
  399. // margin-left: 8rpx;
  400. // }
  401. // }
  402. // .control-title {
  403. // height: 30rpx;
  404. // line-height: 30rpx;
  405. // color: #666666;
  406. // }
  407. // view {
  408. // display: flex;
  409. // align-items: center;
  410. // }
  411. // image {
  412. // width: 23rpx;
  413. // height: 23rpx;
  414. // vertical-align: middle;
  415. // margin-right: 8rpx;
  416. // }
  417. // }
  418. // }
  419. }
  420. .add-btn {
  421. position: fixed;
  422. display: flex;
  423. justify-content: center;
  424. align-items: center;
  425. left: 0;
  426. bottom: 0;
  427. width: 750rpx;
  428. height: 100rpx;
  429. background: white;
  430. .btn {
  431. display: flex;
  432. align-items: center;
  433. justify-content: center;
  434. width: 85%;
  435. height: 80rpx;
  436. border-radius: 40rpx;
  437. color: white;
  438. text-align: center;
  439. font-size: 28rpx;
  440. background: $uni-color;
  441. }
  442. }
  443. }
  444. @media all and (min-width: 961px) {
  445. .add-btn {
  446. left: 50% !important;
  447. transform: translateX(-50%);
  448. }
  449. }
  450. //选择位置地图样式
  451. :deep(.uni-system-choose-location) {
  452. z-index: 99999 !important;
  453. }
  454. </style>