复习计划管理系统 - 新增/编辑复习计划
<script>
import wPicker from '@/components/w-picker/w-picker.vue';
import xiaEditor from '@/components/xia-editor/xia-editor';
import multipleSelect from '@/components/momo-multipleSelect/momo-multipleSelect';
export default {
data() {
return {
cross: '',
ruleForm: {
jihuabianhao: this.getUUID(),
jihuabiaoti: '',
fengmian: '',
dengjishijian: '',
jihuaxiangqing: '',
yonghuzhanghao: '',
yonghuxingming: '',
},
// 登录用户信息
user: {},
ro: {
jihuabianhao : false,
jihuabiaoti : false,
fengmian : false,
dengjishijian : false,
jihuaxiangqing : false,
yonghuzhanghao : false,
yonghuxingming : false,
},
}
},
components: {
wPicker,
xiaEditor,
multipleSelect
},
computed: {
baseUrl() {
return this.$base.url;
},
},
async onLoad(options) {
this.ruleForm.dengjishijian = this.$utils.getCurDate();
let table = uni.getStorageSync('nowTable');
// 获取用户信息
let res = await this.$api.session(table);
this.user = res.data;
// ss读取
this.ruleForm.yonghuzhanghao = this.user.yonghuzhanghao
this.ro.yonghuzhanghao = true;
this.ruleForm.yonghuxingming = this.user.yonghuxingming
this.ro.yonghuxingming = true;
// 如果有登录,获取登录后保存的userid
this.ruleForm.userid = uni.getStorageSync('userid')
if (options.refid) {
// 如果上一级页面传递了refid,获取改refid数据信息
this.ruleForm.refid = options.refid;
this.ruleForm.nickname = uni.getStorageSync('nickname');
}
// 如果是更新操作
if (options.id) {
this.ruleForm.id = options.id;
// 获取信息
res = await this.$api.info('fuxijihua', this.ruleForm.id);
this.ruleForm = res.data;
}
// 跨表
this.cross = options.cross;
if(options.cross){
var obj = uni.getStorageSync('crossObj');
for (var o in obj){
if(o=='jihuabianhao'){
this.ruleForm.jihuabianhao = obj[o];
this.ro.jihuabianhao = true;
continue;
}
if(o=='jihuabiaoti'){
this.ruleForm.jihuabiaoti = obj[o];
this.ro.jihuabiaoti = true;
continue;
}
if(o=='fengmian'){
this.ruleForm.fengmian = obj[o].split(',')[0];
this.ro.fengmian = true;
continue;
}
if(o=='dengjishijian'){
this.ruleForm.dengjishijian = obj[o];
this.ro.dengjishijian = true;
continue;
}
if(o=='jihuaxiangqing'){
this.ruleForm.jihuaxiangqing = obj[o];
this.ro.jihuaxiangqing = true;
continue;
}
if(o=='yonghuzhanghao'){
this.ruleForm.yonghuzhanghao = obj[o];
this.ro.yonghuzhanghao = true;
continue;
}
if(o=='yonghuxingming'){
this.ruleForm.yonghuxingming = obj[o];
this.ro.yonghuxingming = true;
continue;
}
}
}
this.styleChange()
this.$forceUpdate()
},
methods: {
styleChange() {
this.$nextTick(() => {
// document.querySelectorAll('.app-update-pv . .uni-input-input').forEach(el => {
// el.style.backgroundColor = this.addUpdateForm.input.content.backgroundColor
// })
})
},
// 多级联动参数
dengjishijianChange(e) {
this.ruleForm.dengjishijian = e.target.value;
this.$forceUpdate();
},
fengmianTap() {
let _this = this;
this.$api.upload(function(res) {
_this.ruleForm.fengmian = 'upload/' + res.file;
_this.$forceUpdate();
_this.$nextTick(() => {
_this.styleChange()
})
});
},
getUUID () {
return new Date().getTime();
},
async onSubmitTap() {//跨表计算判断
var obj;
//更新跨表属性
var crossuserid;
var crossrefid;
var crossoptnum;
if(this.cross){
var statusColumnName = uni.getStorageSync('statusColumnName');
var statusColumnValue = uni.getStorageSync('statusColumnValue');
if(statusColumnName != '') {
if(!obj) {
obj = uni.getStorageSync('crossObj');
}
if(!statusColumnName.startsWith('[')) {
for (var o in obj){
if(o==statusColumnName){
obj[o] = statusColumnValue;
}
}
var table = uni.getStorageSync('crossTable');
await this.$api.update(`${table}`, obj);
} else {
crossuserid=Number(uni.getStorageSync('userid'));
crossrefid=obj['id'];
crossoptnum=uni.getStorageSync('statusColumnName');
crossoptnum=crossoptnum.replace(/[/, '').replace(/]/, '');
}
}
}
if(crossrefid && crossuserid) {
this.ruleForm.crossuserid=crossuserid;
this.ruleForm.crossrefid=crossrefid;
let params = {
page: 1,
limit: 10,
crossuserid: crossuserid,
crossrefid: crossrefid,
}
let res = await this.$api.list('fuxijihua', params);
if (res.data.total >= crossoptnum) {
this.$utils.msg(uni.getStorageSync('tips'));
return false;
} else {
//跨表计算
if(this.ruleForm.id){
await this.$api.update('fuxijihua', this.ruleForm);
}else{
await this.$api.add('fuxijihua', this.ruleForm);
}
}
}
}
}
</script>
<p>中文详细解释一下内容:该脚本实现了一个表单的功能,包含了以下组件:wPicker(选择器)、xiaEditor(富文本编辑器)、multipleSelect(多选组件)。在data中定义了一些变量,如cross(标识是否跨表)、ruleForm(表单数据)、user(用户信息)、ro(表单数据是否可编辑)。在onLoad方法中,获取了用户信息和传递的参数,并根据参数判断是更新还是新增数据。在方法中,实现了一些功能,如选择器的联动、上传图片、获取UUID等。最后,如果是跨表计算,根据传递的参数进行相应的操作。</p>
原文地址: https://www.cveoy.top/t/topic/n3UF 著作权归作者所有。请勿转载和采集!