buttonGrouop.vue 7.53 KB
Newer Older
wangcong committed
1
<template>
2
  <div ref="btnGroup" class="btngroup-container" :style="btnContainerStyle">
袁成 committed
3
    <ButtonGroup v-if="buttonShow" class="button-group">
wangcong committed
4 5 6 7 8 9 10 11 12
      <div v-for="(item, index) in btnGroup" :key="index">
        <gms-button :define="item.buttonDefine" :context="context" :billStateDisable="item.billStateDisable"></gms-button>
        <Divider type="vertical" />
      </div>
    </ButtonGroup>
  </div>
</template>
<script>
const ACTIONS = GMS.getContext().getEmconCollector().getElements('billAction')
13
const iconMap = {
袁成 committed
14 15 16
  'CW_createBill': '#icon-a-16_GJ_A_rbc_xinjian',
  'CW_editBill': '#icon-a-16_GJ_A_rbc_bianji',
  'CW_deleteBill': '#icon-a-16_GJ_A_rbc_shanchu',
袁成 committed
17
  'CW_tempSave': '#icon-a-16_GJ_A_rbc_zancun',
袁成 committed
18
  'CW_saveAction': '#icon-a-16_GJ_A_rbc_baocun',
袁成 committed
19
  'CW_submitAction': '#icon-a-16_GJ_A_rbc_tijiao',
20 21 22 23
  'first': '#icon-shouzhang',
  'upward': '#icon-shangyizhang',
  'down': '#icon-xiayizhang',
  'last': '#icon-mozhang',
袁成 committed
24 25 26
  'CW_printAction': '#icon-a-16_GJ_A_rbc_dayin1',
  'CW_rejectAction': '#icon-a-16_GJ_A_rbc_bohui',
  'CW_agreeAction': '#icon-a-16_GJ_A_rbc_tongyi',
袁成 committed
27
  'CW_closeAction': '#icon-a-16_GJ_A_rbc_guanbi'
28
}
wangcong committed
29 30 31 32 33 34 35 36 37 38 39
export default {
  inject: ['tmpBill'],
  props: ['define', 'context'],
  data() {
    return {
      btnContainerStyle: {
        position: '',
        top: '',
        bottom: ''
      },
      btnGroup: [],
袁成 committed
40 41
      workflowState: 0,
      buttonShow: true
wangcong committed
42 43 44 45 46 47 48 49 50
    }
  },
  watch: {
    'tmpBill.state': {
      handler() {
        this.getBtnGroup()
      },
      immediate: true,
    },
袁成 committed
51 52 53 54 55 56 57 58
    'tmpBill.type': {
      handler(nv) {
        if (nv === 'draftLoad') {
          this.buttonShow = false
        }
      },
      immediate: true
    },
59 60 61 62 63 64 65 66
    'tmpBill.$attrs.hideButtonGroup': {
      handler(nv) {
        if (nv) {
          this.buttonShow = false
        }
      },
      immediate: true
    },
wangcong committed
67 68 69 70 71
  },

  mounted() {
    // 判断是否在typesBill组件中
    const location = this.define.layout.adsorption === 'bottom' ? 'bottom' : 'top'
72
    if (this.checkParent()) {
wangcong committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
      if (location === 'top') {
        this.btnContainerStyle = {
          position: 'fixed',
          top: '36px',
        }
      } else {
        this.btnContainerStyle = {
          position: 'fixed',
          bottom: '0px',
        }       
      }
    } else {
      this.btnContainerStyle = {
        position: 'absolute',
        [location]: '0px',
      } 
    }
90
    // 监听工作流状态改变
91
    GMS.vbus.$on("workflow-state-change", this.handleWorkflowStateChange)
92 93
  },
  beforeDestroy() {
94
    GMS.vbus.$off("workflow-state-change", this.handleWorkflowStateChange);
wangcong committed
95 96
  },
  methods: {
97 98 99 100
    handleWorkflowStateChange(val) {
      this.workflowState = val
      this.getBtnGroup()
    },
101 102 103 104 105 106 107 108 109 110
    checkParent() {
      let curNode = this.$refs.btnGroup
      while (curNode) {
        if (!curNode.nodeName) break
        if (curNode.nodeName.toLowerCase() == 'body') break
        if (curNode.classList.contains('initHeight')) return true
        curNode = curNode.parentNode
      }
      return false
    },
wangcong committed
111 112 113 114 115 116 117 118 119 120
    getBtnGroup() {
      const keys = this.define.config ? this.define.config.btnConfig : []
      this.btnGroup = keys.map((item) => {
        let btnConfg = {
          buttonDefine: {
            config: {
              action: 'ButtonControl_1_action_gams',
              size: 'default',
              text: '关闭',
              type: 'text',
121
              leftIcon: ''
wangcong committed
122 123 124 125
            },
            layout: {},
            name: 'ButtonControl_1',
            title: '关闭',
袁成 committed
126
            except: true
wangcong committed
127 128 129 130 131 132 133 134 135 136 137 138 139
          },
          billStateDisable: false
        }
        btnConfg.buttonDefine.config.action = this.define.config.action + item
        btnConfg.buttonDefine.config.text =
          this.define.btnGroupAction &&
          this.define.btnGroupAction[item] &&
          this.define.btnGroupAction[item].btnName
            ? this.define.btnGroupAction[item].btnName
            : ACTIONS[item].title.substring(
                ACTIONS[item].title.indexOf('_') + 1,
                ACTIONS[item].title.indexOf('[')
              )
140 141 142
        btnConfg.buttonDefine.config.leftIcon =
          this.define.btnGroupAction &&
          this.define.btnGroupAction[item] &&
143
          this.define.btnGroupAction[item].btnIcon? this.define.btnGroupAction[item].btnIcon: iconMap[item]
wangcong committed
144
        btnConfg.billStateDisable = this.getBillStateDisable(
145
          ACTIONS[item].btnDisable, item
wangcong committed
146 147 148 149 150
        )
        btnConfg.buttonDefine.name = this.define.config.action + item
        return btnConfg
      })
    },
151
    getBillStateDisable(val, btnItem) {
qiaoyanqi committed
152 153 154 155 156 157 158 159 160 161
      let disableState = val.split(";");
      const getBillState = () => {
          if (this.tmpBill.state === "") {
            return disableState.includes("billEdit");
          } else if (this.tmpBill.state === "readOnly") {
            return disableState.includes("billReadOnly");
          } else {
            return false;
          }
      };
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
      if (//不走工作流的情况下,执行自定义的按钮禁用状态
        this.define.btnGroupAction &&
        this.define.btnGroupAction[btnItem] &&
        this.define.btnGroupAction[btnItem].disArr &&
        this.define.btnGroupAction[btnItem].disArr.length > 0
      ) {
        let arr = this.define.btnGroupAction[btnItem].disArr;
        let flag = false;//不禁用
        for(let i=0;i<arr.length;i++){
          let valueArr = arr[i].value.split(";");
          let billField = this.context.bill.getMasterData().getValue(arr[i].key.split('.')[1]);
          if(valueArr.includes(billField)){
            flag = true;//禁用
            break;
          }
        }
qiaoyanqi committed
178
        return flag || getBillState();
179
      } else {
180 181 182 183 184 185 186 187 188
        if (!val) return false;
        let approveState = null;
        if (this.workflowState === 0) {
          approveState = this.context.bill
            .getMasterData()
            .getValue("billState");
        } else {
          approveState = this.workflowState;
        }
qiaoyanqi committed
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
        // 配置工作流已提交未审批90, billReadOnly状态下可用
        // 主要用于保存在审批状态下可用,审批还能修改··
        if (
          this.define.btnGroupAction &&
          this.define.btnGroupAction[btnItem] &&
          this.define.btnGroupAction[btnItem].isApprove
        ) {
          disableState = disableState.filter((item) => {
            if (item === "90") {
              return false;
            } else {
              return true;
            }
          });
        }
        switch (approveState) {
          case 90: // 待审批
            return disableState.includes("90");
          case 91: // 被驳回
            return disableState.includes("91") || getBillState();
          case 92: // 审批完成
            return disableState.includes("92");
          case 1: // 已暂存
            return disableState.includes("1") || getBillState();
          case 2: // 已保存
            return disableState.includes("2") || getBillState();
          default:
            return getBillState();
wangcong committed
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
        }
      }
    },
  },
}
</script>
<style scoped lang="less">
.btngroup-container {
  width: 100% !important;
  position: absolute;
  left: 0;
  z-index: 900;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  border-top: 1px solid #e8e8e8;
  /deep/ .dy-button {
    margin: 0;
    .ivu-tooltip-rel {
      .ivu-btn {
        margin: 0;
        padding: 0 5px;
      }
    }
    .ivu-btn {
      padding: 0 5px;
    }
    .ivu-btn-text:focus {
      box-shadow: none;
    }
  }

  .button-group {
    display: flex;
    padding: 0 10px;
252 253 254 255
    /deep/ .ivu-divider, .ivu-divider-vertical {
      height: 1.3em;
      top: 0;
    }
wangcong committed
256 257
  }
}
qiaoyanqi committed
258
</style>