index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view>
  3. <view class="address-box">
  4. <template v-if="addrs.length > 0 && type == 0">
  5. <view v-for="(item,index) in addrs" :key="index" class="address-box-list">
  6. <view class="address-box-left">
  7. <text class="address-box-title">{{item.name}} {{item.phone}}</text>
  8. <text class="address-box-desc">{{item.content}}</text>
  9. </view>
  10. <view class="address-box-right" @click="handleEdit(item)">
  11. <image src="../../images/edit.png"></image>
  12. </view>
  13. </view>
  14. </template>
  15. <template v-if="addrs.length > 0 && type == 1">
  16. <radio-group @change="radioChange">
  17. <view class="address-box-list" v-for="(item, index) in addrs" :key="index">
  18. <label>
  19. <view class="address-box-select">
  20. <radio :value="item.id" :checked="item.id === current" />
  21. </view>
  22. <view class="address-box-left2">
  23. <text class="address-box-title">{{item.name}} {{item.phone}}</text>
  24. <text class="address-box-desc">{{item.address1}} {{item.address2}} {{item.room}}</text>
  25. </view>
  26. </label>
  27. <view class="address-box-right" @click="handleEdit(item)">
  28. <image src="../../images/edit.png"></image>
  29. </view>
  30. </view>
  31. </radio-group>
  32. </template>
  33. <view v-if="addrs.length == 0" class="no-data">
  34. <image src="../../images/no_data.png" mode=""></image>
  35. <view class="no-data-text">
  36. 空空如也~
  37. </view>
  38. </view>
  39. </view>
  40. <view class="bottom-btn" @click="handleAdd">
  41. 新增收货地址
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. var app = getApp();
  47. export default {
  48. data() {
  49. return {
  50. addrs: [],
  51. page: 1,
  52. size: 20,
  53. flag: 0,
  54. type: 0,
  55. current: 0
  56. }
  57. },
  58. onLoad(option) {
  59. var that = this;
  60. this.type = option.type?option.type:0;
  61. if(this.type == 1){
  62. uni.setNavigationBarTitle({
  63. title: '选择地址'
  64. });
  65. const eventChannel = this.getOpenerEventChannel()
  66. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  67. eventChannel.on('acceptDataFromOpenerPage', function(data) {
  68. that.current = data.addressId;
  69. })
  70. }
  71. },
  72. onShow(){
  73. var that = this;
  74. this.flag = 0;
  75. this.page = 1;
  76. this.getAddress();
  77. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  78. var apiname = res.data.apiname;
  79. console.log(res);
  80. if(apiname == 'addr'){
  81. that.addrs = res.data.data;
  82. if (that.addrs.length < that.size) {
  83. that.flag = 1;
  84. } else {
  85. that.page++;
  86. }
  87. }
  88. }
  89. },
  90. onPullDownRefresh() {
  91. this.flag = 0;
  92. this.page = 1;
  93. this.getAddress();
  94. },
  95. onReachBottom() { //上拉加载
  96. console.log('11111111');
  97. this.getAddress();
  98. },
  99. methods: {
  100. handleAdd(){
  101. uni.navigateTo({
  102. url: '/pages/address/add'
  103. });
  104. },
  105. handleEdit(obj){
  106. uni.navigateTo({
  107. url: '/pages/address/add?id='+obj.id
  108. });
  109. },
  110. getAddress(){
  111. if(this.flag == 1){
  112. return;
  113. }
  114. app.ajax({
  115. url: app.globalData.serverUrl + 'shopAddress/list',
  116. type: 'POST',
  117. apiname: 'addr',
  118. data: {
  119. page: this.page,
  120. size: this.size
  121. }
  122. });
  123. },
  124. radioChange(evt) {
  125. this.addrs.forEach((item,index) => {
  126. if (item.id === evt.detail.value) {
  127. this.current = item.id;
  128. const eventChannel = this.getOpenerEventChannel()
  129. eventChannel.emit('acceptDataFromOpenedPage', item);
  130. uni.navigateBack({
  131. delta: 1
  132. });
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .address-box{
  141. padding-bottom: 100rpx;
  142. }
  143. .address-nodata{
  144. margin-top: 150rpx;
  145. text-align: center;
  146. font-size: 32rpx;
  147. color: #666666;
  148. }
  149. .address-box-list{
  150. background-color: #FFFFFF;
  151. margin: 10rpx 0;
  152. padding: 10rpx 20rpx;
  153. overflow: hidden;
  154. }
  155. .address-box-left{
  156. display: inline-block;
  157. width: 630rpx;
  158. height: auto;
  159. float: left;
  160. }
  161. .address-box-left .address-box-title{
  162. display: inline-block;
  163. width: 100%;
  164. height: 30rpx;
  165. line-height: 30rpx;
  166. color: #3E3E3E;
  167. font-size: 32rpx;
  168. }
  169. .address-box-left .address-box-desc{
  170. display: inline-block;
  171. width: 100%;
  172. height: 30rpx;
  173. line-height: 30rpx;
  174. color: #949494;
  175. font-size: 28rpx;
  176. }
  177. .address-box-right{
  178. display: inline-block;
  179. width: 60rpx;
  180. height: auto;
  181. float: right;
  182. text-align: center;
  183. }
  184. .address-box-right image{
  185. width: 40rpx;
  186. height: 40rpx;
  187. vertical-align: middle;
  188. margin-top: 20rpx;
  189. }
  190. .address-box-left2{
  191. display: inline-block;
  192. width: 570rpx;
  193. height: auto;
  194. float: left;
  195. }
  196. .address-box-left2 .address-box-title{
  197. display: inline-block;
  198. width: 100%;
  199. height: 30rpx;
  200. line-height: 30rpx;
  201. color: #3E3E3E;
  202. font-size: 32rpx;
  203. }
  204. .address-box-left2 .address-box-desc{
  205. display: inline-block;
  206. width: 100%;
  207. height: 30rpx;
  208. line-height: 30rpx;
  209. color: #949494;
  210. font-size: 28rpx;
  211. }
  212. .bottom-btn{
  213. width: 100%;
  214. height: 98rpx;
  215. line-height: 98rpx;
  216. background-color: $theme-color;
  217. color: #FFFFFF;
  218. text-align: center;
  219. position: fixed;
  220. z-index: 100;
  221. left: 0;
  222. bottom: 0;
  223. }
  224. .address-box-select{
  225. display: inline-block;
  226. width: 60rpx;
  227. height: auto;
  228. float: left;
  229. }
  230. .address-box-select radio{
  231. width: 40rpx;
  232. height: 40rpx;
  233. // vertical-align: middle;
  234. margin-top: 20rpx;
  235. }
  236. </style>