| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  | <template> | 
					
						
							| 
									
										
										
										
											2022-04-19 17:58:39 +08:00
										 |  |  |  |   <view> | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |     <text v-for="(item, index) in textArray" :key="index" :style="{ fontSize: (index === 1 ? integerSize : size) + 'px', color, textDecoration }"> | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |       {{ item }} | 
					
						
							|  |  |  |  |     </text> | 
					
						
							|  |  |  |  |   </view> | 
					
						
							|  |  |  |  | </template> | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | <script> | 
					
						
							|  |  |  |  | /** | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |  * 此组件简单的显示(驼峰式)的价格 | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | export default { | 
					
						
							| 
									
										
										
										
											2022-11-19 21:40:26 +08:00
										 |  |  |  |   name: 'yd-text-price', | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |   components: {}, | 
					
						
							|  |  |  |  |   props: { | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |     //货币符号
 | 
					
						
							|  |  |  |  |     symbol: { | 
					
						
							|  |  |  |  |       type: String, | 
					
						
							|  |  |  |  |       default: '¥' | 
					
						
							|  |  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |     price: { | 
					
						
							|  |  |  |  |       type: [String, Number], | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |       default: '' | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |     }, | 
					
						
							|  |  |  |  |     color: { | 
					
						
							|  |  |  |  |       type: String, | 
					
						
							|  |  |  |  |       default: '#333333' | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     //字体大小
 | 
					
						
							|  |  |  |  |     size: { | 
					
						
							|  |  |  |  |       type: [String, Number], | 
					
						
							|  |  |  |  |       default: 15 | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     //整形部分字体大小可单独定义
 | 
					
						
							|  |  |  |  |     intSize: { | 
					
						
							|  |  |  |  |       type: [String, Number], | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |       default: '' | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     //文字装饰,下划线,中划线等
 | 
					
						
							|  |  |  |  |     decoration: { | 
					
						
							|  |  |  |  |       type: String, | 
					
						
							|  |  |  |  |       default: 'none' | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   }, | 
					
						
							|  |  |  |  |   data() { | 
					
						
							|  |  |  |  |     return { | 
					
						
							|  |  |  |  |       textDecoration: this.decoration | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   }, | 
					
						
							|  |  |  |  |   computed: { | 
					
						
							|  |  |  |  |     textArray() { | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |       let array = [] | 
					
						
							|  |  |  |  |       if (this.price === '' || this.price === undefined) { | 
					
						
							|  |  |  |  |         return [] | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       array.push(this.symbol) | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |       if (!/^\d+(\.\d+)?$/.test(this.price)) { | 
					
						
							| 
									
										
										
										
											2022-11-23 00:20:35 +08:00
										 |  |  |  |         console.error('组件<yd-text-price :text="???" 此处参数应为金额数字') | 
					
						
							| 
									
										
										
										
											2022-04-16 22:04:02 +08:00
										 |  |  |  |       } else { | 
					
						
							|  |  |  |  |         let arr = parseFloat(this.price).toFixed(2).split('.') | 
					
						
							|  |  |  |  |         array.push(arr[0]) | 
					
						
							|  |  |  |  |         array.push('.' + arr[1]) | 
					
						
							|  |  |  |  |       } | 
					
						
							|  |  |  |  |       return array | 
					
						
							|  |  |  |  |     }, | 
					
						
							|  |  |  |  |     integerSize() { | 
					
						
							|  |  |  |  |       return this.intSize ? this.intSize : this.size | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | </script> | 
					
						
							| 
									
										
										
										
											2022-04-19 17:58:39 +08:00
										 |  |  |  | <style scoped></style> |