<template>
  <!-- 过程节点配置 -->
  <div class="DynamicProcessNodeConfig">
    <div>
      <div class="splitItem">节点配置</div>
      <div class="nodeSetbox">
        <Form>
          <!-- 节点名称 -->
          <FormItem label="节点名称：" :label-width="100">
            <Input v-model="configData.name" placeholder="请输入" :disabled="readOnly"/>
          </FormItem>

          <!-- 单据类型选择 -->
          <FormItem label="单据类型：" :label-width="100" >
            <DropDownSelectFilter
              :disabled="readOnly"
              v-bind="tableConfig.props"
              v-on="tableConfig.event"
            >

            </DropDownSelectFilter>
          </FormItem>

          <!-- 可见按钮 -->
          <FormItem label="可见按钮：" :label-width="100">
            <Select v-model="configData.visibleBt" :disabled="readOnly" multiple @on-change="visibleBtChange" >
              <Option v-for="(item,index) in visibleButtons" :key="index" :value="item.ID">{{item.Label}}</Option>
            </Select>
          </FormItem>

          <!-- 节点必经 -->
          <FormItem label="节点必经：" :label-width="100">
            <Select v-model="configData.inevitable" :disabled="readOnly" >
              <Option  :value="0" :key="0">是</Option>
              <Option  :value="1" :key="1">否</Option>
              <Option  :value="2" :key="2">扩展</Option>
            </Select>
          </FormItem>
          <FormItem  :label-width="100" v-if="configData.inevitable === 2">
            <label slot="label"><i class="requireStyle">*</i>规则配置：</label>
            <RuleConfig headTitle="节点必经规则" :tableConfig="{tableId:configData.nodeFormId,tableName:configData.nodeForm}" :defaultData="configData.inevitableExts" @getResult="inevitableResult"></RuleConfig>
          </FormItem>

          <!-- 节点指派 -->
          <FormItem label="节点必指派：" :label-width="100">
            <Select v-model="configData.assignNode" :disabled="readOnly" >
              <Option  :value="0" :key="0">是</Option>
              <Option  :value="1" :key="1">否</Option>
            </Select>
          </FormItem>

          <!-- 审批人 -->
          <FormItem  :label-width="100">
            <label slot="label"><i class="requireStyle">*</i>选择操作人：</label>
            <Select v-model="configData.approverStyle" :disabled="readOnly" @on-change="approverStyleChange">
              <Option  :value="0" :key="0">直接选择</Option>
              <Option  :value="1" :key="1">扩展程序</Option>
            </Select>
          </FormItem>
          <FormItem  :label-width="100" v-if="configData.approverStyle === 0">
            <label slot="label"><i class="requireStyle">*</i>操作人：</label>
            <complexPop :title="'选择操作人'" :resultData="resultData" :disabled="readOnly" @getTotalResult="getResult"></complexPop>
          </FormItem>
          <FormItem  :label-width="100" v-if="configData.approverStyle === 1">
            <label slot="label"><i class="requireStyle">*</i>扩展程序：</label>
            <Input v-model="configData.actionConfig[0].handleValue" placeholder="请输入" :disabled="readOnly" />
          </FormItem>

          <!-- 动态指派操作人 -->
          <FormItem label="动态指派操作人：" :label-width="110">
            <!-- <Select v-model="configData.assignApprover" :disabled="readOnly" >
              <Option  :value="0" :key="0">动态指派节点操作人</Option>
              <Option  :value="1" :key="1">默认操作人</Option>
            </Select> -->
            <i-switch class="switchPage" v-model="configData.assignApprover" :true-value="0" :false-value="1" :disabled="readOnly" />
          </FormItem>

          <!-- 审批条件 -->
          <FormItem label="审批条件：" :label-width="100" v-if="configData.category === 'Approval'">
            <Select v-model="configData.approveCondition" :disabled="readOnly" >
              <Option  :value="0" :key="0">自定义人数配置</Option>
              <Option  :value="1" :key="1">会签</Option>
              <Option  :value="2" :key="2">或签</Option>
            </Select>
          </FormItem>
          <FormItem v-if="configData.approveCondition === 0 && configData.category === 'Approval'">
              <Row>
                  <Col span="24" style="display:flex">
                    <span>
                      <i class="requireStyle">*</i>
                      <Icon
                        v-if="pageBtnData[0].color"
                        :type="pageBtnData[0].icontype===1?'ios-checkmark-circle':'ios-close-circle'"
                        :color="pageBtnData[0].color"
                      />
                      {{pageBtnData[0].label}}：
                    </span>
                    <Input v-model="pageBtnData[0].value"  :regx="/^[0-9]*$/" @on-blur="onBlur(...arguments,0)" style="flex:1" :disabled="readOnly" />
                  </Col>
              </Row>
          </FormItem>
          <FormItem v-if="configData.approveCondition === 0 && configData.category === 'Approval'">
              <Row>
                  <Col span="24" style="display:flex">
                    <span>
                      <i class="requireStyle">*</i>
                      <Icon
                        v-if="pageBtnData[2].color"
                        :type="pageBtnData[2].icontype===1?'ios-checkmark-circle':'ios-close-circle'"
                        :color="pageBtnData[2].color"
                      />
                      {{pageBtnData[2].label}}：
                    </span>
                    <Input v-model="pageBtnData[2].value"  :regx="/^[0-9]*$/" @on-blur="onBlur(...arguments,2)" style="flex:1" :disabled="readOnly" />
                  </Col>
              </Row>
          </FormItem>

          <!-- 当前可为驳回节点 -->
          <FormItem label="可为驳回节点：" :label-width="100">
            <Select v-model="configData.whetherBack" :disabled="readOnly" >
              <Option  :value="0" :key="0">是</Option>
              <Option  :value="1" :key="1">否</Option>
            </Select>
          </FormItem>

          <!-- 驳回按钮 -->
          <FormItem label="驳回按钮：" :label-width="100">
            <i-switch class="switchPage" v-model="configData.nodeBack" :true-value="0" :false-value="1" :disabled="readOnly" />
          </FormItem>

          <!-- 驳回操作 -->
          <FormItem label="驳回操作：" :label-width="100" v-if="configData.category === 'Approval'">

            <Select v-model="configData.assignBack" :disabled="readOnly" >
              <Option  :value="0" :key="0">动态指派(在流程中手动指派节点)</Option>
              <Option  :value="1" :key="1">指定驳回节点</Option>
            </Select>
          </FormItem>
          <FormItem :label-width="100" v-if="configData.assignBack === 1 && configData.category === 'Approval'">
            <label slot="label"><i class="requireStyle">*</i>驳回节点：</label>
            <Select v-model="configData.backId" :disabled="readOnly">
                <Option v-for="item in rejectedNodes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <!-- <FormItem label="操作人：" :label-width="100" v-if="(configData.assignBack === 0 || configData.assignBack === 1) && configData.category === 'Approval'">
            <Select v-model="configData.assignApprover" :disabled="readOnly" >
              <Option  :value="0" :key="0">动态指派(手动指派驳回节点的操作人)</Option>
              <Option  :value="1" :key="1">默认(下一阶段设置的操作人)</Option>
            </Select>
          </FormItem> -->

          <!-- 同意按钮 -->
          <FormItem label="同意操作：" :label-width="100" v-if="configData.category === 'Approval'">
            <i-switch class="switchPage" v-model="configData.nodeAgree" :true-value="0" :false-value="1" :disabled="readOnly" />
          </FormItem>

          <!-- 直接结束流程 -->
          <FormItem label="直接结束流程:"  :label-width="100" v-if="configData.category === 'Approval'">
            <i-switch class="switchPage" v-model="configData.manualConfig" :true-value="'1'" :false-value="'0'" :disabled="readOnly" />
          </FormItem>


          <!-- 跳转路径 -->
          <FormItem label="跳转路径：" :label-width="100">
            <Input v-model="configData.nodeUrl" placeholder="请输入" :disabled="readOnly"/>
          </FormItem>

          <!-- 前置事件 -->
          <FormItem label="前置事件：" :label-width="100">
            <!-- <Input v-model="configData.nodeUrl" placeholder="请输入" :disabled="readOnly"/> -->
            <RuleConfig headTitle="前置事件规则" :tableConfig="{tableId:configData.nodeFormId,tableName:configData.nodeForm}" :defaultData="configData.preEvent" @getResult="preEventResult"></RuleConfig>
          </FormItem>

          <!-- 后置事件 -->
          <FormItem label="后置事件：" :label-width="100">
            <!-- <Input v-model="configData.nodeUrl" placeholder="请输入" :disabled="readOnly"/> -->
            <RuleConfig headTitle="后置事件规则" :tableConfig="{tableId:configData.nodeFormId,tableName:configData.nodeForm}" :defaultData="configData.behindEvent" @getResult="behindEventResult"></RuleConfig>
          </FormItem>


        </Form>
      </div>

      <div class="splitItem">节点操作权限</div>
      <div class="nodeSetbox">
        <Form>
          <!-- 显示字段 -->
          <FormItem label="显示字段：" :label-width="100">
            <Row>
                <Col span="19">
                    <DropMultiSelectFilter
                      :disabled="readOnly"
                      :single="false"
                      :totalRowCount="modifyField.totalRowCount"
                      :pageSize="modifyField.pageSize"
                      @on-page-change="changePage"
                      :dataEmptyMessage="modifyField.dataEmptyMessage"
                      @on-input-value-change="inputChange"
                      @on-fkrp-selected="OnFkrpSelected"
                      @on-popper-show="onPopperShow"
                      @on-clear="onClear"
                      :data="modifyField.data"
                      :hidecolumns="modifyField.columns"
                      :AutoData="modifyField.AutoData"
                      :default-selected="modifyField.defaultSelected"
                      :columnsKey="modifyField.columnsKey"
                    ></DropMultiSelectFilter>
                </Col>
                <Col span="4" offset="1">
                  <span style="color:#5B85E4;cursor:pointer" v-if="configData.modifiableField.length > 0" @click="modifiableFieldClick">{{modifyTableShow?'关闭修改':'更改权限'}}</span>
                  <span style="color:#ccc;cursor:pointer" v-if="configData.modifiableField.length === 0">更改权限</span>
                </Col>
            </Row>
          </FormItem>
          <FormItem v-if="modifyTableShow && configData.modifiableField.length > 0">
            <Row>
              <Table border height="200" :columns="modifyColumns" :data="configData.modifiableField"></Table>
            </Row>
          </FormItem>

          <!-- 作废操作 -->
          <FormItem label="作废操作：" :label-width="100">
            <Select v-model="configData.nodeCancle" :disabled="readOnly" >
              <Option  :value="0" :key="0">直接作废</Option>
              <Option  :value="1" :key="1">发起作废(提交作废申请)</Option>
              <Option  :value="2" :key="2">否(不显示作废按钮)</Option>
            </Select>
          </FormItem>
          <FormItem  :label-width="100" v-if="configData.nodeCancle === 1">
            <label slot="label"><i class="requireStyle">*</i>申请地址：</label>
            <Input v-model="configData.cancleUrl" placeholder="请输入" :disabled="readOnly"/>
          </FormItem>

          <!-- 指派流转节点 -->
          <FormItem label="指派流转节点：" :label-width="100">
            <Select v-model="configData.assignNext" :disabled="readOnly" >
              <Option  :value="0" :key="0">是(可批量指派接下来几节点的审批人)</Option>
              <Option  :value="1" :key="1">否(节点不需要流转)</Option>
            </Select>
          </FormItem>
          <FormItem  :label-width="100" v-if="configData.assignNext === 0">
            <label slot="label"><i class="requireStyle">*</i>节点范围：</label>
            <Select v-model="configData.assignRange" multiple :disabled="readOnly" >
              <Option v-for="item in assignedNodes" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>


        </Form>
      </div>

      <div class="splitItem">超时设置</div>
      <div class="nodeSetbox">
        <div class="boxItem">
          <Form>
            <FormItem label="超时提醒:" :label-width="100">
              <i-switch v-model="status1" @on-change="change1" :disabled="readOnly" />
            </FormItem>
            <FormItem label="超时阀值:" :label-width="100" :required="status1" v-if="status1">
              <Input v-model="setOvertime.threshold" :regx="/^[1-9]\d*$/" :disabled="readOnly">
                <Select v-model="setOvertime.sources" slot="append" style="width:70px" :disabled="readOnly">
                  <Option :value="0">小时</Option>
                  <Option :value="1">天</Option>
                </Select>
              </Input>
            </FormItem>
            <FormItem label="邮箱接口:" :label-width="100" :required="status1" v-if="status1">
              <Input v-model="setOvertime.handleValue" :disabled="readOnly" />
              <!-- <Select v-model="setOvertime.handle_type" slot="prepend" style="width: 90px;dispaly:none">
                  <Option :value="11">邮箱</Option>
                  <Option :value="12">钉钉消息</Option>
              </Select>-->
              <!-- <span class="tipMessage">超过这个时间段系统将自动发送提醒消息</span> -->
            </FormItem>
          </Form>
        </div>
        <div class="boxItem" v-if="configData.category === 'Approval'">
          <Form>
            <FormItem label="自动处理:" :label-width="100">
              <i-switch v-model="status2" @on-change="change2" :disabled="readOnly" />
            </FormItem>
            <FormItem label="自动处理阀值:" :label-width="100" :required="status2" v-if="status2">
              <Input v-model="autoDetail.threshold" :regx="/^[1-9]\d*$/" :disabled="readOnly">
                <Select v-model="autoDetail.sources" slot="append" style="width: 70px" :disabled="readOnly">
                  <Option :value="0">小时</Option>
                  <Option :value="1">天</Option>
                </Select>
              </Input>
            </FormItem>
            <FormItem label="自动处理方式:" :label-width="100" :required="status2" v-if="status2">
              <Select v-model="autoDetail.handleType" :disabled="readOnly">
                <Option :value="20">同意</Option>
                <Option :value="21">驳回</Option>
              </Select>
            </FormItem>
          </Form>
        </div>
      </div>
    </div>
    <p>
      <Button type="fcdefault" @click="closeDrawer">取消</Button>
      <Button type="primary" @click="saveConfig" v-if="!readOnly">确定</Button>
    </p>
  </div>
</template>
<script>
import complexPop from "@/components/complexPop";
import RuleConfig from "@/components/RuleConfig"
export default {
  name: "DynamicProcessNodeConfig",
  components: { complexPop, RuleConfig },
  props: {
    configData: {
      type: Object,
      default() {
        return {};
      }
    },
    TABLE_ID: {
    }, //模版第一步配置表数据
    node:{},  //当前节点
    status:null,
    rejectedNodes:{
      type: Array,
      default: () => {
        return []
      }
    },
    assignedNodes:{
      type: Array,
      default: () => {
        return []
      }
    },
    readOnly:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      //节点表的配置
      tableConfig:{
        props:{
          columnsKey: ['NAME'],
          AutoData: [],
          hidecolumns: ['id'],
          data: {},
          totalRowCount: 0,
          defaultSelected: [],
          isBackRowItem: true
        },
        event:{
          'on-input-value-change': (value) => {
              // 外键的模糊搜索
              this.tableConfig.props.AutoData = []
              this.$network.post('/p/c/meta/table/list',{DESCRIPTION:value}).then(res => {
                if(res.data.code === 0){
                  // this.row = res.data.data.row.concat([])
                  this.tableConfig.props.AutoData = res.data.data.row.reduce((arr,item) => {
                    arr.push({
                      value:item.NAME.val,
                      id:item.ID.val,
                      NAME:item.DESCRIPTION.val
                    })
                    return arr
                  },[]);
                }

              })
          },
          'on-popper-show': ($this) => {
            // 当外键下拉站开始去请求数据
            // this.freshDropDownSelectFilterData($this)
            this.$network.post('/p/c/meta/table/list',{
              pageSize:$this.pageSize,
              page:1
            }).then(res => {
              if(res.data.code === 0){
                res.data.data.tabth.forEach(item => {
                  if(item.colname === 'DESCRIPTION'){
                    item.isak = true
                  }
                  return item
                })
                this.tableConfig.props.data = res.data.data;
                this.tableConfig.props.totalRowCount = res.data.data.totalRowCount;
              }

            })
          },
          'on-page-change': (currentPage, $this) => {
            // 外键的分页查询
            // this.freshDropDownSelectFilterData($this,currentPage)
            this.$network.post('/p/c/meta/table/list',{
              pageSize:$this.pageSize,
              page:currentPage
            }).then(res => {
              if(res.data.code === 0){
                res.data.data.tabth.forEach(item => {
                  if(item.colname === 'DESCRIPTION'){
                    item.isak = true
                  }
                  return item
                })
                this.tableConfig.props.data = res.data.data;
                this.tableConfig.props.totalRowCount = res.data.data.totalRowCount;
              }

            })
          },
          'on-blur':(event,instance) => {
            // if(Object.prototype.toString.call(this.data.businessType) !== '[object Array]' || this.data.businessType.length === 0){
            //   instance.inputValue = ''

            //   /*
            //     todo
            //     清空所有和主表有关的数据
            //   */

            // }
          },
          'on-fkrp-selected': (value) => {
            if(value.length > 0){
              this.configData.nodeForm = value[0].rowItem.NAME.val?value[0].rowItem.NAME.val:value[0].rowItem.NAME
              this.configData.nodeFormId = value[0].ID
              this.configData.nodeFormName = value[0].Label

              this.getVisibleButtons()
            }else{
              this.configData.nodeForm = null
              this.configData.nodeFormId = null
              this.configData.nodeFormName = null
            }

            // 清除有关字段数据
            this.onClear()
            this.modifyField.defaultSelected = []
            this.configData.behindEvent = []
            this.configData.preEvent = []
            this.configData.inevitableExts = []
            this.configData.visibleBt = []
          },
          'on-clear': () => {
            // 清除有关字段数据
            this.onClear()
            this.modifyField.defaultSelected = []
            this.configData.behindEvent = []
            this.configData.preEvent = []
            this.configData.inevitableExts = []
            this.configData.visibleBt = []

            this.configData.nodeForm = null
            this.configData.nodeFormId = null
            this.configData.nodeFormName = null
            this.tableConfig.props.AutoData = []
              this.$network.post('/p/c/meta/table/list',{DESCRIPTION:''}).then(res => {
                if(res.data.code === 0){
                  this.tableConfig.props.AutoData = res.data.data.row.reduce((arr,item) => {
                    arr.push({
                      value:item.NAME.val,
                      id:item.ID.val,
                      NAME:item.DESCRIPTION.val
                    })
                    return arr
                  },[]);
                }
              })
          }
        }
      },

      visibleButtons:[], // 可见按钮


      //修改字段配置

      // 可显示字段
      modifyField: {
        modifiable_field: "选中的字段",
        modifiable_field_name: "", //选中的字段名称1
        totalRowCount: 0, //数据总条数
        pageSize: 10, //每页数据条数
        dataEmptyMessage: "数据为空", //没数据时的提示
        data: {}, //表格数据
        columnsKey: ["value"], //input显示的字段
        columns: ["id"], //模糊搜索隐藏的列
        AutoData: [],
        defaultSelected: []
      },
      modifyTableShow: false,
      modifyColumns:[
        {
          title: '序号',
          render: (h, params) => {
              return h('span', {},params.index + 1);
          }
        },
        {
          title: '字段名',
          key: 'Label'
        },
        // {
        //   title: '必填',
        //   key: 'isnotnull',
        //   render: (h, params) => {
        //       return h('Checkbox', {
        //         props:{
        //           'value':params.row.isnotnull
        //         },
        //         on:{
        //           'on-change': (value) => {
        //             this.configData.modifiableField[params.index].isnotnull = value
        //           }
        //         }
        //       });
        //   }
        // },
        {
          title: '只读',
          key: 'readonly',
          render: (h, params) => {
              return h('Checkbox', {
                props:{
                  'value':params.row.readonly
                },
                on:{
                  'on-change': (value) => {
                    this.configData.modifiableField[params.index].readonly = value
                  }
                }
              });
          }
        },
        {
          title:'操作',
          render:(h,params) => {
            return h('span',{
              style:{
                color:'rgba(16, 142, 233, 1)',
                cursor:'pointer'
              },
              on:{
                click:() => {
                  this.configData.modifiableField = this.configData.modifiableField.filter((item,index) => index !== params.index)
                  this.modifyField.defaultSelected = this.configData.modifiableField
                  if(this.modifyField.defaultSelected.length === 0){
                    this.modifyTableShow = false
                  }
                }
              }
            },'删除')
          }
        }
      ],

      pageBtnData: [
        {
          label: "最少同意人数",
          icontype: 1,
          color: "#09A155",
          value: ""
        },
        {
          label: "同意状态别名",
          icontype: 1,
          color: "#09A155",
          value: ""
        },
        {
          label: "最少拒绝人数",
          icontype: 2,
          color: "#ED4014",
          value: ""
        },
        {
          label: "拒绝状态别名",
          icontype: 2,
          color: "#ED4014",
          value: ""
        }
      ],
      status1: false, //超时提醒
      status2: false, //自动处理
      openControl: false, //控制弹框是否显示
      loading: false, // z最大loading
      resultData: {}, // 选中结果
      open: false, // 是否打开
      obj: {}, //传给table的对象
      saveObj: {}, //存储的每次节点的对象
      selectRow: [], //弹框多选单击一行的数据
      approves: "", //审批相关数据
      setOvertime: {
        threshold: "",
        sources: 0,
        status: 1,
        handleValue: "",
        handleType: 11,
        extraMsg: ""
      },
      autoDetail: {
        threshold: "",
        sources: 0,
        status: 1,
        handleType: 20,
        extraMsg: "",
        handleValue: ""
      },
      approvelList: [], //存放审批相关的数据
      closeType: false, //控制审批确定取消显示状态
      isCallInterface: false,

      defaultObj:{},  //默认数据



    };
  },
  computed: {
    tableInfo () {
      return {tableId:this.configData.nodeFormId,tableName:this.configData.nodeForm}
    },
    actServiceS() {
      return [this.setOvertime, this.autoDetail];
    }
  },
  watch: {
    pageBtnData: {
      handler(newVal) {

        let temArr = [
          {
            actType: 0,
            actName: newVal[1].value,
            actLimit: newVal[0].value
          },
          {
            actType: 1,
            actName: newVal[3].value,
            actLimit: newVal[2].value
          }
        ];
        if (this.configData.ruleList.length < 1) {
          this.configData.ruleList = temArr;
        } else {
          this.configData.ruleList.map((item) => {
            temArr.map(inner => {
              if (item.actType === inner.actType) {
                item = Object.assign(item, inner);
              }
            });
          });
        }
      },
      deep: true
    },
    actServiceS: {
      handler(newVal) {
        this.configData.actServiceS = newVal;
      },
      deep: true
    },
    approvelList: {
      handler(newVal) {
        this.configData.approvelList = newVal;
      },
      deep: true
    }
  },
  methods: {
    onBlur(event, ins, key) {
      let res = /^[0-9]*$/;
      if (res.test(key)) {
        if (this.pageBtnData[key].value === "" && key == 0) {
          this.$Message.warning("最少同意人数不能为空");
        }
        if (this.pageBtnData[key].value === "" && key == 1) {
          this.$Message.warning("同意状态别名不能为空");
        }
        if (this.pageBtnData[key].value === "" && key == 2) {
          this.$Message.warning("最少拒绝人数不能为空");
        }
        if (this.pageBtnData[key].value === "" && key == 3) {
          this.$Message.warning("拒绝状态别名不能为空");
        }
      }
    },
    //可显字段下拉多选事件
    OnFkrpSelected(selected) {
      if(selected.length === 0){
        this.modifyTableShow = false
      }
      selected.map(item => {
        // item.isnotnull = false
        item.readonly = false
        return item
      })
      this.modifyField.modifiableField = selected;
      this.configData.modifiableField = selected;
    },
    onPopperShow() {
      //下拉多选
      this.findField({ AD_TABLE_ID: this.configData.nodeFormId });
    },
    changePage(val) {
      this.findField({
        pageSize: this.modifyField.pageSize,
        page: val,
        AD_TABLE_ID: this.configData.nodeFormId
      });
    },
    modifiableFieldClick () {  //可显字段只读/必填控制
      if(this.modifyTableShow){  //保存权限

      }else{  //更改权限

      }

      this.modifyTableShow = !this.modifyTableShow
    },
    //模糊查找input事件
    inputChange(val) {
      this.findField({ DESCRIPTION: val, AD_TABLE_ID: this.configData.nodeFormId });
    },
    onClear() {
      this.modifyTableShow = false
      this.modifyField.modifiableField = [];
      this.configData.modifiableField = [];
    }, //可显字段清除事件
    change1(val) {
      this.status1 = val;
      this.setOvertime = {
        threshold: "",
        sources: 0,
        status: 1,
        handleValue: "",
        handleType: 11,
        extraMsg: "",
        id:this.setOvertime.id
      }

      if (val) {
        this.setOvertime.status = 0;
      } else {
        this.setOvertime.status = 1;
      }
    },
    change2(val) {
      this.status2 = val;
      this.autoDetail = {
        threshold: "",
        sources: 0,
        status: 1,
        handleType: 20,
        extraMsg: "",
        handleValue: "",
        id:this.autoDetail.id
      }
      if (val) {
        this.autoDetail.status = 0;
      } else {
        this.autoDetail.status = 1;
      }
    },
    getResult(data) {
      this.resultData = Object.assign({}, data);
      if (this.resultData.list.length > 0) {
        this.approvelList = this.resultData.list.map(item => {
          let tem = Object.assign({}, item);
          delete tem.string;
          return tem;
        });
      } else {
        this.approvelList = [];
      }
    },
    //获取可修改字段
    findField(param) {
      this.$network.post("/p/c/meta/column/list", param).then(res => {
        if (res.data.code === 0) {
          if (param.hasOwnProperty("DESCRIPTION")) {
            this.modifyField.AutoData = [];
            this.modifyField.AutoData = res.data.data.row.reduce(
              (arr, item) => {
                arr.push({
                  value: item.DESCRIPTION.val,
                  id: item.ID.val
                });
                return arr;
              },
              []
            );
          }
          res.data.data.tabth.map(item => {
            if (item.colname === "DESCRIPTION") {
              item.isak = true;
            } else {
              item.isak = false;
            }
          });
          this.modifyField.data = res.data.data;
          this.modifyField.totalRowCount = res.data.data.totalRowCount;
        }
      });
    },

    saveConfig () {  //确定按钮点击

      // 节点必经
      if(this.configData.inevitable === 2 && (!this.configData.inevitableExts || this.configData.inevitableExts.length === 0)){
        this.$Modal.fcError({
            title: '错误',
            content: '规则配置不能为空',
            mask: true
          })
          return
      }

      // 操作人
      if(this.configData.approverStyle === 0){  //直接选择
        // 审批人为空
        if(this.configData.approvelList && this.configData.approvelList.length === 0){
          this.$Modal.fcError({
            title: '错误',
            content: '审批人不能为空',
            mask: true
          })

          return
        }
      }else{  //扩展程序
        // 扩展程序为空
        if(this.configData.actionConfig[0] && !this.configData.actionConfig[0].handleValue){
          this.$Modal.fcError({
            title: '错误',
            content: '扩展程序不能为空',
            mask: true
          })
          return
        }
      }

      // 审批条件
      if(this.configData.approveCondition === 0){
        // 最少同意人数
        if(!this.pageBtnData[0].value){
          this.$Modal.fcError({
              title: '错误',
              content: '最少同意人数不能为空',
              mask: true
            })
          return
        }
        // 最少拒绝人数
        if(!this.pageBtnData[2].value){
          this.$Modal.fcError({
              title: '错误',
              content: '最少拒绝人数不能为空',
              mask: true
            })
          return
        }
      }


      // 驳回节点
      if(this.configData.assignBack === 1 && !this.configData.backId){
        this.$Modal.fcError({
            title: '错误',
            content: '驳回节点不能为空',
            mask: true
          })
        return
      }

      // 作废操作 --发起作废申请
      if(this.configData.nodeCancle === 1 && !this.configData.cancleUrl){
        this.$Modal.fcError({
            title: '错误',
            content: '作废申请地址不能为空',
            mask: true
          })
        return
      }

      // 指派流转节点
      if(this.configData.assignNext === 0 && (!this.configData.assignRange || this.configData.assignRange.length === 0)){
        this.$Modal.fcError({
            title: '错误',
            content: '节点范围不能为空',
            mask: true
          })
        return
      }

      // 超时提醒
      if(this.status1 && (!this.setOvertime.threshold || !this.setOvertime.handleValue)){
        this.$Modal.fcError({
            title: '错误',
            content: '请填写完善超时提醒信息',
            mask: true
          })
        return
      }
      //自动处理
      if(this.status2 && (!this.autoDetail.threshold)){
        this.$Modal.fcError({
            title: '错误',
            content: '请填写完善自动处理信息',
            mask: true
          })
        return
      }

      // 控制自动处理时间大于超时提醒时间
      if(this.status1 && this.status2){
        let start = this.setOvertime.sources === 0?Number(this.setOvertime.threshold):Number(this.setOvertime.threshold)*24
        let end = this.autoDetail.sources === 0?Number(this.autoDetail.threshold):Number(this.autoDetail.threshold)*24

        if(start >= end){
          this.$Modal.fcError({
              title: '错误',
              content: '超时提醒时间不能大于自动处理时间',
              mask: true
            })
          return
        }
      }

      let guiStyle = JSON.parse(this.$parent.$parent.myDesigner.getFlowData())
      guiStyle.nodeDataArray.map(item => {
        if(this.configData.key === item.key){
          item.text = this.configData.name
        }
        return item
      })


      if((this.defaultObj.nodeFormId !== this.configData.nodeFormId) && this.defaultObj.nodeFormId){
        this.$Modal.fcError({
          title: '错误',
          content: '当前节点的表单已修改，节点后的连线配置将会清空，是否确认保存？',
          mask: true,
          showCancel: true,
          onOk: () => {
            this.node.findLinksOutOf().map(item => {
              delete this.$parent.$parent.pathMsg[item.data.key]

              let guiStyle = JSON.parse(this.$parent.$parent.myDesigner.getFlowData())
              guiStyle.linkDataArray = guiStyle.linkDataArray.filter(temp => temp.key !== item.data.key)
            })
            this.$parent.$parent.data.guiStyle = JSON.stringify(guiStyle)
            this.$parent.$parent.init()
            this.$emit('closeDrawer')
          }
        })
        return
      }else{
        this.$parent.$parent.data.guiStyle = JSON.stringify(guiStyle)
        this.$parent.$parent.init()
        this.$emit('closeDrawer')
      }

    },
    closeDrawer () {  //取消按钮点击
      this.$parent.$parent.nodeMsg[Number(this.configData.key)] = this.defaultObj
      this.$emit('closeDrawer')
    },
    approverStyleChange () {  //选择审批人类型切换
      this.configData.actionConfig[0].handleValue = null
      this.resultData = {}
      this.approvelList = [];
    },

    // 审批条件 扩展
    inevitableResult (value) {
      this.configData.inevitableExts = value
    },
    preEventResult (value) {  //前置事件处理
      this.configData.preEvent = value
    },
    behindEventResult (value) { //后置事件处理
      this.configData.behindEvent = value
    },
    getVisibleButtons () { //获取可见按钮
      this.$network.post('/p/cs/node/define/bt',{
        id: this.configData.nodeFormId,
        vueDispaly: 0
      })
      .then(res => {
        if(res.data.resultCode === 0){
          this.visibleButtons = res.data.data.difineData
        }else{
          this.visibleButtons = []
        }
      })
    },
    visibleBtChange (value) {  //可见按钮选择
      if(value[0] === 'bSelect-all'){
        this.configData.visibleBt = this.visibleButtons.reduce((arr,current) => {
          arr.push(current.ID)
          return arr
        },[])
      }
    }
  },
  created() {
    // 保存默认值
    this.defaultObj = JSON.parse(JSON.stringify(this.configData))

    if (this.configData.actionConfig.length === 0) {
      this.configData.actionConfig = [
        {
          id: null,
          handleType: 33,
          handleValue: null,
          extraMsg: null
        }
      ];
    } else {
      this.configData.actionConfig = [
        {
          id: this.configData.actionConfig[0].id,
          handleType: 33,
          handleValue: this.configData.actionConfig[0].handleValue,
          extraMsg: this.configData.actionConfig[0].extraMsg
        }
      ];
    }

    if (this.configData.modifiableField) {
      this.modifyField.defaultSelected = this.configData.modifiableField
    }


    if (
      this.configData.approvelList &&
      this.configData.approvelList.length > 0
    ) {
      this.configData.approvelList.map(item => {
        let temObj = Object.assign({}, item);
        this.approves += item.approveValueName?item.approveValueName:item.approve_value_name + ",";
        temObj.approve_type = temObj.approveType?temObj.approveType:temObj.approve_type;
        temObj.approve_value = temObj.approveValue?temObj.approveValue:temObj.approve_value;
        temObj.approve_value_name = item.approveValueName?item.approveValueName:item.approve_value_name;
        delete temObj.approveType;
        delete temObj.approveValue;
        delete temObj.approveValueName;

        let temL = Object.assign({}, temObj);
        this.approvelList.push(temObj);
        temL.string = item.approveValueName?item.approveValueName:item.approve_value_name;
        this.resultData.list
          ? this.resultData.list.push(temL)
          : this.$set(this.resultData, "list", [temL]);
      });
      this.resultData.total
        ? (this.resultData.total = this.resultData.list.length)
        : this.$set(this.resultData, "total", this.resultData.list.length);
      if (this.approves.length > 0) {
        this.approves = this.approves.substring(0, this.approves.length - 1);
      }
    }

    if (
      this.configData.ruleList &&
      this.configData.ruleList.length > 0
    ) {
      this.configData.ruleList.map(item => {
        if (item.actType === 0) {
          this.pageBtnData[1].value = item.actName;
          this.pageBtnData[0].value = item.actLimit;
        }
        if (item.actType === 1) {
          this.pageBtnData[3].value = item.actName;
          this.pageBtnData[2].value = item.actLimit;
        }
      });
    }

    if (
      this.configData.actServiceS &&
      this.configData.actServiceS.length > 0
    ) {
      this.configData.actServiceS.map(item => {
        if (item.handleType >= 20) {
          this.autoDetail = item;
        } else {
          this.setOvertime = item;
        }
      });
      this.setOvertime.status === 0
        ? (this.status1 = true)
        : (this.status1 = false);
      this.autoDetail.status === 0
        ? (this.status2 = true)
        : (this.status2 = false);
    } else {
      this.configData.actServiceS = [
        {
          threshold: "",
          sources: 0,
          status: 1,
          handleValue: "",
          handleType: 11
        },
        {
          threshold: "",
          sources: 0,
          status: 1,
          handleType: 20,
          handleValue: ""
        }
      ];
    }

    // 处理节点表配置默认值
    if(this.configData.nodeFormId){
      this.tableConfig.props.defaultSelected = [
        {
          ID: this.configData.nodeFormId,
          Label: this.configData.nodeFormName
        }
      ]
    }

    // 可见按钮
    if(this.configData.nodeFormId){
      this.getVisibleButtons()
    }
  },
  mounted() {
    //this.getTreeData();
    /**/
  }
};
</script>
<style lang="scss">
.DynamicProcessNodeConfig {
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  >p{
      text-align: right;
      margin-top: 16px;

      >button:first-child{
        margin-right: 10px;
      }
    }
  >div{
    flex: 1;
    overflow: auto;
  }
  .nodeSetbox {
    padding: 16px;
    border: 1px solid #dcdee2;
    .boxItem {
      padding: 16px 40px;
      border-bottom: 1px solid #dcdee2;
      &:last-child {
        border-bottom: none;
      }
    }
    .tipMessage {
      color: #929292;
      line-height: 16px;
    }
    .burgeon-form-item {
      margin-bottom: 16px;
      &:last-child {
        margin-bottom: 0px;
      }
    }
    &:last-child {
      padding: 0;
    }
  }
  .requireStyle {
    font-size: 14px;
    vertical-align: middle;
    color: red;
    padding-top: 5px;
    display: inline-block;
  }
  .splitItem {
    font-size: 14px;
    line-height: 40px;
    color: #929292;
    &:first-child{
      margin-top: -10px;
    }
  }
  .burgeon-fkrp-select-icon {
    top: 2px;
  }
}
</style>
