Browse Source

客户报备

wushaodong 4 năm trước cách đây
mục cha
commit
70e40c1b8f

+ 1 - 0
apps/account/models.py

@@ -42,6 +42,7 @@ class User(AbstractBaseUser, PermissionsMixin):
     )
     username = models.CharField(verbose_name=u'用户名', max_length=30, unique=True, db_index=True,
                                 help_text=u'不多于20个字符。只能用字母、数字和字符。')
+    password = models.CharField(u'密码', max_length=128, blank=True)
 
     is_active = models.BooleanField(verbose_name=u'是否可用', default=True, editable=False)
     date_joined = models.DateTimeField(verbose_name=u'注册时间', auto_now_add=True, editable=False)

+ 4 - 6
apps/account/serializers.py

@@ -91,14 +91,12 @@ class EmployeeSerializer(serializers.ModelSerializer):
 
     def update(self, instance, validated_data):
         instance.groups.clear()
-        password = instance.password
+        validated_data['password'] = instance.password
         validated_data['is_superuser'] = instance.is_superuser
         instance = super(EmployeeSerializer, self).update(instance, validated_data)
-        if not 'password' in validated_data or not validated_data['password']:
-            instance.password = instance.password
-        else:
-           instance.set_password(validated_data['password'])
-        instance.save()
+        if 'password' in validated_data:
+            instance.set_password(validated_data['password'])
+            instance.save()
 
         groups = self.context['request'].data.get('groups', None)
         if groups:

+ 2 - 1
apps/agent/models.py

@@ -12,7 +12,8 @@ class Agent(models.Model):
     tel = models.CharField(verbose_name=u'电话', max_length=20, null=True)
     area = models.CharField(verbose_name=u'区域', max_length=50)
     address = models.CharField(verbose_name=u'地址', max_length=200)
-    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'添加人',related_name='agent_create_user', on_delete=models.PROTECT)
+    create_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'添加人',related_name='agent_create_user',
+                                    editable=False, on_delete=models.PROTECT)
     create_time = models.DateTimeField(verbose_name=u'添加时间', auto_now_add=True, editable=False)
 
     class Meta:

+ 1 - 1
apps/agent/urls.py

@@ -7,6 +7,6 @@ urlpatterns = [
 ]
 
 router = SimpleRouter()
-router.register(r'', AgentViewSet)
+router.register(r'agent', AgentViewSet)
 router.register(r'store', StoreViewSet)
 urlpatterns += router.urls

+ 2 - 2
apps/customer/models.py

@@ -25,11 +25,11 @@ class ReportCustomer(models.Model):
     address = models.CharField(max_length=100, verbose_name=u'地址')
     source = models.ForeignKey(Option, verbose_name=u'来源', related_name='customer_source',
                                on_delete=models.PROTECT)
-    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category')
+    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category', editable=False, null=True,blank=True,)
     notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
     report_status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'报备状态', default=NOT_CHECKED)
     check_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'审核人', related_name='customer_check_user',
-                                   on_delete=models.PROTECT,null=True)
+                                   on_delete=models.PROTECT, null=True)
     check_time = models.DateTimeField(verbose_name=u'审核时间', null=True)
 
     class Meta:

+ 23 - 7
apps/customer/serializers.py

@@ -1,7 +1,8 @@
 # coding=utf-8
+import json
 from rest_framework import serializers
-
 from apps.option.models import Option
+from utils.exceptions import CustomError
 from apps.option.serializers import OptionSerializer
 from .models import ReportCustomer
 
@@ -9,9 +10,9 @@ class ReportCustomerSerializer(serializers.ModelSerializer):
     gender_text = serializers.CharField(source='get_gender_display', read_only=True)
     report_status_text = serializers.CharField(source='get_report_status_display', read_only=True)
     check_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
-    project = serializers.SerializerMethodField()
+    project_text = serializers.SerializerMethodField()
 
-    def get_project(self, obj):
+    def get_project_text(self, obj):
         return OptionSerializer(obj.project, many=True).data
 
     class Meta:
@@ -19,11 +20,26 @@ class ReportCustomerSerializer(serializers.ModelSerializer):
         fields = '__all__'
 
     def create(self, validated_data):
-        print(111111111,int(self.initial_data['project']))
-        # validated_data['project'] = self.initial_data['project']
         instance = super(ReportCustomerSerializer, self).create(validated_data)
+        projects = self.initial_data['project']
+        if projects:
+            projects = json.loads(projects)
+        else:
+            raise CustomError(u'请选择项目')
+
+        for project in projects:
+            instance.project.add(project)
         return instance
 
-    # def update(self, instance, validated_data):
-    #     if instance.project == self.initial_data['project']
+    def update(self, instance, validated_data):
+        instance = super(ReportCustomerSerializer, self).update(instance, validated_data)
+        projects = self.initial_data['project']
+        if projects:
+            projects = json.loads(projects)
+        else:
+            raise CustomError(u'请选择项目')
+
+        for project in projects:
+            instance.project.add(project)
+        return instance
 

+ 2 - 2
uis/views/agent/index.html

@@ -119,7 +119,7 @@
 
         table.render({
             elem: '#customer_datagrid'
-            , url: '/agent/'
+            , url: '/agent/agent/'
             , cols: [[
                 {field: 'name', title: '名称', width: 150}
                 , {field: 'relation_user', title: "联系人", width: 100}
@@ -130,7 +130,7 @@
                 , {field: 'account', title: '信用代码', width: 200}
                 , {field: 'enable_text', title: '是否在用', width: 100}
                 , {field: 'notes', title: '备注', width: 200}
-                , {field: 'create_user', title: '创建人', width: 100}
+                , {field: 'create_user_text', title: '创建人', width: 100}
                 , {field: 'create_time', title: '创建时间', width: 150}
                 , {width: 150, align: 'center', fixed: 'right', toolbar: '#customer-operate-bar'}
             ]]

+ 6 - 5
uis/views/customer/edit.html

@@ -41,7 +41,7 @@
                         <div>
                             <label class="layui-form-label"><font color='red' size="4">*</font>性别:</label>
                             <div class="layui-input-block">
-                                <input type="radio" name="gender" value="2" title="男">
+                                <input type="radio" name="gender" value="2" title="男" checked>
                                 <input type="radio" name="gender" value="1" title="女">
                             </div>
                         </div>
@@ -79,7 +79,7 @@
                         <div>
                             <label class="layui-form-label"><font color='red' size="4">*</font>项目:</label>
                             <div class="layui-input-block">
-                                 <select lay-verify="required" name="project" id="tags" xm-select="tags" xm-select-skin="primary">
+                                 <select lay-verify="required" name="project" xm-select="selectProject" xm-select-skin="primary">
                                      <option value="">请选择</option>
                                  </select>
                             </div>
@@ -150,7 +150,7 @@
                         return {value: item.id, name: item.name, selected: item.selected }
                     });
                 }
-                formSelects.data('tags', 'local', {
+                formSelects.data('selectProject', 'local', {
                     arr: tempData
                 });
                 form.val("component-form-element", editdata);
@@ -167,8 +167,9 @@
                 url = '/customer/reportcustomer/';
                 type = 'post'
             }
-            if(data.field.source) data.field.source = parseInt(data.field.source);
-            console.log(data.field, "opopopopop")
+            var submitData = data.field;
+            var project = formSelects.value('selectProject', 'val');
+            submitData.project = JSON.stringify(project);
             admin.req({
                 url: url
                 , data: data.field

+ 1 - 1
uis/views/customer/index.html

@@ -129,7 +129,7 @@
                 , {field: 'village', title: '小区', width: 200}
                 , {field: 'address', title: '地址', width: 200}
                 , {field: 'source', title: '来源', width: 100}
-                , {field: 'project', title: '项目', width: 200}
+                , {field: 'project_text', title: '项目', width: 200}
                 , {field: 'notes', title: '备注', width: 200}
                 , {field: 'report_status_text', title: '报备状态', width: 200}
                 , {field: 'check_user', title: '审核人', width: 100}