address.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <view :class="[AppTheme]" class="all_box content b-t">
  3. <view class="list_index">
  4. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  5. <view class="wrapper">
  6. <view class="u-box">
  7. <view>
  8. <text class="name">{{item.name}}</text>
  9. <text class="mobile">{{item.mobile}}</text>
  10. </view>
  11. <u-icon name="trash" color="#999" size="26" @click="deletes(item)"></u-icon>
  12. </view>
  13. <view class="address-box">
  14. <view class="address">{{item.address}} {{item.area || ""}}
  15. {{(item.community==''||item.community==null)?'':item.community}}
  16. </view>
  17. </view>
  18. <view class="bianji">
  19. <view class="bianji_1">
  20. <label class="radio" style="font-size: 28rpx;" @click.stop="changetarpty(item,index)">
  21. <u-icon v-if="item.is_default==1" labelPos="right" label="设为默认" size="20"
  22. name="checkmark-circle-fill" :color="primary"></u-icon>
  23. <u-icon v-else labelPos="right" label="设为默认" size="20" name="checkmark-circle-fill"
  24. color="#606266"></u-icon>
  25. </label>
  26. </view>
  27. <view class="bianji_2" @click.stop="popup(item)">编辑</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view v-if="!addressList.length" style="padding-top: 80rpx;">
  32. <u-empty marginTop="0" text="暂无收货地址" mode="address"></u-empty>
  33. </view>
  34. </view>
  35. <view style="height: 60rpx;"></view>
  36. <view class="btnview">
  37. <view class="add-btn bg-linear-gradient" @click="addAddress()">
  38. <u-icon name="plus" size="10" color="#ffffff" labelColor="#ffffff" label="新增收货地址"></u-icon>
  39. </view>
  40. <!-- #ifdef MP-WEIXIN -->
  41. <view class="add-btn bg-linear-gradient" @click="chooseAddr()">
  42. <u-icon name="plus" size="10" color="#ffffff" labelColor="#ffffff" label="微信地址"></u-icon>
  43. </view>
  44. <!-- #endif -->
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import api from "../../../api/address/address.js"
  50. export default {
  51. data() {
  52. return {
  53. primary: this.$theme.primary,
  54. source: 0,
  55. addressList: [],
  56. settingFile: getApp().globalData.siteinfo,
  57. checked: false,
  58. show: false,
  59. name: '',
  60. mobile: '',
  61. address: '',
  62. type: '', // 1 编辑 2 新增 3 默认
  63. id: '',
  64. title: '',
  65. addindex: -1,
  66. is_default:''
  67. }
  68. },
  69. onLoad(option) {
  70. this.source = option.source;
  71. this.getaddress()
  72. },
  73. onShow() {
  74. this.getaddress()
  75. },
  76. methods: {
  77. close() {
  78. this.show = false
  79. },
  80. popup(e) {
  81. this.id = e.id
  82. this.addressList.forEach(item => {
  83. if (item.id === e.id) {
  84. this.name = item.name
  85. this.mobile = item.mobile
  86. this.address = item.address
  87. uni.navigateTo({
  88. url: `/pagesD/pages/address/addressManage?type=1&data=${JSON.stringify({
  89. id:item.id,
  90. name:item.name,
  91. mobile:item.mobile,
  92. community:item.community,
  93. is_default:item.is_default,
  94. address:item.address
  95. })}`
  96. })
  97. }
  98. })
  99. },
  100. //提交
  101. confirm() {
  102. let obj = {}
  103. if (this.type == 3) {
  104. obj = {
  105. id: this.id,
  106. type: this.type,
  107. is_default:this.is_default,
  108. }
  109. } else {
  110. if (!this.name) {
  111. this.$api.msg('请填写收货人姓名');
  112. return;
  113. }
  114. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.mobile)) {
  115. this.$api.msg('请输入正确的手机号码');
  116. return;
  117. }
  118. if (!this.address) {
  119. this.$api.msg('请填写收货地址');
  120. return;
  121. }
  122. obj = {
  123. id: this.id,
  124. address: this.address,
  125. name: this.name,
  126. mobile: this.mobile,
  127. type: this.type,
  128. }
  129. }
  130. console.log(obj, 'obj')
  131. api.addressSet(obj).then(res => {
  132. console.log(res)
  133. if (res.status == 200) {
  134. this.show = false
  135. this.$api.msg(res.msg);
  136. this.getaddress()
  137. }
  138. })
  139. },
  140. changetarpty(item, index) {
  141. this.addindex = index
  142. this.is_default=item.is_default
  143. this.id = item.id
  144. this.type = 3
  145. if (item.is_default == 1) {
  146. this.is_default = 0
  147. } else {
  148. this.is_default = 1
  149. }
  150. this.confirm()
  151. },
  152. //选择地址
  153. checkAddress(item) {
  154. if (this.source == 1) {
  155. this.$api.prePage().addressData = item;
  156. uni.navigateBack()
  157. }
  158. },
  159. // 获取收货地址
  160. getaddress() {
  161. api.address().then(res => {
  162. console.log(res)
  163. if (res.status == 200) {
  164. this.addressList = res.data.data
  165. this.addindex = res.data.index
  166. } else {
  167. this.$api.msg(res.msg);
  168. }
  169. })
  170. },
  171. addAddress() {
  172. uni.navigateTo({
  173. url: `/pagesD/pages/address/addressManage?type=2`
  174. })
  175. },
  176. //删除地址
  177. deletes(e) {
  178. console.log(e)
  179. api.addressDel({
  180. id: e.id
  181. }).then(res => {
  182. console.log(res)
  183. if (res.status == 200) {
  184. this.addressList.forEach((item, index) => {
  185. item.id == e.id && this.addressList.splice(index, 1)
  186. })
  187. this.$api.msg(res.msg);
  188. } else {
  189. this.$api.msg(res.msg);
  190. }
  191. })
  192. },
  193. //添加或修改成功之后回调
  194. refreshList(data, type) {
  195. //添加或修改后事件,这里直接在最前面添加了一条数据,实际应用中直接刷新地址列表即可
  196. this.addressList.unshift(data);
  197. console.log(data, type);
  198. },
  199. chooseAddr() {
  200. const that = this
  201. uni.chooseAddress({
  202. success(res) {
  203. const obj = {
  204. id: 0,
  205. address: res.provinceName + res.cityName + res.countyName + res.detailInfo,
  206. name: res.userName,
  207. mobile: res.telNumber,
  208. type: 2,
  209. is_default: 0
  210. }
  211. api.addressSet(obj).then(res => {
  212. if (res.status == 200) {
  213. that.getaddress()
  214. }
  215. })
  216. },
  217. fail(err) {
  218. console.log('err', JSON.stringify(err))
  219. }
  220. })
  221. },
  222. },
  223. onPullDownRefresh() {
  224. this.addressList = [];
  225. this.getaddress();
  226. setTimeout(() => {
  227. uni.stopPullDownRefresh();
  228. }, 600);
  229. },
  230. }
  231. </script>
  232. <style lang='scss'>
  233. .all_box {
  234. min-height: calc(100vh);
  235. background-color: #fff;
  236. }
  237. .content {
  238. position: relative;
  239. }
  240. .list_index {
  241. margin: 0 2.5%;
  242. width: 95%;
  243. }
  244. .list {
  245. border-radius: 18rpx;
  246. display: flex;
  247. align-items: center;
  248. padding: 30upx 15upx;
  249. background: #fff;
  250. }
  251. .wrapper {
  252. display: flex;
  253. flex-direction: column;
  254. flex: 1;
  255. .bianji {
  256. display: flex;
  257. justify-content: space-between;
  258. margin-top: 30rpx;
  259. .bianji_1 {}
  260. .bianji_2 {
  261. color: #999;
  262. font-size: 28rpx;
  263. }
  264. }
  265. }
  266. .address-box {
  267. display: flex;
  268. align-items: center;
  269. .tag {
  270. min-width: 80rpx;
  271. display: flex;
  272. justify-content: center;
  273. padding: 0 20rpx;
  274. font-size: 24upx;
  275. margin-right: 10upx;
  276. background: #fffafb;
  277. border-width: 1px;
  278. border-style: solid;
  279. border-radius: 4upx;
  280. padding: 4upx 10upx;
  281. line-height: 1;
  282. }
  283. .address {
  284. overflow: hidden;
  285. text-overflow: ellipsis;
  286. display: -webkit-box; //将对象作为弹性伸缩盒子模型显示。
  287. -webkit-box-orient: vertical; //从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式)
  288. -webkit-line-clamp: 2; //这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。此处为2行
  289. word-wrap: break-word; //允许
  290. margin-right: 3vh;
  291. line-height: 40rpx;
  292. font-size: 28rpx;
  293. color: #a3a3a3;
  294. }
  295. }
  296. .u-box {
  297. display: flex;
  298. justify-content: space-between;
  299. /* margin-bottom: 20rpx; */
  300. .name {
  301. font-size: 32rpx;
  302. margin-right: 30upx;
  303. font-weight: 600;
  304. }
  305. .mobile {
  306. font-size: 28rpx;
  307. }
  308. }
  309. .icon-bianji {
  310. display: flex;
  311. align-items: center;
  312. height: 80upx;
  313. font-size: 40upx;
  314. color: $font-color-light;
  315. }
  316. .btnview {
  317. position: fixed;
  318. display: flex;
  319. justify-content: space-evenly;
  320. left: 30upx;
  321. right: 30upx;
  322. bottom: 25rpx;
  323. z-index: 95;
  324. .add-btn {
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. width: 300rpx;
  329. height: 80upx;
  330. font-size: 30rpx;
  331. color: #fff;
  332. border-radius: 50rpx;
  333. }
  334. }
  335. .content_one {
  336. display: flex;
  337. flex-direction: column;
  338. /* height: 40vh;
  339. width: 40vh; */
  340. padding: 30rpx;
  341. /* position: relative; */
  342. .content_one_1 {
  343. text-align: center;
  344. font-size: 34rpx;
  345. padding: 1vh;
  346. }
  347. .footer-img {
  348. text-align: center;
  349. width: 60%;
  350. margin-left: 20%;
  351. margin-top: 15vw;
  352. line-height: 60rpx;
  353. border-radius: 40rpx;
  354. background-color: limegreen;
  355. .text {
  356. color: #fff;
  357. font-size: 28rpx;
  358. }
  359. }
  360. .item {
  361. display: flex;
  362. justify-content: flex-start;
  363. align-items: center;
  364. border-bottom: 2rpx solid #DBDBDB;
  365. padding: 40rpx 0rpx 5rpx 0rpx;
  366. .check {
  367. width: 60%;
  368. height: 60rpx;
  369. text-align: center;
  370. line-height: 60rpx;
  371. color: white;
  372. border-radius: 50rpx;
  373. font-size: 27rpx;
  374. }
  375. ._label {
  376. width: 35%;
  377. color: #999;
  378. font-size: 32rpx;
  379. }
  380. ._label_1 {
  381. font-size: 32rpx;
  382. }
  383. }
  384. }
  385. /* } */
  386. </style>