<template>
  <el-form
    class="mam-form"
    v-if="dialogVisibleAdd"
    :model="addInfo"
    ref="formAdd"
    :label-width="labelWidth"
    :label-position="addInfo['infos'][0]['options']['labelPosition']"
  >
    <div
      v-for="(se,index) in addInfo.infos"
      v-if="!se.isFixed && handleEvalExpression(se.options.js_content)"
      :key="index"
    >
      <!-- 说明外层是 “栅格” -->
      <div v-if="se.type == 'grid'">
        <el-card class="mam-form__card" v-if="se.options.isCard">
          <div slot="header" class="clearfix">
            <div class="mam-form__title">{{se.options.title}}</div>
          </div>
          <el-row :gutter="se.options.gutter">
            <el-col :span="gr.span" v-for="(gr,indet) in se.columns" :key="indet">
              <el-form-item
                v-for="(ggc,indexGgc) in gr.columns"
                :key="indexGgc+indet"
                v-if="ggc[ruleName].see && handleEvalExpression(ggc.options.js_content)"
                :rules="testRule([...ggc.rules,{required:ggc[ruleName] == undefined ? false : ggc[ruleName].must, message: `${ggc.name}不能为空`, trigger:ggc.type==='mamselect'?'blur':['blur', 'change']}])"
                :prop="`infos.${index}.columns.${indet}.columns.${indexGgc}.value`"
                :label="`${ggc.name}:`"
              >
                <component
                  @validatorMethods="validatorMethods"
                  :taxPool.sync="taxPool"
                  :editNow="editNow"
                  :poolDate="addPool"
                  :disabled="ggc[ruleName] == undefined ? true : ggc[ruleName].write"
                  :dataInfo.sync="ggc"
                  :is="ggc.type==='mamComponent'?$store.state.dynamicComponent.components[ggc.options.aliasName]:ggc.type"
                  :paramsKey="paramsKey"
                ></component>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <div v-else>
          <el-row :gutter="se.options.gutter">
            <el-col :span="gr.span" v-for="(gr,indet) in se.columns" :key="indet">
              <el-form-item
                v-for="(ggc,indexGgc) in gr.columns"
                :key="indexGgc+indet"
                v-if="ggc[ruleName].see && handleEvalExpression(ggc.options.js_content)"
                :rules="testRule([...ggc.rules,{required:ggc[ruleName] == undefined ? false : ggc[ruleName].must, message: `${ggc.name}不能为空`, trigger:ggc.type==='mamselect'?'blur':['blur', 'change']}])"
                :prop="`infos.${index}.columns.${indet}.columns.${indexGgc}.value`"
                :label="`${ggc.name}:`"
              >
                <component
                  @validatorMethods="validatorMethods"
                  :taxPool.sync="taxPool"
                  :editNow="editNow"
                  :poolDate="addPool"
                  :disabled="ggc[ruleName] == undefined ? true : ggc[ruleName].write"
                  :dataInfo="ggc"
                  :is="ggc.type==='mamComponent'?$store.state.dynamicComponent.components[ggc.options.aliasName]:ggc.type"
                  :paramsKey="paramsKey"
                ></component>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
      <!-- 说明外层是 “tab 标签页” -->
      <div v-else-if="se.type == 'tabs'">
        <el-tabs class="mam-form__tabs" type="border-card" :style="{ 'margin-bottom': '15px', 'margin-left': labelWidth }">
          <el-tab-pane v-for="(tabs,indexTab) in se.columns" :key="indexTab" :label="tabs.name">
            <!-- tab页 -->
            <div v-for="(tabCol,tabIndex) in tabs.columns" :key="tabIndex">
              <div v-if="tabCol.type == 'grid'">
                <!-- 栅格 -->
                <el-card class="mam-form__card" v-if="tabCol.options.isCard">
                  <div slot="header" class="clearfix">
                    <div class="mam-form__title">{{tabCol.options.title}}</div>
                  </div>
                  <el-row :gutter="tabCol.options.gutter">
                    <el-col :span="gr.span" v-for="(gr,indet) in tabCol.columns" :key="indet">
                      <div v-for="(ggc,indexGgc) in gr.columns" :key="indexGgc+indet">
                        <el-form-item
                          v-if="(ggc[ruleName]===undefined?true:ggc[ruleName].see) && handleEvalExpression(ggc.options.js_content)"
                          :rules="testRule([...ggc.rules,{required:ggc[ruleName] == undefined ? false : ggc[ruleName].must, message: `${ggc.name}不能为空`, trigger: ['blur', 'change']}])"
                          :prop="`infos.${index}.columns.${indexTab}.columns.${tabIndex}.columns.${indet}.columns.${indexGgc}.value`"
                          :label="`${ggc.name}:`"
                        >
                          <component
                            @validatorMethods="validatorMethods"
                            :taxPool.sync="taxPool"
                            :editNow="editNow"
                            :poolDate="addPool"
                            :disabled="ggc[ruleName] == undefined ? true : ggc[ruleName].write"
                            :dataInfo.sync="ggc"
                            :is="ggc.type==='mamComponent'?$store.state.dynamicComponent.components[ggc.options.aliasName]:ggc.type"
                            :paramsKey="paramsKey"
                          ></component>
                        </el-form-item>
                      </div>
                    </el-col>
                  </el-row>
                </el-card>
                <div v-else>
                  <el-row :gutter="tabCol.options.gutter">
                    <el-col :span="gr.span" v-for="(gr,indet) in tabCol.columns" :key="indet">
                      <div v-for="(ggc,indexGgc) in gr.columns" :key="indexGgc">
                        <el-form-item
                          v-if="(ggc[ruleName]===undefined?true:ggc[ruleName].see) && handleEvalExpression(ggc.options.js_content)"
                          :key="indexGgc+indet"
                          :rules="testRule([...ggc.rules,{required:ggc[ruleName] == undefined ? false : ggc[ruleName].must, message: `${ggc.name}不能为空`, trigger: ['blur', 'change']}])"
                          :prop="`infos.${index}.columns.${indexTab}.columns.${tabIndex}.columns.${indet}.columns.${indexGgc}.value`"
                          :label="`${ggc.name}:`"
                        >
                          <component
                            @validatorMethods="validatorMethods"
                            :taxPool.sync="taxPool"
                            :poolDate="addPool"
                            :editNow="editNow"
                            :disabled="ggc[ruleName] == undefined ? true : ggc[ruleName].write"
                            :dataInfo.sync="ggc"
                            :is="ggc.type==='mamComponent'?$store.state.dynamicComponent.components[ggc.options.aliasName]:ggc.type"
                            :paramsKey="paramsKey"
                          ></component>
                        </el-form-item>
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </div>
              <div v-else>
                <!-- 非栅格 -->
                <div v-if="tabCol[ruleName] == undefined ? true : tabCol[ruleName].see">
                  <el-form-item
                    :prop="`infos.${index}.columns.${indexTab}.columns.${tabIndex}.value`"
                    :label="`${tabCol.name}:`"
                    v-if="tabCol.type == 'childrenTable'"
                  >
                    <component
                      @validatorMethods="validatorMethods"
                      :taxPool.sync="taxPool"
                      :editNow="editNow"
                      :poolDate="addPool"
                      :disabled="tabCol[ruleName] == undefined ? true : tabCol[ruleName].write"
                      :dataInfo.sync="tabCol"
                      :is="tabCol.type==='mamComponent'?$store.state.dynamicComponent.components[tabCol.options.aliasName]:tabCol.type"
                      :paramsKey="paramsKey"
                    ></component>
                  </el-form-item>
                  <template v-else>
                    <el-form-item
                    :rules="testRule([...tabCol.rules,{required:tabCol[ruleName] == undefined ? false : tabCol[ruleName].must, message: `${tabCol.name}不能为空`, trigger:tabCol.type==='mamselect'?'blur':['blur', 'change']}])"
                    :prop="`infos.${index}.columns.${indexTab}.columns.${tabIndex}.value`"
                    :label="`${tabCol.name}:`"
                    v-if="handleEvalExpression(tabCol.options.js_content)"
                  >
                    <component

                      @validatorMethods="validatorMethods"
                      :taxPool.sync="taxPool"
                      :editNow="editNow"
                      :poolDate="addPool"
                      :disabled="tabCol[ruleName] == undefined ? true : tabCol[ruleName].write"
                      :dataInfo.sync="tabCol"
                      :is="tabCol.type==='mamComponent'?$store.state.dynamicComponent.components[tabCol.options.aliasName]:tabCol.type"
                      :paramsKey="paramsKey"
                    ></component>
                  </el-form-item>
                  </template>

                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 普通的 “组件” -->
      <div v-else>
        <div v-if="se[ruleName] == undefined ? true : se[ruleName].see">
          <el-form-item
            :prop="`infos.${index}.value`"
            :label="`${se.name}:`"
            v-if="componentStatus(se)"
          >
            <component
              @validatorMethods="validatorMethods"
              :editNow="editNow"
              :taxPool.sync="taxPool"
              :poolDate="addPool"
              :disabled="se[ruleName] == undefined ? true : se[ruleName].write"
              :dataInfo.sync="se"
              :is="se.type==='mamComponent'?$store.state.dynamicComponent.components[se.options.aliasName]:se.type"
              :paramsKey="paramsKey"
            ></component>
          </el-form-item>
          <el-form-item
            :rules="testRule([...se.rules,{required:se[ruleName] == undefined ? false : se[ruleName].must, message: `${se.name}不能为空`, trigger: se.type === 'mamselect' ? 'change' : ['blur', 'change']}])"
            :prop="`infos.${index}.value`"
            :label="`${se.name}:`"
            v-else
          >
            <component
              @validatorMethods="validatorMethods"
              :taxPool.sync="taxPool"
              :editNow="editNow"
              :poolDate="addPool"
              :disabled="se[ruleName] == undefined ? true : se[ruleName].write"
              :dataInfo.sync="se"
              :is="se.type==='mamComponent'?$store.state.dynamicComponent.components[se.options.aliasName]:se.type"
              :paramsKey="paramsKey"
            ></component>
          </el-form-item>
        </div>
      </div>
    </div>
    <!--整体禁用遮罩-->
    <slot name="mask"></slot>
  </el-form>
</template>
<script>
import Mixin from "./mixin.js";
export default {
  name: "render-assembly",
  mixins: [Mixin],
  props: [
    "call",
    "watch",
    "validate",
    "info",
    "verifi-cation",
    "ruleName",
    "editNow",
    "action"
  ],
  provide() {
    return {
      formPage: this
    };
  },
  data() {
    return {
      dialogVisibleAdd: false,
      addInfo: {
        infos: []
      },
      addPool: {},
      taxPool: {},
      methEdit: [],
      methAdd: [],
      labelWidth: '125px'
    };
  },
  methods: {
    // 子表控制显示隐藏逻辑
    componentStatus(data) {
      if (data.type === "childrenTable") {
        if (this.action === "add") {
          return data.valueAdd && data.valueAdd.see;
        } else if (this.action === "edit") {
          return data.valueEdit && data.valueEdit.see;
        } else {
          console.warn("不知道是编辑还是新增，啥玩意？？");
          return false;
        }
      } else {
        return false;
      }
    },
    // 汇总相关处理逻辑
    loopSearch(Dom, about) {
      var info = "";
      if (about) {
        Dom.forEach(warp => {
          if (warp.type == "childrenTable") {
            if (warp.model == about.table) {
              let vals = 0;
              // 做一层容错处理
              if (warp.value && warp.value.length > 0) {
                // 1.先计算总数
                warp.value.forEach(val => {
                  vals += Number(val[about.value]);
                });
                info += vals;
                // 如果是汇总-平均
                if (about.avg) {
                  info = info / warp.value.length;
                }
              }
            }
          } else {
            if (warp.type == "tabs") {
              warp.columns.forEach(tab => {
                tab.columns.forEach(col => {
                  if (col.type == "childrenTable") {
                    if (col.model == about.table) {
                      let vals = 0;
                      col.value.forEach(val => {
                        vals += Number(val[about.value]);
                      });
                      info += vals;
                    }
                  }
                });
              });
            }
          }
        });
      }
      return info;
    },
    validatorMethods(meth, tax) {
      tax == 0 ? this.methEdit.push(meth) : "";
      tax == 1 ? this.methAdd.push(meth) : "";
    },
    //查看一个字符串在另一个字符串中出现的次数
    checkStrCount(re, s) {
      re = eval("/" + re + "/ig");
      return s.match(re).length;
    },
    // 新增
    addFrom() {
      var parms = false;
      let lock = false;
      this.methAdd.forEach(s => {
        if (!s()) {
          lock = true;
          return;
        }
      });
      this.$refs.formAdd.validate(valid => {
        let choose = false;
        this.addInfo.infos.forEach(ele => {
          if (ele.type == "childrenTable" && ele.choose == false) {
            choose = true;
          }
        });
        if (choose) return;
        if (valid) {
          // 子表主表校验信息一起调试
          if (lock) return parms;
          this.addLoading = true;
          let parm = {
            ...this.addPool
          };
          this.addInfo.infos.forEach(ele => {
            if (ele.type == "tabs") {
              ele.columns.forEach(tab => {
                tab.columns.forEach(columnsTab => {
                  if (columnsTab.type == "grid") {
                    columnsTab.columns.forEach(ec => {
                      ec.columns.forEach(li => {
                        parm[li.model] = li.value;
                      });
                    });
                  } else {
                    parm[columnsTab.model] = columnsTab.value;
                  }
                });
              });
            } else {
              if (ele.type == "grid") {
                ele.columns.forEach(ec => {
                  ec.columns.forEach(li => {
                    parm[li.model] = li.value;
                  });
                });
              } else {
                parm[ele.model] = ele.value;
              }
            }
          });
          parms = parm;
        }
      });

      return parms;
    },
    // 编辑
    EditRecord() {
      var parms = false;
      // if (this.addLoading) return;
      let lock = false;
      this.methEdit.forEach(s => {
        if (!s()) {
          lock = true;
          return;
        }
      });
      this.$refs.formAdd.validate(valid => {
        let choose = false;
        this.addInfo.infos.forEach(ele => {
          if (ele.type == "childrenTable" && ele.choose == false) {
            choose = true;
          }
        });
        if (choose) return;
        if (valid) {
          // 子表主表校验信息一起调试
          if (lock) return parms;
          this.addLoading = true;
          let parm = {
            ...this.addPool
          };
          this.addInfo.infos.forEach(ele => {
            if (ele.type == "tabs") {
              ele.columns.forEach(tab => {
                tab.columns.forEach(columnsTab => {
                  if (columnsTab.type == "grid") {
                    columnsTab.columns.forEach(ec => {
                      ec.columns.forEach(li => {
                        parm[li.model] = li.value;
                      });
                    });
                  } else {
                    parm[columnsTab.model] = columnsTab.value;
                  }
                });
              });
            } else {
              if (ele.type == "grid") {
                ele.columns.forEach(ec => {
                  ec.columns.forEach(li => {
                    parm[li.model] = li.value;
                  });
                });
              } else {
                parm[ele.model] = ele.value;
              }
            }
          });
          parms = parm;
        }
      });
      return parms;
    },
    verification() {
      var parms = false;
      // if (this.addLoading) return;
      let lock = false;
      if (this.action === "add") {
        this.methAdd.forEach(s => {
          if (!s()) {
            lock = true;
            return;
          }
        });
      } else if (this.action === "edit") {
        this.methEdit.forEach(s => {
          if (!s()) {
            lock = true;
            return;
          }
        });
      }

      this.$refs.formAdd.validate(valid => {
        let choose = false;
        this.addInfo.infos.forEach(ele => {
          if (ele.type == "childrenTable" && ele.choose == false) {
            choose = true;
          }
        });
        if (choose) return;
        if (valid) {
          if (lock) return parms;
          this.addLoading = true;
          let parm = {
            ...this.addPool
          };
          this.addInfo.infos.forEach(ele => {
            if (ele.type == "tabs") {
              ele.columns.forEach(tab => {
                tab.columns.forEach(columnsTab => {
                  if (columnsTab.type == "grid") {
                    columnsTab.columns.forEach(ec => {
                      ec.columns.forEach(li => {
                        parm[li.model] = li.value;
                      });
                    });
                  } else {
                    parm[columnsTab.model] = columnsTab.value;
                  }
                });
              });
            } else {
              if (ele.type == "grid") {
                ele.columns.forEach(ec => {
                  ec.columns.forEach(li => {
                    parm[li.model] = li.value;
                  });
                });
              } else {
                parm[ele.model] = ele.value;
              }
            }
          });
          parms = parm;
        }
      });
      return parms;
    },
    testRule(s) {
      let rule = [];
      rule = [...rule, s.filter(fi => fi.required != undefined)[0]];
      s.filter(fi => fi.type || fi.pattern).forEach(es => {
        switch (es.type) {
          case "tel":
            rule.push({
              validator: (rule, value, callback) => {
                //如果为空也可以保存。
                if (value == "") {
                  callback();
                  return;
                }
                //如果不为空就需要加载
                if (!/^1[3456789]\d{9}$/.test(value)) {
                  callback(new Error(es.message));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            });
            break;
          case "url":
            rule.push({
              validator: (rule, value, callback) => {
                if (value == "") {
                  callback();
                  return;
                }
                if (
                  !/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test(
                    value
                  )
                ) {
                  callback(new Error(es.message));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            });
            break;
          case "email":
            rule.push({
              validator: (rule, value, callback) => {
                if (value == "") {
                  callback();
                  return;
                }
                if (
                  !/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(
                    value
                  )
                ) {
                  callback(new Error(es.message));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            });
            break;
          case "number":
            rule.push({
              validator: (rule, value, callback) => {
                if (value == "") {
                  callback();
                  return;
                }
                if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value)) {
                  callback(new Error(es.message));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            });
            break;
          default:
            break;
        }

        // 自定义校验
        if (es.pattern && es.pattern !== "") {
          try {
            const reg = eval(es.pattern);
            if (reg instanceof RegExp) {
              rule.push({
                validator: (rule, value, callback) => {
                  if (!reg.test(value)) {
                    callback(new Error(es.message));
                  } else {
                    callback();
                  }
                },
                trigger: "blur"
              });
            } else {
              this.$notify({
                title: "警告",
                message: "正则表达式格式错误",
                type: "warning"
              });
            }
          } catch (e) {
            console.warn("正则表达式格式错误 ", es.pattern);
            this.$notify({
              title: "警告",
              message: "正则表达式格式错误",
              type: "warning"
            });
          }
        }
      });
      return rule;
    },
    dataCollation() {
      // ruleAdd
      let lock = false;
      this.methAdd.forEach(s => {
        if (!s()) {
          lock = true;
          this.$emit("update:validate", false);
          return;
        }
      });
      if (lock) return;
      this.$refs.formAdd.validate(valid => {
        let choose = false;
        this.addInfo.infos.forEach(ele => {
          if (ele.type == "childrenTable" && ele.choose == false) {
            choose = true;
          }
        });
        if (choose) return;
        if (valid) {
          let parm = {
            ...this.addPool
          };
          this.addInfo.infos.forEach(ele => {
            if (ele.type == "tabs") {
              ele.columns.forEach(tab => {
                tab.columns.forEach(columnsTab => {
                  if (columnsTab.type == "grid") {
                    columnsTab.columns.forEach(ec => {
                      ec.columns.forEach(li => {
                        parm[li.model] = li.value;
                      });
                    });
                  } else {
                    parm[columnsTab.model] = columnsTab.value;
                  }
                });
              });
            } else {
              if (ele.type == "grid") {
                ele.columns.forEach(ec => {
                  ec.columns.forEach(li => {
                    parm[li.model] = li.value;
                  });
                });
              } else {
                parm[ele.model] = ele.value;
              }
            }
          });
          this.$emit("update:validate", true);
        } else {
          this.$emit("update:validate", false);
        }
      });
    }
  },
  watch: {
    taxPool: {
      deep: true,
      handler(newVal, oldVal) {
        for (let bbc in newVal) {
          let pools = newVal[bbc];
          this.addInfo.infos = this.addInfo.infos.map(mp => {
            if (mp.type == "childrenTable") {
              return {
                ...mp,
                value:
                  pools.param[mp.model] == undefined
                    ? mp.value
                    : pools.target[pools.param[mp.model]],
                columns: mp.columns.map(pp => {
                  return {
                    ...pp,
                    columns: pp.columns.map(li => {
                      return {
                        ...li,
                        value:
                          pools.param[mp.model] == undefined
                            ? mp.value
                            : pools.target[pools.param[mp.model]]
                      };
                    })
                  };
                })
              };
            } else {
              if (mp.type == "tabs") {
                return {
                  ...mp,
                  value:
                    pools.param[mp.model] == undefined
                      ? mp.value
                      : pools.target[pools.param[mp.model]],
                  columns: mp.columns.map(tab => {
                    return {
                      ...tab,
                      columns: tab.columns.map(rpt => {
                        if (rpt.type == "childrenTable") {
                          return {
                            ...rpt,
                            value:
                              pools.param[rpt.model] == undefined
                                ? rpt.value
                                : pools.target[pools.param[rpt.model]],
                            columns: rpt.columns.map(pp => {
                              return {
                                ...pp,
                                columns: pp.columns.map(li => {
                                  return {
                                    ...li,
                                    value:
                                      pools.param[pp.model] == undefined
                                        ? pp.value
                                        : pools.target[pools.param[pp.model]]
                                  };
                                })
                              };
                            })
                          };
                        } else {
                          if (rpt.type == "grid") {
                            return {
                              ...rpt,
                              value:
                                pools.param[rpt.model] == undefined
                                  ? rpt.value
                                  : pools.target[pools.param[rpt.model]],
                              columns: rpt.columns.map(pp => {
                                return {
                                  ...pp,
                                  columns: pp.columns.map(li => {
                                    this.dataList.filter(
                                      fi => fi.model == li.model
                                    )[0].isDetail = li.isDetail;
                                    return {
                                      ...li,
                                      value:
                                        pools.param[li.model] == undefined
                                          ? li.value
                                          : pools.target[pools.param[li.model]]
                                    };
                                  })
                                };
                              })
                            };
                          } else {
                            this.dataList.filter(
                              fi => fi.model == rpt.model
                            )[0].isDetail = rpt.isDetail;
                            return {
                              ...rpt,
                              value:
                                pools.param[rpt.model] == undefined
                                  ? rpt.value
                                  : pools.target[pools.param[rpt.model]]
                            };
                          }
                        }
                        //
                      })
                    };
                  })
                };
              } else {
                if (mp.type == "grid") {
                  return {
                    ...mp,
                    value:
                      pools.param[mp.model] == undefined
                        ? mp.value
                        : pools.target[pools.param[mp.model]],
                    columns: mp.columns.map(pp => {
                      return {
                        ...pp,
                        columns: pp.columns.map(li => {
                          this.dataList.filter(
                            fi => fi.model == li.model
                          )[0].isDetail = li.isDetail;
                          return {
                            ...li,
                            value:
                              pools.param[li.model] == undefined
                                ? li.value
                                : pools.target[pools.param[li.model]]
                          };
                        })
                      };
                    })
                  };
                } else {
                  this.dataList.filter(fi => fi.model == mp.model)[0].isDetail =
                    mp.isDetail;
                  return {
                    ...mp,
                    value:
                      pools.param[mp.model] == undefined
                        ? mp.value
                        : pools.target[pools.param[mp.model]]
                  };
                }
              }
            }
          });
        }
      }
    },
    addInfo: {
      deep: true,
      handler(newVal, oldVal) {
        let math = "";
        if (!this.delock) {
          this.delock = false;
          newVal.infos.forEach(warp => {
            // 说明该字段是“汇总”字段
            if (warp.options.about) {
              // 外层(关联表单)
              this.delock = true;
              warp.value = this.loopSearch(newVal.infos, warp.options.about);
            } else {
              // 切换
              if (warp.type == "tabs") {
                warp.columns.forEach(tab => {
                  tab.columns.forEach(col => {
                    if (col.options.about) {
                      this.delock = true;
                      this.$set(
                        col,
                        "value",
                        this.loopSearch(newVal.infos, col.options.about)
                      );
                    }
                  });
                });
              } else {
                // 栅格
                if (warp.type == "grid") {
                  warp.columns.forEach(col => {
                    col.columns.forEach(list => {
                      if (list.options.about) {
                        this.delock = true;
                        this.$set(
                          list,
                          "value",
                          this.loopSearch(newVal.infos, list.options.about)
                        );
                      }
                      else {
                        this.$set(list, "value", list.value);
                      }
                    });
                    col = Object.assign({}, col);
                  });
                }
              }
            }
          });

          this.handleAllKey()
        } else {
          this.delock = false;
        }

        // tab 栅格
        this.delock = false;
        this.mathlock = false;
      }
    }
  },
  mounted() {
    if (this.ruleName) {
      if (typeof this.ruleName != "string") {
        throw new Error("ruleName只能为字符串");
      }
    } else {
      throw new Error("ruleName不能为空");
    }
    let info = [];
    info = this.info.map(mp => {
      if (mp.type == "childrenTable") {
        return {
          ...mp,
          value: mp.value
            ? mp.value
            : mp.options.defaultValue
              ? mp.options.defaultValue
              : "",
          // columns: mp.columns.map(pp => {
          //   return {
          //     ...pp,
          //     columns: pp.columns.map(li => {
          //       // 验证
          //       return {
          //         ...li
          //       };
          //     })
          //   };
          // })
        };
      } else {
        if (mp.type == "tabs") {
          return {
            ...mp,
            value: mp.value
              ? mp.value
              : mp.options
                ? mp.options.defaultValue
                  ? mp.options.defaultValue
                  : ""
                : "",
            columns: mp.columns.map(tab => {
              return {
                ...tab,
                columns: tab.columns.map(rpt => {
                  if (rpt.type == "childrenTable") {
                    return {
                      ...rpt,
                      value: rpt.value
                        ? rpt.value
                        : rpt.options
                          ? rpt.options.defaultValue
                            ? rpt.options.defaultValue
                            : ""
                          : "",
                      columns: rpt.columns.map(pp => {
                        return {
                          ...pp,
                          columns: pp.columns.map(li => {
                            // this.searchs.push(li);
                            return {
                              ...li
                            };
                          })
                        };
                      })
                    };
                  } else {
                    if (rpt.type == "grid") {
                      return {
                        ...rpt,
                        value: rpt.value
                          ? rpt.value
                          : rpt.options
                            ? rpt.options.defaultValue
                              ? rpt.options.defaultValue
                              : ""
                            : "",
                        columns: rpt.columns.map(pp => {
                          return {
                            ...pp,
                            columns: pp.columns.map(li => {
                              return {
                                ...li,
                                ...function() {
                                  var a = {};
                                  a[this.ruleName] = li[this.ruleName]
                                    ? li[this.ruleName]
                                    : {
                                        must: false,
                                        printing: false,
                                        see: true,
                                        write: true
                                      };
                                  return a;
                                }
                              };
                            })
                          };
                        })
                      };
                    } else if (rpt.type == "digitalformat") {
                      return {
                        ...rpt,
                        ...function() {
                          var a = {};
                          a[this.ruleName] = rpt[this.ruleName]
                            ? rpt[this.ruleName]
                            : {
                                must: false,
                                printing: false,
                                see: true,
                                write: true
                              };
                          return a;
                        },
                        value:
                          rpt.value || rpt.value === 0
                            ? rpt.value
                            : rpt.options
                              ? rpt.options.defaultValue
                                ? rpt.options.defaultValue
                                : ""
                              : ""
                      };
                    } else {
                      return {
                        ...rpt,
                        ...function() {
                          var a = {};
                          a[this.ruleName] = rpt[this.ruleName]
                            ? rpt[this.ruleName]
                            : {
                                must: false,
                                printing: false,
                                see: true,
                                write: true
                              };
                          return a;
                        },
                        value: rpt.value
                          ? rpt.value
                          : rpt.options
                            ? rpt.options.defaultValue
                              ? rpt.options.defaultValue
                              : ""
                            : ""
                      };
                    }
                  }
                  //
                })
              };
            })
          };
        } else {
          if (mp.type == "grid") {
            return {
              ...mp,
              value: mp.value
                ? mp.value
                : mp.options
                  ? mp.options.defaultValue
                    ? mp.options.defaultValue
                    : ""
                  : "",
              columns: mp.columns.map(pp => {
                return {
                  ...pp,
                  columns: pp.columns.map(li => {
                    return {
                      ...li,
                      ...function() {
                        var a = {};
                        a[this.ruleName] = li[this.ruleName]
                          ? li[this.ruleName]
                          : {
                              must: false,
                              printing: false,
                              see: true,
                              write: true
                            };
                        return a;
                      }
                    };
                  })
                };
              })
            };
          } else if (mp.type === "digitalformat" || mp.type === "mamselect") {
            return {
              ...mp,
              ...function() {
                var a = {};
                a[this.ruleName] = mp[this.ruleName]
                  ? mp[this.ruleName]
                  : {
                      must: false,
                      printing: false,
                      see: true,
                      write: true
                    };
                return a;
              },
              value:
                mp.value || mp.value === 0
                  ? mp.value
                  : mp.options
                    ? mp.options.defaultValue
                      ? mp.options.defaultValue
                      : ""
                    : ""
            };
          } else {
            return {
              ...mp,
              ...function() {
                var a = {};
                a[this.ruleName] = mp[this.ruleName]
                  ? mp[this.ruleName]
                  : {
                      must: false,
                      printing: false,
                      see: true,
                      write: true
                    };
                return a;
              },
              value: mp.value
                ? mp.value
                : mp.options
                  ? mp.options.defaultValue
                    ? mp.options.defaultValue
                    : ""
                  : ""
            };
          }
        }
      }
    });
    this.addInfo.infos = info
    this.dialogVisibleAdd = true;
  }
};
</script>
<style lang="scss" scoped>
.mam-form {
  .el-form-item {
    margin-bottom: 16px !important;
  }
  .el-table th div {
    line-height: inherit !important;
  }
  .el-table .cell {
    line-height: normal !important;
  }
  /deep/ .el-input__icon {
    line-height: 32px;
  }
}
</style>
