adress.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="content b-t">
  3. <view v-if="isform ==1" @click="choseAdress" style="text-align: right;padding: 10upx 32upx;">
  4. {{isdelete?'管理':'删除'}}
  5. </view>
  6. <view class="list b-b" v-for="(item, index) in addressList" :key="index">
  7. <view @click="checkAddress(item)" style="flex: 15;" class="wrapper">
  8. <view class="u-box">
  9. <text v-if="item.address_is_default == 1" class="tag">↑</text>
  10. <text class="name">{{item.address_realname}}</text>
  11. <text class="mobile">{{item.address_mob_phone}}</text>
  12. </view>
  13. <view class="address-box">
  14. <text class="address">{{item.area_info}} {{item.address_detail}}</text>
  15. </view>
  16. </view>
  17. <van-icon v-if="isdelete" size="30" name="edit" @click="addAddress('edit', item)" color="#D9332E" />
  18. <view v-if="!isdelete" style="flex: 2;border-radius: 100%;">
  19. <van-checkbox-group :value="checkboxList" @change="checkboxChange()">
  20. <van-checkbox checked-color="#D9332E" :name="index"></van-checkbox>
  21. </van-checkbox-group>
  22. </view>
  23. <!-- <text class="yticon icon-bianji" @click.stop="addAddress('edit', item)"></text> -->
  24. </view>
  25. <button v-if="isdelete" class="add-btn" @click="addAddress('add', {})">添加地址</button>
  26. <view v-if="!isdelete" style="position: fixed;bottom: 0;border-top:1px solid #eee;height: 8vh;">
  27. <van-submit-bar
  28. button-text="删除"
  29. @submit="onClickButton"
  30. :tip="true"
  31. >
  32. <van-checkbox checked-color="#D9332E" :value="isAll" shape="round" @change="onChange">
  33. 全选
  34. </van-checkbox>
  35. </van-submit-bar>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. isform: 0,
  44. isAll: false,
  45. source: 0,
  46. isdelete: true,
  47. addressList: [
  48. ],
  49. pricelist: [],
  50. checkboxList:[]
  51. }
  52. },
  53. onLoad(option){
  54. this.source = option.source;
  55. this.isform = option.isform;
  56. this.getlist();
  57. uni.$on("refeshadress",(adress)=>{
  58. this.getlist();
  59. })
  60. },
  61. methods: {
  62. // 全选
  63. onChange(a) {
  64. this.isAll = !this.isAll;
  65. let items = this.addressList;
  66. if(this.isAll) {
  67. items.forEach((item, idx) => {
  68. this.$set(this.checkboxList, idx, idx.toString())
  69. })
  70. let price = [];
  71. this.checkboxList.forEach(item => {
  72. price.push(items[item].address_id)
  73. })
  74. this.pricelist = price;
  75. }else {
  76. this.checkboxList = [];
  77. this.pricelist = [];
  78. }
  79. },
  80. // 地址管理
  81. choseAdress() {
  82. this.isdelete =!this.isdelete;
  83. this.checkboxList = [];
  84. },
  85. checkboxChange(e) {
  86. this.checkboxList = []
  87. e.detail.forEach((item, idx) => {
  88. this.$set(this.checkboxList, idx, item)
  89. })
  90. let array = this.addressList;
  91. let price = [];
  92. this.checkboxList.forEach(item => {
  93. price.push(array[item].address_id)
  94. })
  95. this.pricelist = price;
  96. },
  97. // 删除地址
  98. onClickButton() {
  99. if(this.pricelist.length == 0) {
  100. this.$msg("赶快去新增地址吧");
  101. return;
  102. }
  103. let address_ids = this.pricelist.join(',');
  104. this.request({
  105. url: '/v1/member/address_drop',
  106. method: 'post',
  107. data: {
  108. address_ids: address_ids
  109. },
  110. success: (res) => {
  111. if(res.data.code == 1000) {
  112. this.checkboxList = [];
  113. this.getlist();
  114. }
  115. }
  116. })
  117. },
  118. // 获取地址列表
  119. getlist() {
  120. this.request({
  121. url: '/v2/address/index',
  122. method: 'get',
  123. success: (res) => {
  124. this.addressList = res.data.data.address_list;
  125. }
  126. })
  127. },
  128. //选择地址
  129. checkAddress(item){
  130. if(this.isform!=1&&this.isdelete) {
  131. uni.$emit('getadress', item)
  132. uni.navigateBack();
  133. }
  134. // if(this.source == 1){
  135. // //this.$api.prePage()获取上一页实例,在App.vue定义
  136. // }
  137. // let items = JSON.stringify(item);
  138. // uni.redirectTo({
  139. // url: `/pages/index/sureBuy?item=${items}`
  140. // });
  141. },
  142. addAddress(type, item){
  143. uni.navigateTo({
  144. url: `/pages/myOrder/adressManger?type=${type}&data=${JSON.stringify(item)}`
  145. })
  146. },
  147. //添加或修改成功之后回调
  148. refreshList(data, type){
  149. //添加或修改后事件,这里直接在最前面添加了一条数据,实际应用中直接刷新地址列表即可
  150. this.addressList.unshift(data);
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang='scss'>
  156. page{
  157. padding-bottom: 120upx;
  158. }
  159. .content{
  160. position: relative;
  161. }
  162. .list{
  163. display: flex;
  164. align-items: center;
  165. padding: 20upx 30upx;;
  166. background: #fff;
  167. position: relative;
  168. }
  169. .wrapper{
  170. display: flex;
  171. flex-direction: column;
  172. flex: 1;
  173. }
  174. .address-box{
  175. display: flex;
  176. align-items: center;
  177. .tag{
  178. font-size: 35upx;
  179. color: $base-color;
  180. margin-right: 10upx;
  181. background: #fffafb;
  182. border-radius: 4upx;
  183. padding: 4upx 10upx;
  184. line-height: 1;
  185. }
  186. .address{
  187. font-size: 30upx;
  188. color: $font-color-dark;
  189. }
  190. }
  191. .u-box{
  192. font-size: 28upx;
  193. color: $font-color-light;
  194. margin-top: 16upx;
  195. .name{
  196. margin-right: 30upx;
  197. }
  198. }
  199. .icon-bianji{
  200. display: flex;
  201. align-items: center;
  202. height: 80upx;
  203. font-size: 40upx;
  204. color: $font-color-light;
  205. padding-left: 30upx;
  206. }
  207. .add-btn{
  208. position: fixed;
  209. left: 30upx;
  210. right: 30upx;
  211. bottom: 16upx;
  212. z-index: 95;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. width: 690upx;
  217. height: 80upx;
  218. font-size: 32upx;
  219. color: #fff;
  220. background-color: #D9332E;
  221. border-radius: 10upx;
  222. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  223. }
  224. .isdiaplay .van-submit-bar__text {
  225. visibility: hidden;
  226. }
  227. .isdiaplay {
  228. visibility: hidden;
  229. }
  230. .van-submit-bar__bar {
  231. justify-content: space-between!important;
  232. }
  233. </style>