index.html 17.1 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 533 534 535 536 537 538
<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="utf-8" />
  <meta content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta name="description" content="广联帐户管理中心-员工管理" />
  <meta name="author" content="GLSX Web Team" />
  <meta name="keywords" itemprop="keywords" content="广联,帐户管理,员工管理" />
  <link rel="stylesheet" type="text/css" href="/css/main.css" />
  <style>
    /* 
    .merchant .layui-table-view {
      margin: -5px 20px;
    } */
    .merchant .layui-table {
      margin: 0;
    }

    .merchant #searchForm .layui-inline {
      margin-bottom: 5px;
    }

    .layui-btn-xs {
      cursor: pointer;
    }

    .channel,
    .accountLevel,
    .accountType,
    .customerStatus,
    .searchInputBtn {
      margin-left: 20px;
    }
  </style>
  <title>商户管理</title>
</head>

<body>
  <div class="merchant" id="app">
    <main class="bg-white">
      <div class="context-block">
        <div class="search-block">
          <form class="layui-form layui-form-pane" lay-filter="searchFilter" id="searchForm">
            <div class="layui-inline" id="operateEl">
              <button class="layui-btn" id="addBtn">
                <i class="layui-icon layui-icon-add-circle"></i> 创建商户</button>
              <div class="layui-inline channel" pane>
                <label class="layui-form-label">渠道:</label>
                <div class="layui-input-inline">
                  <select name="channelId" id="channelIdEl">
                    <option value="">全部</option>
                  </select>
                </div>
              </div>
              <div class="layui-inline accountLevel" pane>
                <label class="layui-form-label">账户等级:</label>
                <div class="layui-input-inline">
                  <select name="merchantAccountLevel" id="accountLevelEl">
                    <option value="">全部</option>
                  </select>
                </div>
              </div>
              <div class="layui-inline accountType" pane>
                <label class="layui-form-label">账户类型:</label>
                <div class="layui-input-inline">
                  <select name="accounttypeId" id="accountTypeIdEl">
                    <option value="">全部</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="layui-inline loginName" pane>
              <div class="layui-input-inline" style="width: 120px;">
                <select name="accountOrPhone" lay-filter="nameFilter">
                  <option value="0">登录账号名</option>
                  <option value="1">手机号</option>
                </select>
              </div>
              <div class="layui-input-inline" style="width: 300px;margin-left: -5px;">
                <input class="layui-input" placeholder="请输入" name="merchantLoginAccount">
              </div>
            </div>
            <div class="layui-inline customerStatus" pane>
              <label class="layui-form-label">账户状态:</label>
              <div class="layui-input-inline">
                <select name="status" id="searchStatusEl">
                  <option value="">全部</option>
                </select>
              </div>
            </div>
            <div style="float: right;">
              <div class="layui-inline">
                <input class="layui-input" name="merchantName" placeholder="请输入商户名称">
              </div>
              <div class="layui-inline searchInputBtn">
                <button class="layui-btn" lay-submit lay-filter="searchSubmit">查询</button>
              </div>
            </div>
          </form>
        </div>
        <div class="table-page">
          <table class="layui-table" id="merchantTable" lay-filter="merchant-table-filter"></table>
          <div id="merchantPage" class="align-center"></div>
        </div>
      </div>
    </main>
  </div>

  <script src="https://www.layuicdn.com/layui/layui.js"></script>
  <script src="/js/load.js"></script>

  <script type="text/html" id="accountTypeTpl">
    <ul>
      {{# var accountTypes=d.accountTypeNames.split(",")}}
      {{# }}
      {{# if((d.accountTypeNames)){  }}

      {{#  layui.each(accountTypes,function(index,item){   }}
      <li><span>{{item}}</span></li>
      <!-- <a class="layui-text"  >{{d.accountTypeNames}}</a> -->
      {{# }); }else{         }}
      <a class="layui-text">-</a>
      {{#   }    }}
    </ul>
  </script>
  <script type="text/html" id="merchantBtns">
    <div>
      <a class="layui-btn-xs" lay-event="handleDetail">查看</a>
      {{#  if((d.btn.edit)){ }}
      <a class="layui-btn-xs" lay-event="handleEdit">修改基本信息</a>
      {{#  } }}
    </div>
    <div>
      {{#  if((d.btn.edit)){ }}
      <a class="layui-btn-xs" lay-event="handleAuthority">修改权限</a>
      {{#  } }}
      {{#  if((d.btn.editPeriod)){ }}
      <a class="layui-btn-xs" lay-event="handleVaildPeriod">修改账户有效期</a>
      {{#  } }}
    </div>
    <div>
      {{#  if((d.btn.createStaff)){ }}
      <a class="layui-btn-xs" lay-event="handleAddStaff">创建员工</a>
      {{#  } }}
      {{#  if((d.btn.createSubMerchant)){ }}
      <a class="layui-btn-xs" lay-event="handleAddMerchant">创建子商户/门店</a>
      {{#  } }}
    </div>
  </script>
  <script>
    layui.use(['gtree', 'request', 'helper', 'table', 'laypage', 'layer'], function () {
      var tree = layui.gtree
      var request = layui.request
      var table = layui.table
      var laypage = layui.laypage
      var form = layui.form
      var $ = layui.$
      var helper = layui.helper
      var user = helper.store.get('user')
      var isDxternal = isAppend()

      var baseData = {
        statusList: [],
        channelList: [],
        accountLevelList: [],
        accountTypeList: []
      }

      var page = {
        pageNum: 1,
        pageSize: 10
      }
      var pageOptions = {
        elem: 'merchantPage',
        groups: 5,
        layout: ['count', 'page', 'skip'],
        jump: function (obj, first) {
          //obj包含了当前分页的所有参数,比如:
          // console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
          // console.log(obj.limit); //得到每页显示的条数
          page.pageNum = obj.curr
          page.pageSize = obj.limit
          //首次不执行
          if (!first) {
            //do something
            getTabelList()
          }
        }
      }

      var merchantTable = table.render({
        elem: '#merchantTable',
        page: false,
        skin: 'nob',
        cols: [
          [{
            field: 'index',
            title: '序号',
            align: 'center',
            width: 60
          }, {
            field: 'merchantNo',
            title: '商户号',
            align: 'center'
          }, {
            field: 'merchantName',
            title: '商户名称',
            align: 'center'
          }, {
            field: 'accountTypeNames',
            title: '账户类型',
            align: 'left',
            width: 100,
            templet: '#accountTypeTpl'
          }, {
            field: 'merchantLoginAccount',
            title: '登录账户',
            align: 'center',
            width: 108
          }, {
            field: 'accountLevelName',
            title: '账户等级',
            align: 'center'
          }, {
            field: 'parentMerchant',
            title: '上级商户',
            align: 'center'
          }, {
            field: 'statusName',
            title: '账户状态',
            align: 'center'
          }, {
            field: 'merchantLegalPerson',
            title: '联系人',
            align: 'center'
          }, {
            field: 'merchantLegalPersonPhone',
            title: '手机号',
            align: 'center',
            width: 120
          }, {
            field: 'merchantAddress',
            title: '商户地址',
            align: 'center',
            width: 160
          }, {
            field: 'updatedTime',
            title: '更新时间',
            align: 'center',
            width: 112
          }, {
            align: 'left',
            title: '操作',
            toolbar: '#merchantBtns',
            width: 220
            // fixed: 'right'
          }]
        ]
      })

      table.on('tool(merchant-table-filter)', function (obj) {
        // console.log(obj)
        var eventName = obj.event
        var row = obj.data
        switch (eventName) {
          // 查看
          case 'handleDetail':
            go('merchant', 'detail', {
              merchantId: row.id
            })
            break
            // 修改
          case 'handleEdit':
            // editLevel - 1-创建新商户;2-创建子商户;3-修改
            // step - 1-基本信息;2-权限树
            // merchantAccountLevel 账户等级(1-工厂;2-省代;3-市代;4-门店)
            go('merchant', 'edit', {
              editLevel: 3,
              id: row.id,
              parentId: row.parentId,
              isFactory: (row.merchantAccountLevel == 1),
              step: 1
            })
            break
          case 'handleAuthority':
            // editLevel - 1-创建新商户;2-创建子商户;3-修改
            // step - 1-基本信息;2-权限树
            // merchantAccountLevel 账户等级
            go('merchant', 'edit', {
              editLevel: 3,
              id: row.id,
              parentId: row.parentId,
              isFactory: (row.merchantAccountLevel == 1),
              id: row.id,
              step: 2
            })
            break
            // 创建子商户/门店
          case 'handleAddMerchant':
            // 1-创建新商户;2-创建子商户;3-修改
            go('merchant', 'edit', {
              editLevel: 2,
              parentId: row.id,
              isFactory: 'false',
              step: 1
            })
            break
            // 创建员工
          case 'handleAddStaff':
            go('employee', 'add', {
              merchantId: row.id,
              merchantName: row.merchantName,
              channel: 'merchant'
            })
            break
            // 修改账户有效期
          case 'handleVaildPeriod':
            // console.log(row)
            layer.open({
              type: 2,
              title: '修改账户的有效期',
              area: ['700px', '420px'],
              fixed: false, //不固定
              // maxmin: true,
              btn: ['确定', '取消'],
              content: 'validPeriodForm.html?id=' + row.id + '&effectiveTime=' + row.effectiveTime +
                '&merchantAccountLevel=' + row.merchantAccountLevel + '&status=' + row.status,
              yes: function (index, layero) {
                var body = layer.getChildFrame('body', index)
                helper.store.set('isRefresh', false)
                body.find('#periodVerifyBtn').click()
              },
              end: function () {
                var isRefresh = helper.store.get('isRefresh')
                if (isRefresh) {
                  getTabelList()
                  layer.msg('修改成功', {
                    icon: 1
                  })
                }
                helper.store.remove('isRefresh')
              }
            })
            break
        }
      })

      init()

      $('#addBtn').on('click', function () {
        // 1-创建新商户;2-创建子商户;3-修改
        go('merchant', 'edit', {
          editLevel: 1,
          step: 1,
          isFactory: 'true'
        })
        return false
      })
      // 搜索绑定事件
      form.on('submit(searchSubmit)', function () {
        getTabelList(true)
        return false
      })

      // 查询
      function handleSearch() {
        getTabelList(true)
      }

      // 获取表格数据
      function getTabelList(isResetPageNum) {
        var params = {
          pageNum: page.pageNum,
          pageSize: page.pageSize,
          method: 'cn.com.glsx.merchants.menu.findMerchantByPage'
        }
        var searchData = $('#searchForm [name]').serializeArray()
        // console.log(searchData)
        $.each(searchData, function () {
          if (this.name == 'merchantLoginAccount') {
            var attrName = params.accountOrPhone == '0' ? 'merchantLoginAccount' : 'merchantLegalPersonPhone'
            params[attrName] = this.value
          } else {
            params[this.name] = this.value
          }
        })
        // console.log(params)
        request(params, function (res) {
          var data = helper.formateNullFieldData(res.data)
          $.each(data.data, function (index, item) {
            item.index = index + 1 + page.pageSize * (page.pageNum - 1)
            item.btn = {
              edit: false,
              createSubMerchant: false,
              createStaff: false,
              editPeriod: false
            }
            /** btn
             * check - 查看(无需判断,均有)
             * edit - 修改
             * createSubMerchant - 创建子商户/门店
             * createStaff - 创建员工
             * editPeriod - 修改账户有效期 
             * **/
            // status(账户状态 - 列表):1-草稿;2-正常;3-注销;4-过期
            // merchantAccountLevel(账户等级 - 列表):1-工厂;2-省代;3-市代;4-门店
            // 外部系统
            if (isDxternal) {
              // 状态 - 正常
              if (item.status == 2) {
                // 本身
                if (item.id == user.merchantId) {
                  item.btn.createStaff = true
                  if (item.merchantAccountLevel != 4) {
                    item.btn.createSubMerchant = true
                  }
                } else { // 下级商户
                  // console.log(item)
                  item.btn.edit = true
                  item.btn.editPeriod = true
                  // 直属门店
                  if (item.merchantAccountLevel == 4) {
                    if (item.parentId == user.merchantId) {
                      item.btn.createStaff = true
                    }
                  } else {
                    item.btn.createSubMerchant = true
                  }
                }
              } else if (item.status != 3) {
                item.btn.edit = true
                if (item.status == 4) {
                  item.btn.editPeriod = true
                }
              }
            } else {
              // 超管登录
              if (item.status != 3) {
                item.btn.edit = true
              }
              if ((item.status == 2)) {
                item.btn.createStaff = true
                if (item.merchantAccountLevel != 4) {
                  item.btn.createSubMerchant = true
                }
              }
              if (item.status != 1) {
                item.btn.editPeriod = true
              }
            }
          })
          var options = {
            data: data.data,
          }
          pageOptions.count = data.count
          if (isResetPageNum) {
            pageOptions.curr = 1
          }
          laypage.render(pageOptions)
          merchantTable.reload(options)
        })
      }

      // 获取字典数据
      function getDictData(dictType, fn) {
        request({
          method: 'cn.com.glsx.merchants.menu.findAllDictData',
          dictType: dictType
        }, function (res) {
          fn && fn(res)
        })
      }

      // 设置option
      function setSelectOption(elName, listName, optionId, optionLabel) {
        var el = $(elName)
        $.each(baseData[listName], function (index, item) {
          el.append(new Option(item[optionLabel], item[optionId]))
        })
        form.render('select')
      }

      // 获取有效期
      function getVaildPeriod() {
        getDictData('merchant_status', function (res) {
          baseData.statusList = res.data
          setSelectOption('#searchStatusEl', 'statusList', 'dictValue', 'dictLabel')
        })
      }

      // 获取渠道
      function getChannel() {
        getDictData('channel', function (res) {
          baseData.channelList = res.data
          setSelectOption('#channelIdEl', 'channelList', 'dictValue', 'dictLabel')
        })
      }

      // 获取账户等级 
      function getAccountLevel() {
        getDictData('account_level', function (res) {
          baseData.accountLevelList = res.data
          setSelectOption('#accountLevelEl', 'accountLevelList', 'dictValue', 'dictLabel')
        })
      }

      // 获取账户类型
      function getAccountType() {
        getDictData('account_type', function (res) {
          baseData.accountTypeList = res.data
          setSelectOption('#accountTypeIdEl', 'accountTypeList', 'dictValue', 'dictLabel')
        })
      }

      // 功能点按需出现
      function elRemove() {
        $('#operateEl').remove()
      }

      function init() {
        // 运营系统
        if (!isDxternal) {
          getChannel()
          getAccountLevel()
          getAccountType()
        } else {
          elRemove()
        }
        getVaildPeriod()
        getTabelList()
      }
    })
  </script>
</body>

</html>