InFeedFlowDotModal.vue 9.69 KB
<template>
<a-modal
      :visible="visible"
      :maskClosable="false" 
      :confirmLoading="confirmLoading"
      title='新增'
      @ok="handleSubmit"
      @cancel="handleCancel"
      cancelText="关闭"
    >
    <a-form :form="form" :spinning="confirmLoading">
        <a-form-item label="节点名称:" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol">
          <a-select 
              v-decorator="['name',{ rules: [{ required: true, message: '请选择节点名称' }] }]"
              placeholder="请选择节点名称"
              @change="handleSelectChangeName"
              :disabled = 'disabledName'
          >
              <a-select-option 
                v-for="(item, index) in flowInfoList" :key="index" :value="item.name" :disabled="item.checked">
                {{item.name}}
              </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="节点序号:" :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol">
            <a-select 
              v-decorator="['index',{ rules: [{ required: true, message: '请选择节点序号' }] }]"
              placeholder="请选择节点序号"
              @change="handleSelectChangeIndex"
              :disabled = 'disabledName'
            >
              <a-select-option 
                v-for="(item, index) in flowInfoList" :key="index" :value="index+1" :disabled="item.checked">
                {{index+1}}
              </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="选择节点服务:"  :labelCol="{xs: { span: 8 },sm: { span: 5 }}" :wrapperCol="wrapperCol">
            <a-row v-decorator="[ 'data',{'initialValue':model.data}]"  v-for="(item,index) in flowInfoList" :key="index">
              <div v-if="(item.name == selectVal) && (item.nodeServices != null)">
                <a-col  v-for="(items,indexs) in item.nodeServices" :key="indexs">
                  <a-checkbox :value="items.name" :checked="items.checked || items.necessary" :disabled="items.disabled || items.necessary" @change="onChangeCheckbox(items)" >{{items.name}}</a-checkbox>

                  <a-row :gutter="24" v-if="(items.checked) && (items.data != null)">
                    <a-form-item label="决策类型:" :labelCol="{xs: { span: 8 },sm: { span: 6 }}" :wrapperCol="wrapperCol">
                      <a-select 
                        v-decorator="['data',{'initialValue':model.data}]"
                        placeholder="请选择决策类型"
                        @change="handleSelectChangeType"
                      >
                        <a-select-option 
                          v-for="(itemss, indexss) in items.data" :key="indexss" :value="indexss">
                          {{itemss}}
                        </a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-row>

                </a-col>
              </div>
            </a-row>
            
            
        </a-form-item>
        <a-form-item label="备注" :labelCol="{xs: { span: 8 },sm: { span: 6 }}" :wrapperCol="wrapperCol">
          <a-textarea :rows="4" placeholder="最多输入60字" v-decorator="[ 'remark' ]" />
      </a-form-item>
    </a-form>
</a-modal>

</template>
<script>
  import store from '@/store'
  import pick from 'lodash.pick'
  import {mapMutations,mapState} from 'vuex'
  export default {
    name: "PasswordModal",
    data () {
      return {
        visible: false,
        confirmLoading: false,
        title: '',
        flowNodeData:[],  // 
        parentDotData: [],
        childDotData:[],  //个人节点名称->映射子项
        nodeServices:[],
        validatorRules:{
          name: {
            rules:[{
              required: true,
              message: '请输入节点名称'
            }]
          },
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        emitDataCollect: [],
        form: this.$form.createForm(this),
        model: {},
        personInfoEngineData:[],//决策引擎配置
        value: [],
        checked:false,
        defaultChecked:false,
        status:null,
        //...
        flowListData:[],//原始flow 数据
        selectOptionsData:[],//select options数据
        checkOptionsData:[],//check options数据
        flowInfoList: [], //原始store中数据
        selectVal:'',//节点选择后数据
        disabledName:false
      }
    },
    created() {
    },
    watch:{
      '$store.state.flow.flowInfoList': function (newVal,oldVal) {
        this.flowInfoList = newVal
      }
    },
    methods: {
      //处理编辑回显示节点process数据
      handleFlowListData(data,orgin){
        let arr = []
        for(var idx = 0; idx < orgin.length; idx++) {
          if(orgin[idx].code == data.code){
            orgin[idx].checked = data.checked
            orgin[idx].data = data.data
            return orgin[idx]
          }
        }
        
      },
      //处理编辑回显示节点process数据
      handleFlowListDataToList(data,orgin){
        //先重置所有数据
        var num = null
        this.flowInfoList = this.handleResetCheckedData(orgin)
        for(var idx in orgin){
          if(orgin[idx].code == data.code){
              num = idx
          }
        }
        if(orgin[num].nodeServices){
          for(var idx_1 in orgin[num].nodeServices){
            if(data.nodeServices){
              for(var idx_2 in data.nodeServices){
                if(orgin[num].nodeServices[idx_1].code == data.nodeServices[idx_2].code){
                  orgin[num].nodeServices[idx_1].checked = true
                }
              }
            }
          }
        }
        return orgin
        this.$forceUpdate();
      },
      //处理选中的数据
      handleSelectFlowListData(data,orgin){//新数据,原数据
        var arr = []
        for(var idx = 0; idx < orgin.length; idx++) {
          if(orgin[idx].name == data.name){
            data.checked = true
            data.code = orgin[idx].code
          }
          if(orgin[idx].nodeServices){
            for(var idx1 = 0; idx1 < orgin[idx].nodeServices.length; idx1++) {
              if(orgin[idx].nodeServices[idx1].checked){
                arr.push(orgin[idx].nodeServices[idx1]) 
              }
            }
          }
        }
        data.nodeServices = arr
        return data
      },
      //处理 reset数据
      handleResetCheckedData(orgin){
        for(var idx = 0; idx < orgin.length; idx++) {
          if(orgin[idx].checked){
            delete orgin[idx].checked
          }
          if(orgin[idx].nodeServices){
            for(var idx1 = 0; idx1 < orgin[idx].nodeServices.length; idx1++) {
              
              if(orgin[idx].nodeServices[idx1].code == 'AGREEMENT_SIGNED' && orgin[idx].nodeServices[idx1].checked){
                orgin[idx].nodeServices[idx1].flag = true
              }
               
              if(orgin[idx].nodeServices[idx1].code == 'AGREEMENT_SIGNED' && orgin[idx].nodeServices[idx1].flag){

                for(var idx_1 = 0; idx_1 < orgin.length; idx_1++) {
                  if(orgin[idx_1].nodeServices){
                    for(var idx_2 = 0, _nodeServices = orgin[idx_1].nodeServices; idx_2 < _nodeServices.length; idx_2++) {
                      if(orgin[idx_1].nodeServices[idx_2].code == 'AGREEMENT_SIGNED'){
                       orgin[idx_1].nodeServices[idx_2].disabled = true
                      }
                    }
                  }
                }
                orgin[idx].nodeServices[idx1].disabled = false
              }
              
              
              if(orgin[idx].nodeServices[idx1].checked){
                delete orgin[idx].nodeServices[idx1].checked
              }
            }
          }
        }
        return orgin
      },
      handleSelectChangeName(val) {
        this.selectVal = val
      },
      //select 选择框选择内容
      handleSelectChangeIndex(val) {
        
      },
      handleSelectChangeType(){

      },
      onChangeCheckbox(e){
        e.checked = !e.checked
        this.$forceUpdate();
      },
      edit (record,val) {
        this.status = 1
        this.model = record;
        this.disabledName = true
        this.selectVal = record.name
        this.form.resetFields();
        this.visible = true;
        this.$nextTick(() => {
          this.flowListData = this.handleFlowListDataToList(record,val)
          this.form.setFieldsValue(pick(record,'name','index','remark'));
         
        });
      },
      add (val) {
        //新增时候拿到原始flowList数据
        this.status = 0
        this.model = {};
        this.disabledName = false
        this.form.resetFields();
        //将选中的数据重置
        this.flowInfoList = this.handleResetCheckedData(val)
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue();
        });
      },

      close () {
        this.$emit('close');
        this.visible = false;
        this.disableSubmit = false;
        this.checkedRole = [];
      },
      handleSubmit () {
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
          this.confirmLoading = true;
          let formData = this.handleSelectFlowListData(values,this.flowInfoList)
          // console.log(formData)
          this.$emit('ok', formData,this.status);
          this.confirmLoading = false;
          this.close();
          this.reset()
          }
        })
      },
      handleCancel () {
        this.close()
      },
      reset(){
        this.selectVal = ''
      }
    }
  }
</script>
<style scoped>

</style>