wangting
2024-09-09 e347c62b06319cc9a6018b323d7dce55ead19e11
Source/plt-web/plt-web-ui/src/views/modelingMenu/queryTemplate/linkTypeQuery/formQueryDialog.vue
@@ -1,33 +1,34 @@
<template>
  <div style="padding: 0 10px">
    <div style="text-align: center;margin-bottom: 10px">
      <avue-radio v-model="radioForm"  :dic="radioDic" style="margin: 0 20px 0 0;display: inline-block"></avue-radio>
      <el-button  plain size="mini" type="primary" @click="clearValue">清空值</el-button>
      <el-button  plain size="mini" type="primary" @click="delAll">删除全部条件</el-button>
      <avue-radio v-model="radioForm" :disabled ="readOnly" :dic="radioDic" style="margin: 0 20px 0 0;display: inline-block"></avue-radio>
      <el-button  v-if="!readOnly" plain size="mini" type="primary" @click="clearValue">清空值</el-button>
      <el-button  v-if="!readOnly" plain size="mini" type="primary" @click="delAll">删除全部条件</el-button>
    </div>
    <div v-if="radioForm==0" @drop="drop" @dragover.prevent style="height: 220px;text-align: center;">
      <div v-for="(condition,index) in conditionList" :key="index" class="el-input--small" style="margin-bottom: 5px; text-align:left">
        <span style="width: 200px;display: inline-block;text-align: right" :title="condition.clause">{{condition.clause}}</span>
        <avue-select v-model="condition.operator" type="tree" :dic="condition.operatorDic" :clearable="false" style="width: 80px;margin: 0 5px;"></avue-select>
        <el-date-picker v-if="condition.type=='VTDate'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;" value-format="YYYY-MM-DD"
        <avue-select :disabled ="readOnly" v-model="condition.operator" type="tree" :dic="condition.operatorDic" :clearable="false" style="width: 80px;margin: 0 5px;"></avue-select>
        <el-date-picker :disabled ="readOnly" v-if="condition.type=='VTDate'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;" value-format="YYYY-MM-DD"
                        type="date">
        </el-date-picker>
        <el-date-picker v-else-if="condition.type=='VTDateTime'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"
        <el-date-picker :disabled ="readOnly" v-else-if="condition.type=='VTDateTime'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"
                        type="datetime">
        </el-date-picker>
        <el-time-select v-else-if="condition.type=='VTTime'" v-model="condition.ordinaryValue" value-format="HH:mm:ss" style="width:300px;margin-right: 5px;display: inline-block;">
        <el-time-select :disabled ="readOnly" v-else-if="condition.type=='VTTime'" v-model="condition.ordinaryValue" value-format="HH:mm:ss" style="width:300px;margin-right: 5px;display: inline-block;">
        </el-time-select>
        <avue-input-number v-else-if="condition.type=='VTInteger'" precision="0" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"></avue-input-number>
        <avue-input-number v-else-if="condition.type=='VTLong' || condition.type=='VTDouble'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"></avue-input-number>
        <avue-input v-else v-model="condition.ordinaryValue" placeholder="" style="width: 300px;margin-right: 5px;"></avue-input>
        <el-button  plain size="mini" type="primary" @click="checkTemp(index)">选择查询模板</el-button>
        <el-button  size="mini" type="danger" icon="el-icon-delete" @click="delCondition(index)" style="padding: 7px 8px"></el-button>
        <avue-input-number :disabled ="readOnly" v-else-if="condition.type=='VTInteger'" precision="0" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"></avue-input-number>
        <avue-input-number :disabled ="readOnly" v-else-if="condition.type=='VTLong' || condition.type=='VTDouble'" v-model="condition.ordinaryValue" style="width:300px;margin-right: 5px;display: inline-block;"></avue-input-number>
        <avue-input :disabled ="readOnly" v-else v-model="condition.ordinaryValue" placeholder="" style="width: 300px;margin-right: 5px;"></avue-input>
        <el-button v-if="!readOnly"  plain size="mini" type="primary" @click="checkTemp(index)">选择查询模板</el-button>
        <el-button v-if="!readOnly"  size="mini" type="danger" icon="el-icon-delete" @click="delCondition(index)" style="padding: 7px 8px"></el-button>
      </div>
    </div>
    <div v-else @drop="drop" @dragover.prevent style="height: 220px;text-align: left">
      <avue-tree ref="tree" @node-drop="handleDrop" style="height: 220px" :data="treeData" :option="treeOption"  @node-click="nodeClick" node-key="value"></avue-tree>
      <avue-tree ref="tree" @node-drag-end="handleDragEnd" @node-drag-leave="handleDragLeave"  @node-drag-over="handleDragOver"
                  style="height: 220px" :data="treeData" :option="treeOption"  @node-click="nodeClick" node-key="value"></avue-tree>
    </div>
    <div style="text-align: right;margin-top: 10px;">
    <div v-if="!readOnly" style="text-align: right;margin-top: 10px;">
      <el-button v-if="radioForm==1"  plain size="mini" type="primary" @click="addHandler">增加逻辑</el-button>
      <el-button v-if="radioForm==1"  plain size="mini" type="primary" @click="editHandler">修改条件</el-button>
      <el-button v-if="radioForm==1"  plain size="mini" type="primary" @click="delHandler">删除</el-button>
@@ -93,6 +94,7 @@
        <el-button size="small" @click="cancleQueryDialog">取 消</el-button>
      </div>
    </el-dialog>
    <!--查询-->
    <el-dialog v-dialogDrag
               :title="queryResultDialog.title"
               :visible.sync="queryResultDialog.showDialog"
@@ -101,7 +103,7 @@
               class="avue-dialog"
               :destroy-on-close="true"
               :close-on-click-modal="false"
               @close="queryResultDialog.showDialog='false'">
               @close="queryResultDialog.showDialog=false">
      <div class="el-input--small">
        <avue-crud  ref="crud" :data="resultData" :option="resultOption"
                    :table-loading="queryResultDialog.loading">
@@ -130,6 +132,10 @@
    levelFlag:{
      type: Number,
      default: 0
    },
    readOnly:{
      type:Boolean,
      default:false
    }
  },
  data() {
@@ -379,12 +385,20 @@
                  let inputValue='';
                  let operator='';
                  let showLabel=''
                  if(values.length>1){
                    operator=values[1];
                    if(values.length>2){
                      inputValue=values[2];
                  if(item.column.indexOf('not in')!=-1){
                    operator='not in';
                    if(values.length>3){
                      inputValue=values[3];
                    }
                  }else{
                    if(values.length>1){
                      operator=values[1];
                      if(values.length>2){
                        inputValue=values[2];
                      }
                    }
                  }
                  if(values[0].indexOf('.')!=-1){
                    const labels=values[0].split('.')
                    showLabel=labels[labels.length-1];
@@ -444,36 +458,60 @@
      const data = JSON.parse(event.dataTransfer.getData('item'));
      if (this.radioForm == 0) {
        const params = {
          clause: data.value,
          clause: data.name,
          operator: '=',
          ordinaryValue: ''
        }
        if (data.atttributes.vtDataType == 'VTInteger' || data.atttributes.vtDataType == 'VTDouble' || data.atttributes.vtDataType == 'VTLong') {
        if (data.vtDataType == 'VTInteger' || data.vtDataType == 'VTDouble' || data.vtDataType == 'VTLong') {
          params.operatorDic =JSON.parse(JSON.stringify(this.operatorIntDic)) ;
        } else if (data.atttributes.vtDataType == 'VTDateTime' || data.atttributes.vtDataType == 'VTDate' || data.atttributes.vtDataType == 'VTTime') {
        } else if (data.vtDataType == 'VTDateTime' || data.vtDataType == 'VTDate' || data.vtDataType == 'VTTime') {
          params.operatorDic = JSON.parse(JSON.stringify(this.operatorDateDic))
        } else {
          params.operatorDic = JSON.parse(JSON.stringify(this.operatorDic))
        }
        params.type=data.atttributes.vtDataType;
        params.type=data.vtDataType;
        this.conditionList.push(params)
      }else {
        if (this.clickNode.label != '并且' && this.clickNode.label != '或者') {
          this.$message.error('请选中逻辑条件添加查询项');
          return;
        }
        this.treeIndex++;
        this.$refs.tree.append({
          label: data.value,
          value: data.value + this.treeIndex,
          valueIndex: 'v' + this.treeIndex,
          children: []
        }, this.clickNode);
        this.$refs.tree.append(this.initItem(data), this.clickNode);
      }
    },
    handleDrop(draggingNode, dropNode, dropType, ev) {
    initItem(data){
      this.treeIndex++;
      let item={
        label: data.name,
        value: data.name + this.treeIndex,
        valueIndex: 'v' + this.treeIndex,
        type:data.vtDataType,
        children: [],
        inputValue:'',
        operator:'=',
        showLabel:data.name
      };
      let showLabel='';
      if(data.name.indexOf('.')!=-1){
        const labels=data.name.split('.')
        showLabel=labels[labels.length-1];
      }else {
        showLabel=data.name;
      }
      item.showLabel=showLabel;
      return item
    },
    handleDragEnd(draggingNode, dropNode, dropType, ev) {
      debugger;
      console.log('tree drop: ', dropNode.label, dropType);
      console.log('tree drag end: ', dropNode && dropNode.label, dropType);
    },
    handleDragOver({event}) {
      // 阻止默认事件,允许放置
      event.preventDefault();
    },
    handleDragLeave({event}) {
      // 清除放置效果
      event.preventDefault();
    },
    //删除普通查询条件
    delCondition(index) {
@@ -498,9 +536,13 @@
        if(node.children){
          this.clearTreeValue(node.children)
        }else {
          let values=node.label.split(' ');
          if(values.length>2){
            node.label=values[0]+' '+values[1];
          if(node.label.indexOf('not in')!=-1){
            node.label=node.label.split(' ')[0]+' not in'
          }else {
            let values = node.label.split(' ');
            if (values.length > 2) {
              node.label = values[0] + ' ' + values[1];
            }
          }
        }
      })
@@ -578,21 +620,7 @@
    },
    //查询
    queryHandler(){
      this.$parent.$parent.$parent.$parent.$refs.form.validate((valid) => {
        if (valid) {
          this.queryResultDialog.loading=true;
          const formData=this.$parent.$parent.$parent.$parent.initFormData();
          getCriteria(formData).then(res => {
            if (res.data.success) {
              this.resultData=res.data.data;
              this.queryResultDialog.showDialog=true;
              this.queryResultDialog.loading=false;
            }
          });
        } else {
          return false;
        }
      });
      this.$emit('queryHandler');
    },
    //选择查询模板
    checkTemp(index) {
@@ -610,15 +638,19 @@
    //查询条件保存
    submitDialog() {
      const values= this.clickNode.label.split(' ');
      if(['VTDateTime'].includes(this.clickNode.type)){
        this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue);
      }else  if(['VTDate'].includes(this.clickNode.type)){
        this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue ,'yyyy-MM-dd');
      }else  if(['VTTime'].includes(this.clickNode.type)){
        this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue ,'hh:mm:ss');
      }else {
        this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+this.clickNode.inputValue;
      this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+this.clickNode.inputValue;
      try{
        if(['VTDateTime'].includes(this.clickNode.type)){
          this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue);
        }else  if(['VTDate'].includes(this.clickNode.type)){
          this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue ,'yyyy-MM-dd');
        }else  if(['VTTime'].includes(this.clickNode.type)){
          this.clickNode.label = values[0]+' '+this.clickNode.operator+' '+dateFormat(this.clickNode.inputValue ,'hh:mm:ss');
        }
      }catch (e) {
      }
      this.dialog.showDialog = false;
    },
    //获取查询模板列表