Pārlūkot izejas kodu

新增工程所在地下拉选择

zhangweicheng 4 gadi atpakaļ
vecāks
revīzija
4b280764d0

+ 2 - 1
modules/all_models/compilation.js

@@ -74,6 +74,7 @@ let modelSchema = {
     categoryID: {
         type: Number,
         default: 12 // 总部id
-    }
+    },
+    defaultLocation:String//默认工程所在地
 };
 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));

+ 6 - 0
modules/common/const/locationList.js

@@ -0,0 +1,6 @@
+const locationList = ['北京','天津','河北','山西','内蒙古','辽宁',
+'吉林','黑龙江','上海','江苏','浙江','安徽','福建','江西','山东','河南',
+'湖北','湖南','四川','贵州','云南','西藏','陕西','甘肃','青海','宁夏','新疆',
+'广东','广西','海南','重庆']
+
+export default locationList

+ 25 - 0
modules/users/controllers/compilation_controller.js

@@ -26,6 +26,8 @@ import basicInfoFacade from "../../basic_info_lib/facade/basic_info_facade";
 import progressiveFacade from "../../progressive_interval_lib/facade/progressive_facade";
 import vvTaxFacade from "../../vehicleVessel_lib/facade/vvTax_facade";
 import {default as category, List as categoryList} from "../../common/const/category_const.js";
+import locationList from  "../../common/const/locationList";
+
 let config = require("../../../config/config.js");
 const fs = require('fs');
 
@@ -71,6 +73,7 @@ class CompilationController extends BaseController {
             id: id,
             compilationList: compilationList,
             categoryList: categoryList,
+            locationList:locationList,
             selectedCompilation: selectedCompilation,
             title : config[process.env.NODE_ENV].title?config[process.env.NODE_ENV].title:'养护云版',
             layout: 'users/views/layout/layout',
@@ -718,6 +721,28 @@ class CompilationController extends BaseController {
             response.json({error: 1, message: '更新数据错误', data: null});
         }
     }
+      /**
+     * 更改编办默认工程所在工
+     *
+     * @param request
+     * @param response
+     * @return {Promise.<void>}
+     */
+    async changeLocation(request, response) {
+        let valuationId = request.body.id;
+        let location = request.body.location;
+        try {
+            let compilationModel = new CompilationModel();
+            let result = await compilationModel.updateLocation(valuationId, location);
+            if (result) {
+                response.json({error: 0, message: '', data: null});
+            } else {
+                response.json({error: 1, message: '更新数据错误', data: null});
+            }
+        } catch(error) {
+            response.json({error: 1, message: '更新数据错误', data: null});
+        }
+    }
 
 }
 

+ 12 - 1
modules/users/models/compilation_model.js

@@ -36,7 +36,7 @@ class CompilationModel extends BaseModel {
      */
     async getCompilationList(fields = null) {
         // 筛选字段
-        let field = fields == null ?{_id: 1, name: 1, is_release: 1,release_time:1, categoryID: 1, description: 1,overWriteUrl: 1,example: 1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
+        let field = fields == null ?{_id: 1, name: 1, is_release: 1,release_time:1, defaultLocation:1,categoryID: 1, description: 1,overWriteUrl: 1,example: 1, "ration_valuation.id": 1, "ration_valuation.name": 1, "ration_valuation.enable": 1,
             "bill_valuation.id": 1, "bill_valuation.name": 1, "bill_valuation.enable": 1}:fields;
         let compilationData = await this.findDataByCondition({name: {$ne: ''}}, field, false);
 
@@ -375,6 +375,17 @@ class CompilationModel extends BaseModel {
         return await this.updateById(compilationId, {categoryID: category});
     }
 
+     /*
+     * 设置工程默认所在地
+     *
+     * @param {String} compilationId
+     * @param {int} location
+     * @return {Promise}
+     * */
+    async updateLocation(compilationId, location) {
+        return await this.updateById(compilationId, {defaultLocation: location});
+    }
+
 }
 
 export default CompilationModel;

+ 1 - 1
modules/users/routes/compilation_route.js

@@ -34,6 +34,6 @@ module.exports = function (app) {
     router.post('/copyRationLibs', compilationController.auth, compilationController.init, compilationController.copyRationLibs);
 
     router.post('/changeCategory', compilationController.auth, compilationController.init, compilationController.changeCategory);
-
+    router.post('/changeLocation', compilationController.auth, compilationController.init, compilationController.changeLocation);
     app.use("/compilation", router);
 };

+ 14 - 0
web/users/js/compilation.js

@@ -523,6 +523,20 @@ $(document).ready(function() {
         });
     })
 
+    // 选择默认所在地
+    $('#location-select').change(function () {
+        $.ajax({
+            url: '/compilation/changeLocation',
+            type: 'post',
+            data: {id: id, location: $(this).val()},
+            dataType: "json",
+            success: function(response) {
+                if (response.error !== 0) {
+                    alert('更改失败');
+                }
+            }
+        });
+    })
 });
 
 /**

+ 8 - 0
web/users/views/compilation/index.html

@@ -109,6 +109,14 @@
                         <% }) %>
                     </select>
                 </td></tr>
+                <tr><td><p>默认工程所在地</p>
+                    <select class="form-control" style="width:200px" id="location-select">
+                        <option value=""></option>
+                        <% locationList.forEach(function(location) { %>
+                            <option value="<%= location %>" <% if (selectedCompilation.defaultLocation !== undefined && location === selectedCompilation.defaultLocation) { %>selected="selected"<% } %> ><%= location %></option>
+                            <% }) %>
+                    </select>
+                </td></tr>
             </table>
         </div>
         <input type="hidden" name="id" value="<%= selectedCompilation._id %>" id="compilation-id">