<template>
  <!-- 修改登录账户 -->
  <a-modal class="commonModal add-business-info"
           title="修改账户"
           v-model:visible="visible"
           @cancel="cancel"
           centered
           :maskClosable="false"
           width="890px">
    <template #footer>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="submit">完成</a-button>
    </template>
    <a-form class="inlineForm"
            ref="formRef"
            :model="formState"
            :rules="rules">
      <a-row :gutter="24">
        <a-col :span="12">
          <a-form-item label="账户角色"
                       name="roleids">
            <a-checkbox-group class="commonCheckboxGroup"
                              v-model:value="formState.roleids">
              <a-row>
                <a-col :span="12">
                  <a-checkbox :value="22">业务员</a-checkbox>
                </a-col>
                <a-col :span="12">
                  <a-checkbox :value="23">跟单员</a-checkbox>
                </a-col>
              </a-row>
            </a-checkbox-group>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="账户名称"
                       name="loginname">
            <a-input class="dialogInput"
                     style="width: 200px"
                     v-model:value="formState.loginname"
                     placeholder="请输入账户名称" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="登录账号"
                       name="logincode">
            <a-input class="dialogInput"
                     style="width: 200px"
                     readonly
                     v-model:value="formState.logincode"
                     placeholder="请输入登录账号" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="手机号码"
                       name="mobile">
            <a-input class="dialogInput"
                     style="width: 200px"
                     v-model:value="formState.mobile"
                     placeholder="请输入手机号码" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, ref, PropType } from 'vue';
import { handleBusinessForm } from '../setup';
import { BusinessFormState } from '../interface';
import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
import { loginAccountOperate } from '@/services/proto/accountinfo';
import { mergeTwoObj } from '@/utils/objHandle';
import { ErmcpLoginUser } from '@/services/go/ermcp/account/interface';
import { getUserId } from '@/services/bus/account';
import { validateAction } from '@/common/setup/form';
import { _closeModal } from '@/common/setup/modal/modal';

export default defineComponent({
    name: 'account_info_business_btn_modify',
    emits: ['cancel', 'update'],
    components: {},
    props: {
        selectedRow: {
            default: {},
            type: Object as PropType<ErmcpLoginUser>,
        },
    },
    setup(props, context) {
        // // 控制关闭弹窗
        const { visible, cancel } = _closeModal(context);
        const { rules, formState, formRef } = handleBusinessForm();
        const loading = ref<boolean>(false);
        mergeTwoObj(formState, props.selectedRow);
        // roletype	:string;//角色类型(逗号隔开,如22,23), 22:业务员 23:跟单员 24:交易员
        formState.roleids = props.selectedRow.roletype.split(',').map((e) => +e);
        function submit() {
            validateAction<BusinessFormState>(formRef, formState).then((param) => {
                const name = param.loginname;
                const reqParam = {
                    operatetype: 2,
                    userid: props.selectedRow.userid,
                    loginid: props.selectedRow.loginid,
                    logincode: param.logincode,
                    areauserid: Number(getUserId()),
                    accountname: name,
                    password: '',
                    logintaaccounts: [],
                };
                Object.assign(reqParam, param);
                reqParam.accountname = name;
                requestResultLoadingAndInfo(loginAccountOperate, reqParam, loading, ['修改账户成功', '修改账户失败:']).then(() => {
                    cancel(true);
                });
            });
        }
        return {
            formState,
            rules,
            formRef,
            visible,
            cancel,
            submit,
            loading,
        };
    },
});
</script>

<style lang="less">
.add-business-info {
}
</style
>;

