// 已废弃
export default {
  data() {
    return {
    }
  },
  methods: {
    //  监听数据
    setformWatch({ group, column }, watchObj) {
      this.watchColumn(column, group, watchObj)
      if (group && group.length > 0) {
        group.forEach((g) => {
          this.watchColumn(g.column, group, watchObj)
        })
      }
    },

    watchColumn(column = [], group = [], watchObj = "widgetModels") {
      column.forEach((c) => {
        if (c.type === "group" || c.type === "dynamic") {
          let col = c.children.column
          this.watchColumn(col, column, watchObj)
        } else {
          this.setDicData(c)
          // 表单子项控制显隐
          const dynamicshSet = c.dynamicshSet || []
          if (dynamicshSet.length > 0) {
            this.$watch(
              `${watchObj}.${c.prop}`,
              function (val) {
                const dyMap = {} // 显示数据集合
                dynamicshSet.forEach((dy) => {
                  if (dyMap[dy.target]) {
                    dyMap[dy.target].push(dy.value)
                  } else {
                    dyMap[dy.target] = [dy.value]
                  }
                })
                Object.keys(dyMap).forEach((key) => {
                  let targetItem = column.find((_) => _.prop === key)
                  if (!targetItem) {
                    targetItem = group.find((_) => _.prop === key)
                  }
                  if (!targetItem) return
                  const values = dyMap[key]
                  let display = false
                  if (Array.isArray(val)) {
                    display = values.filter((v) => val.includes(v)).length > 0
                  } else {
                    display = values.includes(val)
                  }
                  this.$set(targetItem, "display", Boolean(display))
                })
              },
              {
                immediate: true,
              }
            )
          }
        }
      })
    },
    // 添加字典数据
    setDicData(c) {
      const { dicType, dicData } = c
      if (dicType) {
        if (dicData && dicData.length !== 0) return
        let data = this.dictMap[dicType] || []
        this.$set(c, "dicData", data)
      }
    },
  },
}
