# encoding: utf-8
class OrderFile < ActiveRecord::Base
  has_paper_trail
  self.table_name = "list_files"
  belongs_to :depart_record, :foreign_key => :depart
  STATUS_ENUM = [["未支付","unpay"],["已关闭","closed"],["待确认","unconfirmed"],["处理中","processing"],["已完成","complete"],["待收货","dispatch"],["已退款","refunded"]]

  after_update :generate_file

  def generate_file
    #发放未发放赠品
    url = "#{CONFIG_FILE["app_host"]}/railsadmin/recharge/award/#{self.id}"
    p url
    open(url)
  end


  rails_admin do
    navigation_label '商品管理'
    parent Order

    weight -500
    list do
      filters [:order_no,:order_status]
      field :id
      field :order_no
      field :order_status, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :paied_date
      field :paied_date_end
      #field :paied_time
      #field :depart
      field :depart_record

      field :pdf_file do
        read_only true
        pretty_value do
          v = bindings[:view]
          url = value
          # value will point to bindings[:object].name
          if value.length>0
            v.link_to("清单文件.pdf", url, target: '_blank', rel: 'noopener noreferrer')
          end
        end
      end

      field :list_file do
        read_only true
        pretty_value do
          v = bindings[:view]
          url = value
          # value will point to bindings[:object].name
          if value.length>0
            v.link_to("清单文件", url, target: '_blank', rel: 'noopener noreferrer')
          end
        end
      end
      field :line_file do
        read_only true
        pretty_value do
          v = bindings[:view]
          url = value
          # value will point to bindings[:object].name
          if value.length>0
            v.link_to("快递打印单", url, target: '_blank', rel: 'noopener noreferrer')
          end
        end
      end
      field :status
      field :created_at
      # field :updated_at
    end
    show do
      field :id
      field :order_no
      field :order_status, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :paied_date
      field :paied_date_end
      #field :paied_time
      # field :depart
      field :depart_record
      field :list_file
      field :line_file
      field :status
      field :created_at
      # field :updated_at
    end

    edit do
      field :order_no
      field :order_status, :enum do
        enum do
          STATUS_ENUM
        end
      end
      field :paied_date
      field :paied_date_end
      #field :paied_time
      #field :depart
      field :depart_record
      field :list_file
      field :status
      field :created_at
    end

  end

end
