input.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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" :placeholder="placeholder" maxlength="-1">
  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. placeholder: {
  90. Type: String,
  91. default: null
  92. },
  93. disabled: false
  94. },
  95. data() {
  96. return {
  97. val: '',
  98. searchText: ''
  99. }
  100. },
  101. watch: {
  102. value(newVal) {
  103. this.val = newVal
  104. },
  105. modelValue(newVal) {
  106. this.val = newVal
  107. }
  108. },
  109. mounted() {
  110. if(this.value){
  111. this.val = this.value
  112. }
  113. },
  114. methods: {
  115. input: function(e) {
  116. this.$emit('input', this.val)
  117. },
  118. openSearch() {
  119. console.log('click ---> Test')
  120. this.$refs.searchPopup.open('bottom')
  121. },
  122. changeNumber(e) {
  123. this.$emit('change', this.val)
  124. },
  125. //获取/查询 信息
  126. async getSearchApiData() {
  127. const {
  128. data: res
  129. } = await this.$httpRequest({
  130. url: '/app/' + this.searchApi + this.searchText,
  131. urlType: this.$getUrlType()
  132. });
  133. if (res.code === 200) {
  134. this.searchData = res.data
  135. }
  136. },
  137. //选择赋值给value
  138. dataToValue(item) {
  139. this.$emit('input', item[this.searchLabelKey])
  140. this.$refs.searchPopup.close()
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .desc {
  147. padding: 10rpx 15rpx 0 15rpx;
  148. color: #818181;
  149. font-size: 20rpx;
  150. }
  151. .pickerView {
  152. // align-items: flex-end;
  153. padding: 10rpx 20rpx;
  154. border: 1rpx #eeeeee solid;
  155. }
  156. .pickerText {
  157. font-size: 26rpx;
  158. color: #b1b1b1;
  159. }
  160. </style>