---
# System prepended metadata

title: 抽共用方法邏輯

---

# 抽共用方法邏輯

## 1. 共用Dialog放Index.html

 <!-- VERIFY PASSWORD DIALOG -->
    <div id="pwdInputVerifyModal" style="display: none">
        <form class="form-horizontal" id="pwdInputVerifyModalForm">
            <input type="hidden" name="rowId" id="rowId"/>
            <div class="form-group" style="padding-top: 10px">
                <label class="col-xs-3 col-sm-3 col-md-3 col-lg-3 control-label">請輸入密碼 </label>
                <div class="row" style="margin-left: 20px; display: flex">
                    <input type="password" id="password" placeholder="請輸入密碼" class="form-control" style="width: 80%;">
                </div>
            </div>
        </form>
        <div class="form-actions">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="text-align: center">
                    <button class="btn btn-primary" type="submit" onclick="sms.verifyPasswordFunction()">
                        <i class="fa fa-save"></i>
                        確認
                    </button>
                </div>
            </div>
        </div>
    </div>

## 2. JS放sms.js

    var funTest;
    //是否啟用密碼驗證
    sms.systemIsVerifyPwdFuntion = function (fun) {
        //按下確認後，執行停用前，先確認是否有啟用密碼驗證
        var callback = (result) => {
            if (result && result.systemValue === 'Y') {
                // 有啟用則打開密碼驗證視窗
                funTest = fun;
                pwdInputVerifyModal.dialog('open');
                // 無啟用則直接執行停用
            } else if (result && result.systemValue === 'N') {
                fun();
            } else {
                sms.showErrorMsg(result);
            }
        }
        sms.ajaxSet({}, callback, '/checkIsVerifyPwd', "get", 'share', true, ".ui-widget");
    }

    //密碼驗證
    sms.verifyPasswordFunction = function () {
        var callback = (result) => {
            if (result.status == 200) {
                // 執行成功 關閉
                pwdInputVerifyModal.dialog('close');
                //驗證後執行停用
                funTest();
            } else {
                sms.showErrorMsg(result, verifyFormId);
            }
        }
        sms.ajaxSet({password: $('#password').val()}, callback, '/verifyPassword', "get", 'share', true, ".ui-widget");
    }
    
     //密碼驗證Dialog
       sms.initDialog = function () {
        pwdInputVerifyModal.dialog({
            create: function(event, ui) {
                $(event.target).parent().css('position', 'fixed');
            },
            autoOpen: false,
            width: 535,
            height: 180,
            modal: true,
            title: '密碼驗證'
        });
    }
   

## 3. Controller放ShareController
#### 記得funcPropMap要另外設定(沒有頁面，無權限)
    
      @GetMapping(PATH_NAME + "/checkIsVerifyPwd")
    public ResponseEntity<SystemConfig> checkIsVerifyPwd(HttpServletRequest request) {
        **funcPropMap = createFuncPropMap("dashboard", null);**
    //        if (!authCheck()) {
    //            return null;
    //        }
        return new ResponseEntity<>(supplierService.findSystemConfig(), HttpStatus.OK);
    }

    @ResponseBody
    @GetMapping(PATH_NAME + "/verifyPassword")
    public ResultData verifyPassword(HttpServletRequest request) {
        **funcPropMap = createFuncPropMap("dashboard", null);**
    //        if (!authCheck()) {
    //            return ResultData.fail(ResultCode.NO_AUTH);
    //        }
        String password = request.getParameter("password");
        User user = userService.selectByUserId((Long) funcPropMap.get("loginUserId"));
        if (!passwordEncoder.matches(password, user.getPassword())) {
            return ResultData.fail(ResultCode.USER_PASSWORD_FAIL);
        }
        return ResultData.success(ResultCode.SUCCESS);
    }

## 在supplier.js 底下開發的js --- statusStop func
### stopFunction重複的部分，整個function設為變數傳遞到sms.systemIsVerifyPwdFunction(stopFunc)

     prop.statusStop = function (id) {
        var rowData = $jqgrid.getRowData(id);
        swal({
            title: '確定停用供應商【' + rowData.custName.replace('<br>', '') + '】？',
            text:'*注意: 若停用該供應商，則此供應商所屬通道將全數停用。',
            icon: 'warning',
            buttons: ['取消', '確認'],
            dangerMode: true
        }).then((willDisable) => {
            if (willDisable) {
                var stopFunc = function () {
                    var customer = JSON.parse(rowData.customer);
                    var data = {
                        custId: customer.custId,
                        statusNo: 902,
                        contactPersonEmail: customer.contactPersonEmail,
                        custType: customer.custType,
                        phoneNumber: customer.phoneNumber,
                        countryPhoneCode: customer.countryPhoneCode
                    };
                    sms.ajaxSet(data, function (result) {
                        if (result.status == 200) {
                            swal({text: result.message, icon: "success"});
                            sms.reload(prop.jqgridOption);
                        } else {
                            sms.showErrorMsg(result);
                        }
                    }, '/updateStatus', 'put', prop.pathName, true, "#main")
                }
                sms.systemIsVerifyPwdFuntion(stopFunc);
            }
        });
    }

![](https://i.imgur.com/pJTfHkQ.png)
![](https://i.imgur.com/9oW8MJN.png)

