searchquery.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div>
  3. <div style="display:flex">
  4. <!--<slot v-if="slot" name="slot"></slot>-->
  5. <div style="width: 100%;">
  6. <el-select style="width: 100%" v-model="selectValue" :size="size" :placeholder="placeholder"
  7. :filterable="filterable" :clearable="clearable" :remote="remote" :remote-method="remoteMethod"
  8. :multiple="multiple" :collapse-tags="collapseTags" :disabled="disabled" :allow-create="allowCreate"
  9. @change="corpChange" @focus="corpFocus" @clear="corpClear">
  10. <el-option v-for="item in datalist" :key="item[forParameter.key]" :label="item[forParameter.label]"
  11. :value="item[forParameter.value]"
  12. :disabled="item[forParameter.disabled] ? item[forParameter.disabled] == disabledStatus : false">
  13. <span v-if="!joinData" style="float: left">{{ item[forParameter.label] }}</span>
  14. <span v-if="joinData" style="float: left">
  15. <span v-if="!special">{{ item[forParameter.label] }} - {{ item[forParameter.short] }}</span>
  16. <span v-if="special">{{ item[forParameter.short] }} - {{ item[forParameter.label] }}</span>
  17. </span>
  18. <span v-if="desc" style="float: right; color: #8492a6; font-size: 13px">{{
  19. item[forParameter.desc]}}</span>
  20. </el-option>
  21. </el-select>
  22. </div>
  23. <div v-if="buttonIf" style="display: flex;align-items: center">
  24. <div class="bottonBox" v-if="tableIf" :class="disabled ? 'disabledBox' : ''" @click="bottonSearchfun">
  25. <i class="el-icon-search"></i>
  26. </div>
  27. <el-tooltip effect="dark" content="获取最新资料" placement="top-start">
  28. <div class="bottonBox" :class="disabled ? 'disabledBox' : ''" @click="refreshData"><i
  29. class="el-icon-refresh"></i></div>
  30. </el-tooltip>
  31. <el-tooltip v-if="addIf" effect="dark" content="新建数据" placement="top-start">
  32. <div class="bottonBox" :class="disabled ? 'disabledBox' : ''" @click="addJump"><i
  33. class="el-icon-plus"></i>
  34. </div>
  35. </el-tooltip>
  36. </div>
  37. </div>
  38. <el-dialog :title="title" :visible.sync="corpVisible" width="80%" top="5vh" append-to-body @closed="closed"
  39. class="el-dialogDeep" :close-on-click-modal="false" v-dialog-drag>
  40. <div>
  41. <el-row>
  42. <el-col :span="24">
  43. <slot></slot>
  44. </el-col>
  45. </el-row>
  46. </div>
  47. <span slot="footer" class="dialog-footer">
  48. <el-button @click="corpVisible = false">取 消</el-button>
  49. <el-button type="primary" @click="confirm">确 定</el-button>
  50. </span>
  51. </el-dialog>
  52. </div>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. // 弹窗关闭
  59. corpVisible: false,
  60. }
  61. },
  62. props: {
  63. // 选择框的数据
  64. datalist: {
  65. type: Array,
  66. default: []
  67. },
  68. // 选择框数据选择的参数
  69. forParameter: {
  70. type: Object,
  71. default: {
  72. key: 'value',
  73. label: 'label',
  74. value: 'value',
  75. disabled: false,
  76. desc: 'desc'
  77. }
  78. },
  79. // 两个按钮是否显示
  80. buttonIf: {
  81. type: Boolean,
  82. default: true,
  83. },
  84. // 绑定的值
  85. selectValue: {
  86. default: null
  87. },
  88. // 是否禁用
  89. disabled: {
  90. type: Boolean,
  91. default: false
  92. },
  93. // 是否多选
  94. multiple: {
  95. type: Boolean,
  96. default: false
  97. },
  98. // 多选时是否将选中值按文字的形式展示
  99. collapseTags: {
  100. type: Boolean,
  101. default: false
  102. },
  103. // 是否可以搜索
  104. filterable: {
  105. type: Boolean,
  106. default: false
  107. },
  108. // 是否可以创建条目
  109. allowCreate: {
  110. type: Boolean,
  111. default: false
  112. },
  113. // 是否为远程搜索
  114. remote: {
  115. type: Boolean,
  116. default: false
  117. },
  118. // 是否可以清空选择项
  119. clearable: {
  120. type: Boolean,
  121. default: false
  122. },
  123. // 弹窗的标题
  124. title: {
  125. type: String,
  126. default: '选择数据'
  127. },
  128. // 是否禁用
  129. disabledStatus: {
  130. type: Number,
  131. default: 1
  132. },
  133. // 未输入的文字提示
  134. placeholder: {
  135. type: String,
  136. default: '请选择'
  137. },
  138. // 表格按钮
  139. tableIf: {
  140. type: Boolean,
  141. default: true
  142. },
  143. // 添加跳转按钮
  144. addIf: {
  145. type: Boolean,
  146. default: false
  147. },
  148. // 尺寸大小
  149. size: {
  150. type: String,
  151. default: 'small'
  152. },
  153. desc: {
  154. type: Boolean,
  155. default: false
  156. },
  157. joinData: {
  158. type: Boolean,
  159. default: false
  160. },
  161. joinType: {
  162. type: Number,
  163. default: 1
  164. },
  165. special: {
  166. type: Boolean,
  167. default: false
  168. }
  169. },
  170. watch: {
  171. // // 监听
  172. // selectValue:{
  173. // // 执行方法
  174. // handler(oldValue,newValue) {
  175. // console.log(oldValue,145)
  176. // console.log(newValue,146)
  177. // },
  178. // deep: true, // 深度监听
  179. // immediate: true // 第一次改变就执行
  180. // },
  181. },
  182. methods: {
  183. addJump() {
  184. if (this.disabled) {
  185. return
  186. }
  187. this.$emit('addJump')
  188. },
  189. // 聚焦事件
  190. corpFocus() {
  191. this.$emit('corpFocus')
  192. },
  193. corpClear() {
  194. this.$emit('corpClear')
  195. },
  196. // 下拉change
  197. corpChange(value) {
  198. this.$emit('corpChange', value)
  199. this.selectValue = value
  200. },
  201. /* 远程模糊查询操作用户 */
  202. remoteMethod(name) {
  203. if (name == null || name === "") {
  204. return false;
  205. }
  206. this.$emit('remoteMethod', name)
  207. },
  208. // 获取最新数据
  209. refreshData() {
  210. if (this.disabled) {
  211. return
  212. }
  213. this.$emit('remoteMethod')
  214. },
  215. // 弹窗确认事件
  216. confirm() {
  217. // this.corpVisible = false
  218. this.$emit('eldialogConfirm')
  219. },
  220. // 打开弹窗
  221. bottonSearchfun() {
  222. if (this.disabled) return
  223. if (!this.disabled) {
  224. this.corpVisible = true
  225. this.$emit('bottonSearchfun')
  226. }
  227. },
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .bottonBox {
  233. height: 32px;
  234. background: #FFF;
  235. border: 1px solid #DCDFE6;
  236. font-size: 12px;
  237. border-radius: 3px;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. padding: 0 10px;
  242. box-sizing: border-box;
  243. }
  244. .disabledBox {
  245. color: #C0C4CC;
  246. cursor: not-allowed;
  247. background-image: none;
  248. background-color: #FFF;
  249. border-color: #EBEEF5;
  250. }
  251. </style>