slambb-picker.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <view class="padding-sm">
  4. <view class=" text-center text-black text-bold padding-bottom-sm margin-sm">{{currentPicker.pickerTitle}}</view>
  5. <view v-if="currentPicker.showInput" class="flex justify-center">
  6. <input class="picker-input" maxlength="4" @input="onKeyInput" placeholder-style="font-size:10px;" placeholder="直接输入" />
  7. <view class="make-text-bPurple">{{currentPicker.pickerUnit}}</view>
  8. </view>
  9. <pickerItem v-if="currentPicker.pickerType=='doubleItem'" :itemObj="currentPicker" :bDouble="true" @bindChangeItem="bindChange"
  10. @touchstart="onStart">
  11. </pickerItem>
  12. <pickerItem v-else-if="currentPicker.pickerType=='singleItem'" :itemObj="currentPicker" :bDouble="false"
  13. @bindChangeItem="bindChange" @touchstart="onStart">
  14. </pickerItem>
  15. <pickerCity v-else-if="currentPicker.pickerType == 'city'" :itemObj="currentPicker" @bindChangeCity="bindChange"></pickerCity>
  16. <pickerDateItem v-else @bindChangeDate="bindChange" @touchstart="onStart"></pickerDateItem>
  17. </view>
  18. <view class="flex justify-center cu-bar margin-bottom">
  19. <view class="action left-button " :class="bRolling?'bDisable':''" @tap="onConfirm">确定</view>
  20. <view class="action right-button" @tap="onCancel">取消</view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import pickerItem from "@/components/slambb-picker/slambb-picker-item.vue";
  26. import pickerDateItem from "@/components/slambb-picker/slambb-picker-date.vue";
  27. import pickerCity from "@/components/slambb-picker/slambb-picker-city.vue";
  28. export default {
  29. components: {
  30. pickerItem,
  31. pickerDateItem,
  32. pickerCity
  33. },
  34. props: {
  35. //对象
  36. pickerObj: Object,
  37. pickerTitle: {
  38. type: String,
  39. default: ""
  40. },
  41. pickerType: {
  42. type: String,
  43. default: ""
  44. },
  45. pickerLeftList: Array,
  46. pickerRightList: Array,
  47. pickerUnit: {
  48. type: String,
  49. default: ""
  50. },
  51. },
  52. data() {
  53. return {
  54. confirmValue: 0,
  55. valueIndex: 0,
  56. currentPicker: this.pickerObj,
  57. //是否正在滚动
  58. bRolling: false
  59. }
  60. },
  61. watch: {
  62. pickerObj(val) {
  63. // 重新赋值
  64. console.log('watch pickerObj:', val);
  65. this.currentPicker = val;
  66. this.confirmValue = 0;
  67. this.valueIndex = 0;
  68. }
  69. },
  70. methods: {
  71. onStart() {
  72. console.log('onStart')
  73. this.bRolling = true;
  74. },
  75. bindChange(value, index) {
  76. this.bRolling = false;
  77. // console.log('bindChange=', value, index);
  78. this.confirmValue = value;
  79. this.valueIndex = index;
  80. },
  81. onConfirm() {
  82. if (this.bRolling) {
  83. uni.showToast({
  84. title: '请等待滚动完成',
  85. icon: "none"
  86. })
  87. return;
  88. }
  89. this.$emit("confirmEvent", {
  90. type: this.currentPicker.pickerType,
  91. value: this.confirmValue,
  92. index: this.valueIndex
  93. })
  94. },
  95. onCancel() {
  96. this.$emit("cancelEvent")
  97. },
  98. onKeyInput(event) {
  99. // !(/(^[1-9]\d*$)/).test(event.target.value)
  100. if (isNaN(event.target.value)) {
  101. //如果不是数字...
  102. // uni.showToast({
  103. // title: '输入正整数',
  104. // icon:'none',
  105. // mask:true
  106. // })
  107. this.confirmValue = 1;
  108. } else {
  109. this.confirmValue = Math.abs(event.target.value);
  110. }
  111. console.log("this.confirmValue:", this.confirmValue);
  112. // this.$set(this.currentPicker, 'defaultValue', this.confirmValue);
  113. }
  114. }
  115. }
  116. </script>
  117. <style>
  118. .cu-dialog {
  119. width: 100%;
  120. border-top-left-radius: 20upx;
  121. border-top-right-radius: 20upx;
  122. }
  123. .left-button,
  124. .right-button {
  125. margin-bottom: 20upx;
  126. padding: 15upx 60upx;
  127. background-color: #FFFFFF;
  128. }
  129. .bDisable {
  130. /* background-color: ;
  131. */
  132. opacity: 0.5;
  133. }
  134. .left-button {
  135. border-top-left-radius: 20px;
  136. border-bottom-left-radius: 20px;
  137. border-right: 1upx solid #E6E6E6;
  138. /* color:rgba(245, 245, 245, 1); */
  139. }
  140. .right-button {
  141. border-top-right-radius: 20px;
  142. border-bottom-right-radius: 20px;
  143. }
  144. .picker-input {
  145. margin-left: 20rpx;
  146. margin-right: 20rpx;
  147. border: 1rpx solid #AAAAAA;
  148. background-color: #FFFFFF;
  149. width: 330rpx;
  150. border-radius: 5px;
  151. }
  152. </style>