const _Http = getApp().globalData.http; const getHeight = require("../../utils/GetRheRemainingHeight.js"); Page({ /** * 页面的初始数据 */ data: { update: true, // 修改权限 userDelete: false, // 删除 height: 0, roleid: -1, //角色id appList: [], //应用列表 fromList: [{ label: "角色名称", error: false, errMsg: "", type: "text", value: "", placeholder: "请填写", valueName: "rolename", //绑定的字段名称 required: true, //必填 }, { label: "角色描述", error: false, errMsg: "", type: "text", value: "", placeholder: "请填写", valueName: "remarks", //绑定的字段名称 required: true, //必填 }], disabled: true, //按钮禁用 loading: false, //按钮加载 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options) if (options.item) { let item = JSON.parse(options.item) this.setData({ roleid: item.roleid, ['fromList[0].value']: item.rolename, ['fromList[1].value']: item.remarks, disabled: false, update: options.update, userDelete: options.userDelete }); console.log(this.data.userDelete) }; this.query_appselect(); }, /* 查询应用列表 */ query_appselect() { _Http.basic({ "classname": "sale.role.role", "method": "query_appselect", "content": { "roleid": this.data.roleid } }).then(res => { console.log("应用列表", res) if (res.msg != '成功') return wx.showToast({ title: res.msg, icon: "none" }) this.setData({ roleid: this.data.roleid == -1 ? 0 : this.data.roleid, appList: res.data }) }) }, /* 提交数据 */ submitRole() { if (this.data.disabled || this.data.loading) return; this.setData({ loading: true }) let { isReturn, returnData } = this.selectComponent("#form").getData(); _Http.basic({ "classname": "sale.role.role", "method": "insertormodify_role", "content": { "roleid": this.data.roleid, ...returnData } }).then(res => { console.log("新建角色", res) this.setData({ loading: false }) if (res.msg != '成功') return wx.showToast({ title: res.msg, icon: "none" }) this.setData({ disabled: true }) let systemapps = this.selectComponent("#myCateg").backData(); if (systemapps.length > 0) _Http.basic({ "classname": "sale.role.role", "method": "add_appauth", "content": { "roleid": res.data.roleid, systemapps } }).then(res => { console.log("绑定授权", res) }) this.navBack(); }) }, deleteRole() { const that = this; wx.showModal({ title: "提示", content: "是否确认删除该角色?", success: (s) => { if (s.confirm) { console.log('删除') _Http.basic({ id: '20221101132002', "content": { "roleid": [this.data.roleid] } }).then(res => { if (res.msg != '成功') return wx.showToast({ title: res.msg, }); that.navBack('删除成功'); }) } } }) }, navBack(tips = '保存成功') { let pages = getCurrentPages(), prevPage = pages[pages.length - 2]; prevPage.getList(true); setTimeout(() => { wx.navigateBack({ delta: 0 }) wx.showToast({ title: tips, }) }, 300) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { getHeight.getHeight('.module-navigation', this).then(res => { this.setData({ height: res * 2 }) }) }, /* 表单是否完成 */ formCompletedOrNot({ detail }) { this.setData({ disabled: !detail }) }, onShareAppMessage() { } })