import {selectDialogMixins} from "@base/mixins/selectDialog";
import {getJsxLink} from "@base/views/bd/setting/utils/index";

let modules = {};
modules = {
  props: ['visiable', 'multi', 'checkRowIds', 'param', 'selectLastLevel', 'serviceName'],
  mixins: [selectDialogMixins],
  created() {
    this.initSetting();

    if (this.param) {
      if (this.param.companyCode !== null) {
        this.formData.companyCode = this.param.companyCode;
      }
      if (this.param.moveButton !== null) {
        this.moveButton = this.param.moveButton;
      }
    }
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    var that = this;
    return {
      showDialog: true,
      falseValue: false,
      selectMulti: true,
      moveButton: false,
      formData: {},
      vxeOption: {}
    };
  },
  methods: {
    initTableM1() {
      let that = this;
      let url = USER_PREFIX + '/menuKind/getAllList';
      let tableOption = {
        vue: that,
        tableRef: 'table-m1',
        tableName: 'bd_menuKind_dialog-m1',
        path: url,
        treeNodeUrl: USER_PREFIX + '/menuKind/getChildren',
        treeNodeParam(row) {
          return {
            parent: row.id,
            enabled: true
          };
        },
        param: () => {
          return {
            enabled: true,
            ...this.formData,
            ...this.param
          }
        },
        columns: [
          {type: 'checkbox', width: 50, resizable: false, fixed: 'left'},
          {
            title: this.$t1('表单分类名称'),
            field: 'name',
            width: 250,
            fixed: 'left',
            treeNode: true,
            slots: {
              default: ({row}) => {
                return getJsxLink({
                  content: row.name,
                  onclick: (event) => {
                    event.stopPropagation();
                    this.$refs['table-m1'].toggleTreeExpand(row);
                  }
                });
              }
            }
          },
          {title: this.$t1('上级分类'), field: 'treePathName', width: 200},
          {field: 'menuKindCode', title: this.$t1('表单分类编码'), width: 150},
          {field: 'serviceName', title: this.$t1('服务名'), width: 150},
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false
          }
        ],
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row',
            checkMethod: ({row}) => {
              let auth = true;
              if (this.serviceName) {
                auth = row.serviceName === this.serviceName;
              }
              if (!row.editAuth) {
                auth = false;
              } else {
                if (this.selectLastLevel) {
                  if (row.hasChild) {
                    auth = false;
                  }
                }
              }
              return auth;
            }
          }
        }
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        that.vxeOption = opts;
      });
    },

    movePrimary() {
      let menuKindCodeRow = this.checkRows[0];
      let menuKindCode = menuKindCodeRow.menuKindCode;
      // console.log("menuKindCode===="+menuKindCode);

      this.$baseConfirm(this.$t1('您确定要移动表单分类吗？')).then(() => {
        this.$http({
          aes: true,
          method: "post",
          url: USER_PREFIX + `/szTaMb/moveToMenuKind`,
          data: {
            menuKindCode: menuKindCode,
            szTaMbIds: this.checkRowIds,
          },
          isLoading: true,
          success: (res) => {
            this.$message({
              message: res.content,
              type: "success",
              duration: 500,
            });
            this.dialogClose();
          },
        });
      });
    }
  }
};
export default modules
