adress.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view class="content b-t">
  3. <view @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. // 单选
  87. console.log(e);
  88. this.checkboxList = []
  89. e.detail.forEach((item, idx) => {
  90. this.$set(this.checkboxList, idx, item)
  91. })
  92. let array = this.addressList;
  93. let price = [];
  94. this.checkboxList.forEach(item => {
  95. price.push(array[item].address_id)
  96. })
  97. this.pricelist = price;
  98. console.log(this.pricelist)
  99. },
  100. // 删除地址
  101. onClickButton() {
  102. console.log(address_ids)
  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) {
  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. console.log(data, type);
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang='scss'>
  157. page{
  158. padding-bottom: 120upx;
  159. }
  160. .content{
  161. position: relative;
  162. }
  163. .list{
  164. display: flex;
  165. align-items: center;
  166. padding: 20upx 30upx;;
  167. background: #fff;
  168. position: relative;
  169. }
  170. .wrapper{
  171. display: flex;
  172. flex-direction: column;
  173. flex: 1;
  174. }
  175. .address-box{
  176. display: flex;
  177. align-items: center;
  178. .tag{
  179. font-size: 35upx;
  180. color: $base-color;
  181. margin-right: 10upx;
  182. background: #fffafb;
  183. border-radius: 4upx;
  184. padding: 4upx 10upx;
  185. line-height: 1;
  186. }
  187. .address{
  188. font-size: 30upx;
  189. color: $font-color-dark;
  190. }
  191. }
  192. .u-box{
  193. font-size: 28upx;
  194. color: $font-color-light;
  195. margin-top: 16upx;
  196. .name{
  197. margin-right: 30upx;
  198. }
  199. }
  200. .icon-bianji{
  201. display: flex;
  202. align-items: center;
  203. height: 80upx;
  204. font-size: 40upx;
  205. color: $font-color-light;
  206. padding-left: 30upx;
  207. }
  208. .add-btn{
  209. position: fixed;
  210. left: 30upx;
  211. right: 30upx;
  212. bottom: 16upx;
  213. z-index: 95;
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. width: 690upx;
  218. height: 80upx;
  219. font-size: 32upx;
  220. color: #fff;
  221. background-color: #D9332E;
  222. border-radius: 10upx;
  223. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  224. }
  225. .isdiaplay .van-submit-bar__text {
  226. visibility: hidden;
  227. }
  228. .isdiaplay {
  229. visibility: hidden;
  230. }
  231. .van-submit-bar__bar {
  232. justify-content: space-between!important;
  233. }
  234. </style>