MySearch.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <u-popup lock-scroll :show="show" closeOnClickOverlay mode="top" @close="close" @open="open">
  3. <view class="container">
  4. <u--form ref="form" labelPosition="left" :model="formData" labelWidth="180" labelAlign="left">
  5. <block v-for="(item, index) in formItems" :key="index">
  6. <!-- <slot name='slot'></slot> -->
  7. <u-form-item :label="item.label" :prop="item.prop">
  8. <component :is="item.component" v-model="formData[item.prop]" v-bind="item.props"
  9. v-on="item.events" />
  10. </u-form-item>
  11. </block>
  12. </u--form>
  13. <view class="action">
  14. <u-button text="重置" shape="circle" style="color: #000;" @click="reset"></u-button>
  15. <u-button type="primary" text="确定" shape="circle" @click="search"></u-button>
  16. </view>
  17. </view>
  18. </u-popup>
  19. </template>
  20. <script>
  21. import MyInput from '@/uni_modules/uview-ui/components/u--input/u--input.vue'
  22. import MyPicker from '@/uni_modules/uview-ui/components/u-picker/u-picker.vue'
  23. import MyDateRange from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue'
  24. export default {
  25. name: "MySearch",
  26. components: {
  27. MyInput,
  28. MyPicker,
  29. MyDateRange
  30. },
  31. props: {
  32. show: {
  33. type: Boolean,
  34. default: false
  35. },
  36. formItems: {
  37. type: Array,
  38. default: () => []
  39. },
  40. initialData: {
  41. type: Object,
  42. default: () => ({})
  43. }
  44. },
  45. data() {
  46. return {
  47. formData: {},
  48. };
  49. },
  50. watch: {
  51. initialData: {
  52. handler(newVal) {
  53. this.formData = {
  54. ...newVal
  55. };
  56. },
  57. deep: true
  58. }
  59. },
  60. methods: {
  61. change(){
  62. console.log(this);
  63. },
  64. open() {
  65. },
  66. close() {
  67. this.$emit('update:show', false)
  68. },
  69. maskClick(e) {
  70. console.log('maskClick事件:', e);
  71. },
  72. reset() {
  73. this.formData = {}
  74. console.log(this.formData);
  75. },
  76. search() {
  77. this.close()
  78. this.$emit('search',this.formData)
  79. }
  80. },
  81. created() {
  82. console.log(this);
  83. },
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .container {
  88. padding: 20rpx;
  89. }
  90. /deep/.u-form-item__body {
  91. padding: 16rpx 0
  92. }
  93. /deep/.uni-date__icon-clear {
  94. border: none !important;
  95. transform: translateY(25%);
  96. }
  97. .action {
  98. padding: 20rpx;
  99. display: flex;
  100. }
  101. /deep/.u-button {
  102. width: 40%;
  103. }
  104. .form-button-container {
  105. display: flex;
  106. justify-content: space-around;
  107. margin-top: 20px;
  108. }
  109. </style>