diff --git a/app/coffeescripts/admin_application.coffee b/app/coffeescripts/admin_application.coffee index f3f04208..0f26da6d 100644 --- a/app/coffeescripts/admin_application.coffee +++ b/app/coffeescripts/admin_application.coffee @@ -14,7 +14,8 @@ App = Customer: Index: Filter: {} - Show: {} + Show: + Order: {} CustomerGroup: Index: {} Product: diff --git a/app/coffeescripts/views/customers/show/index.coffee b/app/coffeescripts/views/customers/show/index.coffee index 885feaf4..71f186e5 100644 --- a/app/coffeescripts/views/customers/show/index.coffee +++ b/app/coffeescripts/views/customers/show/index.coffee @@ -6,3 +6,4 @@ App.Views.Customer.Show.Index = Backbone.View.extend render: -> new App.Views.Customer.Show.Show model: @model + new App.Views.Customer.Show.Order.Index model: @model diff --git a/app/coffeescripts/views/customers/show/orders/index.coffee b/app/coffeescripts/views/customers/show/orders/index.coffee new file mode 100644 index 00000000..8340fe8f --- /dev/null +++ b/app/coffeescripts/views/customers/show/orders/index.coffee @@ -0,0 +1,13 @@ +App.Views.Customer.Show.Order.Index = Backbone.View.extend + el: '#show-customer-screen' + + initialize: -> + self = this + @collection = new App.Collections.Orders @model.get('orders') + this.render() + + render: -> + self = this + template = Handlebars.compile $('#customer-facts-item').html() + $('#customer-facts').html template @model.attributes + @collection.each (model) -> new App.Views.Customer.Show.Order.Show model: model diff --git a/app/coffeescripts/views/customers/show/orders/show.coffee b/app/coffeescripts/views/customers/show/orders/show.coffee new file mode 100644 index 00000000..71d64316 --- /dev/null +++ b/app/coffeescripts/views/customers/show/orders/show.coffee @@ -0,0 +1,21 @@ +App.Views.Customer.Index.Filter.Show = Backbone.View.extend + className: 'filter-tag' + + events: + "click .close-filter-tag": 'destroy' # 删除主过滤器 + + initialize: -> + self = this + _.bindAll this, 'render' + this.render() + + # 删除过滤器 + destroy: -> + @model.collection.remove @model + this.remove() + false + + render: -> + template = Handlebars.compile $('#customer-search_filters-item').html() + $(@el).html template @model.attributes + $('#customer-search_filters').append @el diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 2b8b3b94..e771702c 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -58,9 +58,10 @@ class CustomersController < ApplicationController expose(:customer_json) do customer.to_json({ include: { - addresses: { methods: [:province_name, :city_name, :district_name] } + addresses: { methods: [:province_name, :city_name, :district_name] }, + orders: {} }, - methods: [ :address, :status_name ], + methods: [ :address, :order, :status_name ], except: [ :created_at, :updated_at ] }) end diff --git a/app/models/customer.rb b/app/models/customer.rb index 980d6fdb..f57ecf89 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -14,6 +14,11 @@ def address json['customer_address'] end + # 首次下单 + def order + self.orders.where(status: [:paid, :pending, :authorized]).first.as_json['order'] + end + def status_name KeyValues::Customer::State.find_by_code(status).name end diff --git a/app/views/customers/show.html.haml b/app/views/customers/show.html.haml index b9522294..23fc16cb 100644 --- a/app/views/customers/show.html.haml +++ b/app/views/customers/show.html.haml @@ -1,5 +1,5 @@ =content_for :javascripts do - =javascript_include_tag 'models/customer', 'views/customers/show/index', 'views/customers/show/show' + =javascript_include_tag 'models/customer', 'models/order', 'collections/orders', 'views/customers/show/index', 'views/customers/show/show', 'models/order', 'views/customers/show/orders/index', 'views/customers/show/orders/show' %h2#title #action-links @@ -22,16 +22,6 @@ .customer.col-8.last #show-customer-screen #customer-facts.box2(style="margin-top:20px;") - %ul - %li.first - %p.big ¥95.00 - %span 消费金额 - %li - %p.big 2 - %span 订单数 - %li.last - %p.big Jun 05 - %span 首次下单 #orders %table#order-table.ssb.data(cellpadding="0" cellspacing="0") %tr @@ -154,6 +144,17 @@ or %a.close-lightbox(href="#") Cancel +%script(id="customer-facts-item" type="text/x-jquery-tmpl") + %ul + %li.first + %p.big {{{total_spent}}} + %span 消费金额 + %li + %p.big {{{orders_count}}} + %span 订单数 + %li.last + %p.big Jun 05 + %span 首次下单 %script(id="customer-summary-item" type="text/x-jquery-tmpl") %tbody %tr.first