| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081 |
- define(['bootstrap'], function($){
- var trade = {};
- var reg_credit = /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i;
- var reg_int = /^[0-9]\d*$/i;
- trade.init = function() {
- $('.modal-trade').on('click', function(){
- $('#consume-Modal, #credit-Modal, #card-Modal, #card-edit-Modal, #group-Modal').remove();
- var type = $(this).data('type');
- var uid = parseInt($(this).data('uid'));
- if(type == 'consume') {
- trade.consume(uid);
- } else if(type == 'credit1' || type == 'credit2') {
- trade.credit(type, uid);
- } else if(type == 'card') {
- trade.card(uid);
- } else if(type == 'cardsn') {
- trade.card_edit(uid);
- }
- });
- };
- trade.consume = function(uid) {
- var html = '<div class="modal fade" id="consume-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
- ' <div class="modal-dialog modal-lg" role="document">'+
- ' <div class="modal-content">'+
- ' <form class="table-responsive form-inline" method="post" action="" id="form-consume">'+
- ' <div class="modal-header">'+
- ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'+
- ' <h4 class="modal-title" id="myModalLabel">会员消费</h4>'+
- ' </div>'+
- ' <div class="modal-body">'+
- ' <table class="table table-hover table-bordered">'+
- ' <tr>'+
- ' <th width="150">'+
- ' <select name="type" id="type" class="form-control">'+
- ' <option value="mobile">手机号</option>'+
- ' <option value="uid">会员UID</option>'+
- ' </select>'+
- ' </th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr id="user" style="display: none">'+
- ' <th>会员信息</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <strong class="form-control-static"></strong>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>消费总计</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <input type="text" value="" name="total" id="total" class="form-control"/>'+
- ' <span class="input-group-addon">元</span>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>实收金额</th>'+
- ' <td>'+
- ' <div class="input-group">'+
- ' <input type="text" value="" name="money" id="money" class="form-control" readonly/>'+
- ' <span class="input-group-addon">元</span>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th rowspan="3">支付方式</th>'+
- ' <td>'+
- ' <label class="checkbox-inline">'+
- ' <input type="checkbox" name="is_credit2_pay" id="is_credit2_pay" value="1" /> 余额支付'+
- ' </label>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <input type="text" value="0" name="credit2" id="credit2" disabled class="form-control"/>'+
- ' <span class="input-group-addon">元</span>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <td>'+
- ' <label class="checkbox-inline">'+
- ' <input type="checkbox" name="is_credit1_pay" id="is_credit1_pay" value="1" /> 积分抵现'+
- ' </label>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <input type="text" value="0" name="credit1" id="credit1" disabled class="form-control"/>'+
- ' <span class="input-group-addon">积分 抵消</span>'+
- ' <input type="text" value="0" name="offset_money" id="offset_money" disabled class="form-control"/>'+
- ' <span class="input-group-addon">元</span>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <td>'+
- ' <label class="checkbox-inline">'+
- ' <input type="checkbox" value="1" name="is_cash_pay" id="is_cash_pay" /> 现金支付'+
- ' </label>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <input type="text" value="0" name="cash" id="cash" disabled class="form-control"/>'+
- ' <span class="input-group-addon">元 找零</span>'+
- ' <input type="text" value="0" name="return_cash" id="return_cash" disabled class="form-control"/>'+
- ' <span class="input-group-addon">元</span>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>备注</th>'+
- ' <td>'+
- ' <textarea name="remark" class="form-control" cols="81"></textarea>'+
- ' </td>'+
- ' </tr>'+
- ' </table>'+
- ' </div>'+
- ' <div class="modal-footer">'+
- ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
- ' <input type="button" class="btn btn-primary" id="submit-form" value="提交">'+
- ' </div>'+
- ' </form>'+
- ' </div>'+
- ' </div>'+
- '</div>';
- require(['validator'], function($){
- $('#consume-Modal').remove();
- $(document.body).append(html);
- var dialog = $('#consume-Modal');
- dialog.modal('show');
- $('#username').focus();
- $('#form-consume').bootstrapValidator({
- fields: {
- username: {
- validators: {
- notEmpty: {
- message: '请填写用户手机或UID'
- }
- }
- },
- total: {
- validators: {
- notEmpty: {
- message: '请填写消费总计'
- },
- regexp: {
- regexp: reg_credit,
- message: '最多只保留小数点后2位的正数'
- }
- }
- },
- credit2: {
- validators: {
- notEmpty: {
- message: '请填写余额支付金额'
- },
- regexp: {
- regexp: reg_credit,
- message: '最多只保留小数点后2位的正数'
- },
- between: {
- min: 0,
- max: 100000000,
- money: 0,
- message : '超出可用余额'
- }
- }
- },
- credit1: {
- validators: {
- notEmpty: {
- message: '请填写积分数量'
- },
- regexp: {
- regexp: reg_int,
- message: '积分数量只能是正整数'
- },
- between: {
- min: 0,
- max: 1000000000,
- message : '超出会员所拥有的积分或超出最多可抵消金额'
- }
- }
- },
- cash: {
- validators: {
- notEmpty: {
- message: '请填写现金支付金额'
- },
- regexp: {
- regexp: reg_credit,
- message: '最多只保留小数点后2位的正数'
- }
- }
- }
- }
- });
- var Validator = $('#form-consume').data('bootstrapValidator');
- var consume = {
- 'user': {},
- 'card': {},
- 'total': 0,
- 'money': 0,
- 'last_money': 0,
- 'return_cash':0,
- 'is_credit1_pay': false,
- 'is_credit2_pay': false,
- 'is_cash_pay': false,
- 'credit1': 0,
- 'credit2': 0,
- 'cash': 0,
- 'offset_money': 0,
- 'password': '',
- 'init': function(uid) {
- Validator.enableFieldValidators('credit2');
- Validator.enableFieldValidators('credit1');
- Validator.enableFieldValidators('cash');
- this.getuser();
- if(uid > 0) {
- $('#type').val('uid');
- $('#username').val(uid);
- $('#username').trigger('blur');
- $('#username, #type').attr('disabled', true);
- }
- this.initmoney();
- this.initconsume();
- this.submit();
- },
- 'checkuser': function() {
- if(this.user.uid == undefined || !this.user.uid) {
- this.user = {};
- this.card = {};
- $('#username').focus();
- Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- //util.message('未找到对应会员');
- return false;
- }
- return true;
- },
- 'getuser': function(){
- var _this = this;
- $('#username').blur(function(){
- Validator.validateField('username');
- var username = $.trim($('#username').val());
- var type = $('#type').val();
- if(username) {
- $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
- var data = $.parseJSON(data);
- if(data.error != 'none') {
- _this.user = {};
- _this.card = {};
- $('#user').hide();
- Validator.updateMessage('username', 'notEmpty', data.message);
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- } else {
- _this.user = data.user;
- _this.card = data.card;
- $('#user strong').html(data.html);
- $('#user').show();
- }
- });
- }
- });
- },
- 'initmoney': function() {
- var _this = this;
- $('#total').blur(function(){
- if(!_this.checkuser()) {
- return false;
- }
- var total = parseFloat($(this).val());
- _this.total = total;
- money = total;
- if(_this.user.discount && total >= _this.user.discount.condition) {
- if(_this.card.discount_type == 1) {
- money = total - _this.user.discount.discount;
- } else {
- if(!_this.user.discount.discount) {
- _this.user.discount.discount = 1;
- }
- money = total * _this.user.discount.discount;
- }
- if(money < 0) {
- money = 0;
- }
- }
- $('#money').val(money);
- _this.money = money;
- _this.last_money = money;
- });
- },
- 'initcredit1': function() {
- var _this = this;
- $('#credit1').keyup(function(){
- if(!_this.checkuser()) {
- return false;
- }
- _this.credit1 = parseInt($(this).val());
- if(isNaN(_this.credit1)) {
- _this.credit1 = 0;
- }
- if(_this.credit1 >= 0 && _this.card.offset_rate > 0 && _this.card.offset_max > 0) {
- $('#offset_money').val(_this.credit1 / _this.card.offset_rate);
- _this.offset_money = _this.credit1/_this.card.offset_rate;
- }
- var credit1 = parseInt($(this).val());
- if(_this.user.credit1 < credit1) {
- Validator.updateOption('credit1', 'between', 'max', _this.user.credit1);
- Validator.updateMessage('credit1', 'between', '超出会员账户可用积分');
- Validator.updateStatus('credit1', 'INVALID', 'between');
- } else if(_this.card && (_this.card.offset_rate > 0) && (_this.card.offset_max > 0) && (credit1 > (_this.card.offset_rate * _this.card.offset_max))) {
- Validator.updateOption('credit1', 'between', 'max', _this.card.offset_rate * _this.card.offset_max);
- Validator.updateMessage('credit1', 'between', '积分最多可抵消'+_this.card.offset_max);
- Validator.updateStatus('credit1', 'INVALID', 'between');
- }
- _this.updatereturn();
- });
- },
- 'initcredit2': function() {
- var _this = this;
- $('#credit2').keyup(function(){
- if(!_this.checkuser()) {
- return false;
- }
- var money = $('#money').val();
- if(money > 0) {
- var credit2 = parseFloat($('#credit2').val());
- if(_this.user.credit2 < credit2) {
- Validator.updateOption('credit2', 'between', 'max', _this.user.credit2);
- Validator.updateMessage('credit2', 'between', '超出会员账户可用余额');
- Validator.updateStatus('credit2', 'INVALID', 'between');
- } else if(credit2 > money) {
- Validator.updateOption('credit2', 'between', 'max', money);
- Validator.updateMessage('credit2', 'between', '使用余额不能大于应付金额');
- Validator.updateStatus('credit2', 'INVALID', 'between');
- }
- _this.credit2 = credit2;
- _this.updatereturn();
- }
- });
- },
- 'initcash': function() {
- var _this = this;
- $('#cash').keyup(function(){
- if(!_this.checkuser()) {
- return false;
- }
- var money = $('#money').val();
- if(money > 0) {
- var cash = parseFloat($('#cash').val());
- _this.cash = cash;
- _this.updatereturn();
- }
- });
- },
- 'updatereturn': function() {
- var _this = this;
- _this.return_cash = _this.money - _this.credit2 - _this.offset_money - _this.cash;
- if(_this.return_cash > 0) {
- _this.last_money = _this.return_cash;
- $('#return_cash').val(0);
- } else {
- _this.last_money = 0;
- $('#return_cash').val(Math.abs(_this.return_cash));
- }
- },
- 'updatecredit1': function(){
- var _this = this;
- if(_this.card.offset_rate >= 0 || _this.card.offset_max >= 0 && _this.last_money > 0) {
- var min = Math.min.apply(null, [_this.user.credit1, _this.card.offset_rate * _this.card.offset_max, _this.card.offset_rate * _this.last_money]);
- $('#credit1').val(min).focus().select();
- $('#offset_money').val(min/_this.card.offset_rate);
- _this.credit1 = min;
- _this.offset_money = min/_this.card.offset_rate;
- }
- },
- 'updatecredit2': function(){
- var _this = this;
- var min = Math.min(_this.user.credit2, _this.last_money);
- $('#credit2').val(min);
- _this.credit2 = min;
- },
- 'updatecash': function(){
- var _this = this;
- $('#cash').val(_this.last_money);
- _this.cash = _this.last_money;
- },
- 'initconsume': function() {
- var _this = this;
- _this.is_credit1_pay = $('#is_credit1_pay').prop('checked');
- _this.is_credit2_pay = $('#is_credit2_pay').prop('checked');
- _this.is_cash_pay = $('#is_cash_pay').prop('checked');
- _this.credit1 = parseInt($('#credit1').val());
- _this.credit2 = parseFloat($('#credit2').val());
- _this.cash = parseFloat($('#cash').val());
- _this.initcredit1();
- _this.initcredit2();
- _this.initcash();
- $('#is_credit1_pay').click(function(){
- if(!_this.checkuser()) {
- return false;
- }
- if(!_this.money) {
- Validator.updateStatus('total', 'INVALID', 'regexp');
- $('#total').focus().select();
- return false;
- }
- if(!$(this).prop('checked')) {
- //如果是非选中状态
- Validator.updateStatus('credit1', 'VALID');
- $('#credit1').attr('disabled', true);
- Validator.enableFieldValidators('credit1', false);
- $('#credit1').val(0);
- $('#offset_money').val(0);
- $(this).prop('checked', false);
- _this.is_credit1_pay = false;
- _this.credit1 = 0;
- _this.offset_money = 0;
- } else if(_this.last_money >= 0) {
- if(_this.last_money == 0) {
- return false;
- }
- _this.is_credit1_pay = true;
- $('#credit1').removeAttr('disabled');
- Validator.enableFieldValidators('credit1', true);
- _this.updatecredit1();
- }
- _this.updatereturn();
- });
- $('#is_credit2_pay').click(function(){
- if(!_this.checkuser()) {
- return false;
- }
- if(!_this.money) {
- Validator.updateStatus('total', 'INVALID', 'regexp');
- $('#total').focus().select();
- return false;
- }
- if(!$(this).prop('checked')) {
- //如果是非选中状态
- Validator.updateStatus('credit2', 'VALID');
- $('#credit2').attr('disabled', true);
- Validator.enableFieldValidators('credit2', false);
- $('#credit2').val(0);
- $(this).prop('checked', false);
- _this.is_credit2_pay = false;
- _this.credit2 = 0;
- } else if(_this.last_money >= 0) {
- if(_this.last_money == 0) {
- return false;
- }
- $('#credit2').removeAttr('disabled');
- Validator.enableFieldValidators('credit2', true);
- _this.is_credit2_pay = true;
- _this.updatecredit2();
- }
- _this.updatereturn();
- });
- $('#is_cash_pay').click(function(){
- if(!_this.checkuser()) {
- return false;
- }
- if(!_this.money) {
- Validator.updateStatus('total', 'INVALID', 'regexp');
- $('#total').focus().select();
- return false;
- }
- if(!$(this).prop('checked')) {
- //如果是非选中状态
- Validator.updateStatus('cash', 'VALID');
- $('#cash').attr('disabled', true);
- Validator.enableFieldValidators('cash', false);
- $('#cash').val(0);
- $(this).prop('checked', false);
- _this.is_cash_pay = false;
- _this.cash = 0;
- } else if(_this.last_money >= 0) {
- if(_this.last_money == 0) {
- return false;
- }
- $('#cash').removeAttr('disabled');
- Validator.enableFieldValidators('cash', true);
- _this.is_cash_pay = true;
- _this.updatecash();
- }
- _this.updatereturn();
- });
- },
- 'submit': function() {
- var _this = this;
- _this.updatereturn();
- $('#form-consume #submit-form').click(function(){
- Validator.validate();
- if(Validator.isValid()) {
- if(_this.last_money > 0) {
- util.message('支付金额小于实收金额,请检查表单');
- return false;
- }
- _this.password = $.trim($(':input[name="password"]').val());
- _this.remark = $.trim($('textarea[name="remark"]').val());
- var param = {
- 'uid': _this.user.uid,
- 'total': _this.total,
- 'money': _this.money,
- 'credit2': _this.credit2,
- 'credit1': _this.credit1,
- 'cash': _this.cash,
- 'offset_money': _this.offset_money,
- 'return_cash': _this.return_cash,
- 'password': _this.password,
- 'remark': _this.remark
- }
- $.post('./index.php?c=mc&a=trade&do=consume', param, function(data){
- if(data != 'success') {
- util.message(data, '', 'error');
- return false;
- } else {
- dialog.modal('hide');
- util.message('交易成功', 'refresh', 'success');
- return false;
- }
- });
- }
- });
- }
- };
- consume.init(uid);
- });
- };
- trade.credit = function(type, uid) {
- var types = {'credit1': '积分', 'credit2': '余额'};
- var html = '<div class="modal fade" id="credit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
- ' <div class="modal-dialog modal-lg" role="document">'+
- ' <div class="modal-content">'+
- ' <form class="table-responsive form-inline" method="post" action="" id="form-credit">'+
- ' <div class="modal-header">'+
- ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'+
- ' <h4 class="modal-title" id="myModalLabel">会员'+types[type]+'操作</h4>'+
- ' </div>'+
- ' <div class="modal-body">'+
- ' <table class="table table-hover table-bordered">'+
- ' <tr>'+
- ' <th width="150">'+
- ' <select name="type" id="type" class="form-control">'+
- ' <option value="mobile">手机号</option>'+
- ' <option value="uid">会员UID</option>'+
- ' </select>'+
- ' </th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr id="user" style="display: none">'+
- ' <th>会员信息</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <strong class="form-control-static"></strong>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>修改'+types[type]+'(增减)</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="num" id="total" class="form-control"/>'+
- ' <div class="help-block">输入500,则标识增加500;输入-500则表示减少500</div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>备注</th>'+
- ' <td>'+
- ' <textarea name="remark" class="form-control" cols="81"></textarea>'+
- ' </td>'+
- ' </tr>'+
- ' </table>'+
- ' </div>'+
- ' <div class="modal-footer">'+
- ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
- ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
- ' </div>'+
- ' </form>'+
- ' </div>'+
- ' </div>'+
- '</div>';
- require(['validator'], function($){
- $('#credit-Modal').remove();
- $(document.body).append(html);
- var dialog = $('#credit-Modal');
- dialog.modal('show');
- $('#form-credit').bootstrapValidator({
- fields: {
- username: {
- validators: {
- notEmpty: {
- message: '请填写用户手机或UID'
- }
- }
- },
- num: {
- validators: {
- notEmpty: {
- message: '请填写数量'
- },
- regexp: {
- regexp: /^[+-]?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/i,
- message: '最多只保留小数点后2位的正数'
- }
- }
- }
- }
- });
- var Validator = $('#form-credit').data('bootstrapValidator');
- var credit = {
- 'user': {},
- 'card': {},
- 'init': function(type, uid) {
- this.type = type,
- this.getuser();
- if(uid > 0) {
- $('#type').val('uid');
- $('#username').val(uid);
- $('#username').trigger('blur');
- $('#username, #type').attr('disabled', true);
- }
- this.submit();
- },
- getuser: function() {
- var _this = this;
- $('#username').blur(function(){
- Validator.validateField('username');
- var username = $.trim($('#username').val());
- var type = $('#type').val();
- if(username) {
- $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
- var data = $.parseJSON(data);
- if(data.error != 'none') {
- _this.user = {};
- _this.card = {};
- $('#user').hide();
- Validator.updateMessage('username', 'notEmpty', data.message);
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- } else {
- _this.user = data.user;
- _this.card = data.card;
- $('#user strong').html(data.html);
- $('#user').show();
- }
- });
- }
- });
- },
- 'checkuser': function() {
- if(this.user.uid == undefined || !this.user.uid) {
- this.user = {};
- this.card = {};
- $('#username').focus();
- Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- //util.message('未找到对应会员');
- return false;
- }
- return true;
- },
- 'submit': function() {
- var _this = this;
- $('#form-credit .btn-primary').click(function(){
- _this.checkuser();
- Validator.validate();
- if(Validator.isValid()) {
- _this.password = $.trim($(':input[name="password"]').val());
- _this.num = $.trim($(':text[name="num"]').val());
- _this.remark = $.trim($('textarea[name="remark"]').val());
- var param = {
- 'uid': _this.user.uid,
- 'num': _this.num,
- 'password': _this.password,
- 'remark': _this.remark,
- 'type': _this.type
- }
- $.post('./index.php?c=mc&a=trade&do=credit', param, function(data){
- if(data != 'success') {
- util.message(data, '', 'error');
- return false;
- } else {
- dialog.modal('hide');
- util.message('操作成功', 'refresh', 'success');
- return false;
- }
- });
- }
- });
- }
- };
- credit.init(type, uid);
- });
- };
- trade.card = function(uid) {
- var html = '<div class="modal fade" id="card-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
- ' <div class="modal-dialog modal-lg" role="document">'+
- ' <div class="modal-content">'+
- ' <form class="table-responsive form-inline" method="post" action="" id="form-card">'+
- ' <div class="modal-header">'+
- ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'+
- ' <h4 class="modal-title" id="myModalLabel">发放会员卡</h4>'+
- ' </div>'+
- ' <div class="modal-body">'+
- ' <table class="table table-hover table-bordered">'+
- ' <tr>'+
- ' <th width="150">'+
- ' <select name="type" id="type" class="form-control">'+
- ' <option value="mobile">手机号</option>'+
- ' <option value="uid">会员UID</option>'+
- ' </select>'+
- ' </th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr id="user" style="display: none">'+
- ' <th>会员信息</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <strong class="form-control-static"></strong>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' </table>'+
- ' </div>'+
- ' <div class="modal-footer">'+
- ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
- ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
- ' </div>'+
- ' </form>'+
- ' </div>'+
- ' </div>'+
- '</div>';
- require(['validator'], function($){
- $('#card-Modal').remove();
- $(document.body).append(html);
- var dialog = $('#card-Modal');
- dialog.modal('show');
- $('#form-card').bootstrapValidator({
- fields: {
- username: {
- validators: {
- notEmpty: {
- message: '请填写用户手机或UID'
- }
- }
- }
- }
- });
- var Validator = $('#form-card').data('bootstrapValidator');
- var card = {
- 'user': {},
- 'card': {},
- 'init': function(uid) {
- this.getuser();
- if(uid > 0) {
- $('#type').val('uid');
- $('#username').val(uid);
- $('#username').trigger('blur');
- if(this.user.uid > 0) {
- $('#username, #type').attr('disabled', true);
- }
- }
- this.submit();
- },
- getuser: function() {
- var _this = this;
- $('#username').blur(function(){
- Validator.validateField('username');
- var username = $.trim($('#username').val());
- var type = $('#type').val();
- if(username) {
- $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
- var data = $.parseJSON(data);
- if(data.error != 'none') {
- _this.user = {};
- _this.card = {};
- $('#user').hide();
- Validator.updateMessage('username', 'notEmpty', data.message);
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- } else {
- _this.user = data.user;
- _this.card = data.card;
- $('#user strong').html(data.html);
- $('#user').show();
- }
- });
- }
- });
- },
- 'checkuser': function() {
- if(this.user.uid == undefined || !this.user.uid) {
- this.user = {};
- this.card = {};
- $('#username').focus();
- Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- }
- if(this.card.id > 0) {
- util.message('该会员已领取会员卡');
- return false;
- }
- return true;
- },
- 'submit': function() {
- var _this = this;
- $('#form-card .btn-primary').click(function(){
- _this.checkuser();
- Validator.validate();
- if(Validator.isValid()) {
- _this.password = $.trim($(':input[name="password"]').val());
- var param = {
- 'uid': _this.user.uid,
- 'password': _this.password,
- }
- $.post('./index.php?c=mc&a=trade&do=card', param, function(data){
- if(data != 'success') {
- util.message(data, '', 'error');
- return false;
- } else {
- dialog.modal('hide');
- util.message('发放会员卡成功', 'refresh', 'success');
- return false;
- }
- });
- }
- });
- }
- };
- card.init(uid);
- });
- }
- trade.card_edit = function(uid) {
- var html = '<div class="modal fade" id="card-edit-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">'+
- ' <div class="modal-dialog modal-lg" role="document">'+
- ' <div class="modal-content">'+
- ' <form class="table-responsive form-inline" method="post" action="" id="form-card">'+
- ' <div class="modal-header">'+
- ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'+
- ' <h4 class="modal-title" id="myModalLabel">更改会员卡号</h4>'+
- ' </div>'+
- ' <div class="modal-body">'+
- ' <table class="table table-hover table-bordered">'+
- ' <tr>'+
- ' <th width="150">'+
- ' <select name="type" id="type" class="form-control">'+
- ' <option value="mobile">手机号</option>'+
- ' <option value="uid">会员UID</option>'+
- ' </select>'+
- ' </th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="username" id="username" class="form-control"/>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr id="user" style="display: none">'+
- ' <th>会员信息</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <div class="input-group">'+
- ' <strong class="form-control-static"></strong>'+
- ' </div>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>原卡号</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <p class="label label-danger" id="old_cardsn"></p>'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' <tr>'+
- ' <th>设置新卡号</th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" name="cardsn" id="cardsn" value="" class="form-control">'+
- ' </div>'+
- ' </td>'+
- ' </tr>'+
- ' </table>'+
- ' </div>'+
- ' <div class="modal-footer">'+
- ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>'+
- ' <input type="submit" class="btn btn-primary" id="submit" name="提交"value="提交">'+
- ' </div>'+
- ' </form>'+
- ' </div>'+
- ' </div>'+
- '</div>';
- require(['validator'], function($){
- $('#card-edit-Modal').remove();
- $(document.body).append(html);
- var dialog = $('#card-edit-Modal');
- dialog.modal('show');
- $('#form-card').bootstrapValidator({
- fields: {
- username: {
- validators: {
- notEmpty: {
- message: '请填写用户手机或UID'
- }
- }
- },
- cardsn: {
- validators: {
- notEmpty: {
- message: '新卡号不能为空'
- },
- remote: {
- url: "./index.php?c=mc&a=trade&do=cardsn&type=check",
- data: function(validator) {
- return {
- data: validator.getFieldElements('cardsn').val()
- };
- },
- message: '卡号已经被其他用户使用'
- }
- }
- }
- }
- });
- var Validator = $('#form-card').data('bootstrapValidator');
- var card_edit = {
- 'user': {},
- 'card': {},
- 'init': function(uid) {
- this.getuser();
- if(uid > 0) {
- $('#type').val('uid');
- $('#username').val(uid);
- $('#username').trigger('blur');
- if(this.user.uid > 0) {
- $('#username, #type').attr('disabled', true);
- }
- }
- this.submit();
- },
- getuser: function() {
- var _this = this;
- $('#username').blur(function(){
- Validator.validateField('username');
- var username = $.trim($('#username').val());
- var type = $('#type').val();
- if(username) {
- $.post('./index.php?c=mc&a=trade&do=user&', {'type':type, 'username':username}, function(data){
- var data = $.parseJSON(data);
- if(data.error != 'none') {
- _this.user = {};
- _this.card = {};
- $('#user').hide();
- Validator.updateMessage('username', 'notEmpty', data.message);
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- } else {
- _this.user = data.user;
- _this.card = data.card;
- $('#user strong').html(data.html);
- $('#old_cardsn').html(data.user.cardsn);
- $('#user').show();
- }
- });
- }
- });
- },
- 'checkuser': function() {
- if(this.user.uid == undefined || !this.user.uid) {
- this.user = {};
- this.card = {};
- $('#username').focus();
- Validator.updateMessage('username', 'notEmpty', '未找到对应会员');
- Validator.updateStatus('username', 'INVALID', 'notEmpty');
- return false;
- }
- return true;
- },
- 'submit': function() {
- var _this = this;
- $('#form-card .btn-primary').click(function(){
- _this.checkuser();
- Validator.validate();
- if(Validator.isValid()) {
- var param = {
- 'uid': _this.user.uid,
- 'cardsn': $.trim($('#cardsn').val()),
- 'password': $.trim($(':input[name="password"]').val())
- }
- $.post('./index.php?c=mc&a=trade&do=cardsn', param, function(data){
- if(data != 'success') {
- util.message(data, '', 'error');
- return false;
- } else {
- dialog.modal('hide');
- util.message('更改卡号成功', 'refresh', 'success');
- return false;
- }
- });
- }
- });
- }
- };
- card_edit.init(uid);
- });
- }
- return trade;
- });
|