input.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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" @change="change" />
  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. change: function(e) {
  109. this.$emit('input', e)
  110. },
  111. input: function(e) {
  112. this.$emit('input', this.val)
  113. },
  114. openSearch() {
  115. console.log('click ---> Test')
  116. this.$refs.searchPopup.open('bottom')
  117. },
  118. changeNumber(e) {
  119. this.$emit('change', this.val)
  120. },
  121. //获取/查询 信息
  122. async getSearchApiData() {
  123. const {
  124. data: res
  125. } = await this.$httpRequest({
  126. url: '/app/' + this.searchApi + this.searchText,
  127. urlType: this.$getUrlType()
  128. });
  129. if (res.code === 200) {
  130. this.searchData = res.data
  131. }
  132. },
  133. //选择赋值给value
  134. dataToValue(item) {
  135. this.$emit('input', item[this.searchLabelKey])
  136. this.$refs.searchPopup.close()
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .desc {
  143. padding: 10rpx 15rpx 0 15rpx;
  144. color: #818181;
  145. font-size: 20rpx;
  146. }
  147. .pickerView {
  148. // align-items: flex-end;
  149. padding: 10rpx 20rpx;
  150. border: 1rpx #eeeeee solid;
  151. }
  152. .pickerText {
  153. font-size: 26rpx;
  154. color: #b1b1b1;
  155. }
  156. </style>