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

268 lines
6.5 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. let current = e.target.value;
  115. let id = null;
  116. this.list.forEach((item, index) => {
  117. if(current == index){
  118. item.is_default = 1;
  119. id = item.id;
  120. }else{
  121. item.is_default = 0;
  122. }
  123. })
  124. this.switchDefaultAddress(id);
  125. },
  126. switchDefaultAddress(id){
  127. var token = this.$cookieStorage.get('user_token');
  128. this.$http.ajax({
  129. api: 'api/address/'+ id,
  130. method: 'PUT',
  131. header: {
  132. Authorization: token
  133. },
  134. data: {
  135. is_default: 1
  136. }
  137. }).then(res => {
  138. this.$msg('操作成功', {icon: 'success'});
  139. }).catch(err => {
  140. this.$msg('切换默认地址失败');
  141. })
  142. },
  143. setInfo(e) {
  144. // var from = e.currentTarget.dataset.info;
  145. var from = e;
  146. var data = this.$cookieStorage.get('order_form');
  147. // var from=JSON.parse(from);
  148. if (!data) {
  149. return this.view(from.id);
  150. }
  151. var order_no = this.order_no;
  152. if (order_no && data.order_no === order_no) {
  153. data.address = from;
  154. this.$cookieStorage.set('order_form', data);
  155. wx.navigateBack({
  156. url: '/' + this.url
  157. });
  158. } else {
  159. return this.view(from.id);
  160. }
  161. },
  162. view(id) {
  163. wx.navigateTo({
  164. url: '/pages/address/add/add?id=' + id
  165. });
  166. },
  167. add() {
  168. wx.navigateTo({
  169. url: '/pages/address/add/add'
  170. });
  171. },
  172. // 查询收货地址列表
  173. queryAddressList() {
  174. this.is_load = true;
  175. var token = this.$cookieStorage.get('user_token');
  176. this.$http.get({
  177. api: 'api/address',
  178. header: {
  179. Authorization: token
  180. }
  181. }).then(res => {
  182. if (res.statusCode == 200) {
  183. res = res.data;
  184. if (res.status) {
  185. this.setData({
  186. list: res.data
  187. });
  188. } else {
  189. wx.showToast({
  190. title: res.message,
  191. image: '../../../static/error.png'
  192. });
  193. }
  194. } else {
  195. wx.showToast({
  196. title: '获取信息失败',
  197. image: '../../../static/error.png'
  198. });
  199. }
  200. this.is_load = false;
  201. }).catch(err => {
  202. this.is_load = false;
  203. })
  204. },
  205. setData: function (obj) {
  206. let that = this;
  207. let keys = [];
  208. let val, data;
  209. Object.keys(obj).forEach(function (key) {
  210. keys = key.split('.');
  211. val = obj[key];
  212. data = that.$data;
  213. keys.forEach(function (key2, index) {
  214. if (index + 1 == keys.length) {
  215. that.$set(data, key2, val);
  216. } else {
  217. if (!data[key2]) {
  218. that.$set(data, key2, {});
  219. }
  220. }
  221. data = data[key2];
  222. });
  223. });
  224. }
  225. },
  226. computed: {},
  227. watch: {}
  228. };
  229. </script>
  230. <style>
  231. page{
  232. background-color: #F8F8F8;
  233. }
  234. </style>
  235. <style rel="stylesheet/less" lang="less">
  236. @import "list";
  237. .lf-color-red{
  238. color: red;
  239. }
  240. .user-item, .menu-item{
  241. height: 50rpx;
  242. width: 100%;
  243. }
  244. .address-item{
  245. width: 100%;
  246. margin-top: 10rpx;
  247. font-size: 28rpx;
  248. color: #333333;
  249. }
  250. </style>