<template>
  <sd-webflow ref="webflow" :validate-form="validForm">
    <template v-slot:form="{ model, FlowData }">
      <sd-form-by-builder ref="builderform"    :form-data="initDaF(FlowData.processFormData)"  :keep-hidden-cell="false" />
    </template>
  </sd-webflow>
</template>

<script>
import moment from 'moment'
import { getUserInfo } from '@/common/store-mixin'
import components from './_import-components/cpm-policy-check-import'

export default {
  name: 'CpmPolicyCheck',
  metaInfo: {
    title: 'CpmPolicyCheck',
  },
  components,
  data() {
    return {}
  },
  created() {
  //  this.initData()
    setTimeout(() => {
        this.initData()
      }, 1000)
  },
  methods: {
    initDaF(array) {
      if (array) {
        array.attrFD.keepHiddenCell = false
      }
      return array
    },
    validForm() {
      this.$refs.webflow.setFieldValue('ZDJCSC', 'true')
      this.$refs.webflow.setFieldValue('FLHGBYJ', 'true')
      return new Promise((resolve, reject) => {
        resolve(true)
      })
    },
    changebj() {
      console.log('---change')
    },

    initData() {
      const   FLOW_STEP_NAME= this.$refs.webflow.getFieldValue('FLOW_STEP_NAME')
      if(FLOW_STEP_NAME=== '法律合规部审查'){
        if(this.$refs.webflow.getFieldValue('LAW_EDIT_ID')==null){
          this.$refs.webflow.setFieldValue('LAW_EDIT_ID', getUserInfo().id)
        }

        if(this.$refs.webflow.getFieldValue('LAW_EDIT_CODE')==null){
          this.$refs.webflow.setFieldValue('LAW_EDIT_CODE', getUserInfo().account)
        }

        if(this.$refs.webflow.getFieldValue('LAW_EDIT_NAME').length<2){
          const users = []
          users.push({
            type: 'User',
            name: getUserInfo().name,
            text: getUserInfo().name,
            code: getUserInfo().account,
            id: getUserInfo().id ? getUserInfo().id : '',
            attrNames: [],
          })
          this.$refs.webflow.setFieldValue('LAW_EDIT_NAME', users)
        }

        if(this.$refs.webflow.getFieldValue('LAW_EDIT_TIME')==null){
         this.$refs.webflow.setFieldValue('LAW_EDIT_TIME', moment(new Date()))
        }
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
