| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <template>
- <div class="container add_edit">
- <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
- <el-form-item label="账号" prop="username" ref="username">
- <el-input v-model="form.username" placeholder="请输入账号" clearable></el-input>
- </el-form-item>
- <el-form-item label="密码" prop="password" ref="password" v-if="dataId === ''">
- <el-input v-model="form.password" show-password placeholder="请输入密码"></el-input>
- </el-form-item>
- <!-- <el-form-item label="角色" prop="role" ref="role">
- <el-select class="sele" multiple v-model="role" @change="roleAdd">
- <el-option v-for="(item, idx) in roleOptions" :key="idx" :label="item.role_id"
- :value="item.role_id"></el-option>
- </el-select>
- <div class="remark_txt">用户可拥有多种角色</div>
- </el-form-item> -->
- <el-form-item label="性别">
- <!-- <el-radio v-model="form.gender" label="0">未知</el-radio> -->
- <el-radio v-model="form.gender" label="1">男</el-radio>
- <el-radio v-model="form.gender" label="2">女</el-radio>
- </el-form-item>
- <el-form-item label="头像">
- <uni-file-picker v-model="imageValue" fileMediatype="image" returnType="object"
- :image-styles="imageStyle" @select="imgUpload" @delete="imgDelete" />
- </el-form-item>
- <el-form-item label="手机号">
- <el-input v-model="form.phone" type="number" placeholder="请输入手机号" clearable></el-input>
- </el-form-item>
- <!-- <el-form-item label="备注">
- <el-input v-model="form.comment" placeholder="请输入备注" clearable></el-input>
- </el-form-item> -->
- <!-- <el-form-item label="状态">
- <el-switch v-model="form.state" active-color="#ff6a6c" inactive-color="#bbb" :active-value="0"
- :inactive-value="1"></el-switch>
- </el-form-item> -->
- <el-form-item>
- <el-button round icon="el-icon-check" class="confirm_btn" @click="submitForm('ruleForm')">提交</el-button>
- <el-button round icon="el-icon-back" @click="returnPage">返回</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
- <script>
- import bus from '@/common/bus';
- const __name = 'uni-id-users';
- const __role = 'uni-id-roles';
- export default {
- data() {
- // const validateUsername = async (rule, value, callback) => {
- // if (!value) {
- // return callback(new Error('请输入账号'));
- // }
- // let res = await this.$db[__name]
- // .field('username')
- // .where({
- // _id: this.$db.$cmd.neq(this.dataId),
- // username: value
- // })
- // .tofirst({
- // loadding: false
- // });
- // if (res.datas) {
- // callback(new Error(value + ' 账号已存在'));
- // return;
- // }
- // callback();
- // };
- return {
- dataId: '',
- roleOptions: [],
- role: [],
- form: {
- username: '',
- password: '',
- role: [],
- gender: '0',
- avatar: '',
- phone: '',
- comment: '',
- state: 0
- },
- imageValue: null,
- imageStyle: {
- height: '150px',
- width: '150px'
- },
- rules: {
- username: [{
- required: true,
- // validator: validateUsername,
- trigger: 'change'
- }],
- password: [{
- required: true,
- message: '请输入密码',
- trigger: 'change'
- }],
- // role: [{
- // required: true,
- // message: '请选择角色',
- // trigger: 'change'
- // }]
- }
- };
- },
- methods: {
- loadData() {
- // await this.$db[__role].tolist({
- // page: 1,
- // rows: 500
- // }).then(res => {
- // if (res.code == 200) {
- // this.roleOptions = res.datas;
- // }
- // });
- if (!this.dataId) {
- return;
- }
- // await this.$db[__name]
- // .field('username, role, gender, avatar, mobile, comment, status')
- // .tofirst(this.dataId)
- // .then(res => {
- // if (res.code == 200) {
- // for (let item in this.form) {
- // this.form[item] = res.datas[item];
- // }
- // this.roleOptions.forEach(x => {
- // if (res.datas.role.find(g => g == x.role_id)) {
- // this.role.push(x.role_id);
- // }
- // });
- // if (this.form.avatar) {
- // this.imageValue = {};
- // this.imageValue.url = this.form.avatar;
- // }
- // }
- // });
- },
- submitForm(formName) {
- // this.$refs[formName].validate((valid, obj) => {
- // this.$api.set_unvalidated_form_focus(this, obj);
- // if (valid) {
- if (!this.dataId) {//新增
- this.$axios.post("/admin/save",
- {
- 'createBy':uni.getStorageSync("nickName"),//创建人
- 'createTime':this.now_date,//创建时间
- "username": this.form.username,
- "phone": this.form.phone,
- "avatar": this.form.avatar,
- "password": this.form.password,
- "state": 1,
- "gender": this.form.gender
- },
- {
- headers:{
- 'Mall-Token': uni.getStorageSync("token")
- }
- }).then(response => {
- let res = response
- console.log(res)
- if (res.success) {
- this.getOpenerEventChannel().emit('loadData');
- this.returnPage();
- } else {
- }
- }).catch(res =>{
- });
- } else {
- // delete this.form.password;
- // let userData = uni.getStorageSync('useadmin_user');
- // this.form.dataId = this.dataId;
- // this.$func.useadmin.call('user/edit', this.form).then(res => {
- // if (res.code == 200) {
- // if (userData._id == this.dataId) {
- // userData.avatar = this.form.avatar;
- // uni.setStorageSync('useadmin_user', userData);
- // bus.$emit('setUserMsg');
- // }
- // this.getOpenerEventChannel().emit('loadData');
- // this.returnPage();
- // }
- // });
- }
- // }
- // });
- },
- // roleAdd() {
- // this.form.role = [];
- // this.roleOptions.forEach(x => {
- // if (this.role.find(g => g == x.role_id)) {
- // this.form.role.push(x.role_id);
- // }
- // });
- // },
- //获取当前时间
- getNowDate() {
- var _this = this;
- // this.timer = setInterval(function() {
- var aData = new Date();
- var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
- var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
- var date2 = aData.getDate() <= 9 ? "0" + (aData.getDate()-1) : (aData.getDate()-1);
- var Hour = aData.getHours() <= 9 ? "0" + (aData.getHours()) : aData.getHours();
- var Miunte = aData.getMinutes() <= 9 ? "0" + (aData.getMinutes()) : aData.getMinutes();
- var Seconds = aData.getSeconds() <= 9 ? "0" + (aData.getSeconds()) : aData.getSeconds();
- // console.log(aData.getTime())
- _this.now_date = aData.getFullYear() + "-" + month + "-" + date + ' '+ Hour +":"+ Miunte +":"+ Seconds;
- // console.log(aData.getFullYear() + "-" + month + "-" + date2)昨天
- // }, 86400000);
- },
- imgUpload(e) {
- this.form.avatar = e.tempFiles[0].file;
- const file = this.form.avatar;
-
- const formData = new FormData();
- formData.append('file', file);
- // 文件上传
- this.$axios.post("/file/open/",formData,
- {
- headers:{
- 'Content-type' : 'multipart/form-data'
- }
- }).then(response => {
- let res = response
- if (res.success) {
- this.form.avatar =res.data
- } else {
- uni.showToast({
- icon:'error',
- title: '请重新上传!'
- });
- this.form.avatar =''
- this.imageValue = null;
- }
- }).catch(res =>{
- uni.showToast({
- icon:'error',
- title: '请重新上传!'
- });
- this.form.avatar =''
- this.imageValue = null;
- });
- },
- imgDelete() {
- this.imageValue = null;
- this.form.avatar = '';
- },
- returnPage() {
- bus.$emit('closeTab');
- this.$router.push('/pages/system_set/account/account');
- }
- },
- created() {
- this.dataId = this.$route.query.id || '';
- // this.loadData();
- }
- };
- </script>
- <style></style>
|