class Merchant < ActiveRecord::Base
    has_paper_trail
    self.table_name = "merchants"
    belongs_to :user, :foreign_key => :user_id
    validates :user_id, presence: true

    VOUCHER_TYPE = [
    ['普通发票', 'ordinary'],
    ['增值发票', 'appreciation'],
    ['收据', 'receipt']
    ]

    def wx_user
      wxUser = WxUser.where("user_id = ?", self.user_id).first
      if !wxUser.blank?
        return wxUser.nickname
      else
        return "不存在"
      end
    end

    rails_admin do 

        navigation_label '商品管理'
        weight -100

        list do 
          filters [:id,:name]
          field :id      
          field :name 
          # field :user_id
          # field :user
          # field :wx_user
          # field :contact
          # field :tel
          field :payee
          field :bank_card_no
          field :bank_name
          field :back_voucher, :enum do 
            enum do 
              VOUCHER_TYPE
            end
          end
          field :created_at

        end

        show do
          field :id      
          field :name 
          # field :user_id
          # field :user
          # field :wx_user
          # field :contact
          # field :tel
          field :payee
          field :bank_card_no
          field :bank_name
          field :back_voucher, :enum do 
            enum do 
              VOUCHER_TYPE
            end
          end
          field :created_at
          field :updated_at
        end

        edit do     
          field :name 
          field :user_id
          field :contact
          field :tel
          field :payee
          field :bank_card_no
          field :bank_name
          field :back_voucher
          field :back_voucher, :enum do 
            enum do 
              VOUCHER_TYPE
            end
          end
        end
    end
end