edit.blade.php 10 KB

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