uni-popup-dialog.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="uni-popup-dialog">
  3. <view class="uni-dialog-title">
  4. <text class="uni-dialog-title-text" :class="['uni-popup__'+dialogType]">{{title}}</text>
  5. </view>
  6. <view class="uni-dialog-content">
  7. <text class="uni-dialog-content-text" v-if="mode === 'base'">{{content}}</text>
  8. <input v-else class="uni-dialog-input" v-model="val" type="text" :placeholder="placeholder" :focus="focus">
  9. </view>
  10. <view class="uni-dialog-picker" v-if="isSkm">
  11. <picker @change="bindPickerChange" :value="index" :range="array">
  12. <view class="picker-val">支付方式:{{array[index]}}</view>
  13. </picker>
  14. </view>
  15. <view class="uni-dialog-button-group">
  16. <view class="uni-dialog-button" @click="close">
  17. <text class="uni-dialog-button-text">取消</text>
  18. </view>
  19. <view class="uni-dialog-button uni-border-left" @click="onOk">
  20. <text class="uni-dialog-button-text uni-button-color">确定</text>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. /**
  27. * PopUp 弹出层-对话框样式
  28. * @description 弹出层-对话框样式
  29. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  30. * @property {String} value input 模式下的默认值
  31. * @property {String} placeholder input 模式下输入提示
  32. * @property {String} type = [success|warning|info|error] 主题样式
  33. * @value success 成功
  34. * @value warning 提示
  35. * @value info 消息
  36. * @value error 错误
  37. * @property {String} mode = [base|input] 模式、
  38. * @value base 基础对话框
  39. * @value input 可输入对话框
  40. * @property {String} content 对话框内容
  41. * @property {Boolean} beforeClose 是否拦截取消事件
  42. * @event {Function} confirm 点击确认按钮触发
  43. * @event {Function} close 点击取消按钮触发
  44. */
  45. export default {
  46. name: "uniPopupDialog",
  47. props: {
  48. value: {
  49. type: [String, Number],
  50. default: ''
  51. },
  52. placeholder: {
  53. type: [String, Number],
  54. default: '请输入内容'
  55. },
  56. /**
  57. * 对话框主题 success/warning/info/error 默认 success
  58. */
  59. type: {
  60. type: String,
  61. default: 'error'
  62. },
  63. /**
  64. * 对话框模式 base/input
  65. */
  66. mode: {
  67. type: String,
  68. default: 'base'
  69. },
  70. /**
  71. * 对话框标题
  72. */
  73. title: {
  74. type: String,
  75. default: '提示'
  76. },
  77. /**
  78. * 对话框内容
  79. */
  80. content: {
  81. type: String,
  82. default: ''
  83. },
  84. /**
  85. * 拦截取消事件 ,如果拦截取消事件,必须监听close事件,执行 done()
  86. */
  87. beforeClose: {
  88. type: Boolean,
  89. default: false
  90. },
  91. isSkm: {
  92. type: Boolean,
  93. default: false
  94. }
  95. },
  96. data() {
  97. return {
  98. dialogType: 'error',
  99. focus: false,
  100. val: "",
  101. array: ['余额','消费券','积分'],
  102. index:0
  103. }
  104. },
  105. inject: ['popup'],
  106. watch: {
  107. type(val) {
  108. this.dialogType = val
  109. },
  110. mode(val) {
  111. if (val === 'input') {
  112. this.dialogType = 'info'
  113. }
  114. },
  115. value(val) {
  116. this.val = val
  117. },
  118. },
  119. created() {
  120. // 对话框遮罩不可点击
  121. this.popup.mkclick = false
  122. if (this.mode === 'input') {
  123. this.dialogType = 'info'
  124. this.val = this.value
  125. } else {
  126. this.dialogType = this.type
  127. }
  128. },
  129. mounted() {
  130. this.focus = true
  131. },
  132. methods: {
  133. /**
  134. * 点击确认按钮
  135. */
  136. onOk() {
  137. this.$emit('confirm', () => {
  138. this.popup.close()
  139. if (this.mode === 'input') this.val = this.value
  140. }, this.mode === 'input' ? this.val : '')
  141. },
  142. /**
  143. * 点击取消按钮
  144. */
  145. close() {
  146. if (this.beforeClose) {
  147. this.$emit('close', () => {
  148. this.popup.close()
  149. })
  150. return
  151. }
  152. this.popup.close()
  153. },
  154. // 改变支付方式
  155. bindPickerChange(e) {
  156. this.index = e.target.value
  157. this.$emit('changeShowPayType',this.index)
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .uni-popup-dialog {
  164. width: 300px;
  165. border-radius: 15px;
  166. background-color: #fff;
  167. }
  168. .uni-dialog-title {
  169. /* #ifndef APP-NVUE */
  170. display: flex;
  171. /* #endif */
  172. flex-direction: row;
  173. justify-content: center;
  174. padding-top: 15px;
  175. padding-bottom: 5px;
  176. }
  177. .uni-dialog-title-text {
  178. font-size: 16px;
  179. font-weight: 500;
  180. }
  181. .uni-dialog-content {
  182. /* #ifndef APP-NVUE */
  183. display: flex;
  184. /* #endif */
  185. flex-direction: row;
  186. justify-content: center;
  187. align-items: center;
  188. padding: 5px 15px 15px 15px;
  189. }
  190. .uni-dialog-content-text {
  191. font-size: 14px;
  192. color: #6e6e6e;
  193. }
  194. .uni-dialog-button-group {
  195. /* #ifndef APP-NVUE */
  196. display: flex;
  197. /* #endif */
  198. flex-direction: row;
  199. border-top-color: #f5f5f5;
  200. border-top-style: solid;
  201. border-top-width: 1px;
  202. }
  203. .uni-dialog-button {
  204. /* #ifndef APP-NVUE */
  205. display: flex;
  206. /* #endif */
  207. flex: 1;
  208. flex-direction: row;
  209. justify-content: center;
  210. align-items: center;
  211. height: 45px;
  212. }
  213. .uni-border-left {
  214. border-left-color: #f0f0f0;
  215. border-left-style: solid;
  216. border-left-width: 1px;
  217. }
  218. .uni-dialog-button-text {
  219. font-size: 14px;
  220. }
  221. .uni-button-color {
  222. color: $uni-color-primary;
  223. }
  224. .uni-dialog-input {
  225. flex: 1;
  226. font-size: 14px;
  227. }
  228. .uni-popup__success {
  229. color: $uni-color-success;
  230. }
  231. .uni-popup__warn {
  232. color: $uni-color-warning;
  233. }
  234. .uni-popup__error {
  235. color: $uni-color-error;
  236. }
  237. .uni-popup__info {
  238. color: #909399;
  239. }
  240. .picker-val {
  241. padding: 0rpx 0 30rpx 30rpx;
  242. // text-align: center;
  243. font-size: 14px;
  244. width: 100%;
  245. // background-color: red;
  246. }
  247. </style>