123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <template>
- <div class="searchComponent">
- <div class="field">
- <el-select v-model="label" filterable size="small" @change="getObject">
- <el-option v-for="item in SearchFields" :key="item.value" :label="item.label" :value="item.value"></el-option>
- </el-select>
- </div>
- <div class="value">
- <div v-if="field.type == 2" style="display: flex; width: 100%">
- <el-date-picker v-model="value" type="date" style="width: 100%" size="small" value-format="yyyy-MM-dd"
- :placeholder="getPlaceholder()">
- </el-date-picker>
- </div>
- <div v-else-if="field.type == 5" style="display: flex; width: 100%">
- <el-date-picker v-model="value" type="year" style="width: 100%" size="small" value-format="yyyy"
- :placeholder="getPlaceholder()">
- </el-date-picker>
- </div>
- <div v-else-if="field.type == 6" style="display: flex; width: 100%">
- <el-date-picker v-model="value" type="month" style="width: 100%" size="small" value-format="yyyy-MM"
- :placeholder="getPlaceholder()">
- </el-date-picker>
- </div>
- <div v-else-if="field.type == 3" style="width: 100%">
- <el-select v-model="value" size="small" multiple filterable collapse-tags :placeholder="getPlaceholder()"
- style="width: 100%">
- <el-option v-for="item in field.options || []" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select>
- </div>
- <div v-else-if="field.type == 4" style="width: 100%">
- <el-select v-model="value" size="small" filterable :placeholder="getPlaceholder()"
- style="width: 100%">
- <el-option v-for="item in field.options || []" :key="item.value" :label="item.label" :value="item.value+''">
- </el-option>
- </el-select>
- </div>
- <div v-else style="width: 100%">
- <el-input size="small" style="width: 100%" v-model="value" :placeholder="getPlaceholder()"></el-input>
- </div>
- </div>
- <div class="btn">
- <el-button size="small" type="primary" @click="search" class="indicia-top-button" style="width:100%"
- :disabled="disabled">搜 索</el-button>
- </div>
- <div class="option" v-if="searchOptions.length > 0">
- <el-popover placement="bottom" title="" width="300" trigger="hover" class="margin-left_10">
- <div class="main">
- <div v-for="(item, index) in searchOptions" :key="index" class="box">
- <el-alert type="success" :closable="false">
- <div class="content">
- <span class="color-black">{{ item.label }}</span>
- <b class="padding_0_5">=</b>
- <span class="color-black">
- <span v-if="item.type == 3">
- <span class="padding_0_5">(</span>
- <span v-for="(data, i) in item.searchValue" :key="data.label">
- <span class="query-data-label" @click="handleCancelQueryParams(item, index, i)">{{ data.label }}<i
- class="el-icon-close"></i></span>
- <b v-if="item.searchValue.length - 1 > i" class="padding_0_5 color-primary">OR</b>
- </span>
- <span class="padding_0_5">)</span>
- </span>
- <span v-else>
- <span class="query-data-label" @click="handleCancelQueryParams(item, index)">{{ item.searchValue.label
- }}<i class="el-icon-close"></i></span>
- </span>
- </span>
- </div>
- </el-alert>
- </div>
- </div>
- <el-button slot="reference" size="small" type="primary" style="width:100%">
- 检索条件<i class="el-icon-arrow-down el-icon--right"></i>
- </el-button>
- </el-popover>
- </div>
- </div>
- </template>
- <script>
- export default {
- components: {},
- props: {
- SearchFields: {
- default: () => {
- return [];
- },
- },
- disabled: {
- default: false
- },
- searchValue: {
- default: () => {
- return {};
- },
- },
- projectId: {
- default:null
- },
- taskId: {
- default:null
- }
- },
- data() {
- return {
- inner: false,
- label: '',
- value: null,
- field: {},
- searchOptions: [],
- innerChange: false
- };
- },
- watch: {
- SearchFields() {
- if (this.innerChange) {
- return
- }
- this.getLabel()
- },
- searchValue: {
- deep: true,
- handler(n, o) {
- if (!this.inner) {
- this.getSearchOptions()
- } else {
- this.inner = false
- }
- }
- }
- },
- computed: {},
- created() { },
- mounted() {
- this.getLabel()
- this.getSearchOptions()
- },
- methods: {
- getSearchOptions() {
- this.searchOptions = []
- if (Object.keys(this.searchValue).length > 0) {
- var data = Object.keys(this.searchValue)
- data.forEach(key => {
- if (this.searchValue[key] || (typeof this.searchValue[key] == 'object' && this.searchValue[key].length > 0)) {
- var field = this.SearchFields.find(item => {
- return item.value == key
- })
- if(!field){
- return false
- }
- if (typeof this.searchValue[key] == 'object') {
- this.searchOptions.push(
- {
- ...field,
- searchValue: field.options.filter(item => {
- return this.searchValue[key].indexOf(item.value) != -1
- })
- }
- )
- } else {
- this.searchOptions.push(
- {
- ...field,
- searchValue: {
- label: this.searchValue[key]
- }
- }
- )
- }
- }
- })
- }
- },
- getLabel() {
- if (this.SearchFields.length > 0) {
- this.label = this.SearchFields[0].value
- this.getObject(this.label)
- }
- },
- handleCancelQueryParams(data, index, i) {
- this.inner = true
- if (data.type == 3) {
- data.searchValue.splice(i, 1)
- if (data.searchValue.length == 0) {
- this.searchOptions.splice(index, 1)
- }
- } else {
- this.searchOptions.splice(index, 1)
- }
- this.$emit('search', this.searchOptions)
- },
- search() {
- this.inner = true
- if ((typeof this.value == 'string' && this.value) || (typeof this.value == 'object' && this.value.length > 0)) {
- var searchValue = {}
- if (this.field.type == 3) {
- searchValue = this.field.options.filter(item => {
- return this.value.indexOf(item.value) != -1
- })
- }else if (this.field.type == 4){
- searchValue = this.field.options.find(item => {
- return this.value == item.value
- })
- }
- else {
- searchValue = {
- label: this.value,
- value: this.value
- }
- }
- this.searchOptions.push(
- {
- ...this.field,
- searchValue: searchValue
- }
- )
- this.getValue()
- }
- this.$emit('search', this.searchOptions)
- },
- getObject(val) {
- this.field = this.SearchFields.find(item => {
- return item.value == val
- })
- this.getValue()
- this.getOption()
- },
- //获取选项
- getOption() {
- if (this.field.type == '3') {
- if (this.field.options && this.field.options.length > 0) {
- return false
- }
- switch (this.field.group) {
- case 'customField':
- this.getCustomField()
- break;
- case 'product':
- this.queryProductCategory(2)
- break;
- case 'productCategory':
- this.queryProductCategory(1)
- break;
- case 'technical':
- this.queryProductCategory(3)
- break;
- case 'nos':
- break;
- default:
- break
- }
- } else {
- return false
- }
- },
- //获取自定义选项
- getCustomField() {
- if (this.field.type == 'tree') {
- this.queryProductCategory(4)
- return false
- }
- let params = {
- customFieldId: this.field.value,
- }
- this.innerChange = true
- this.$api.queryCustomOption(params).then(response => {
- if (response.code == 200) {
- var a = response.data.data.map(item => {
- return {
- label: item.name,
- value: item.id
- }
- })
- this.$set(this.field, 'options', a)
- this.$nextTick(() => {
- this.innerChange = false
- })
-
- }
- }).catch(error => {
- // this.field.options = []
- })
- },
- //获取产品或产品类别架构以及技术分类
- queryProductCategory(type) {
- let params = {
- projectId: this.projectId,
- taskId: this.taskId,
- type: type,//类型:1产品类别,2产品,3技术分类,4自定义树
- typeId: this.field.value,//产品或类别id
- }
- this.innerChange = true
- this.$api.queryTreeNodeTree(params).then(res => {
- if (res.code == 200) {
- this.$set(this.field, 'options', response.data.data)
- this.$nextTick(() => {
- this.innerChange = false
- })
- }
- }).catch(err => {
-
- })
- },
- getValue() {
- if (this.field.type == 3) {
- this.value = []
- } else {
- this.value = ''
- }
- },
- getPlaceholder() {
- var placeholder = '请输入'
- if (this.field.placeholder) {
- placeholder = this.field.placeholder
- } else {
- if (this.field.type) {
- if (this.field.type == 1) {
- placeholder = '请输入'
- } else if (this.field.type == 2) {
- placeholder = '请选择时间'
- } else if (this.field.type == 3) {
- placeholder = '请选择'
- }
- }
- }
- return placeholder
- }
- },
- };
- </script>
- <style lang="scss" scoped>
- .main {
- padding: 0 !important;
- height: 250px;
- overflow-y: auto;
- .box {
- margin-top: 10px;
- .content {
- line-height: 30px;
- font-size: 14px;
- }
- }
- }
- .query-data-label {
- cursor: pointer;
- &:hover {
- text-decoration: underline;
- color: red;
- }
- }
- .searchComponent {
- padding: 0 10px;
- display: flex;
- // width: 100%;
- }
- .searchComponent>* {
- margin-right: 10px;
- width: 100%;
- }
- .value {
- width: 100%
- }
- .btn {
- width: 100px;
- margin-right: 0;
- }
- .field {
- max-width: 150px;
- }
- .option {
- width: 100px;
- margin-right: 0;
- }
- </style>
|