create.blade.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. @extends('layouts.front.app')
  2. @section('content')
  3. <!-- Main content -->
  4. <section class="container content">
  5. @include('layouts.errors-and-messages')
  6. <div class="box">
  7. <form action="{{ route('customer.address.store', $customer->id) }}" method="post" class="form" enctype="multipart/form-data">
  8. <input type="hidden" name="status" value="1">
  9. <div class="box-body">
  10. {{ csrf_field() }}
  11. <div class="form-group">
  12. <label for="alias">Alias <span class="text-danger">*</span></label>
  13. <input type="text" name="alias" id="alias" placeholder="Home or Office" class="form-control" value="{{ old('alias') }}">
  14. </div>
  15. <div class="form-group">
  16. <label for="address_1">Address 1 <span class="text-danger">*</span></label>
  17. <input type="text" name="address_1" id="address_1" placeholder="Address 1" class="form-control" value="{{ old('address_1') }}">
  18. </div>
  19. <div class="form-group">
  20. <label for="address_2">Address 2 </label>
  21. <input type="text" name="address_2" id="address_2" placeholder="Address 2" class="form-control" value="{{ old('address_2') }}">
  22. </div>
  23. <div class="form-group">
  24. <label for="country_id">Country </label>
  25. <select name="country_id" id="country_id" class="form-control select2">
  26. @foreach($countries as $country)
  27. <option @if(env('SHOP_COUNTRY_ID') == $country->id) selected="selected" @endif value="{{ $country->id }}">{{ $country->name }}</option>
  28. @endforeach
  29. </select>
  30. </div>
  31. <div id="provinces" class="form-group" style="display: none;"></div>
  32. <div id="cities" class="form-group" style="display: none;"></div>
  33. <div class="form-group">
  34. <label for="zip">Zip Code </label>
  35. <input type="text" name="zip" id="zip" placeholder="Zip code" class="form-control" value="{{ old('zip') }}">
  36. </div>
  37. <div class="form-group">
  38. <label for="phone">Your Phone </label>
  39. <input type="text" name="phone" id="phone" placeholder="Phone number" class="form-control" value="{{ old('phone') }}">
  40. </div>
  41. </div>
  42. <!-- /.box-body -->
  43. <div class="box-footer">
  44. <div class="btn-group">
  45. <a href="{{ route('accounts', ['tab' => 'address']) }}" class="btn btn-default">Back</a>
  46. <button type="submit" class="btn btn-primary">Create</button>
  47. </div>
  48. </div>
  49. </form>
  50. </div>
  51. <!-- /.box -->
  52. </section>
  53. <!-- /.content -->
  54. @endsection
  55. @section('css')
  56. <link href="{{ asset('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css') }}" rel="stylesheet" />
  57. @endsection
  58. @section('js')
  59. <script src="{{ asset('https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js') }}"></script>
  60. <script type="text/javascript">
  61. function findProvinceOrState(countryId) {
  62. $.ajax({
  63. url : '/api/v1/country/' + countryId + '/province',
  64. contentType: 'json',
  65. success: function (res) {
  66. if (res.data.length > 0) {
  67. let html = '<label for="province_id">Provinces </label>';
  68. html += '<select name="province_id" id="province_id" class="form-control select2">';
  69. $(res.data).each(function (idx, v) {
  70. html += '<option value="'+ v.id+'">'+ v.name +'</option>';
  71. });
  72. html += '</select>';
  73. $('#provinces').html(html).show();
  74. $('.select2').select2();
  75. findCity(countryId, 1);
  76. $('#province_id').change(function () {
  77. var provinceId = $(this).val();
  78. findCity(countryId, provinceId);
  79. });
  80. } else {
  81. $('#provinces').hide().html('');
  82. $('#cities').hide().html('');
  83. }
  84. }
  85. });
  86. }
  87. function findCity(countryId, provinceOrStateId) {
  88. $.ajax({
  89. url: '/api/v1/country/' + countryId + '/province/' + provinceOrStateId + '/city',
  90. contentType: 'json',
  91. success: function (data) {
  92. let html = '<label for="city_id">City </label>';
  93. html += '<select name="city_id" id="city_id" class="form-control select2">';
  94. $(data.data).each(function (idx, v) {
  95. html += '<option value="'+ v.id+'">'+ v.name +'</option>';
  96. });
  97. html += '</select>';
  98. $('#cities').html(html).show();
  99. $('.select2').select2();
  100. },
  101. errors: function (data) {
  102. console.log(data);
  103. }
  104. });
  105. }
  106. function findUsStates() {
  107. $.ajax({
  108. url : '/country/' + countryId + '/state',
  109. contentType: 'json',
  110. success: function (res) {
  111. if (res.data.length > 0) {
  112. let html = '<label for="state_code">States </label>';
  113. html += '<select name="state_code" id="state_code" class="form-control select2">';
  114. $(res.data).each(function (idx, v) {
  115. html += '<option value="'+ v.state_code+'">'+ v.state +'</option>';
  116. });
  117. html += '</select>';
  118. $('#provinces').html(html).show();
  119. $('.select2').select2();
  120. findUsCities('AK');
  121. $('#state_code').change(function () {
  122. let state_code = $(this).val();
  123. findUsCities(state_code);
  124. });
  125. } else {
  126. $('#provinces').hide().html('');
  127. $('#cities').hide().html('');
  128. }
  129. }
  130. });
  131. }
  132. function findUsCities(state_code) {
  133. $.ajax({
  134. url : '/state/' + state_code + '/city',
  135. contentType: 'json',
  136. success: function (res) {
  137. if (res.data.length > 0) {
  138. let html = '<label for="city">City </label>';
  139. html += '<select name="city" id="city" class="form-control select2">';
  140. $(res.data).each(function (idx, v) {
  141. html += '<option value="'+ v.name+'">'+ v.name +'</option>';
  142. });
  143. html += '</select>';
  144. $('#cities').html(html).show();
  145. $('.select2').select2();
  146. $('#state_code').change(function () {
  147. let state_code = $(this).val();
  148. findUsCities(state_code);
  149. });
  150. } else {
  151. $('#provinces').hide().html('');
  152. $('#cities').hide().html('');
  153. }
  154. }
  155. });
  156. }
  157. let countryId = +"{{ env('SHOP_COUNTRY_ID') }}";
  158. $(document).ready(function () {
  159. if (countryId === 226) {
  160. findUsStates(countryId);
  161. } else {
  162. findProvinceOrState(countryId);
  163. }
  164. $('#country_id').on('change', function () {
  165. countryId = +$(this).val();
  166. if (countryId === 226) {
  167. findUsStates(countryId);
  168. } else {
  169. findProvinceOrState(countryId);
  170. }
  171. });
  172. $('#city_id').on('change', function () {
  173. cityId = $(this).val();
  174. findProvinceOrState(countryId);
  175. });
  176. $('#province_id').on('change', function () {
  177. provinceId = $(this).val();
  178. findProvinceOrState(countryId);
  179. });
  180. });
  181. </script>
  182. @endsection