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.

282 lines
5.8 KiB

  1. <template>
  2. <view class="key-container" @click="hide" 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. this.show = false;
  89. setTimeout(()=>{
  90. this.showMask = false;
  91. },this.duration)
  92. },
  93. open(){
  94. this.value = '';
  95. this.show = true;
  96. this.showMask = true;
  97. },
  98. del(){
  99. if(this.value.length){
  100. this.value = this.value.slice(0,this.value.length-1);
  101. }
  102. },
  103. keydown(e){
  104. switch(e){
  105. case '.':
  106. // 当输入为点的时候,如果第一次输入点,则补零
  107. if(!this.value.length){
  108. this.value = '0.';
  109. }else{
  110. if(this.value.indexOf('.')>-1){
  111. // 如果已经有点,则无效
  112. }else{
  113. this.value = this.value+''+e;
  114. }
  115. }
  116. break;
  117. case '0':
  118. if(this.value.length === 0){
  119. this.value = this.value+''+e;
  120. }
  121. if(Number(this.value) === 0 && this.value.indexOf('.')== -1){
  122. // 当输入为零的时候,如果value转换成数字为零,且没有点则无效
  123. }else{
  124. this.value = this.value+''+e;
  125. }
  126. break;
  127. default:
  128. this.value = this.value+''+e;
  129. break;
  130. }
  131. },
  132. hide(){
  133. this.$emit('hide');
  134. this.close();
  135. },
  136. confirm(){
  137. this.$emit('confirm',this.value);
  138. this.close();
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. @font-face {
  145. font-family: 'zm'; /* project id 2442084 */
  146. src: url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.eot');
  147. src: url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.eot?#iefix') format('embedded-opentype'),
  148. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.woff2') format('woff2'),
  149. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.woff') format('woff'),
  150. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.ttf') format('truetype'),
  151. url('https://at.alicdn.com/t/font_2442084_o72ps3802ih.svg#zm') format('svg');
  152. }
  153. .zm {
  154. font-family: "zm" !important;
  155. font-size: 16px;
  156. font-style: normal;
  157. -webkit-font-smoothing: antialiased;
  158. -moz-osx-font-smoothing: grayscale;
  159. }
  160. .iconbackspace:before {
  161. content: "\ef11";
  162. }
  163. .flex{
  164. display: flex;
  165. }
  166. .flex-wrap{
  167. flex-wrap: wrap;
  168. }
  169. .cu-btn {
  170. position: relative;
  171. border: 0rpx;
  172. display: inline-flex;
  173. align-items: center;
  174. justify-content: center;
  175. box-sizing: border-box;
  176. padding: 0 30rpx;
  177. font-size: 28rpx;
  178. height: 64rpx;
  179. line-height: 1;
  180. text-align: center;
  181. text-decoration: none;
  182. overflow: visible;
  183. margin-left: initial;
  184. transform: translate(0rpx, 0rpx);
  185. margin-right: initial;
  186. }
  187. .cu-btn::after {
  188. display: none;
  189. }
  190. .text-xl{
  191. font-size:36rpx;
  192. font-weight: bold;
  193. font-family: 'microsoft-yahei';
  194. }
  195. .text-black{
  196. color:#333;
  197. }
  198. .active{
  199. background-color: #ddd !important;
  200. transform: translate(2rpx,2rpx);
  201. }
  202. .key-container{
  203. position: fixed;
  204. bottom: 0;
  205. top:0;
  206. left:0;
  207. right:0;
  208. .key-content{
  209. position: absolute;
  210. bottom: 0;
  211. width: 100vw;
  212. background-color: #F7F7F7;
  213. }
  214. }
  215. .key-box{
  216. width: 100%;
  217. box-sizing: border-box;
  218. padding:10rpx 10rpx 0;
  219. .key-left{
  220. width: 75%;
  221. }
  222. .key-right{
  223. width: 25%;
  224. display: flex;
  225. flex-direction: column;
  226. }
  227. .key-bottom{
  228. width: 100%;
  229. display: flex;
  230. }
  231. }
  232. .del{
  233. width: 100%;
  234. }
  235. .btn-box{
  236. width: 33.33%;
  237. padding:0 10rpx 10rpx 0;
  238. box-sizing: border-box;
  239. }
  240. .btn-zero{
  241. width: 66.66%;
  242. padding:0 10rpx 10rpx 0;
  243. box-sizing: border-box;
  244. }
  245. .btn-point{
  246. width: 33.33%;
  247. padding:0 10rpx 10rpx 0;
  248. box-sizing: border-box;
  249. }
  250. .key-right{
  251. flex-shrink: 0;
  252. }
  253. .key-btn{
  254. background-color: #fff;
  255. width: 100%;
  256. height: 90rpx;
  257. }
  258. .confirm{
  259. width: 100%;
  260. flex:1;
  261. padding: 10rpx 0 10rpx 0;
  262. box-sizing: border-box;
  263. button{
  264. width: 100%;
  265. height: 100%;
  266. .confirm-text{
  267. color:#fff;
  268. display: block;
  269. font-size: 32rpx;
  270. }
  271. }
  272. }
  273. </style>