ConditionSetting.vue 34 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
<template>
  <el-container>
    <el-row style="width: 100%">
      <el-col :span="7">
        <el-table
          ref="conditionSettingTable"
          border
          :max-height="tabHeight"
          :data="conditionSettingFields"
          tooltip-effect="dark"
          @row-dblclick="fillToCondition"
          default-expand-all
          :tree-props="{children: 'fields'}"
          row-key="tempId"
          @select="selectChange"
          @select-all="selectAllChange"
          @selection-change="selectionChangeHandler"
        >
          >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column
            prop="name"
            label="列名"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="desc"
            label="注释"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="type"
            label="类型"
            width="80"
          ></el-table-column>
        </el-table>
      </el-col>
      <el-col :span="1" style="text-align:center">
        <el-button
          type="primary"
          circle
          icon="icon-hide"
          title="将所选字段添加为查询条件"
          style="-webkit-transform: rotate(270deg); transform: rotate(270deg)"
          @click="allfillToCondition()"
        />
      </el-col>
      <el-col :span="16">
        <div class="tablebox">
          <el-table
            ref="conditionTable"
            border
            :max-height="tabHeight"
            :data="conditionFields"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              label="序号"
              type="index"
              width="50"
              fixed="left"
            ></el-table-column>
            <el-table-column
              prop="na"
              label="列名"
              width="120"
              fixed="left"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column prop="cm" label="显示名" width="240">
              <template scope="scope">
                <el-input
                  v-model="scope.row.cm"
                  placeholder="请输入显示名称"
                  maxlength="50"
                  show-word-limit
                >
                  <el-button
                    icon="icon-guojihua"
                    slot="append"
                    style="width: 50px"
                    @click="editI18nMessage(scope.row.name)"
                  >
                  </el-button>
                </el-input>
              </template>
            </el-table-column>
            <el-table-column prop="ct" label="控件类型" width="140">
              <template scope="scope">
                <div v-if="scope.row.ty != 'date'">
                  <ht-select
                    :clearable="false"
                    v-model="scope.row.ct"
                    :options="controlTypes.filter(item => item.key != 'date')"
                    @change="controlTypeChange(scope.$index, scope.row)"
                    :validate="{required: true}"
                    style="width: 100%"
                  />
                </div>
                <div v-if="scope.row.ty == 'date'">
                  <ht-select
                    :clearable="false"
                    v-model="scope.row.ct"
                    :options="controlTypes.filter(item => item.key == 'date')"
                    @change="controlTypeChange(scope.$index, scope.row)"
                    :validate="{required: true}"
                    style="width: 100%"
                  />
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="op" label="条件" width="120">
              <template scope="scope">
                <ht-select
                  v-model="scope.row.op"
                  :clearable="false"
                  @change="changeQt(scope.row, scope.$index)"
                  :options="getOpOptions(scope.row.ty, scope.row.op)"
                  :validate="{required: true}"
                  style="width: 100%"
                />
              </template>
            </el-table-column>
            <el-table-column
              prop="mg"
              align="center"
              label="合并查询"
              width="80"
            >
              <template scope="scope">
                <el-checkbox
                  v-model="scope.row.mg"
                  v-if="scope.row.ty !== 'date'"
                />
              </template>
            </el-table-column>
            <el-table-column label="默认值" width="330">
              <template slot-scope="scope">
                <el-input-number
                  v-if="scope.row.ty === 'number'"
                  v-model="scope.row.defaultValue"
                  placeholder="请输入默认值"
                  controls-position="right"
                  style="width: 100%"
                ></el-input-number>
                <div
                  v-if="
                    scope.row.ty === 'date' &&
                      scope.row.ct === 'date' &&
                      scope.row.op != '6'
                  "
                >
                  <el-date-picker
                    style="width: 100%"
                    v-model="scope.row.defaultValue"
                    :type="
                      scope.row.format == 'yyyy-MM-dd HH:mm:ss'
                        ? 'datetime'
                        : 'date'
                    "
                    key="date"
                    :value-format="
                      scope.row.format ? scope.row.format : 'yyyy-MM-dd'
                    "
                    placeholder="选择日期"
                  >
                  </el-date-picker>
                </div>
                <div
                  v-if="
                    scope.row.ty === 'date' &&
                      scope.row.ct === 'date' &&
                      scope.row.op == '6'
                  "
                >
                  <el-date-picker
                    style="width: 315px"
                    v-model="scope.row.defaultValue"
                    :type="
                      scope.row.format == 'yyyy-MM-dd HH:mm:ss'
                        ? 'datetimerange'
                        : 'daterange'
                    "
                    :value-format="
                      scope.row.format ? scope.row.format : 'yyyy-MM-dd'
                    "
                    size="mini"
                    key="range"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    @input="changeTime(scope.row, scope.$index, $event)"
                  >
                  </el-date-picker>
                </div>
                <el-input
                  v-if="scope.row.ty === 'varchar' || scope.row.ty === 'clob'"
                  v-model="scope.row.defaultValue"
                  placeholder="请输入默认值"
                  style="width: 100%"
                  clearable
                  show-word-limit
                  :maxlength="50"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="管理" width="300" fixed="right">
              <template slot="header" slot-scope="scope">
                <span style="margin-right:10px">管理</span>
                <el-button
                  @click="handleClearSelected"
                  v-show="conditionFields && conditionFields.length > 0"
                  >清空</el-button
                >
              </template>
              <template slot-scope="scope">
                <el-button
                  @click="sort(scope.$index, 'down')"
                  size="mini"
                  title="下降"
                  icon="el-icon-arrow-down"
                  plain
                ></el-button>
                <el-button
                  @click="sort(scope.$index, 'up')"
                  size="mini"
                  title="上升"
                  icon="el-icon-arrow-up"
                  plain
                ></el-button>
                <el-button
                  :plain="!scope.row.isShow"
                  class="mobile-btn"
                  size="mini"
                  :title="scope.row.isShow ? '隐藏' : '显示'"
                  :icon="
                    scope.row.isShow
                      ? 'icon-application-display'
                      : 'icon-application-hide'
                  "
                  :class="{
                    'is-active__btn': scope.row.isShow
                  }"
                  @click="isShow(scope.row)"
                ></el-button>
                <el-button
                  :plain="scope.row.mpDisplay === btnType.notShow"
                  class="mobile-btn"
                  size="mini"
                  title="移动端查询"
                  icon="icon-shoujiduanxianshi"
                  :class="{
                    'is-active__btn': scope.row.mpDisplay === btnType.isShow
                  }"
                  v-show="
                    scope.row.mpDisplay
                      ? (scope.row.mpDisplay = scope.row.mpDisplay)
                      : initMpDisplay(scope.row)
                  "
                  @click="btnChange(scope.row)"
                ></el-button>
                <el-button
                  plain
                  class="mobile-btn"
                  size="mini"
                  title="校验"
                  icon="icon-xiaoyan"
                  :class="{
                    'is-active__btn':
                      scope.row.validateList &&
                      scope.row.validateList.length > 0
                  }"
                  :disabled="scope.row.isShow"
                  @click="validateChange(scope.$index, scope.row)"
                ></el-button>
                <el-button
                  @click="remove(scope.$index, scope.row)"
                  size="mini"
                  title="删除"
                  icon="el-icon-delete"
                  plain
                ></el-button>
                <el-button
                  @click="
                    addCtrlField(scope.$index, scope.row, conditionFields)
                  "
                  type="info"
                  size="mini"
                  v-if="
                    scope.row.ct == 'select' ||
                      scope.row.ct == 'radio' ||
                      scope.row.ct == 'customDialog'
                  "
                  :plain="
                    !(
                      (scope.row.controlContent &&
                        scope.row.controlContent.length > 0) ||
                      (scope.row.controlContent &&
                        scope.row.controlContent.alias) ||
                      (scope.row.dateFormat && scope.row.dateFormat != '')||
                      (scope.row.option && scope.row.option.choiceType == 'dynamic'&& 
                      scope.row.option.bind && scope.row.option.bind.length)

                    )
                  "
                  >控</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>
    <!-- 添加查询控件对话框  -->
    <template-ctrl-field-dialog
      ref="templateCtrlFieldDialog"
      name="templateCtrlFieldDialog"
      :controlTypes="controlTypes"
      @onConfirm="ctrlFieldDialogOnConfirm"
      append-to-body
    />
    <!--表单对话框 -->
    <validate-dialog
      ref="ValidateDialog"
      :boData="conditionFields"
      @onConfirm="formSubmitVerificationOk"
    />
    <i18n-message-edit
      ref="i18nMessageEdit"
      :messageKey="i18nMessageKey"
      @after-save="afterSaveI18n"
    />
  </el-container>
</template>

<script>
import deepmerge from 'deepmerge'
const templateCtrlFieldDialog = () =>
  import('@/components/form/dataTemplate/TemplateCtrlFieldDialog.vue')
const ValidateDialog = () =>
  import('@/components/form/dataTemplate/ValidateDialog.vue')
import i18nMessageEdit from '@/components/system/I18nMessageEdit.vue'
const BTN_TYPE = {
  isShow: '1',
  notShow: '2'
}
export default {
  name: 'condition-setting',
  components: {
    templateCtrlFieldDialog,
    ValidateDialog,
    i18nMessageEdit
  },
  props: ['data'],
  data() {
    return {
      btnType: BTN_TYPE, //移动端显示隐藏按钮
      dataTemplate: {},
      // conditionSettingFields: [],
      conditionFields: [],
      tabHeight: `${document.documentElement.clientHeight}` - 245,
      controlTypes: [
        {
          key: 'onetext',
          value: '单行文本框',
          options: {
            dataType: 'string|number',
            validateList: [],
            validateType:
              'confirmed|email|regex|id_card|min|max|min_value|max_value|isAfter|isBefore|isStart|isEnd|numeric|between|is|digits|mobile|required|row_unique|alpha_spaces|alpha_dash|alpha_num|alpha|frontJSValidate|backendValidate|decimal'
          }
        },
        {
          key: 'date',
          value: '日期控件',
          options: {
            validateType:
              'isAfter|isBefore|isStart|isEnd|required|row_unique|frontJSValidate',
            validateList: []
          }
        },
        {
          key: 'select',
          value: '下拉选项',
          options: {
            validateType: 'required|row_unique|frontJSValidate',
            validateList: [],
            dataType: 'string|number'
          }
        },
        {
          key: 'radio',
          value: '单选按钮',
          options: {
            dataType: 'string|number',
            validateType: 'required|row_unique|frontJSValidate',
            validateList: []
          }
        },
        {
          key: 'customDialog',
          value: '自定义对话框',
          options: {
            validateType: 'required|row_unique|frontJSValidate',
            validateList: []
          }
        }
      ],
      editField: {},
      editFieldIndex: -1,
      option: {
        choiceType: 'static',
        customQuery: {}
      },
      i18nMessageKey: '',
      selections: []
    }
  },
  computed: {
    conditionSettingFields() {
      // 去掉流程字段
      let conditionSettingFields = JSON.parse(
        JSON.stringify(this.$store.getters['form/conditionFormListCommonVar'])
      )
      if (conditionSettingFields.length) {
        conditionSettingFields[0].fields = conditionSettingFields[0].fields.filter(
          item => !item.flowField
        )
      }
      //处理字段列表,添加相应的字段
      let tempId = 0
      conditionSettingFields.forEach(p => {
        p['tempId'] = tempId = tempId + 1
        p['isParent'] = true
        p.fields &&
          p.fields.forEach(s => {
            s['tempId'] = tempId = tempId + 1
            s['isParent'] = false
          })
      })
      return conditionSettingFields
    }
  },
  mounted() {
    this.dataTemplate = this.data.bpmDataTemplate
    if (this.data.fields) {
      let fields = deepmerge({}, this.data.fields, {clone: true})
      if (fields.length && fields[0] && fields[0].fields) {
        fields[0].fields = fields[0].fields.filter(item => {
          return !item.flowField
        })
      }
      // fields=fields.filter(item=>!item.flowField);
      this.conditionSettingFields = fields.filter(item => !item.flowField)
      // 处理字段列表,添加相应的字段
      let tempId = 0
      this.conditionSettingFields.forEach(p => {
        p['tempId'] = tempId = tempId + 1
        p['isParent'] = true
        p.fields &&
          p.fields.forEach(s => {
            s['tempId'] = tempId = tempId + 1
            s['isParent'] = false
          })
      })
    }
    this.templates = this.data.templates
    this.initData()
  },
  methods: {
    getDataId(data) {
      return data['tempId']
    },
    selectChange(selection, row) {
      // 如果selection中存在row代表是选中,否则是取消选中
      if (
        selection.find(val => {
          return this.getDataId(val) === this.getDataId(row)
        })
      ) {
        if (row.fields) {
          //注意这里的children是后台返回数据的children字段
          row.fields.forEach(val => {
            this.$refs.conditionSettingTable.toggleRowSelection(val, true)
            // selection.push(val)
            if (val.fields) {
              this.selectChange(selection, val)
            }
          })
        }
      } else {
        this.toggleRowSelection(selection, row)
      }
    },

    /**
     * 用于树形表格多选, 选中所有
     * @param selection
     */
    selectAllChange(selection) {
      // 如果选中的数目与请求到的数目相同就选中子节点,否则就清空选中
      if (
        selection &&
        selection.length === this.conditionSettingFields.length
      ) {
        selection.forEach(val => {
          this.selectChange(selection, val)
        })
      } else {
        this.$refs.conditionSettingTable.clearSelection()
      }
    },

    // 选择改变
    selectionChangeHandler(val) {
      this.selections = val
      // this.unique(this.selections,'id')//这里有一个问题就是这样点选完之后,数据有重复,所以根据id手动去重,期待优化
    },

    /**
     * 切换选中状态
     * @param selection
     * @param data
     */
    toggleRowSelection(selection, data) {
      if (data.children) {
        //注意这里的children也是后台返回数据的children字段
        data.children.forEach(val => {
          this.$refs.conditionSettingTable.toggleRowSelection(val, false)
          if (val.children) {
            this.toggleRowSelection(selection, val)
          }
        })
      }
    },
    isShow(row) {
      this.$set(row, 'isShow', !row.isShow)
    },
    btnChange(row) {
      this.$set(row, 'mpDisplay', row.mpDisplay === '1' ? '2' : '1')
    },
    //保存查询条件数据
    saveConditionField() {
      let unPassCondtionArr = []
      let errorArr = []
      let fieldOpErrorArr = []
      this.conditionFields.forEach(c => {
        //合并查询只能用like查询比较符
        if (c.mg && c.qt.indexOf('LIKE') < 0) {
          errorArr.push(c.cm)
        }
        //没有配置控件类型
        if (
          (c.ct == 'select' || c.ct == 'radio' || c.ct == 'customDialog') &&
          !c.controlContent
        ) {
          unPassCondtionArr.push(c.cm)
        }
        //查询条件的op必须是数字,否则就是异常的数据
        if (c.op && !parseInt(c.op) > 0) {
          fieldOpErrorArr.push(c.cm)
        }
      })
      if (errorArr.length > 0) {
        this.$message.error(
          '查询字段【' +
            errorArr.join(',') +
            '】,在使用了合并查询后,不可再使用非like条件,无法保存'
        )
        return 'false'
      }
      if (unPassCondtionArr.length > 0) {
        this.$message.error(
          '查询字段【' +
            unPassCondtionArr.join(',') +
            '】尚未配置控件,无法保存'
        )
        return 'false'
      }
      if (fieldOpErrorArr.length > 0) {
        this.$message.error(
          '查询字段【' +
            fieldOpErrorArr.join(',') +
            '】的条件配置有异常,请删除该查询字段后重新配置。'
        )
        return 'false'
      }
      this.dataTemplate.conditionField = this.conditionFields
        ? JSON.stringify(this.conditionFields)
        : null
    },
    //初始化处理
    initData() {
      if (this.dataTemplate.conditionField) {
        this.conditionFields = JSON.parse(this.dataTemplate.conditionField)
      }
      if (this.conditionFields) {
        this.conditionFields.forEach(item => {
          if (
            item.ct != 'onetext' &&
            item.ct != 'date' &&
            item.ct != 'select' &&
            item.ct != 'radio' &&
            item.ct != 'customDialog'
          ) {
            item.ct = 'onetext'
          }
        })
      }
    }, //查询字段控件设置
    addCtrlField(index, row, conditionFields) {
      if ((row.ct == 'select' || row.ct == 'radio') && !row.option) {
        row.option = {
          choiceType: 'static',
          customQuery: {}
        }
      }
      this.editFieldIndex = index
      this.editField = row
      this.$refs.templateCtrlFieldDialog.showDialog(row, conditionFields)
    },

    //回填查询字段控件设置
    ctrlFieldDialogOnConfirm(field) {
      // this.editField = field
      this.conditionFields.splice(this.editFieldIndex, 1, field)
    },
    //双击字段列表中的字段时将该字段加入到显示字段
    fillToCondition(row, event, column) {
      if (row.isParent) {
        // this.$message.warning('请选择字段')
        return
      }
      let isIn = this.isInConditionFields(row.name)
      if (!isIn) {
        let field = this.getConditionField(row)
        this.conditionFields.push(field)
      }
      this.doLayoutTable()
    },
    //将字段列表中的已选字段加入到显示字段列表
    allfillToCondition() {
      let selectrows = this.$refs.conditionSettingTable.store.states.selection
      selectrows = selectrows.filter(item => !item.isParent)
      if (!selectrows || selectrows.length < 1) {
        this.$message({
          message: '请在左侧列表中选择要作为条件的字段',
          type: 'warning'
        })
      }
      selectrows.forEach(obj => {
        let ctrlType = obj.ctrlType
        if (ctrlType == 'dialog') {
          ctrlType = 'customDialog'
        } else if (ctrlType == 'input') {
          ctrlType = 'onetext'
        }
        if (obj.type === 'date') {
          ctrlType = 'date'
        }
        let isTrue = false
        for (let i = 0; i < this.controlTypes.length; i++) {
          if (ctrlType == this.controlTypes[i].key) {
            isTrue = true
            break
          }
        }
        if (!isTrue) {
          ctrlType = 'onetext'
        }
        this.$set(obj, 'ctrlType', ctrlType)
        if (!this.isInConditionFields(obj.name)) {
          let field = this.getConditionField(obj)
          this.conditionFields.push(field)
        }
      })
      this.doLayoutTable()
    },
    doLayoutTable() {
      this.$nextTick(() => {
        this.$refs.conditionTable.doLayout()
      })
    },
    //显示字段排序
    sort(index, type) {
      if ('up' == type) {
        if (index === 0) {
          this.$message({
            message: '已经是列表中第一位',
            type: 'warning'
          })
        } else {
          let temp = this.conditionFields[index - 1]
          this.$set(
            this.conditionFields,
            index - 1,
            this.conditionFields[index]
          )
          this.$set(this.conditionFields, index, temp)
        }
      } else {
        if (index === this.conditionFields.length - 1) {
          this.$message({
            message: '已经是列表中最后一位',
            type: 'warning'
          })
        } else {
          let i = this.conditionFields[index + 1]
          this.$set(
            this.conditionFields,
            index + 1,
            this.conditionFields[index]
          )
          this.$set(this.conditionFields, index, i)
        }
      }
    },
    //删除显示字段(其他查询字段校验验绑定该字段的也需要删除)
    remove(index, row) {
      this.$confirm(
        '删除此数据,其他查询字段校验如绑定该字段的也同时清除, 是否继续?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {
          this.conditionFields.forEach(item => {
            if (item.validateList && item.validateList.length > 0) {
              for (var i = 0; i < item.validateList.length; i++) {
                if (
                  item.validateList[i].value &&
                  item.validateList[i].value.includes(row.name)
                ) {
                  item.validateList.splice(i, 1)
                  i--
                }
              }
            }
          })
          this.conditionFields.splice(index, 1)
        })
        .catch(() => {})
    },
    handleClearSelected() {
      this.$confirm('确认清空所有查询字段?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.conditionFields = []
          this.$refs.conditionSettingTable.clearSelection()
        })
        .catch(() => {})
    },
    //判断字段是否已在显示字段列表中
    isInConditionFields(name) {
      let isIn = false
      if (this.conditionFields && this.conditionFields.length > 0) {
        this.conditionFields.forEach(obj => {
          if (obj.name == name) {
            isIn = true
            return
          }
        })
      }
      return isIn
    },
    getConditionField(field) {
      let option = field.option ? JSON.parse(field.option) : null
      let ctrlType = field.ctrlType
      let resultField
      ctrlType = ctrlType == 'multiselect' ? 'select' : ctrlType //下拉框多选也为下拉框
      if (ctrlType == 'selector' && option) {
        ctrlType = this.getSelectorOptions(option.selector.type.alias)
        for (var bind in option.bind) {
          if (
            option.bind[bind].json &&
            option.bind[bind].json.name == field.name
          ) {
            resultField = option.bind[bind].key
            break
          }
        }
        if (!resultField) {
          resultField = option.bind[0].key
        }
      }
      if ('text' == ctrlType || 'checkbox' == ctrlType) {
        ctrlType = 'onetext'
      }
      if (field.type == 'date') {
        ctrlType = 'date'
      }
      var colPrefix = this.data.colPrefix
      const tableName = this.getTableNameByField(field)
      let opInt = field.type == 'varchar' || field.type == 'clob' ? '3' : '1'
      let format = field.format
      return {
        queryPre: field.queryPre || '',
        colPrefix: field.colPrefix || '',
        tableName,
        name: field.name,
        na: field.name,
        ty: field.type,
        op: opInt,
        cm: field.desc,
        format: format,
        va: '',
        vf: (option && option.choiceType) || 'static',
        ct: ctrlType || 'onetext',
        qt: this.getQueryType(field.fieldType || field.type, opInt),
        option: option,
        defaultValue: field.type=='number'? undefined: field.defaultValue || '',
        validateList: field.validateList || [],
        validate: field.validate || '',
        controlContent:
          resultField ||
          (option && option.choice) ||
          (option && option[ctrlType]) ||
          ''
      }
    },
    getQueryType(type, op) {
      let qt = 'equal'
      op = parseInt(op)
      switch (type) {
        case 'varchar':
        case 'clob':
          if (op) {
            switch (op) {
              case 1:
                qt = 'EQUAL'
                break
              case 2:
                qt = 'NOT_EQUAL'
                break
              case 3:
                qt = 'LIKE'
                break
              case 4:
                qt = 'RIGHT_LIKE'
                break
              case 5:
                qt = 'LEFT_LIKE'
                break
              case 6:
                qt = 'IN'
                break
              default:
                qt = 'LIKE'
                break
            }
          }
          break
        case 'int':
        case 'number':
          if (op) {
            switch (op) {
              case 1:
                qt = 'EQUAL'
                break
              case 2:
                qt = 'GREAT'
                break
              case 3:
                qt = 'LESS'
                break
              case 4:
                qt = 'GREAT_EQUAL'
                break
              case 5:
                qt = 'LESS_EQUAL'
                break
              default:
                qt = 'EQUAL'
                break
            }
          }
          break
        case 'date':
          if (op) {
            switch (op) {
              case 1:
                qt = 'EQUAL'
                break
              case 2:
                qt = 'GREAT'
                break
              case 3:
                qt = 'LESS'
                break
              case 4:
                qt = 'GREAT_EQUAL'
                break
              case 5:
                qt = 'LESS_EQUAL'
                break
              case 6:
                qt = 'between'
                break
              default:
                qt = 'EQUAL'
                break
            }
          }
          break
        default:
          qt = 'equal'
          break
      }
      return qt
    },
    getSelectorOptions(type) {
      let selector = 'userSelector'
      switch (type) {
        case 'RoleDialog':
          selector = 'roleSelector'
          break
        case 'PostDialog':
          selector = 'postSelector'
          break
        case 'OrgDialog':
          selector = 'orgSelector'
          break
        default:
          selector = 'userSelector'
          break
      }
      return selector
    },
    getOpOptions(type, _case) {
      let options = {
        varchar: [
          {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
          {key: '2', value: '!='},
          {key: '3', value: 'like'},
          {key: '4', value: 'left_like'},
          {key: '5', value: 'right_like'},
          {key: '6', value: 'in'}
        ],
        clob: [
          {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
          {key: '2', value: '!='},
          {key: '3', value: 'like'},
          {key: '4', value: 'left_like'},
          {key: '5', value: 'right_like'},
          {key: '6', value: 'in'}
        ],
        number: [
          {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
          {key: '2', value: '>'},
          {key: '3', value: '<'},
          {key: '4', value: '>='},
          {key: '5', value: '<='}
        ],
        int: [
          {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
          {key: '2', value: '>'},
          {key: '3', value: '<'},
          {key: '4', value: '>='},
          {key: '5', value: '<='}
        ],
        date: [
          {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
          {key: '2', value: '>'},
          {key: '3', value: '<'},
          {key: '4', value: '>='},
          {key: '5', value: '<='},
          {key: '6', value: '日期范围'}
        ]
      }
      let otherOption = [
        {key:  _case && _case === 'equal' ? 'equal' : '1', value: '='},
        {key: '2', value: '>'},
        {key: '3', value: '<'},
        {key: '4', value: '>='},
        {key: '5', value: '<='}
      ]
      if (options[type]) {
        return options[type]
      } else {
        return otherOption
      }
    },
    changeQt(row, index) {
      let qt = this.getQueryType(row.ty, row.op)
      this.conditionFields[index].qt = qt
      this.conditionFields[index].defaultValue = null
    },
    initMpDisplay(row) {
      this.$set(row, 'mpDisplay', '2')
    },
    controlTypeChange(index, row) {
      this.conditionFields[index].controlContent = ''
      this.$set(row, 'ty', row.ty)
      this.$set(row, 'validateList', [])
      this.$set(row, 'validate', '')
      if (this.conditionFields[index].ct == 'select') {
        this.$set(this.conditionFields[index], 'option', this.option)
      }
    },
    // 通过字段获取字段所属表名
    getTableNameByField(field) {
      // 解构字段的属性
      const {joinTableField, colPrefix, desc, name} = field
      // 非关联表时直接返回主表的表名缩写
      if (!joinTableField) {
        return 't'
      }
      // 默认获取当前表单列表的主表
      let tableName = this.data.tableName
      // 当前表单列表的所有表数组
      const fieldArrs = this.data.fields
      fieldArrs.forEach(arr => {
        arr.fields.forEach(f => {
          // 如果该表下面的字段的以下三个属性和传入字段的一致,认为该字段属于该表
          if (f.colPrefix == colPrefix && f.desc == desc && f.name == name) {
            // 获取到表名
            tableName = arr.name
          }
        })
      })
      return tableName
    },
    //查询字段校验设置
    validateChange(index, row) {
      this.controlTypes &&
        this.controlTypes.filter(item => {
          if (item.key == row.ct) {
            row.validateType = item.options.validateType
          }
        })
      //数字类型的校验规则
      if (row.ty == 'number' && row.ct == 'onetext') {
        row.validateType =
          'min_value|max_value|confirmed|numeric|between|digits|required|row_unique|frontJSValidate|mobile'
      }
      this.$refs.ValidateDialog.handleOpen(row)
    },
    //保存表单提交校验配置信息
    formSubmitVerificationOk(verification) {
      this.conditionFields.forEach(item => {
        if (item.name == verification.name) {
          item.validateList = verification.validateList
          item.validate = verification.validate
        }
      })
    },
    changeTime(row, index, e) {
      this.$forceUpdate()
      this.$set(row, 'defaultValue', e)
    },
    /**
     * 国际化配置
     */
    editI18nMessage(columnName) {
      this.i18nMessageKey = `formTemplate.${this.dataTemplate.alias}.search.${columnName}`
      this.$refs.i18nMessageEdit.handleOpen()
    },
    afterSaveI18n(data) {
      //保存后做一些数据处理
      data.key = data.key.replace('$', '#')
      this.dataTemplate.desc = data.key
      this.dataTemplate.desc_zh = data.desc
    }
  }
}
</script>
<style lang="scss" scoped>
.el-table >>> .el-radio-group {
  margin-left: 10px;
  margin-right: 10px;
}

.mobile-btn {
  &:focus {
    border: 1px solid #dcdfe6;
    color: #606266;
  }
}

.is-active__btn {
  border: 1px solid #409eff;
  background: #409eff;
  color: #fff;

  &:focus {
    color: #fff;
  }
}

/deep/.default-row > .cell {
  overflow: visible !important;
}

/deep/.el-button--mini {
  padding: 7px;
}

.tablebox {
  /deep/ .el-table--scrollable-x .el-table__body-wrapper {
    overflow: auto !important;
  }

  /deep/.el-table__fixed-right-patch {
    background-color: #f5f7fa !important;
  }
}
</style>