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.

298 lines
6.2 KiB

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