input.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="desc">
  3. <uni-row>
  4. <uni-col :span="labelSize">
  5. <view class="desc" style="font-size: 25rpx;">
  6. {{label}}
  7. </view>
  8. </uni-col>
  9. <uni-col :span="inputSpan">
  10. <view style="padding: 0 10rpx 0 0;">
  11. <uni-easyinput v-if="model === 'input'" primaryColor="#37babd" v-model="val" @input="input"
  12. :disabled="disabled">
  13. </uni-easyinput>
  14. <uni-datetime-picker v-if="model === 'date'" type="date" :clear-icon="false" v-model="val"
  15. :disabled="disabled" />
  16. <view v-if="model === 'search'" class="pickerView pickerText">
  17. <view @click="openSearch" class="pickerText" v-if="val">
  18. {{val}}
  19. </view>
  20. <view @click="openSearch" class="pickerText" v-else>
  21. 待 选 择
  22. </view>
  23. </view>
  24. <u-number-box v-if="model === 'number'" v-model="val" @change="changeNumber"></u-number-box>
  25. </view>
  26. </uni-col>
  27. <uni-col :span="2" v-if="unit">
  28. <view style="padding: 10rpx 5rpx 0 2rpx;color: #818181;font-size: 20rpx;">
  29. {{unit}}
  30. </view>
  31. </uni-col>
  32. </uni-row>
  33. <view class="desc">
  34. <uni-easyinput v-if="model === 'textarea'" type="textarea" primaryColor="#37babd" v-model="val"
  35. @input="input" :disabled="disabled">
  36. </uni-easyinput>
  37. </view>
  38. <uni-popup ref="searchPopup" background-color="#fff">
  39. <view style="height: 800rpx;">
  40. <view style="padding: 30rpx;">
  41. <u-search v-model="searchText" :show-action="false" placeholder="快捷搜索" @change="getSearchApiData()">
  42. </u-search>
  43. </view>
  44. <view style="padding: 5rpx;">
  45. <uni-list v-for="item in searchData">
  46. <uni-list-item :clickable="true" @click="dataToValue(item)" :title="item[searchLabelKey]" />
  47. </uni-list>
  48. </view>
  49. </view>
  50. </uni-popup>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. name: 'hs-input',
  56. props: {
  57. value: {
  58. Type: String,
  59. default: null
  60. },
  61. label: {
  62. Type: String,
  63. default: ''
  64. },
  65. unit: {
  66. Type: String,
  67. default: ''
  68. },
  69. model: {
  70. Type: String,
  71. default: 'input'
  72. },
  73. labelSize: {
  74. Type: Number,
  75. default: 5
  76. },
  77. inputSpan: {
  78. Type: Number,
  79. default: 19
  80. },
  81. searchLabelKey: {
  82. Type: String,
  83. default: 'name'
  84. },
  85. searchApi: {
  86. Type: String,
  87. default: null
  88. },
  89. disabled: false
  90. },
  91. data() {
  92. return {
  93. val: '',
  94. searchText: ''
  95. }
  96. },
  97. watch: {
  98. value(newVal) {
  99. this.val = newVal
  100. },
  101. modelValue(newVal) {
  102. this.val = newVal
  103. }
  104. },
  105. mounted() {
  106. },
  107. methods: {
  108. input: function(e) {
  109. this.$emit('input', this.val)
  110. },
  111. openSearch() {
  112. console.log('click ---> Test')
  113. this.$refs.searchPopup.open('bottom')
  114. },
  115. changeNumber(e) {
  116. this.$emit('change', this.val)
  117. },
  118. //获取/查询 信息
  119. async getSearchApiData() {
  120. const {
  121. data: res
  122. } = await this.$httpRequest({
  123. url: '/app/' + this.searchApi + this.searchText,
  124. urlType: this.$getUrlType()
  125. });
  126. if (res.code === 200) {
  127. this.searchData = res.data
  128. }
  129. },
  130. //选择赋值给value
  131. dataToValue(item) {
  132. this.$emit('input', item[this.searchLabelKey])
  133. this.$refs.searchPopup.close()
  134. },
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .desc {
  140. padding: 10rpx 15rpx 0 15rpx;
  141. color: #818181;
  142. font-size: 20rpx;
  143. }
  144. .pickerView {
  145. // align-items: flex-end;
  146. padding: 10rpx 20rpx;
  147. border: 1rpx #eeeeee solid;
  148. }
  149. .pickerText {
  150. font-size: 26rpx;
  151. color: #b1b1b1;
  152. }
  153. </style>