addWorkersLogic.js 1.41 KB
import {_getListUser} from "../service/AppService";
import {observable, computed} from 'mobx'
import {ownerUserId,ownerUserName} from "../service/rpc";
import {taskOwnerId,taskOwnerName} from "../pages/TaskList";
import {currentListId} from "../pages/TaskList";
import Toast from "react-native-simple-toast";
export default class addUserLogic {
	@observable
	users = []
	@observable
	text = ""
	@observable
	chooseWorkers = []

	@computed
	get data() {
		if (!!this.text) {
			return this.users.filter(v => (v.userName.includes(this.text)))
		}
		return this.users
	}

	async get() {
		try{
			const data = await _getListUser({
				taskListId: currentListId,
				pageSize:0
			})
			const {result,errors,firstErrorMessage,} = data
			if(errors.length>0){
				Toast.show(firstErrorMessage)
			}else {
				let array=[]
				if(result.some(v=>v.userId===ownerUserId)){
						result.map(v=>{
							if(v.userId===ownerUserId){
								const {userName,...others}=v
								array.push({
									userName:v.userName+"(我)",
									...others,
								})
							}else{
								array.push(v)
							}
						})
				}else {
					array=[...result]
				}
				// if(taskOwnerId!==ownerUserId){
				// 		array1=[{userName:'未分配'},{userName:`${ownerUserName}`,userId:ownerUserId},...array]
				// }else{
				// 		array1=[{userName:'未分配'},...array]
				//
				// }
				this.users.replace([{userName:'未分配'},...array])
			}

		}catch(e){

		}

	}
}