123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182 |
- 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-credit1, .modal-trade-credit2, .modal-trade-consume, .modal-trade-card, .modal-trade-cardsn, .modal-trade-cardconsume').on('click', function(){
- $('#consume-Modal, #credit-Modal, #card-Modal, #card-edit-Modal, #group-Modal, #cardconsume-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);
- } else if (type == 'cardconsume') {
- trade.cardconsume();
- }
- });
- };
-
- 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;
- money = money.toFixed(1);
- }
- 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());
- _this.username = $.trim($('#username').val());
- var param = {
- 'uid': _this.user.uid,
- 'password': _this.password,
- 'username': _this.username
- }
- $.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.cardconsume = function() {
- 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 height="100">'+
- ' <th width="150">'+
- ' 卡券code码'+
- ' </th>'+
- ' <td>'+
- ' <div class="form-group">'+
- ' <input type="text" value="" name="code" id="code" class="form-control"/>'+
- ' <div class="help-block">请输入卡券code码</div>'+
- ' </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');
- $('#card-Modal').on('shown.bs.modal', function () {
- $('#code').focus();
- });
- $('#form-card').bootstrapValidator({
- fields: {
- code: {
- validators: {
- notEmpty: {
- message: '请填写卡券code码'
- }
- }
- }
- }
- });
- var Validator = $('#form-card').data('bootstrapValidator');
- var card = {
- 'user': {},
- 'card': {},
- 'init': function(uid) {
- if(uid > 0) {
- $('#type').val('uid');
- $('#code').val(uid);
- $('#code').trigger('blur');
- if(this.user.uid > 0) {
- $('#code, #type').attr('disabled', true);
- }
- }
- this.submit();
- },
-
- 'submit': function() {
- var _this = this;
- $('#form-card .btn-primary').click(function(){
- Validator.validate();
- if(Validator.isValid()) {
- _this.code = $.trim($(':input[name="code"]').val());
- var param = {
- 'code': _this.code,
- }
- $.post('./index.php?c=mc&a=trade&do=cardconsume', param, function(data){
- if(data != 'success') {
- util.message(data, '', 'error');
- return false;
- } else {
- dialog.modal('hide');
- util.message('核销成功', 'refresh', 'success');
- return false;
- }
- });
- }
- });
- }
- };
- card.init();
- });
- }
-
- 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;
- });
|