160 lines
3.5 KiB
JavaScript
160 lines
3.5 KiB
JavaScript
// pages/workBench/components/account/index.js
|
|
import request from "../../../../utils/request"
|
|
import { getTenementBackInfo, } from "../../../../service/tenement"
|
|
import { getBackApproveList, removeUser } from "../../../../service/user"
|
|
import { alertInfo, alertSuccess } from "../../../../utils/index"
|
|
const { OK } = request
|
|
|
|
Component({
|
|
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
list: [],
|
|
tenementInfo: {},
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
onParkFocus(e) {
|
|
this.setData({
|
|
show: true,
|
|
title: "园区",
|
|
type: 'park'
|
|
})
|
|
},
|
|
onTenementFocus(e) {
|
|
const { park } = this.data;
|
|
if (!park) {
|
|
alertInfo("请先选择园区")
|
|
return;
|
|
}
|
|
this.setData({
|
|
show: true,
|
|
title: "商户",
|
|
type: 'tenement'
|
|
})
|
|
},
|
|
onConfirm(e) {
|
|
const that = this;
|
|
const { type, data } = e.detail;
|
|
switch(type) {
|
|
case "park":
|
|
this.setData({
|
|
park: data.id,
|
|
parkName: data.name,
|
|
show: false,
|
|
})
|
|
break;
|
|
case "tenement":
|
|
console.log('data', data)
|
|
this.setData({
|
|
tenement: data.id,
|
|
tenementName: data.name,
|
|
show: false,
|
|
}, () => {
|
|
that.initUserList();
|
|
that.getTenementInfo();
|
|
})
|
|
break;
|
|
}
|
|
},
|
|
onConcal() {
|
|
this.setData({
|
|
show: false,
|
|
})
|
|
},
|
|
handleDelete(e) {
|
|
const { id, name } = e.currentTarget.dataset;
|
|
const { tenement } = this.data;
|
|
const that = this;
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: `确认要移除${name}吗?`,
|
|
complete: async (res) => {
|
|
if (res.cancel) {
|
|
|
|
}
|
|
|
|
if (res.confirm) {
|
|
const { code, message } = await removeUser(id, tenement)
|
|
if (code !== OK) {
|
|
alertInfo(message)
|
|
return;
|
|
}
|
|
alertSuccess("删除成功")
|
|
that.initUserList();
|
|
}
|
|
}
|
|
})
|
|
},
|
|
onEditConfirm() {
|
|
this.initUserList()
|
|
this.handleCancel();
|
|
},
|
|
async getTenementInfo() {
|
|
const { tenement, park } = this.data;
|
|
const { code, message, tenement: data } = await getTenementBackInfo(park, tenement)
|
|
if (code !== OK) {
|
|
alertInfo(message)
|
|
return;
|
|
}
|
|
this.setData({
|
|
tenementInfo: data,
|
|
})
|
|
},
|
|
async initUserList() {
|
|
const { tenement } = this.data;
|
|
const { code, message, data } = await getBackApproveList(tenement, 1);
|
|
if (code !== OK) {
|
|
alertInfo(message)
|
|
return;
|
|
}
|
|
this.setData({
|
|
list: data,
|
|
})
|
|
},
|
|
handleAddSon() {
|
|
this.setData({
|
|
visible: true,
|
|
type: "add",
|
|
title: "新建子账号"
|
|
})
|
|
},
|
|
handleChangeMain() {
|
|
const { list = [] } = this.data;
|
|
const main = list?.find(item => item.isAdmin)
|
|
if (!main) {
|
|
return
|
|
}
|
|
this.setData({
|
|
visible: true,
|
|
type: "update",
|
|
title: "编辑管理员",
|
|
phone: main.phone,
|
|
name: main.name,
|
|
id: main.id,
|
|
})
|
|
},
|
|
handleCancel() {
|
|
console.log("-------------")
|
|
this.setData({
|
|
visible: false,
|
|
type: "",
|
|
phone: "",
|
|
name: "",
|
|
id: "",
|
|
})
|
|
}
|
|
}
|
|
}) |