link.js 27.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532


angular.module("xn/template/link.html",[]).run(["$templateCache", function($templateCache){
    "use strict";

    //转交页面 xnForwarded
    $templateCache.put("xn/template/link/link.html",
        "   <div id=\"{{linkId}}\" class=\"xn-link-modal-back\">" +
        "       <div class=\"xn-link-modal\">"+
        "       <div class=\"link-modal-body clearfix\">" +
        "           <div class='linkClose' ng-click='cancel()'></div>"+
        "           <div class='xn-link-tabs clearfix'>" +
        "               <li class=\"tab-item\"   ng-class=\"{'selected\':tabs.number===0}\" ng-click='doTab(0)'>宝贝</li>" +
        "               <li class=\"tab-item\"   ng-class=\"{'selected\':tabs.number===1}\" ng-click='doTab(1)'>类别</li>" +
        "               <li class=\"tab-item\"   ng-class=\"{'selected\':tabs.number===2}\" ng-click='doTab(2)'>关键字</li>" +
        "               <li class=\"tab-item\"   ng-class=\"{'selected\':tabs.number===3}\" ng-click='doTab(3)'>活动页</li>" +
        "               <li class=\"tab-item\"   ng-class=\"{'selected\':tabs.number===4}\" ng-click='doTab(4)'>手工输入</li>" +
        "           </div>" +

        "           <div class='xn-tabs-body mt-10 mb-20'>" +
            //宝贝
        "           <div class='xn-tabs-body-layout' ng-show=\"tabs.number===0\">" +
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-2 xn-lh xn-text-right '>类别:</div>" +
        "                   <div class='xn-col-md-6 '>" +
        "                       <select class=\"form-control \" type=\"text\" name=\"categoryId\" ng-model='vm.categoryId' " +
        "                       ng-options=\"category.id as category.categoryName for category in categoryList\">"+
         "                  <option value=\"\">--请选择--</option> " +
        "                       </select>" +
        "                   </div>" +
        "                   <div class='xn-col-md-2 xn-lh xn-text-right '>关键词</div>" +
        "                   <div class='xn-col-md-6'><input class=\"form-control \" type=\"text\" name=\"keyword\"  ng-model='vm.keyword'   placeholder='输入关键词'></div>" +
        "                   <div class='xn-col-md-2 xn-lh xn-text-right '>排序:</div>" +
        "                   <div class='xn-col-md-6 '>" +
        "                       <select class=\"form-control \" type=\"text\" name=\"orderNumber\" ng-model='vm.orderNumber'" +
        "                       ng-options=\"order.key as order.val for order in orderList\">"+
        "                  <option value=\"\">--请选择--</option> " +
        "                       </select>" +
        "                   </div>" +
        "               </div>"+
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-2 xn-lh xn-text-right '>价格:</div>" +
        "                   <div class='xn-col-md-6'><input class=\"form-control \" type=\"text\" name=\"minShowPrice\"  ng-model='vm.minShowPrice' ></div>" +
        "                   <div class='xn-col-md-2 xn-lh'>-</div>" +
        "                   <div class='xn-col-md-6'><input class=\"form-control \" type=\"text\" name=\"maxShowPrice\"  ng-model='vm.maxShowPrice'></div>" +
        "                   <div class='xn-col-md-8'><bottom class='btn btn-sm btn-success f-right' ng-click='getList()'>查询</bottom></div>" +
        "               </div>"+
        "               <div class=\"xn-table-wrap\"> " +
        "                   <table class=\"table table-bordered table-striped \">" +
                                  "<thead>"+
                                  "<tr>"+
                                      "<th class=\"xn-col-md-3\">缩略图</th>"+
                                      "<th class=\"xn-col-md-18\">详情</th>"+
                                      "<th class=\"xn-col-md-3 xn-text-center\">操作</th>"+
                                  "</tr>"+
                                  "</thead>"+
                                  "<tbody>"+
                                      "<tr  ng-repeat=\"item in itemList\">"+
                                          "<td class=\"xn-col-sm-3\"><img ng-src=\"{{item.pictureUrl}}\" width='50' height='60' >" +
        "                               </td>"+
                                          "<td class=\"xn-col-sm-18\">" +
        "                                   <div >{{item.name}}</div>" +
        "                                   <div><span class='f-left'>价格{{item.showPrice}}元</span><span class='f-right'>出售:{{item.saleQuantity}}笔</span></div>" +
        "                               </td>"+
                                          "<td class=\"xn-col-sm-3 xn-text-center\"><bottom class='btn btn-sm btn-primary' ng-click=\"selectItem(item)\">选择</bottom></td>"+
                                      "</tr>"+
        "                        <tr ng-if=\"itemList.totalCount == 0\"><td colspan=\"9\" class=\"xn-center\">无法找到相应的记录</td></tr>"+
                                  "</tbody>"+
        "                    </table>"+
        "                     <div class=\"xn-text-right clearfix\">"+
        "                         <div class=\"f-left mt-10 mb-10\">共{{vm.totalCount}}条</div>"+
        "                          <pagination  ng-show=\"vm.totalCount>vm.pageSize\" ng-change=\"getList()\" max-size=\"maxPageSize\" total-items=\"vm.totalCount\""+
        "                         ng-model=\"vm.pageNumber\" items-per-page=\"vm.pageSize\" class=\"pagination-sm\"></pagination>"+
        "                     </div>"+
        "                </div>" +
        "          </div>" +
            //宝贝结束
        //类别
        "           <div class='xn-tabs-body-layout'  ng-show=\"tabs.number===1\">" +
        "               <div class=\"xn-table-wrap\"> " +
        "                   <table class=\"table table-bordered table-striped \">" +
        "                           <thead>"+
        "                           <tr>"+
        "                           <th class=\"xn-col-sm-2\" ></th>"+
        "                           <th class=\"xn-col-md-19\">分类</th>"+
        "                           <th class=\"xn-col-md-3 xn-text-center\">操作</th>"+
        "                           </tr>"+
        "                           </thead>"+
        "                           <tbody>"+
            "                           <tr ng-repeat=\"category in categoryList\" ng-show='category.visable'>"+
                "                           <td class=\"xn-col-sm-2\" ng-click='openChildren(category)'>" +
        "                                       <span class='openCategory' ng-show=\"!category.childVisable && category.children.length>0 \">+</span>" +
        "                                       <span class='openCategory' ng-show=\"category.childVisable && category.children.length>0 \">-</span>" +
        "                                   </td>"+
                "                           <td class=\"xn-col-sm-19  category-{{category.level}}\">{{category.categoryName}}</td>"+
                "                           <td class=\"xn-col-sm-3 xn-text-center\"><bottom class='btn btn-sm btn-primary' ng-click=\"selectCategory(category)\">选择</bottom></td>"+
            "                           </tr>"+
        "                        <tr ng-if=\"categoryList.lenght == 0\"><td colspan=\"3\" class=\"xn-center\">无法找到相应的记录</td></tr>"+
        "                           </tbody>"+
    "                        </table>"+
        "               </div>" +
        "           </div>" +
        //类别
        //关键词
        "           <div class='xn-tabs-body-layout'  ng-show=\"tabs.number===2\">" +
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-6 xn-text-right xn-lh'>关键词:" +
        "                   </div>" +
        "                   <div class='xn-col-md-12'>" +
        "                      <input class=\"form-control \" type=\"text\" keyword=\"keyword\"  ng-model=\"search.keyword\" placeholder='输入关键词'>" +
        "                   </div>" +
        "                   <div class='xn-col-md-6 xn-lh'>请输入关键词  </div>" +
        "               </div>"+
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-6 xn-text-right xn-lh'>显示数量:" +
        "                   </div>" +
        "                   <div class='xn-col-md-12'>" +
        "                       <input class=\"form-control \" type=\"text\" name=\"number\"  ng-model=\"search.pageSize\"  placeholder='输入关键词'>" +
        "                   </div>" +
        "                   <div class='xn-col-md-6 xn-lh'>最多显示宝贝数量  </div>" +
        "               </div>"+
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-6 xn-text-right'>宝贝排序:" +
        "                   </div>" +
        "                   <div class='xn-col-md-16 xn-lh'>" +
        "                       <label for=\"orderNumber1\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber1\" ng-model=\"search.orderNumber\" value=1>" +
        "                               <span>销售高到低</span>" +
        "                       </label>"+
        "                       <label for=\"orderNumber2\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber2\" ng-model=\"search.orderNumber\" value=2>" +
        "                               <span>价格高到低</span>" +
        "                       </label>"+
        "                       <label for=\"orderNumber3\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber3\" ng-model=\"search.orderNumber\" value=3>" +
        "                               <span>宝贝新到旧</span>" +
        "                       </label></br>"+
        "                       <label for=\"orderNumber4\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber4\" ng-model=\"search.orderNumber\" value=4>" +
        "                               <span>销售低到高</span>" +
        "                       </label>"+
        "                       <label for=\"orderNumber5\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber5\" ng-model=\"search.orderNumber\" value=5>" +
        "                               <span>价格低到高</span>" +
        "                       </label>"+
        "                       <label for=\"orderNumber6\">" +
        "                           <input class=\"input-radio\" type=\"radio\" name=\"titles\" id=\"orderNumber6\" ng-model=\"search.orderNumber\" value=6>" +
        "                               <span>宝贝旧到新</span>" +
        "                       </label>"+
        "                   </div>" +

        "               </div>"+

        "           </div>" +
        //活动页
        "           <div class='xn-tabs-body-layout'  ng-show=\"tabs.number===3\">" +
        "               <div class=\"xn-table-wrap\"> " +
        "                   <table class=\"table table-bordered table-striped \">" +
        "                           <thead>"+
        "                                <tr>"+
        "                                   <th class=\"xn-col-md-21\">活动名称</th>"+
        "                                    <th class=\"xn-col-md-3 xn-text-center\">操作</th>"+
        "                                </tr>"+
        "                           </thead>"+
        "                           <tbody>"+
        "                                <tr ng-repeat=\"activity in activityList\">"+
        "                                    <td class=\"xn-col-md-21\">{{activity.name}}</td>"+
        "                                    <td class=\"xn-col-md-3 xn-text-center\"><bottom class='btn btn-sm btn-primary' ng-click=\"selectActivity(activity)\">选择</bottom></td>"+
        "                                </tr>"+
        "                                <tr ng-if=\"activity.totalCount == 0\"><td colspan=\"2\" class=\"xn-center\">无法找到相应的记录</td></tr>"+
        "                           </tbody>"+
        "                        </table>"+
        "                        <div class=\"xn-text-right clearfix\">"+
        "                        <div class=\"f-left mt-20 mb-10\">共{{vm.totalCount}}条</div>"+
        "                        <pagination  ng-show=\"activity.totalCount>activity.pageSize\" ng-change=\"getActivityList()\" max-size=\"maxPageSize\" total-items=\"activity.totalCount\""+
        "                        ng-model=\"activity.pageNumber\" items-per-page=\"activity.pageSize\" class=\"pagination-sm\"></pagination>"+
        "                    </div>"+

        "               </div>" +
        "           </div>" +

        //自定义网址
        "           <div class='xn-tabs-body-layout'  ng-show=\"tabs.number===4\">" +
        "               <div  class='xn-input-line clearfix'> " +
        "                   <div class='xn-col-md-2 xn-text-right xn-lh'>网址:" +
        "                   </div>" +
        "                   <div class='xn-col-md-22'>" +
        "                      <input class=\"form-control \" type=\"text\" name=\"url\" ng-model=\"data\"  placeholder='请输入网址'>" +
        "                   </div>" +
        "               </div>"+
        "           </div>" +

        "       </div>" +
        "   </div>"+
        "   <div class=\"modal-footer xn-forwarded-modal clearfix\" >"+
        "       <div class=\"xn-col-md-6 xn-col-md-offset-9 \">" +
        "           <button ng-show=\"tabs.number===2 || tabs.number===4 \" class=\"btn btn-sm btn-primary \" ng-disabled='!data' ng-class=\"{'disabled':!data}\" ng-click='ok()'>确定</button>"+
        "           <button class=\"btn btn-sm btn-default \" ng-click='cancel()'>取消</button>"+
        "       </div>"+
        "   </div>"+
        "   </div>"
    );
}]);


angular.module("xn.directive.link",["xn/template/link.html"])
    .factory("linkService",["$http","xnConfig",function($http,xnConfig){
        var service={};
        /**
         * 用户获取列表
         * @param data
         * @returns {*}
         *   params:{"method":"api.foundation.message.get","ids":[request.id]}
         */
        //类别
        service.apiEbusinessCategoryFind = function (data) {
            var url = xnConfig.ebusinessUrl+"ebusiness/outApi.do";
            return $http({
                method: 'get',
                url: url,
                withCredentials:true,
                params: {"method": "api.ebusiness.category.find","data":JSON.stringify(data)}
            });
        };
        //详情
        service.apiEbusinessCommodityExtendFind = function (data) {
            var url = xnConfig.ebusinessUrl+"ebusiness/outApi.do";
            return $http({
                method: 'get',
                url: url,
                withCredentials:true,
                params: {"method": "api.ebusiness.commodityextend.find","data":JSON.stringify(data)}
            });
        };
        //活动接口
        service.apiEbusinessSitetemplatepageFind = function (data) {
            var url = xnConfig.ebusinessUrl+"ebusiness/outApi.do";
            return $http({
                method: 'get',
                url: url,
                withCredentials:true,
                params: {"method": "api.ebusiness.website.page.find","data":JSON.stringify(data)}
            });
        };
        return service;
    }])
    //连接
    .directive("xnLink",["$compile",'$templateCache',"$http","linkService","dialogService","xnConfig",
        function ($compile,$templateCache,$http,linkService,dialogService,xnConfig) {
            return {
                restrict:"A",
                scope:{
                    data : "=ngModel",
                    websiteId : "@websiteId",
                    systemType : "@systemType",
                    deviceType : "@deviceType",
                    method:"&"
                },
                replace: true,
                require: "?ngModel",

                link:function(scope, element, attrs,controller) {
                    element.on("click", function () {
                        $http.get( "xn/template/link/link.html",{cache: $templateCache}).success(function (tplContent) {
                            angular.element("body").append($compile(tplContent.trim())(scope));
                            //获取类别和列表
                            scope.getCategoryList();
                            scope.getList();
                        });
                    });
                    scope.linkId="xnLink"+new Date().getTime();

                    scope.tabs={
                        number:0
                    };
                    scope.maxPageSize = 3;

                    //切换
                    scope.doTab=function (index) {
                        scope.tabs.number=index;
                        if(index===3){
                            //活动
                            scope.getActivityList();
                        }
                    };


                    //排序查询
                    scope.orderList=[
                        {key:1,val:"销售高到低"},
                        {key:2,val:"价格高到低"},
                        {key:3,val:"宝贝新到旧"},
                        {key:4,val:"销售低到高"},
                        {key:5,val:"价格低到高"},
                        {key:6,val:"宝贝旧到新"}
                        ];


                    //类别设置
                    scope.categoryList=[];

                    //递归
                    var getChild = function(parent,allList,level){
                        level ++;
                        angular.forEach(allList,function(item){
                            if(item.parentId === parent.id){
                                item.level = level;
                                item.visable=false;
                                item.childVisable=false;
                                item.children=[];
                                parent.children.push(item);
                                scope.categoryList.push(item);
                                getChild(item,allList,level);
                            }
                        });
                    };

                    //获取分类
                    scope.getCategoryList = function (name) {
                        var vm={
                            isActive:true,
                            pageSize: 0
                        };
                        linkService.apiEbusinessCategoryFind(vm).success(function (data) {
                            console.log(data);
                            if (data.errors === null || data.errors.length > 0) {
                                dialogService.tip(data.errors, null, null);
                            }else {
                                scope.categoryList=[];
                                var parentIndex=0;
                                angular.forEach(data.result,function(category){
                                    if(category.parentId ==null){
                                        category.level = 0;
                                        category.visable=true;
                                        //子集显示
                                        category.childVisable=false;
                                        category.children=[];
                                        scope.categoryList.push(category);
                                        getChild(category,data.result,0);
                                    }
                                });

                            }
                        });
                    };

                    //类别设置
                    scope.openChildren=function (item) {
                        item.childVisable=!item.childVisable;
                        angular.forEach(item.children,function (child) {
                            child.visable=!child.visable;
                        })
                    };

                    //产品列表设置
                    scope.itemList=[];
                    scope.vm={
                        pageNumber: 1,
                        pageSize: 5,
                        keyword:"",
                        systemType:scope.systemType||"B2B",
                        deviceType:scope.deviceType||"PC",
                        isShelves:true,
                        categoryIds:[]
                    };

                    scope.getList = function () {
                        //类别
                        scope.vm.categoryIds=[];
                        if(scope.vm.categoryId){
                            scope.vm.categoryIds.push(scope.vm.categoryId)
                        }

                        switch (scope.vm.orderNumber){
                            case 1:
                                scope.vm.sortColumn="SALE_QUANTITY";       //销售
                                scope.vm.sortType="DESC";
                                break;
                            case 2:
                                scope.vm.sortColumn="SHOW_PRICE";          //价格
                                scope.vm.sortType="DESC";
                                break;
                            case 3:
                                scope.vm.sortColumn="CREATE_TIME";           //新旧
                                scope.vm.sortType="DESC";
                                break;
                            case 4:
                                scope.vm.sortColumn="SALE_QUANTITY";
                                scope.vm.sortType="ASC";
                                break;
                            case 5:
                                scope.vm.sortColumn="SHOW_PRICE";
                                scope.vm.sortType="ASC";
                                break;
                            case 6:
                                scope.vm.sortColumn="CREATE_TIME";
                                scope.vm.sortType="ASC";
                                break;
                            default:
                                scope.vm.sortColumn="";
                                scope.vm.sortType="";
                                break;
                        }

                        linkService.apiEbusinessCommodityExtendFind(scope.vm).success(function (data) {
                            if (data.errors === null || data.errors.length > 0) {
                                dialogService.tip(data.errors, null, null);
                            }else {
                                scope.itemList = data.result;
                                scope.vm.totalCount = data.totalCount;
                            }
                        });
                    };

                    scope.doFind= function () {
                        scope.vm.pageNumber = 1;
                        scope.getList();
                    };


                    //活动列表
                    //产品列表设置
                    scope.activityList=[];
                    scope.activity={
                        pageNumber: 1,
                        pageSize: 10,
                        websiteId:scope.websiteId
                    };
                    
                    scope.getActivityList = function () {
                        //类别
                        linkService.apiEbusinessSitetemplatepageFind(scope.activity).success(function (data) {
                            if (data.errors === null || data.errors.length > 0) {
                                dialogService.tip(data.errors, null, null);
                            }else {
                                scope.activityList = data.result;
                                scope.activity.totalCount = data.totalCount;
                            }
                        });
                    };

                    scope.doActivityFind= function () {
                        scope.activity.pageNumber = 1;
                        scope.getList();
                    };


                    //选择产品的连接
                    scope.selectItem=function (data) {
                        scope.data=xnConfig.itemUrl+data.id;
                        scope.cancel();
                    };

                    //选择类别
                    scope.selectCategory=function (data) {
                        scope.data=xnConfig.categoryUrl+data.id;
                        scope.cancel();
                    };
                    //选择活动
                    scope.selectActivity=function (data) {
                        scope.data=data.url;
                        scope.cancel();
                    };

                    //关键词排序
                    scope.search={
                        keyword:"",
                        pageSize:"",
                        orderNumber:"1"
                    };

                    //关键词排序
                    scope.ok=function () {

                        if(scope.tabs.number===2){
                            var search={};
                            //secrah
                            switch (scope.search.orderNumber){
                                case "1":
                                    search.sortColumn="SALE_QUANTITY";       //销售
                                    search.sortType="DESC";
                                    break;
                                case "2":
                                    search.sortColumn="SHOW_PRICE";          //价格
                                    search.sortType="DESC";
                                    break;
                                case "3":
                                    search.sortColumn="CREATE_TIME";           //新旧
                                    search.sortType="DESC";
                                    break;
                                case "4":
                                    search.sortColumn="SALE_QUANTITY";
                                    search.sortType="ASC";
                                    break;
                                case "5":
                                    search.sortColumn="SHOW_PRICE";
                                    search.sortType="ASC";
                                    break;
                                case "6":
                                    search.sortColumn="CREATE_TIME";
                                    search.sortType="ASC";
                                    break;
                                default:
                                   search.sortColumn="";
                                   search.sortType="";
                                    break;
                            }
                            scope.data=xnConfig.searchUrl+"?keyword="+scope.search.keyword+"&pageSize="+scope.search.pageSize+"&sortColumn="+search.sortColumn+"&sortType="+search.sortType;
                        }
                        scope.cancel();
                    };

                    //cancel
                    scope.cancel=function () {
                        angular.element("#"+scope.linkId).remove();
                    };

                    //关闭
                    angular.element(document).on("click",function(e){
                        if($(e.target).attr("id")==scope.linkId){
                            scope.cancel();
                        }
                    });


                }
            }
        }]);