<template>
  <div :class="$style.userDiv">
    <sd-user-picker ref="iamRectifyUser" :single="true" @change="save"></sd-user-picker>
  </div>
</template>

<script>
import components from './_import-components/xm-iam-rectify-user-handler-import'

export default {
  name: 'XmIamRectifyUserHandler',
  components,
  data() {
    return {
      visible: false,
      button: {},
      initValues: [],
      childTable: undefined,
      selectedRows: [],
      eventScript: undefined,
    }
  },
  methods: {
    run({ button, eventScript, context: { childTable, selectedRows } }) {
      this.button = button
      this.childTable = childTable
      this.selectedRows = selectedRows
      // 根据需修改的字段，获取字段信息
      this.eventScript = eventScript
      /// 获取非隐藏 且 包含在事件配置修改字段中的字段
      // this.initValues =
      //   childTable?.fields.filter((f) => !f.attrFD?.hidden && modifyFields.includes(f.name)) || []
      this.$refs.iamRectifyUser.openPicker()
    },
    save(userList) {
      this.selectedRows.forEach((item) => {
        if (this.eventScript.userName && this.eventScript.userName.length > 0) {
          item[this.eventScript.userName[0].id] = userList[0].name
        }
        if (this.eventScript.userId && this.eventScript.userId.length > 0) {
          item[this.eventScript.userId[0].id] = userList[0].code
        }
        if (this.eventScript.userAccount && this.eventScript.userAccount.length > 0) {
          item[this.eventScript.userAccount[0].id] = userList[0].code
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.user-div {
  display: none;
}
</style>
