
///////////////////////////////////////////////////////////////////////////////
//文件名称: VmAddLossProductType.cs
//文件描述: VmAddLossProductType.cs
//创 建 者: xls
//创建日期: 2018/9/12 22:37:02
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Com.FirmLib.UI.Common;
using FWindSoft.MVVM;
using FWindSoft.Wpf;
using FWindSoft;
using System.Windows;
using FWindSoft.Wpf.Common;

namespace Com.FirmLib.UI.Seller
{
    public class VmAddLossProductType : BaseViewModel
    {
        public VmAddLossProductType()
        {
            Init();
        }

        private void Init()
        {

        }
        public void Init(LoadParameter parameter)
        {
            List<ProductTypeShowItem> items = parameter.Parameter as List<ProductTypeShowItem>;
            if (items == null)
                return;
            var showItems = items.Select(c => new TCheckBoxItem<ProductTypeShowItem>() { Display = c.ToString(), RefObject = c });
            ProductTypes = new ObservableCollection<TCheckBoxItem<ProductTypeShowItem>>(showItems);
        }
        #region 属性相关
        private ObservableCollection<TCheckBoxItem<ProductTypeShowItem>> m_ProductTypes;
        /// <summary>
        /// 待选类型集合
        /// </summary>
        public ObservableCollection<TCheckBoxItem<ProductTypeShowItem>> ProductTypes
        {
            get { return this.m_ProductTypes; }
            set
            {
                this.m_ProductTypes = value;
                RaisePropertyChanged(() => this.ProductTypes);
            }
        }

        #endregion

        #region 命令相关

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="parameter"></param>
        [Command]
        public void OkCommand(object parameter)
        {

            try
            {
                Window window = parameter as Window;
                if (window != null)
                {
                    var checkedItems = ProductTypes.Where(c => c.IsChecked).Select(c => c.RefObject).ToList();
                    //设置需要处理的值
                    window.SetRealResult<List<ProductTypeShowItem>>(checkedItems);
                    window.DialogResult = true;
                }
            }
            catch (Exception ex)
            {
                MessageTipEx.Show(ex);
            }
        }
        public bool CanOkCommand(object parameter)
        {
            return true;
        }

        #endregion
    }
}
