using Nirvana.Common;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using YBDevice.Application;
using YBDevice.Entity;

namespace YBDevice.NWeb.Pages.Menu
{
    public class MenuEditModel : BaseModel
    {
        public YB_nMenu menu = new YB_nMenu();
        public List<TreeSelectModel> list = new List<TreeSelectModel>();
        private ISystemService _systemService;
        public MenuEditModel(ISystemService systemService)
        {
            _systemService = systemService;
        }
        public async Task OnGetAsync(Guid id)
        {
            var data = await _systemService.GetMenuListAsync();
            var treeList = new List<TreeSelectModel>();
            foreach (var item in data)
            {
                TreeSelectModel treeModel = new TreeSelectModel();
                treeModel.id = item.Id + "";
                treeModel.text = item.Name;
                treeModel.parentId = item.ParentId + "";
                treeModel.data = item;
                treeList.Add(treeModel);
            }
            list = treeList.TreeSelectGuidJson().ToObject<List<TreeSelectModel>>();
            if (id != Guid.Empty)
            {
                menu = await _systemService.DetailMenuAsync(id);
            }
        }
    }
}
