CoordinateHelper.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/8/1
  5. * Time: 下午6:34
  6. */
  7. namespace app\common\helpers;
  8. class CoordinateHelper
  9. {
  10. public static function tpl_form_field_coordinate($field, $value = array())
  11. {
  12. $s = '';
  13. if(!defined('TPL_INIT_COORDINATE')) {
  14. $s .= '<script type="text/javascript">
  15. function showCoordinate(elm) {
  16. require(["util"], function(util){
  17. var val = {};
  18. val.lng = parseFloat($(elm).parent().prev().prev().find(":text").val());
  19. val.lat = parseFloat($(elm).parent().prev().find(":text").val());
  20. util.map(val, function(r){
  21. $(elm).parent().prev().prev().find(":text").val(r.lng);
  22. $(elm).parent().prev().find(":text").val(r.lat);
  23. });
  24. });
  25. }
  26. </script>';
  27. define('TPL_INIT_COORDINATE', true);
  28. }
  29. $s .= '
  30. <div class="row row-fix">
  31. <div class="col-xs-4 col-sm-4">
  32. <input type="text" name="' . $field . '[lng]" value="'.$value['lng'].'" placeholder="地理经度" class="form-control" />
  33. </div>
  34. <div class="col-xs-4 col-sm-4">
  35. <input type="text" name="' . $field . '[lat]" value="'.$value['lat'].'" placeholder="地理纬度" class="form-control" />
  36. </div>
  37. <div class="col-xs-4 col-sm-4">
  38. <button onclick="showCoordinate(this);" class="btn btn-default" type="button">选择坐标</button>
  39. </div>
  40. </div>';
  41. return $s;
  42. }
  43. }