DialogBoxW3.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="page-total" v-if="isShow">
  3. <view class="box" :class="AClass[AnIndex][AnIdx]">
  4. <view class="dialog-box">
  5. <view class="close" @click="onCancel">
  6. <image src="../../static/w3/dialog_close.png" mode="widthFix"></image>
  7. </view>
  8. <view class="title">{{options.title}}</view>
  9. <view class="content" v-if="options.DialogType == 'input'">
  10. <input type="text" v-model="options.value" :placeholder="options.placeholder">
  11. <text class="iconfont icon-clear" @click.stop="onClear"></text>
  12. </view>
  13. <view class="inquiry" v-else-if="options.DialogType == 'inquiry'">
  14. <text>{{options.content}}</text>
  15. </view>
  16. <view class="operation-btn">
  17. <view class="btn1" @click="onCancel">
  18. <text>{{options.btn1}}</text>
  19. </view>
  20. <view class="btn2" @click="onConfirm">
  21. <text class="activity">{{options.btn2}}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. AClass: [
  33. ['a-fadein', 'a-fadeout'],
  34. ['a-bouncein', 'a-bounceout'],
  35. ],
  36. AnIndex: 0,
  37. AnIdx: 0,
  38. isShow: false,
  39. SetTime: null,
  40. value: '',
  41. // parmoise
  42. resolve: '',
  43. reject: '',
  44. promise: '',
  45. // 配置
  46. options: {
  47. // 提示标题
  48. title: '',
  49. // 内容
  50. content: '',
  51. btn1: '',
  52. btn2: '',
  53. // 提示内容
  54. placeholder: '请输入内容',
  55. // 提示框类型
  56. DialogType: 'input',
  57. // 动画类型
  58. animation: 0,
  59. },
  60. };
  61. },
  62. props: {
  63. // 提示标题
  64. title: {
  65. type: String,
  66. default: '提示',
  67. },
  68. // 内容
  69. content: {
  70. type: String,
  71. default: '',
  72. },
  73. // 提示内容
  74. placeholder: {
  75. type: String,
  76. default: '请输入内容',
  77. },
  78. // 提示框类型
  79. DialogType: {
  80. type: String,
  81. default: 'input'
  82. },
  83. // 动画类型
  84. animation: {
  85. type: Number,
  86. default: 0
  87. }
  88. },
  89. methods: {
  90. // 询问框
  91. confirm(options) {
  92. this.AnIndex = options.animation || 0;
  93. this.AnIdx = options.animation || 0;
  94. this.options = {
  95. // 提示标题
  96. title: options.title || '',
  97. // 内容
  98. content: options.content || '',
  99. btn1: options.btn1 || '',
  100. btn2: options.btn2 || '',
  101. // 提示内容
  102. placeholder: options.placeholder || '请输入内容',
  103. // 提示框类型
  104. DialogType: options.DialogType || 'input',
  105. // 动画类型
  106. animation: options.animation || 0,
  107. // input输入的值
  108. value: options.value || '',
  109. };
  110. this.show();
  111. this.promise = new Promise((resolve, reject) => {
  112. this.resolve = resolve;
  113. this.reject = reject;
  114. });
  115. return this.promise; //返回promise对象,给父级组件调用
  116. },
  117. /**
  118. * 显示
  119. */
  120. show(callback) {
  121. this.isShow = true;
  122. },
  123. /**
  124. * 隐藏
  125. */
  126. hide() {
  127. this.AnIdx = 1;
  128. this.SetTime = setTimeout(() => {
  129. this.isShow = false;
  130. }, 300);
  131. },
  132. /**
  133. * 清除输入值
  134. */
  135. onClear() {
  136. this.options.value = '';
  137. },
  138. /**
  139. * 取消点击
  140. */
  141. onCancel() {
  142. this.hide();
  143. this.reject({
  144. value: this.options.value,
  145. isConfirm: true,
  146. });
  147. },
  148. /**
  149. * 确定点击
  150. */
  151. onConfirm() {
  152. this.hide();
  153. this.resolve({
  154. value: this.options.value,
  155. isConfirm: true,
  156. });
  157. },
  158. },
  159. }
  160. </script>
  161. <style scoped lang="scss">
  162. @import 'DialogBoxW3.scss'
  163. </style>