Authored by 张文文

路由补充

1 <template> 1 <template>
2 <LayoutApp title="选择地址" :show-back="true"> 2 <LayoutApp title="选择地址" :show-back="true">
3 - <AddressItem :list="addressList" :pageName="pageName" :selectedAddressId="selectedAddressId"></AddressItem> 3 + <CubeScroll class="main-container" ref="scroll" :options="scrollOpts">
  4 + <div class="user-list">
  5 + <div
  6 + v-for="(item, index) in addressList"
  7 + :key="index"
  8 + class="item"
  9 + @click="toOrderPage(item)"
  10 + >
  11 + <slot name="item" :data="item">
  12 + <div class="user-item">
  13 + <div
  14 + :class="{'uncheck-item' : item.address_id !== selectedAddressId , 'check-item' : item.address_id === selectedAddressId }"
  15 + ></div>
  16 + <div class="user-info">
  17 + <div class="extra">
  18 + <p class="name">{{item.consignee}}</p>
  19 + <p class="mobile">{{item.mobile}}</p>
  20 + <div v-if="item.is_default === 'Y'" class="tag-btn">默认</div>
  21 + <div v-if="item.tag_code" class="tag-btn">{{item.tag}}</div>
  22 + <div
  23 + class="option-btn"
  24 + :data-item="JSON.stringify(item)"
  25 + :data-add="0"
  26 + @click="toEditorPage"
  27 + >编辑</div>
  28 + </div>
  29 + <p class="address">{{item.area}}{{item.address}}</p>
  30 + </div>
  31 + </div>
  32 + </slot>
  33 + <div class="border-line"></div>
  34 + </div>
  35 + </div>
  36 + <div class="add-btn" :data-add="1" @click="toEditorPage">新增地址</div>
  37 + </CubeScroll>
4 </LayoutApp> 38 </LayoutApp>
5 </template> 39 </template>
6 40
7 <script> 41 <script>
8 import Layout from "../../../components/layout/layout-app"; 42 import Layout from "../../../components/layout/layout-app";
9 -import AddressItem from "./components/address-item"; 43 +import { get } from "lodash";
  44 +import { Scroll, Loading } from "cube-ui";
  45 +import { SET_USER_ADDRESS_INFO } from "store/address/address/types";
10 46
11 import { createNamespacedHelpers } from "vuex"; 47 import { createNamespacedHelpers } from "vuex";
12 const { mapState, mapMutations, mapActions } = createNamespacedHelpers( 48 const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
@@ -17,59 +53,197 @@ export default { @@ -17,59 +53,197 @@ export default {
17 name: "addressManager", 53 name: "addressManager",
18 components: { 54 components: {
19 LayoutApp: Layout, 55 LayoutApp: Layout,
20 - AddressItem 56 + CubeScroll: Scroll
21 }, 57 },
22 data() { 58 data() {
23 return { 59 return {
  60 + scrollOpts: {
  61 + bounce: false
  62 + },
24 pageName: "", 63 pageName: "",
25 - selectedAddressId: "" 64 + selectedAddressId: "",
  65 + query: {}
26 }; 66 };
27 }, 67 },
28 computed: { 68 computed: {
29 ...mapState(["addressList"]) 69 ...mapState(["addressList"])
30 }, 70 },
31 methods: { 71 methods: {
32 - ...mapMutations({}),  
33 - ...mapActions(["fetchUserAddressList"]) 72 + ...mapMutations({ SET_USER_ADDRESS_INFO }),
  73 + ...mapActions(["fetchUserAddressList"]),
  74 + toOrderPage(item) {
  75 + this.SET_USER_ADDRESS_INFO(item);
  76 + this.$router.push({
  77 + name: this.pageName,
  78 + query: this.query
  79 + });
  80 + },
  81 +
  82 + toEditorPage(event) {
  83 + event.stopPropagation();
  84 + let isAdd = !!parseInt(event.currentTarget.dataset.add);
  85 + let item = event.currentTarget.dataset.item || {};
  86 +
  87 + if (isAdd) {
  88 + if (this.addressList.length >= 5) {
  89 + this.toast = this.$createToast({
  90 + type: "error",
  91 + txt: "地址不能超过5个",
  92 + mask: true
  93 + }).show();
  94 +
  95 + return;
  96 + }
  97 + }
  98 +
  99 + this.$router.push({
  100 + name: "addressEdit",
  101 + params: {
  102 + item: item,
  103 + update: !isAdd,
  104 + title: isAdd ? "添加地址" : "编辑地址"
  105 + }
  106 + });
  107 + }
34 }, 108 },
35 activated() { 109 activated() {
  110 + this.selectedAddressId = this.$route.query.addressId;
36 this.fetchUserAddressList(); 111 this.fetchUserAddressList();
37 }, 112 },
38 beforeRouteEnter(to, from, next) { 113 beforeRouteEnter(to, from, next) {
39 next(vm => { 114 next(vm => {
40 // 通过 `vm` 访问组件实例 115 // 通过 `vm` 访问组件实例
  116 + vm.query = from.query;
41 vm.pageName = from.name; 117 vm.pageName = from.name;
42 }); 118 });
43 - },  
44 - mounted() {  
45 - this.selectedAddressId = this.$route.query.address_id;  
46 } 119 }
47 }; 120 };
48 </script> 121 </script>
49 122
50 <style lang="scss" scoped> 123 <style lang="scss" scoped>
51 -.body {  
52 - height: 100%;  
53 - background-color: #e0e0e0;  
54 - overflow-y: auto;  
55 -} 124 +/deep/ {
  125 + .cube-scroll-content {
  126 + min-height: 100%;
  127 + }
56 128
57 -.address-container {  
58 - margin-bottom: 120px; 129 + .cube-scroll-list-wrapper {
  130 + overflow: auto;
  131 + }
  132 +
  133 + .cube-loading-spinners {
  134 + margin: auto;
  135 + }
59 } 136 }
60 137
61 -.addNew {  
62 - display: block;  
63 - height: 80px;  
64 - margin-top: 20px; 138 +.user-list {
65 background-color: white; 139 background-color: white;
  140 +
  141 + .border-line {
  142 + width: 100%;
  143 + height: 1px;
  144 + background-color: #eee;
  145 + }
  146 +}
  147 +
  148 +.user-item {
  149 + display: flex;
  150 + padding-top: 40px;
  151 + padding-bottom: 44px;
  152 + padding-left: 28px;
  153 + padding-right: 40px;
  154 + align-items: center;
  155 +
  156 + .check-item {
  157 + width: 40px;
  158 + height: 40px;
  159 + background: url(~statics/image/address/selected.png) no-repeat;
  160 + background-size: cover;
  161 + }
  162 + .uncheck-item {
  163 + width: 40px;
  164 + height: 40px;
  165 + background: url(~statics/image/address/unselected.png) no-repeat;
  166 + background-size: cover;
  167 + }
  168 +
  169 + .user-info {
  170 + flex-grow: 1;
  171 + overflow: hidden;
  172 + margin-left: 32px;
  173 + }
  174 +
  175 + .extra {
  176 + display: flex;
  177 + flex-direction: row;
  178 +
  179 + .name {
  180 + font-size: 28px;
  181 + font-weight: 400;
  182 + color: #000000;
  183 + line-height: 40px;
  184 + }
  185 +
  186 + .mobile {
  187 + display: block;
  188 + margin-left: 20px;
  189 + font-size: 28px;
  190 + font-weight: 400;
  191 + color: #000000;
  192 + line-height: 40px;
  193 + }
  194 +
  195 + .tag-btn {
  196 + width: 80px;
  197 + line-height: 44px;
  198 + font-size: 22px;
  199 + text-align: center;
  200 + background-color: #002b47;
  201 + margin-left: 18px;
  202 + color: white;
  203 + border-radius: 4px;
  204 + }
  205 +
  206 + .option-btn {
  207 + display: block;
  208 + width: 48px;
  209 + line-height: 44px;
  210 + letter-spacing: -0.29;
  211 + color: black;
  212 + font-size: 24px;
  213 + position: absolute;
  214 + right: 40px;
  215 + }
  216 + }
  217 +
  218 + .address {
  219 + width: 100%;
  220 + font-size: 24px;
  221 + line-height: 34px;
  222 + margin-top: 16px;
  223 + color: #999;
  224 + display: -webkit-box;
  225 + -webkit-box-orient: vertical;
  226 + -webkit-line-clamp: 2;
  227 + overflow: hidden;
  228 + }
66 } 229 }
67 230
68 -.newText {  
69 - line-height: 80px;  
70 - font-size: 28px;  
71 - letter-spacing: 0.6px;  
72 - white-space: nowrap; 231 +.add-btn {
  232 + height: 88px;
  233 + line-height: 88px;
  234 + font-size: 32px;
  235 + font-weight: bold;
73 text-align: center; 236 text-align: center;
  237 + color: #252525;
  238 + background-color: #fff;
  239 + border-radius: 44px;
  240 + border-style: solid;
  241 + border-width: 1px;
  242 + border-color: #e0e0e0;
  243 +
  244 + position: absolute;
  245 + left: 32px;
  246 + right: 32px;
  247 + bottom: 40px;
74 } 248 }
75 </style> 249 </style>
1 -<template>  
2 - <CubeScroll class="main-container" ref="scroll" :options="scrollOpts">  
3 - <div class="user-list">  
4 - <div v-for="(item, index) in list" :key="index" class="item" @click="toOrderPage(item)">  
5 - <slot name="item" :data="item">  
6 - <div class="user-item">  
7 - <div  
8 - :class="{'uncheck-item' : item.address_id !== selectedAddressId , 'check-item' : item.address_id === selectedAddressId }"  
9 - ></div>  
10 - <div class="user-info">  
11 - <div class="extra">  
12 - <p class="name">{{item.consignee}}</p>  
13 - <p class="mobile">{{item.mobile}}</p>  
14 - <div v-if="item.is_default === 'Y'" class="tag-btn">默认</div>  
15 - <div v-if="item.tag_code" class="tag-btn">{{item.tag}}</div>  
16 - <div  
17 - class="option-btn"  
18 - :data-item="JSON.stringify(item)"  
19 - :data-add="0"  
20 - @click="toEditorPage"  
21 - >编辑</div>  
22 - </div>  
23 - <p class="address">{{item.area}}{{item.address}}</p>  
24 - </div>  
25 - </div>  
26 - </slot>  
27 - <div class="border-line"></div>  
28 - </div>  
29 - </div>  
30 - <div class="add-btn" :data-add="1" @click="toEditorPage">新增地址</div>  
31 - </CubeScroll>  
32 -</template>  
33 -  
34 -<script>  
35 -import { get } from "lodash";  
36 -import { Scroll, Loading } from "cube-ui";  
37 -import { SET_USER_ADDRESS_INFO } from "store/address/address/types";  
38 -  
39 -import { createNamespacedHelpers } from "vuex";  
40 -const { mapState, mapMutations, mapActions } = createNamespacedHelpers(  
41 - "address/address"  
42 -);  
43 -  
44 -export default {  
45 - props: {  
46 - list: {  
47 - type: Array,  
48 - default: function() {  
49 - return [];  
50 - }  
51 - },  
52 - pageName: {  
53 - type: String,  
54 - default: ""  
55 - },  
56 - selectedAddressId: {  
57 - type: String,  
58 - default: ""  
59 - }  
60 - },  
61 - data() {  
62 - return {  
63 - scrollOpts: {  
64 - bounce: false  
65 - }  
66 - };  
67 - },  
68 - methods: {  
69 - ...mapMutations({ SET_USER_ADDRESS_INFO }),  
70 - toOrderPage(item) {  
71 - this.SET_USER_ADDRESS_INFO(item);  
72 - this.$router.push({  
73 - name: this.pageName  
74 - });  
75 - },  
76 - toEditorPage(event) {  
77 - event.stopPropagation();  
78 - let isAdd = !!parseInt(event.currentTarget.dataset.add);  
79 - let item = event.currentTarget.dataset.item || {};  
80 -  
81 - if (isAdd) {  
82 - if (this.list.length >= 5) {  
83 - this.toast = this.$createToast({  
84 - type: "error",  
85 - txt: "地址不能超过5个",  
86 - mask: true  
87 - }).show();  
88 -  
89 - return;  
90 - }  
91 - }  
92 -  
93 - this.$router.push({  
94 - name: "addressEdit",  
95 - params: {  
96 - item: item,  
97 - update: !isAdd,  
98 - title: isAdd ? "添加地址" : "编辑地址"  
99 - }  
100 - });  
101 - }  
102 - },  
103 - components: {  
104 - CubeScroll: Scroll  
105 - }  
106 -};  
107 -</script>  
108 -  
109 -<style lang="scss" scoped>  
110 -/deep/ {  
111 - .cube-scroll-content {  
112 - min-height: 100%;  
113 - }  
114 -  
115 - .cube-scroll-list-wrapper {  
116 - overflow: auto;  
117 - }  
118 -  
119 - .cube-loading-spinners {  
120 - margin: auto;  
121 - }  
122 -}  
123 -  
124 -.user-list {  
125 - background-color: white;  
126 -  
127 - .border-line {  
128 - width: 100%;  
129 - height: 1px;  
130 - background-color: #eee;  
131 - }  
132 -}  
133 -  
134 -.user-item {  
135 - display: flex;  
136 - padding-top: 40px;  
137 - padding-bottom: 44px;  
138 - padding-left: 28px;  
139 - padding-right: 40px;  
140 - align-items: center;  
141 -  
142 - .check-item {  
143 - width: 40px;  
144 - height: 40px;  
145 - background: url(~statics/image/address/selected.png) no-repeat;  
146 - background-size: cover;  
147 - }  
148 - .uncheck-item {  
149 - width: 40px;  
150 - height: 40px;  
151 - background: url(~statics/image/address/unselected.png) no-repeat;  
152 - background-size: cover;  
153 - }  
154 -  
155 - .user-info {  
156 - flex-grow: 1;  
157 - overflow: hidden;  
158 - margin-left: 32px;  
159 - }  
160 -  
161 - .extra {  
162 - display: flex;  
163 - flex-direction: row;  
164 -  
165 - .name {  
166 - font-size: 28px;  
167 - font-weight: 400;  
168 - color: #000000;  
169 - line-height: 40px;  
170 - }  
171 -  
172 - .mobile {  
173 - display: block;  
174 - margin-left: 20px;  
175 - font-size: 28px;  
176 - font-weight: 400;  
177 - color: #000000;  
178 - line-height: 40px;  
179 - }  
180 -  
181 - .tag-btn {  
182 - width: 80px;  
183 - line-height: 44px;  
184 - font-size: 22px;  
185 - text-align: center;  
186 - background-color: #002b47;  
187 - margin-left: 18px;  
188 - color: white;  
189 - border-radius: 4px;  
190 - }  
191 -  
192 - .option-btn {  
193 - display: block;  
194 - width: 48px;  
195 - line-height: 44px;  
196 - letter-spacing: -0.29;  
197 - color: black;  
198 - font-size: 24px;  
199 - position: absolute;  
200 - right: 40px;  
201 - }  
202 - }  
203 -  
204 - .address {  
205 - width: 100%;  
206 - font-size: 24px;  
207 - line-height: 34px;  
208 - margin-top: 16px;  
209 - color: #999;  
210 - display: -webkit-box;  
211 - -webkit-box-orient: vertical;  
212 - -webkit-line-clamp: 2;  
213 - overflow: hidden;  
214 - }  
215 -}  
216 -  
217 -.add-btn {  
218 - height: 88px;  
219 - line-height: 88px;  
220 - font-size: 32px;  
221 - font-weight: bold;  
222 - text-align: center;  
223 - color: #252525;  
224 - background-color: #fff;  
225 - border-radius: 44px;  
226 - border-style: solid;  
227 - border-width: 1px;  
228 - border-color: #e0e0e0;  
229 -  
230 - position: absolute;  
231 - left: 32px;  
232 - right: 32px;  
233 - bottom: 40px;  
234 -}  
235 -</style>