appSelect.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="cu-form-group" style="z-index:10">
  3. <view class="flex align-center">
  4. <view class="title">
  5. <text class="text-red" v-if="required">*</text>
  6. <text space="ensp">{{label}}</text>
  7. </view>
  8. <picker
  9. @change="pickerChange"
  10. :range="selections"
  11. :value="valueIndex"
  12. :disabled="disabled">
  13. <input
  14. :placeholder="placeholder"
  15. name="input"
  16. v-model="selected"
  17. :disabled="true"
  18. ></input>
  19. </picker>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: "AppSecelt",
  26. behaviors: ['uni://form-field'],
  27. props:{
  28. display:{
  29. type:String,
  30. default:'inline-block',
  31. required:false
  32. },
  33. placeholder:{
  34. type:String,
  35. default:'请选择',
  36. required:false
  37. },
  38. label:{
  39. type:String,
  40. default:'',
  41. required:false
  42. },
  43. value:{
  44. type:String,
  45. required:false
  46. },
  47. border:{
  48. type:Boolean,
  49. default:false,
  50. required:false
  51. },
  52. dict:{
  53. type:Array,
  54. default:()=>[],
  55. required:true
  56. },
  57. name:{
  58. type:String,
  59. default:'',
  60. required:false
  61. },
  62. required:{
  63. type:Boolean,
  64. default:false,
  65. required:false
  66. },
  67. disabled:{
  68. type:Boolean,
  69. default:false,
  70. required:false
  71. },
  72. space:{
  73. type:Boolean,
  74. default:false,
  75. required:false
  76. }
  77. },
  78. data(){
  79. return {
  80. show:false,
  81. selected:'',
  82. valueIndex:0,
  83. selections:[]
  84. }
  85. },
  86. watch:{
  87. value:{
  88. immediate:true,
  89. handler(val){
  90. if(!val){
  91. this.selected = ''
  92. this.valueIndex = 0
  93. }else{
  94. this.dict.map((item,index)=>{
  95. if(item.value == val){
  96. this.selected = item.text;
  97. this.valueIndex = index
  98. }
  99. })
  100. }
  101. }
  102. },
  103. dict(){
  104. this.initSelections();
  105. }
  106. },
  107. created(){
  108. this.initSelections();
  109. },
  110. methods:{
  111. initSelections(){
  112. let arr = [];
  113. this.dict.map(item=>{
  114. arr.push(item.text)
  115. });
  116. this.selections = arr
  117. },
  118. pickerChange(e){
  119. console.log("appselect::pickerChange",e.detail.value)
  120. let backString = '';
  121. let obj=this.dict[e.detail.value];
  122. this.selected=obj.text;
  123. backString=obj.value;
  124. console.log("backString",backString)
  125. console.log("this.selected",this.selected)
  126. this.$emit('input',backString);
  127. // #ifndef MP-WEIXIN
  128. this.$emit('change',backString);
  129. // #endif
  130. }
  131. },
  132. model: {
  133. prop: 'value',
  134. event:'change'
  135. }
  136. }
  137. </script>
  138. <style scoped>
  139. .cu-form-group uni-picker::after {
  140. font-family: cuIcon;
  141. display: block;
  142. content: "\e6a3";
  143. position: absolute;
  144. font-size: 14px;
  145. color: #FFFFFF;
  146. line-height: 42px;
  147. width: 25px;
  148. text-align: center;
  149. top: 0;
  150. bottom: 0;
  151. right: -8px;
  152. margin: auto;
  153. }
  154. </style>