123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="title"
- :center="true"
- align="left"
- top="10vh"
- width="750px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- @close="showModelThis = false"
- >
- <el-card style="margin-top: -20px">
- <el-row :gutter="10">
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- :size="'mini'"
- :rules="rulesThis"
- label-width="80px"
- class="demo-ruleForm"
- >
- <el-row style="margin-bottom:20px">
- <el-col :span="24">
- <el-form-item label="真实姓名" prop="nickname">
- <el-input
- v-model="ruleForm.nickname"
- :placeholder="'真实姓名'"
- :disabled="isDetail"
- maxlength="100"
- />
- </el-form-item>
- </el-col>
-
- <el-col :span="24">
- <el-form-item label="手机号" prop="mobile">
- <el-input
- v-model="ruleForm.mobile"
- :placeholder="'手机号'"
- maxlength="11"
- :disabled="isDetail"
- />
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- </el-col>
- <el-col :span="6" class="bottom-btn">
- <el-button v-if="!isDetail" type="primary" @click="submitForm" :size="'mini'"
- >保 存
- </el-button>
- <el-button @click="showModelThis = false" :size="'mini'">{{
- isDetail ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/interest/account";
- import resToken from "@/mixins/resToken";
- import {
- isnumber,
- isMobile,
- validEmail,
- isAlphanumeric,
- isChinese,
- isEmoticon,
- validAlphabets,
- } from "@/utils/validate";
- export default {
- name: "Account",
- props: ["showModel", "id", "isDetail"],
- mixins: [resToken],
- data() {
- const validateusername = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("账号不能为空!"));
- } else {
- if (value.length < 6 || value.length > 18) {
- callback(new Error("账号规则为6~18位数字与字母组合!"));
- } else {
- if (isnumber(value)) {
- callback(new Error("账号规则为6~18位数字与字母组合!"));
- } else if (validAlphabets(value)) {
- callback(new Error("账号规则为6~18位数字与字母组合!"));
- } else if (!isAlphanumeric(value)) {
- callback(new Error("账号规则为6~18位数字与字母组合!"));
- } else {
- callback();
- }
- }
- }
- };
- const validatename = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("真实姓名不能为空!"));
- } else {
- if (value.length < 2 || value.length > 12) {
- callback(new Error("真实姓名规则为2~12位!"));
- } else {
- if (isEmoticon(value)) {
- callback(new Error("真实姓名规则为2~12位!"));
- } else {
- callback();
- }
- }
- }
- };
- const validatemobile = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("手机号不能为空!"));
- } else {
- if (!isMobile(value)) {
- callback(new Error("手机号格式不正确!"));
- } else {
- callback();
- }
- }
- };
- return {
- roleList: [],
- loading: false,
- title: "添加账号",
- organizeList: [],
- showModelThis: this.showModel,
- coptions: [],
- is_mainoptions: [],
- isIndeterminate: false,
- ruleForm: {
- nickname: "", // 真实姓名
- mobile: "", //手机号
- role_id: "", //角色id
- },
- platformoptions: [],
- rulesThis: this.rules,
- rules: {
- nickname: [
- {
- required: true,
- validator: validatename,
- trigger: "blur",
- },
- ],
- mobile: [
- {
- required: true,
- validator: validatemobile,
- trigger: "blur",
- },
- ],
- role_id: [
- {
- required: true,
- message: "请选择角色",
- trigger: "change",
- },
- ],
- },
- };
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.$emit("cancel");
- }
- },
- },
- methods: {
- itemidChange(e) {
- this.ruleForm.itemid = e;
- this.$refs.ruleForm.validateField("itemid");
- },
- async initForm() {
- this.loading = true;
- if (this.id === "add") {
- await this.resetForm();
- } else {
- await this.initData();
- }
- if (this.id === "add") {
- this.title = "添加账号";
- this.rulesThis = this.rules;
- } else {
- if (this.isDetail) {
- this.title = "账号详情";
- this.rulesThis = {};
- } else {
- this.title = "修改账号";
- this.rulesThis = this.rules;
- }
- }
- this.loading = false;
- },
- async getClist() {
- this.organizeList = [];
- const { code, data, message } = await asyncRequest.getClist({
- size: 10000,
- });
- if (code === 0) {
- this.organizeList = data;
- this.recursion(this.organizeList);
- } else if (code >= 100 && code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(message);
- }
- },
- handleCheckedCitiesChange(value) {
- console.log(value);
- let checkedCount = value.length;
- this.ruleForm.is_all = checkedCount === this.coptions.length;
- this.isIndeterminate = checkedCount > 0 && checkedCount < this.coptions.length;
- },
- recursion(list) {
- list.map((v) => {
- if (v && Array.isArray(v.child)) {
- v.value = v.id + "";
- v.label = v.name;
- if (v.child.length === 0) {
- delete v["child"];
- } else {
- this.recursion(v.child);
- }
- }
- return v;
- });
- },
- async getRole() {
- const model = {
- status: "", // 状态
- level: "", // 姓名
- role_name: "",
- };
- const res = await asyncRequest.getRole(model);
- if (res && res.code === 0 && res.data) {
- this.roleList = res.data;
- this.roleList.map((v1) => {
- v1.id += "";
- v1.status += "";
- return v1;
- });
- }
- },
- async initData() {
- const { code, data, message } = await asyncRequest.detail({
- id: this.id,
- });
- if (code === 0) {
- await this.resetForm(data);
- } else if (code >= 100 && code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(message);
- }
- },
- async resetForm(sitem) {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- if (sitem) {
- const {
- nickname,
- mobile,
- id
- } = sitem;
- this.ruleForm = {
- id,
- nickname: nickname || "",
- mobile: mobile || ""
- };
- } else {
- this.ruleForm = {
- nickname: "", // 真实姓名
- mobile: ""
- };
- }
- }
- });
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- if (!this.loading) {
- this.loading = true;
- const {
- nickname,
- mobile,
- id
- } = JSON.parse(JSON.stringify(this.ruleForm));
- const model = {
- nickname,
- mobile,
- id
- };
- let res = {};
- if (this.id === "add") {
- delete model["id"];
- res = await asyncRequest.add(model);
- } else {
- res = await asyncRequest.update(model);
- }
- this.loading = false;
- if (res && res.code === 0) {
- const title = this.id === "add" ? "添加成功" : "修改成功";
- this.$notify.success({
- title,
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- this.$emit("refresh");
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- }
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .account {
- .bottom-btn {
- position: absolute;
- bottom: 0px;
- right: 0;
- text-align: right;
- z-index: 2;
- }
- }
- </style>
|