耀实惠小程序
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.

278 lines
5.5 KiB

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