# encoding: utf-8
class AgentApply < ActiveRecord::Base
  has_paper_trail
  self.table_name = "agent_applys"
  belongs_to :wx_user, :foreign_key => :intro_user_id
  belongs_to :depart_record, :foreign_key => :depart

  validates :intro_user_id,:wx_user_id,:depart,presence: true

  def com_user
    linkUser = WxUser.where("id = ?", self.com_user_id).first
    if !linkUser.blank?
        return linkUser.nickname
    else
      return "--"
    end
  end




  rails_admin do
    navigation_label '用户管理'
    parent WxUser
    weight -500
    list do
      filters [:intro_user_id,:wx_user_id,:nickname]
      field :id
      field :happen_time do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :intro_user_id do
        visible false
        filterable true
      end
      field :wx_user
      field :wx_user_id do
        visible true
        filterable true
      end
      field :nickname
      field :mobile
      field :depart_record
      field :com_user_id
      field :com_user
      field :com_time do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :status
      field :created_at
      # field :updated_at
    end

    show do
      field :id
      field :happen_time do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :wx_user
      field :wx_user_id
      field :nickname
      field :mobile
      field :depart_record
      field :com_user_id
      field :com_user
      field :com_time do
        formatted_value do
          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
        end
      end
      field :status
      field :created_at
      # field :updated_at
    end

    edit do
      field :happen_time
      field :intro_user_id
      field :wx_user_id
      field :nickname
      field :mobile
      field :depart_record
      field :com_user_id
      field :com_time
      field :status
    end

  end

end
