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.

283 lines
5.8 KiB

2 years ago
2 years ago
  1. <template>
  2. <view class="key-container" v-show="showMask">
  3. <uni-transition :modeClass="['slide-bottom']" :show="show"
  4. :styles="{height:'100vh'}"
  5. :duration="duration">
  6. <view class="key-content" @click.stop>
  7. <slot></slot>
  8. <view class="key-box block flex">
  9. <view class="key-left">
  10. <view class="key-top flex flex-wrap">
  11. <view class="btn-box" v-for="(item,index) in numArr" :key="index">
  12. <button hover-class="active" class="cu-btn key-btn text-black text-xl" @click.stop="keydown(item)">{{item}}</button>
  13. </view>
  14. </view>
  15. <view class="key-bottom">
  16. <view class="btn-zero">
  17. <button hover-class="active" class="cu-btn key-btn text-black text-xl" @click.stop="keydown('0')">0</button>
  18. </view>
  19. <view class="btn-point">
  20. <button hover-class="active" class="cu-btn key-btn text-black text-xl" @click.stop="keydown('.')">.</button>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="key-right">
  25. <view class="del">
  26. <button hover-class="active" class="cu-btn key-btn text-black text-xl" @click.stop="del">
  27. <text class="zm iconbackspace text-xl"></text>
  28. </button>
  29. </view>
  30. <view class="confirm">
  31. <button hover-class="active" :style="[confirmStyle]" class="cu-btn" @click.stop="confirm">
  32. <text class="confirm-text">{{confirmText}}</text>
  33. </button>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </uni-transition>
  39. </view>
  40. </template>
  41. <script>
  42. /**
  43. * 付款组件
  44. * @property {Number} duration - 弹出动画时长默认为300
  45. * @event {Function} change - 数字改变触发参数为数字
  46. * @event {Function} confirm - 付款时触发参数为数字
  47. * @event {Function} hide - 关闭键盘触发参数为空
  48. */
  49. // 使用方法,查看同级目录exmple
  50. import uniTransition from '../uni-transition/uni-transition.vue'
  51. export default{
  52. components:{
  53. uniTransition
  54. },
  55. props:{
  56. duration:{
  57. type:Number,//弹出动画时常
  58. default:300
  59. },
  60. confirmText:{
  61. type:String,
  62. default:'付款'
  63. },
  64. confirmStyle:{
  65. type:Object,
  66. default:()=>{
  67. return{
  68. backgroundColor:'#57BE6D'
  69. }
  70. }
  71. }
  72. },
  73. data(){
  74. return{
  75. value:'',//输出的值
  76. show:false,//显示键盘
  77. showMask:false,//遮罩层
  78. numArr:[1,2,3,4,5,6,7,8,9]
  79. }
  80. },
  81. watch:{
  82. value(newval,oldval){
  83. this.$emit("change",newval);
  84. }
  85. },
  86. methods:{
  87. close(){
  88. return
  89. this.show = false;
  90. setTimeout(()=>{
  91. this.showMask = false;
  92. },this.duration)
  93. },
  94. open(){
  95. this.value = '';
  96. this.show = true;
  97. this.showMask = true;
  98. },
  99. del(){
  100. if(this.value.length){
  101. this.value = this.value.slice(0,this.value.length-1);
  102. }
  103. },
  104. keydown(e){
  105. switch(e){
  106. case '.':
  107. // 当输入为点的时候,如果第一次输入点,则补零
  108. if(!this.value.length){
  109. this.value = '0.';
  110. }else{
  111. if(this.value.indexOf('.')>-1){
  112. // 如果已经有点,则无效
  113. }else{
  114. this.value = this.value+''+e;
  115. }
  116. }
  117. break;
  118. case '0':
  119. if(this.value.length === 0){
  120. this.value = this.value+''+e;
  121. }
  122. if(Number(this.value) === 0 && this.value.indexOf('.')== -1){
  123. // 当输入为零的时候,如果value转换成数字为零,且没有点则无效
  124. }else{
  125. this.value = this.value+''+e;
  126. }
  127. break;
  128. default:
  129. this.value = this.value+''+e;
  130. break;
  131. }
  132. },
  133. hide(){
  134. this.$emit('hide');
  135. this.close();
  136. },
  137. confirm(){
  138. this.$emit('confirm',this.value);
  139. this.close();
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. @font-face {
  146. font-family: 'zm'; /* project id 2442084 */
  147. src: url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.eot');
  148. src: url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.eot?#iefix') format('embedded-opentype'),
  149. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.woff2') format('woff2'),
  150. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.woff') format('woff'),
  151. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.ttf') format('truetype'),
  152. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.svg#zm') format('svg');
  153. }
  154. .zm {
  155. font-family: "zm" !important;
  156. font-size: 16px;
  157. font-style: normal;
  158. -webkit-font-smoothing: antialiased;
  159. -moz-osx-font-smoothing: grayscale;
  160. }
  161. .iconbackspace:before {
  162. content: "\ef11";
  163. }
  164. .flex{
  165. display: flex;
  166. }
  167. .flex-wrap{
  168. flex-wrap: wrap;
  169. }
  170. .cu-btn {
  171. position: relative;
  172. border: 0rpx;
  173. display: inline-flex;
  174. align-items: center;
  175. justify-content: center;
  176. box-sizing: border-box;
  177. padding: 0 30rpx;
  178. font-size: 28rpx;
  179. height: 64rpx;
  180. line-height: 1;
  181. text-align: center;
  182. text-decoration: none;
  183. overflow: visible;
  184. margin-left: initial;
  185. transform: translate(0rpx, 0rpx);
  186. margin-right: initial;
  187. }
  188. .cu-btn::after {
  189. display: none;
  190. }
  191. .text-xl{
  192. font-size:36rpx;
  193. font-weight: bold;
  194. font-family: 'microsoft-yahei';
  195. }
  196. .text-black{
  197. color:#333;
  198. }
  199. .active{
  200. background-color: #ddd !important;
  201. transform: translate(2rpx,2rpx);
  202. }
  203. .key-container{
  204. position: fixed;
  205. bottom: 0;
  206. top:0;
  207. left:0;
  208. right:0;
  209. .key-content{
  210. position: absolute;
  211. bottom: 0;
  212. width: 100vw;
  213. background-color: #F7F7F7;
  214. }
  215. }
  216. .key-box{
  217. width: 100%;
  218. box-sizing: border-box;
  219. padding:10rpx 10rpx 0;
  220. .key-left{
  221. width: 75%;
  222. }
  223. .key-right{
  224. width: 25%;
  225. display: flex;
  226. flex-direction: column;
  227. }
  228. .key-bottom{
  229. width: 100%;
  230. display: flex;
  231. }
  232. }
  233. .del{
  234. width: 100%;
  235. }
  236. .btn-box{
  237. width: 33.33%;
  238. padding:0 10rpx 10rpx 0;
  239. box-sizing: border-box;
  240. }
  241. .btn-zero{
  242. width: 66.66%;
  243. padding:0 10rpx 10rpx 0;
  244. box-sizing: border-box;
  245. }
  246. .btn-point{
  247. width: 33.33%;
  248. padding:0 10rpx 10rpx 0;
  249. box-sizing: border-box;
  250. }
  251. .key-right{
  252. flex-shrink: 0;
  253. }
  254. .key-btn{
  255. background-color: #fff;
  256. width: 100%;
  257. height: 90rpx;
  258. }
  259. .confirm{
  260. width: 100%;
  261. flex:1;
  262. padding: 10rpx 0 10rpx 0;
  263. box-sizing: border-box;
  264. button{
  265. width: 100%;
  266. height: 100%;
  267. .confirm-text{
  268. color:#fff;
  269. display: block;
  270. font-size: 32rpx;
  271. }
  272. }
  273. }
  274. </style>