Commit 82ed78cffc3f360c5e14fef3426b816bf585ffe0

Authored by 史婷婷
1 parent c153bb81

feat: 订货单代码优化

Showing 1 changed file with 1 additions and 29 deletions
@@ -136,24 +136,15 @@ export default { @@ -136,24 +136,15 @@ export default {
136 mode: { type: String, default: 'add' }, 136 mode: { type: String, default: 'add' },
137 list: { type: Array, default: () => [] }, 137 list: { type: Array, default: () => [] },
138 max: { type: Number, default: 8 }, 138 max: { type: Number, default: 8 },
139 - options: { type: Array, default: () => [] },  
140 totalQuantity: { type: Number, default: 0 } 139 totalQuantity: { type: Number, default: 0 }
141 }, 140 },
142 data() { 141 data() {
143 return { 142 return {
144 items: [], 143 items: [],
145 collapsedView: false, 144 collapsedView: false,
146 - sheet: { visible: false, title: '请选择性别', options: [], value: '', idx: -1 }  
147 } 145 }
148 }, 146 },
149 computed: { 147 computed: {
150 - selectOptions() {  
151 - const list = Array.isArray(this.options) ? this.options : []  
152 - return list.map(o => ({  
153 - label: o.label != null ? o.label : (o.text != null ? o.text : (o.name != null ? o.name : '')),  
154 - value: o.value != null ? o.value : (o.code != null ? o.code : (o.id != null ? o.id : o.productId))  
155 - }))  
156 - }  
157 }, 148 },
158 watch: { 149 watch: {
159 items: { 150 items: {
@@ -163,19 +154,13 @@ export default { @@ -163,19 +154,13 @@ export default {
163 list: { 154 list: {
164 handler(v) { 155 handler(v) {
165 const arr = Array.isArray(v) ? v : [] 156 const arr = Array.isArray(v) ? v : []
166 - const opts = this.selectOptions  
167 this.items = arr.map(x => { 157 this.items = arr.map(x => {
168 const it = { ...this.defaultItem(), ...x, collapsed: true } 158 const it = { ...this.defaultItem(), ...x, collapsed: true }
169 - const m = opts.find(o => String(o.value) === String(it.sex))  
170 - it.sexName = m ? (m.label || '') : it.sexName  
171 return it 159 return it
172 }) 160 })
173 }, 161 },
174 deep: true 162 deep: true
175 }, 163 },
176 - options: {  
177 - handler() { this.refreshSexNames() }  
178 - }  
179 }, 164 },
180 created() { 165 created() {
181 const init = Array.isArray(this.list) && this.list.length > 0 ? this.list.map(v => ({ ...this.defaultItem(), ...v, collapsed: false })) : [{ ...this.defaultItem(), collapsed: false }] 166 const init = Array.isArray(this.list) && this.list.length > 0 ? this.list.map(v => ({ ...this.defaultItem(), ...v, collapsed: false })) : [{ ...this.defaultItem(), collapsed: false }]
@@ -183,20 +168,7 @@ export default { @@ -183,20 +168,7 @@ export default {
183 }, 168 },
184 methods: { 169 methods: {
185 defaultItem() { 170 defaultItem() {
186 - return { personId: uuid(), name: '', sex: '', sexName: '', nativePlace: '', age: '', position: '', mobile: '', phone: '', email: '', address: '', collapsed: false }  
187 - },  
188 - getSexName(item) {  
189 - const opts = this.selectOptions  
190 - const v = item && item.sex  
191 - const m = opts.find(o => String(o.value) === String(v))  
192 - return m ? (m.label || '') : ((item && item.sexName) || '')  
193 - },  
194 - refreshSexNames() {  
195 - const opts = this.selectOptions  
196 - this.items = (this.items || []).map(it => {  
197 - const m = opts.find(o => String(o.value) === String(it.sex))  
198 - return { ...it, sexName: m ? (m.label || '') : it.sexName }  
199 - }) 171 + return { collapsed: false }
200 }, 172 },
201 toggleItem(idx) { 173 toggleItem(idx) {
202 const it = this.items[idx] 174 const it = this.items[idx]