prompt.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="prompt-box" :hidden="isHidden">
  3. <view class="prompt-content contentFontColor">
  4. <view class="prompt-title">{{title}}</view>
  5. <view class="prompt-text">{{text}}</view>
  6. <input class="prompt-input" type="text" @input="_input" :value="cost" :placeholder="placeholder"/>
  7. <view class="prompt-btn-group">
  8. <button class="btn-item prompt-certain-btn" @tap="_confirm">{{btn_certain}}</button>
  9. <button class="btn-item prompt-cancel-btn contentFontColor" @tap="_cancel">{{btn_cancel}}</button>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. multipleSlots: true,// 在组件定义时的选项中启用多slot支持
  19. isHidden: true,
  20. plac:''
  21. };
  22. },
  23. props:{
  24. title: {
  25. type: String,
  26. default: '提示'
  27. },
  28. btn_cancel: {
  29. type: String,
  30. default: '取消'
  31. },
  32. btn_certain: {
  33. type: String,
  34. default: '确定'
  35. },
  36. text:{
  37. type: String,
  38. default: '',
  39. },
  40. placeholder:{
  41. type:String,
  42. default:''
  43. },
  44. cost: {
  45. type: String,
  46. default: ''
  47. },
  48. },
  49. watch:{
  50. },
  51. methods: {
  52. hide: function () {
  53. this.isHidden=true;
  54. },
  55. show(e) {
  56. this.isHidden=false;
  57. if(e!=null&&e!=undefined&&e!=""){
  58. this.text = e;
  59. }
  60. },
  61. /*
  62. * 内部私有方法建议以下划线开头
  63. * triggerEvent 用于触发事件
  64. */
  65. _cancel () {
  66. //触发cancel事件,即在外部,在组件上绑定cancel事件即可,bind:cancel,像绑定tap一样
  67. // this.cost = '';
  68. this.hide();
  69. this.$emit('onCancel');
  70. },
  71. _confirm () {
  72. //this.triggerEvent("confirm");
  73. // console.log(this.cost);
  74. this.$emit('onConfirm', this.cost);
  75. // this.cost = '';
  76. },
  77. _input(e){
  78. //将参数传出去,这样在getInput函数中可以通过e去获得必要的参数
  79. //this.triggerEvent("getInput",e.detail);
  80. this.cost = e.detail.value;
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. /* components/vas-prompt/vas-prompt.wxss */
  87. .prompt-box {
  88. position: absolute;
  89. left: 0;
  90. top: 0;
  91. width: 100%;
  92. height: 100%;
  93. z-index: 11;
  94. background: rgba(0, 0, 0, 0.5);
  95. }
  96. .prompt-content {
  97. position: absolute;
  98. left: 50%;
  99. top: 40%;
  100. width: 80%;
  101. max-width: 600rpx;
  102. border: 2rpx solid #ccc;
  103. border-radius: 10rpx;
  104. box-sizing: bordre-box;
  105. transform: translate(-50%, -50%);
  106. overflow: hidden;
  107. background: #fff;
  108. }
  109. .prompt-title {
  110. width: 100%;
  111. padding: 10rpx;
  112. text-align: center;
  113. font-size: 30rpx;
  114. border-bottom: 2rpx solid #eee;
  115. color:#333;
  116. font-weight: 600;
  117. }
  118. .prompt-input{
  119. margin: 8%;
  120. padding: 10rpx 15rpx;
  121. width: 80%;
  122. height:60rpx;
  123. border: 1px solid #ccc;
  124. border-radius: 10rpx;
  125. }
  126. .prompt-btn-group{
  127. display: flex;
  128. }
  129. .btn-item {
  130. width: 35%;
  131. margin-bottom: 20rpx;
  132. height: 60rpx;
  133. line-height: 60rpx;
  134. background-color: white;
  135. justify-content: space-around;
  136. }
  137. .prompt-certain-btn{
  138. color: white;
  139. background-color: #2319dc;
  140. }
  141. .prompt-cancel-btn{
  142. background-color: #dddddd;
  143. color:#111;
  144. }
  145. .contentFontColor {
  146. color: #868686;
  147. }
  148. .prompt-text{
  149. margin-top:10rpx;
  150. font-size:30rpx;
  151. }
  152. </style>