金诚优选前端代码
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.

273 lines
6.7 KiB

  1. <template>
  2. <view id="address-list">
  3. <lf-nav title="地址管理" :showIcon="true" bgColor="#fff"></lf-nav>
  4. <view class="list-box">
  5. <view class="list-item" :data-info="JSON.stringify(item)" :data-id="item.id" v-for="(item, index) in list" :key="index">
  6. <!-- <view class="user">
  7. <view class="name">
  8. <text>{{item.accept_name}}</text>
  9. <text class="phone">{{item.mobile}}</text>
  10. </view>
  11. <view class="default" v-if="item.is_default">
  12. 默认
  13. </view>
  14. </view>
  15. <view class="address">{{item.address_name}} {{item.address}}</view> -->
  16. <view class="lf-font-28 user-item">
  17. <text class="lf-color-black lf-font-bold">{{item.accept_name}}</text>
  18. <text class="lf-color-777 lf-m-l-20">{{item.mobile}}</text>
  19. </view>
  20. <view class="address-item lf-line-2">
  21. <text>{{item.address_name}}</text>
  22. <text>{{item.address}}</text>
  23. </view>
  24. <view class="menu-item lf-row-between lf-m-t-30">
  25. <view class="lf-row-center">
  26. <radio-group @change="radioChange">
  27. <radio :checked="item.is_default" :value="index"></radio>
  28. </radio-group>
  29. <text class="lf-m-l-15 lf-font-24 lf-color-777">默认地址</text>
  30. </view>
  31. <view class="lf-row-between">
  32. <view @tap="setInfo(item)">
  33. <text class="lf-iconfont icon-bianji"></text>
  34. <text class="lf-m-l-10">编辑</text>
  35. </view>
  36. <view class="lf-m-l-50 lf-color-red" @click="deleteAddress(item, index)">
  37. <text class="lf-iconfont icon-shanchu"></text>
  38. <text class="lf-m-l-10">删除</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <lf-nocontent src="/static/images/empty.png" text="您还未添加地址" v-if="list.length <= 0 && !is_load"></lf-nocontent>
  44. </view>
  45. <view style="height: 230rpx;"></view>
  46. <view class="add-address" @tap="add">
  47. <view class="small-btn">
  48. <text class="lf-iconfont icon-jia"></text>
  49. <text class="lf-m-l-10">新增收货地址</text>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  56. export default {
  57. data() {
  58. return {
  59. list: [],
  60. order_no: '',
  61. url: '',
  62. id:'',
  63. is_load: true
  64. };
  65. },
  66. onShow() {
  67. this.queryAddressList(); // let app =getApp(); 暂时注释
  68. // app.isBirthday().then(()=>{
  69. // if(this.$cookieStorage.get("birthday_gift")){
  70. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  71. // new app.ToastPannel().__page.showText(giftData);
  72. // }
  73. // });
  74. },
  75. onLoad(e) {
  76. // 暂时注释
  77. // pageLogin(getUrl());
  78. this.setData({
  79. order_no: e.order_no,
  80. url: e.url
  81. });
  82. },
  83. components: {},
  84. props: {},
  85. methods: {
  86. // 删除收货地址
  87. deleteAddress(item, index){
  88. console.log("item", item)
  89. uni.showModal({
  90. title: '温馨提示',
  91. content: '您确定删除该收货地址吗?',
  92. success: result => {
  93. if(result.confirm){
  94. var token = this.$cookieStorage.get('user_token');
  95. this.$http.ajax({
  96. api: '/api/address/'+ item.id,
  97. method: 'DELETE',
  98. header: {
  99. Authorization: token
  100. }
  101. }).then(res => {
  102. console.log("删除地址", res);
  103. this.$msg('删除成功', {icon: 'success'});
  104. this.list.splice(index, 1);
  105. }).catch(err => {
  106. this.$msg('删除失败', {icon: 'error'});
  107. })
  108. }
  109. }
  110. })
  111. },
  112. // 切换默认地址
  113. radioChange(e){
  114. uni.showLoading({
  115. title: '切换默认地址中'
  116. })
  117. let current = e.target.value;
  118. let id = null;
  119. this.list.forEach((item, index) => {
  120. if(current == index){
  121. item.is_default = 1;
  122. id = item.id;
  123. }else{
  124. item.is_default = 0;
  125. }
  126. })
  127. this.switchDefaultAddress(id);
  128. },
  129. switchDefaultAddress(id){
  130. var token = this.$cookieStorage.get('user_token');
  131. this.$http.ajax({
  132. api: 'api/address/'+ id,
  133. method: 'PUT',
  134. header: {
  135. Authorization: token
  136. },
  137. data: {
  138. is_default: 1
  139. }
  140. }).then(res => {
  141. uni.hideLoading();
  142. this.$msg('操作成功', {icon: 'success'});
  143. }).catch(err => {
  144. uni.hideLoading();
  145. this.$msg('切换默认地址失败');
  146. })
  147. },
  148. setInfo(e) {
  149. // var from = e.currentTarget.dataset.info;
  150. var from = e;
  151. var data = this.$cookieStorage.get('order_form');
  152. // var from=JSON.parse(from);
  153. if (!data) {
  154. return this.view(from.id);
  155. }
  156. var order_no = this.order_no;
  157. if (order_no && data.order_no === order_no) {
  158. data.address = from;
  159. this.$cookieStorage.set('order_form', data);
  160. wx.navigateBack({
  161. url: '/' + this.url
  162. });
  163. } else {
  164. return this.view(from.id);
  165. }
  166. },
  167. view(id) {
  168. wx.navigateTo({
  169. url: '/pages/address/add/add?id=' + id
  170. });
  171. },
  172. add() {
  173. wx.navigateTo({
  174. url: '/pages/address/add/add'
  175. });
  176. },
  177. // 查询收货地址列表
  178. queryAddressList() {
  179. this.is_load = true;
  180. var token = this.$cookieStorage.get('user_token');
  181. this.$http.get({
  182. api: 'api/address',
  183. header: {
  184. Authorization: token
  185. }
  186. }).then(res => {
  187. if (res.statusCode == 200) {
  188. res = res.data;
  189. if (res.status) {
  190. this.setData({
  191. list: res.data
  192. });
  193. } else {
  194. wx.showToast({
  195. title: res.message,
  196. image: '../../../static/error.png'
  197. });
  198. }
  199. } else {
  200. wx.showToast({
  201. title: '获取信息失败',
  202. image: '../../../static/error.png'
  203. });
  204. }
  205. this.is_load = false;
  206. }).catch(err => {
  207. this.is_load = false;
  208. })
  209. },
  210. setData: function (obj) {
  211. let that = this;
  212. let keys = [];
  213. let val, data;
  214. Object.keys(obj).forEach(function (key) {
  215. keys = key.split('.');
  216. val = obj[key];
  217. data = that.$data;
  218. keys.forEach(function (key2, index) {
  219. if (index + 1 == keys.length) {
  220. that.$set(data, key2, val);
  221. } else {
  222. if (!data[key2]) {
  223. that.$set(data, key2, {});
  224. }
  225. }
  226. data = data[key2];
  227. });
  228. });
  229. }
  230. },
  231. computed: {},
  232. watch: {}
  233. };
  234. </script>
  235. <style>
  236. page{
  237. background-color: #F8F8F8;
  238. }
  239. </style>
  240. <style rel="stylesheet/less" lang="less">
  241. @import "list";
  242. .lf-color-red{
  243. color: red;
  244. }
  245. .user-item, .menu-item{
  246. height: 50rpx;
  247. width: 100%;
  248. }
  249. .address-item{
  250. width: 100%;
  251. margin-top: 10rpx;
  252. font-size: 28rpx;
  253. color: #333333;
  254. }
  255. </style>