taskListLogic.js 3.48 KB
import {observable,computed} from 'mobx'
import {_getTaskList, _taskFind, _star, _unStar, _done, _todo, _taskCreate,_share,_myTask} from "../service/AppService";
import Toast from "react-native-simple-toast";
import moment from 'moment';
import {tenantId} from "../service/rpc";

export default class taskListLogic {
	@observable
	showFinish = false
	@observable
	showOrdersBar = false
	@observable
	text = ''
	@observable
	marked = false
	@observable
	doneList = []
	@observable
	undoneList = []
	@observable
	loading = true
	params = null
	@observable
	title = ""
	@observable
	changeStatus=false
	@observable
	currentListOwner=""
	@computed
	get showButton(){
		if(this.doneList.length>0){
			return true
		}
		return false
	}


	async taskFind(type) {

		const option = {
			...this.params,
			pageSize: 0,
		}
		if (type) {
			option.sortColumn = type
			option.sortType = "ASC"
		}
		try {
			let data
			if(this.params.myTask){
				data=await _myTask(option)
			}else{
				data = await _taskFind(option)
			}
			const {errors, firstErrorMessage, result, totalCount} = data
			if (errors.length > 0) {
				Toast.show(firstErrorMessage)
			} else {
				this.doneList.clear()
				this.undoneList.clear()
				let resultArray=result
				if(!type){
					const sortArray = result.sort((a, b) => (b.lastUpdateTime || b.creationTime) - (a.lastUpdateTime || a.creationTime))
					const starArray = sortArray.filter(v => v.isStar)
					const notsSartArray = sortArray.filter(v => !v.isStar)
					resultArray = [...starArray, ...notsSartArray];
				}
				this.doneList=resultArray.filter(v => v.isDone && v)
				this.undoneList=resultArray.filter(v => !v.isDone && v)
			}
		} catch (e) {

		}

		this.changeStatus=!this.changeStatus
		this.loading = false
	}

	async todoSetting(status, id, rowVersion) {
		try {
			if (status) {
				await _todo({id, rowVersion})
			} else {
				await _done({id, rowVersion})
			}
		} catch (e) {

		}

	}

	async starSetting(status, id, rowVersion) {
		try {
			if (status) {
				await _unStar({id, rowVersion})
			} else {
				await _star({id, rowVersion})
			}
		} catch (e) {

		}
	}

	async addTask(objectId) {
		try {
			const result = await _taskCreate({
				listId: objectId,
				objectType: "MANUAL",
				isStar: this.marked,
				objectName: this.text,
				ObjectCategory: "NONE",
			})
			const {errors, firstErrorMessage,} = result
			if (errors.length > 0) {
				Toast.show(firstErrorMessage)
			} else {
				this.text = ""
			}
		} catch (e) {

		}

	}

	async getTaskList(id) {
		try{
			const data = await _getTaskList({id})
			const {errors, firstErrorMessage, taskList} = data
			if (errors.length > 0) {
				Toast.show(firstErrorMessage)
			} else {
				const {objectName,ownerUserId} = taskList
				this.title = objectName
				this.currentListOwner=ownerUserId
			}
		}catch(e){
		}

	}
	async share(businessId,userIds){
		const time=moment(new Date()).format("YYYY-MM-DD HH:mm:ss")
		const receiptIds=userIds.map(v=>v.userId)
		const url=`xntalk://rnapp.open/tasklistRN?jj=${businessId}&tenantId=${tenantId}&title=${this.title}&objectType=${this.params.objectType}`
		const option={
			businessId,
			businessType:"TASKLIST_TASK",
			receiptIds,
			messageTitle:this.title,
			messageContent:this.title,
			messageTime:time,
			messageMobileUrl:url
		}
		console.log(url)
		console.log(option)
		try{
			const data=await _share(option)
			const {errors, firstErrorMessage,} = data
			if (errors.length > 0) {
				Toast.show(firstErrorMessage)
			} else {
				Toast.show("分享成功")
			}
		}catch(e){

		}
	}
}