#encoding
module RailsAdmin
  module Config
    module Actions

        class CreateXcxQrcode < RailsAdmin::Config::Actions::Base
            register_instance_option :visible?  do
                authorized?
            end

            register_instance_option :member do
                true
            end

            register_instance_option :link_icon do
                'icon-refresh'
            end

            register_instance_option :pjax? do
                false
            end

            register_instance_option :controller do
                Proc.new do
                    require 'rest-client'
                    wx_user = WxUser.where("id = ? ",@object.id).first
                    n = "此会员已生成二维码"
                    if !wx_user.blank?
                        n = "已成功生成二维码"
                        url = "#{CONFIG_FILE["api_host"]}/railsadmin/create_xcx_qrcode/#{@object.id}"
                        begin
                            ret = RestClient.get url, {} #per_page: 5
                        rescue Exception => e
                            n = "生成失败！"
                        end
                    end
                    redirect_to :back, notice: "#{n}"
                end
            end
        end
    end
  end
end