order.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;
  2. layui.define(['form','upload','flow','laytpl','element'], function (e) {
  3. var s = layui.$,
  4. upload = layui.upload,
  5. flow = layui.flow,
  6. laytpl = layui.laytpl,
  7. element = layui.element,
  8. form = layui.form;
  9. s('.address').on('click',function(){
  10. layui.data('qfsc',{
  11. key:'history',
  12. value:location.href
  13. })
  14. location.href = '/index/address/index.html'
  15. })
  16. form.on('submit(layui-order-add)',function(data){
  17. layui.data('qfsc',{
  18. key:'history',
  19. value:null
  20. })
  21. var message = s('input[name=message]').val();
  22. data.field.message = message;
  23. data.field.account = s('input[name=account]').val();
  24. layer.prompt({title: '输入交易密码,并确认', formType: 1}, function(oppwd, index){
  25. data.field.oppwd = oppwd;
  26. s.post('add.html',data.field,function(r){
  27. layer.msg(r.msg,{time:1000,end:function(){
  28. if (!r.code) {
  29. location.href = '/index/order/index.html'
  30. }
  31. }})
  32. })
  33. layer.close(index);
  34. });
  35. return false;
  36. })
  37. element.on('tab(order)', function(data){
  38. var state = s(this).attr('lay-id');
  39. s('.list').empty();
  40. flow.load({
  41. elem: '.list'
  42. ,done: function(page, next){
  43. s.post('load.html',{page:page,state:state},function(res){
  44. laytpl(s('#order-list').html()).render(res.data, function(html){
  45. next(html, page < res.pages);
  46. })
  47. });
  48. }
  49. });
  50. });
  51. var order = function(){
  52. if(s('input[name=address_id]').length > 0){
  53. order.prototype.address();
  54. }
  55. if (s('.list').length > 0) {
  56. console.log(0)
  57. element.tabChange('order', '0')
  58. }
  59. }
  60. order.prototype.address = function() {
  61. s.post('/index/address/default',{},function(r){
  62. if (!r.code) {
  63. var rdata = r.data;
  64. s('input[name=address_id]').val(rdata.id)
  65. s('span.truename').text(rdata.truename);
  66. s('span.mobile').text(rdata.mobile);
  67. var address = rdata.area+' '+rdata.detail;
  68. s('span.address').text(address);
  69. }else{
  70. layer.confirm('请先添加收货地址', {
  71. btn: ['确定','取消']
  72. }, function(index){
  73. layer.close(index)
  74. layui.data('qfsc',{
  75. key:'history',
  76. value:location.href
  77. })
  78. location.href = '/index/address/index.html'
  79. },function(){
  80. history.go(-1)
  81. });
  82. }
  83. })
  84. };
  85. e('order',new order())
  86. })