# encoding: utf-8
class ShopApplication < ActiveRecord::Base
  has_paper_trail
  self.table_name = "shop_applications"
  DEPART_ENUM= [["部门1",1], ["部门2",2], ["部门3", 3], ["部门4", 4], ["部门5", 5]]
  belongs_to :depart_record, :foreign_key => :depart
  before_save :before_save

  def before_save
    wxUser = WxUser.where("id = ?", self.wx_user_id).first
    if !wxUser.blank?
      self.depart=wxUser.depart
    end
  end
  IMG_STORE_PATH = "shop"


  rails_admin do
    navigation_label '店长申请记录'
    weight -500
    parent WxUser
    list do
      filters [:user_id,:nickname,:wx_user_id,:name,:total,:depart]
      field :id
      field :user_id
      field :name
      field :wx_user_id
      field :nickname
      field :mobile
      # field :total
      field :total do
        visible true
        label "订单总金额(元)"
        pretty_value do
          value!=0 ? (value.to_f / 100):0
        end
      end
      field :address
      field :status
      field :remark
      field :pass_time
      field :depart do
        visible false
        filterable true
      end
      field :depart_record
      field :created_at
      field :updated_at
    end

    show do
      field :id
      field :user_id
      field :name
      field :wx_user_id
      field :nickname
      field :mobile
      field :total
      field :address
      field :status
      field :remark
      field :pass_time
      field :depart
      field :depart_record
      field :created_at
      field :updated_at
    end

    edit do
      field :user_id
      field :name
      field :wx_user_id
      field :nickname
      field :mobile
      field :total
      field :address
      field :status
      field :remark
      field :pass_time
=begin
      field :depart, :enum do
        enum do
          DEPART_ENUM
        end
      end
=end
    end
  end

end
