QS-pickerTemplate.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view :style="{'z-index': zIndex}" @touchmove.stop="voidFc()" @tap.prevent.stop="voidFc()">
  3. <view class="mask" :class="[(showPicker?'show':'hide')]" :style="{'z-index': (Number(zIndex) + 1)}" @touchmove.prevent.stop="voidFc()"
  4. @tap.prevent.stop="hide()"></view>
  5. <view class="flex_column" :class="[(mode||'middle'), (showPicker?'show':'hide')]" :style="{'z-index': (Number(zIndex) + 2)}"
  6. @touchmove.prevent.stop="voidFc()" @tap.prevent.stop="voidFc()">
  7. <view class="flex_column" :class="(mode||'middle') + '_view'" :style="{'height': heightSize}">
  8. <view v-if="mode==='bottom'" class="flex_row_between_c width100 padding20rpx" :style="{'font-size': titleSize, 'background-color': bgColor_title||'#f8f8f8'}">
  9. <view class="flex_row_none_c width250rpx " :style="{'color': buttonSet.cancleColor||'#ADADAD'}" @tap="hide()">
  10. {{buttonSet.cancleName||'取消'}}
  11. </view>
  12. <view class="flex_row_c_c width250rpx" :style="{'color': titleColor||'#999'}">
  13. {{title||''}}
  14. </view>
  15. <view class="flex_row_e_c width250rpx" :style="{'color': buttonSet.confirmColor||'#3399FF'}" @tap="confirm()">
  16. {{buttonSet.confirmName||'确定'}}
  17. </view>
  18. </view>
  19. <view v-if="mode==='middle' && title" class="flex_row_c_c width100 padding20rpx" :style="{'font-size': titleSize, 'background-color': bgColor_title||'#f8f8f8', 'color': titleColor||'#999'}">
  20. {{title||''}}
  21. </view>
  22. <slot></slot>
  23. <view v-if="mode==='top'" class="flex_row_between_c width100 padding20rpx" :style="{'font-size': titleSize, 'background-color': bgColor_title||'#f8f8f8'}">
  24. <view class="flex_row_none_c width250rpx " :style="{'color': buttonSet.cancleColor||'#ADADAD'}" @tap="hide()">
  25. {{buttonSet.cancleName||'取消'}}
  26. </view>
  27. <view class="flex_row_c_c width250rpx" :style="{'color': titleColor||'#999'}">
  28. {{title||''}}
  29. </view>
  30. <view class="flex_row_e_c width250rpx" :style="{'color': buttonSet.confirmColor||'#3399FF'}" @tap="confirm()">
  31. {{buttonSet.confirmName||'确定'}}
  32. </view>
  33. </view>
  34. </view>
  35. <view class="flex_row" style="margin-top: 20px;" v-if="mode==='middle'">
  36. <view class="flex_row_c_c width50">
  37. <button :type="buttonSet.cancelType||'default'" @tap="hide()" :style="classObj.btnSize + (buttonSet.cancelStyle||'')">{{buttonSet.cancelName||'取消'}}</button>
  38. </view>
  39. <view class="flex_row_c_c width50">
  40. <button :type="buttonSet.confirmType||'primary'" @tap="confirm()" :style="classObj.btnSize + (buttonSet.confirmStyle||'')">{{buttonSet.confirmName||'确定'}}</button>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import _app from '../../../js/app.js';
  48. const wH = _app.Sys.windowHeight;
  49. const wW = _app.Sys.windowWidth;
  50. export default {
  51. name: 'QS-pickerTemplate',
  52. props: {
  53. height: { //picker高度
  54. type: Number,
  55. default: 0
  56. },
  57. fontScale: { //picker内文字大小
  58. type: Number,
  59. default: .034
  60. },
  61. buttonSet: { //按钮设置
  62. type: Object,
  63. default () {
  64. return {};
  65. }
  66. },
  67. title: { //title标题
  68. type: String,
  69. default: ''
  70. },
  71. mode: {
  72. type: String,
  73. default: 'bottom'
  74. },
  75. zIndex: {
  76. type: [Number, String],
  77. default: 9999
  78. },
  79. bgColor_title: {
  80. type: String,
  81. default: '#F8F8F8'
  82. },
  83. titleColor: {
  84. type: String,
  85. default: '#999'
  86. }
  87. },
  88. data() {
  89. const defaultSize = this.mode === 'middle'?.3:.45;
  90. // console.log('defaultSize:' + defaultSize);
  91. const height = this.height || defaultSize;
  92. // console.log('height:' + height);
  93. const countHeight = wH * (Number(height));
  94. // console.log('countHeight:' + countHeight);
  95. const heightSize = countHeight + 'px';
  96. // console.log('heightSize:' + heightSize);
  97. const defaultFontScale = this.fontScale || .034;
  98. // console.log('defaultFontScale:' + defaultFontScale);
  99. const titleSizeScale = Number(defaultFontScale) + .003;
  100. // console.log('titleSizeScale:' + titleSizeScale);
  101. const countTitleSize = wW * titleSizeScale;
  102. // console.log('countTitleSize:' + countTitleSize);
  103. const titleSize = countTitleSize + 'px';
  104. // console.log('titleSize:' + titleSize);
  105. const countContentSize = wW * Number(defaultFontScale);
  106. // console.log('countContentSize:' + countContentSize);
  107. const contentSize = countContentSize + 'px';
  108. // console.log('contentSize:' + contentSize);
  109. return {
  110. showPicker: false,
  111. classObj: {
  112. btnSize: 'font-size: ' + (wW * (this.fontScale + .005)) + 'px;',
  113. },
  114. heightSize,
  115. titleSize,
  116. contentSize
  117. };
  118. },
  119. watch: {
  120. height() {
  121. this.countPickerHeight();
  122. }
  123. },
  124. methods: {
  125. countPickerHeight() {
  126. const defaultSize = this.mode === 'middle'?.3:.45;
  127. const height = this.height || defaultSize;
  128. this.$set(this, 'heightSize', (wH * height + 'px'));
  129. },
  130. confirm() {
  131. this.$emit('confirm');
  132. },
  133. show() {
  134. this.showPicker = true;
  135. },
  136. hide() {
  137. this.showPicker = false;
  138. },
  139. voidFc() {}
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. @import url("../css/QS-picker.css");
  145. </style>