index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/js/cropbox/jquery.cropbox.css">
  2. <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/cropbox/hammer.js"></script>
  3. <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/cropbox/jquery.mousewheel.js"></script>
  4. <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/cropbox/jquery.cropbox.js?v=2016032201"></script>
  5. <form class="am-form tech-form">
  6. <fieldset>
  7. <legend><?=$name?><small>个人信息</small></legend>
  8. <div class="am-form-group">
  9. <label for="doc-ta-1">介绍</label>
  10. <textarea class="intro" rows="5" id="doc-ta-1"><?=$desc?></textarea>
  11. </div>
  12. <div class="am-form-group am-form-file">
  13. <label for="doc-ipt-file-2">头像</label>
  14. <div>
  15. <button type="button" class="am-btn am-btn-default am-btn-sm tech-avatar-btn">
  16. <i class="am-icon-cloud-upload"></i> 选择图片</button>
  17. <input type="file" id="tech-avatar" style="top: initial;bottom: 0;font-size: 1.4rem;padding: .25em 1em;">
  18. </div>
  19. </div>
  20. <p class="img-preview">
  21. <img src="<?=$avatar?>" alt="" class="" width="200" height="200">
  22. </p>
  23. <p>
  24. <!-- <button type="submit" class="am-btn am-btn-default btn-edit">编辑</button> -->
  25. <button type="submit" class="am-btn am-btn-success btn-submit">提交</button>
  26. </p>
  27. </fieldset>
  28. </form>
  29. <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  30. <div class="am-modal-dialog">
  31. <div class="am-modal-hd">提示信息</div>
  32. <div class="am-modal-bd">
  33. 介绍或者头像不能为空
  34. </div>
  35. <div class="am-modal-footer">
  36. <span class="am-modal-btn">确定</span>
  37. </div>
  38. </div>
  39. </div>
  40. <script>
  41. $(function(){
  42. /* 初始化参数 */
  43. var tech_name = <?=json_encode($name)?>; // 保洁师姓名
  44. var tech_id = <?=json_encode($_id)?>; // 保洁师后台ID
  45. var token = <?=json_encode($qiniu_token)?>; // 七牛上传token
  46. var url = <?=json_encode($qiniu_url)?>; // 七牛上传url_prefix
  47. var avatar = <?=json_encode($avatar)?>;
  48. var intro = <?=json_encode($desc)?>;
  49. var cropImg = '';
  50. var apiUrl = 'http:// api.yiguanjia.me';
  51. if (location.host == ' apitest.yiguanjia.me') {
  52. apiUrl = 'http:// apitest.yiguanjia.me';
  53. } else if (location.host == 'api.yiguanjiadev.me') {
  54. apiUrl = 'http://api.yiguanjiadev.me';
  55. }
  56. function edit() {
  57. $('.tech-form').find('.intro').removeAttr('readonly');
  58. $('#tech-avatar').removeAttr('disabled');
  59. $('.tech-avatar-btn').removeClass('am-disabled');
  60. }
  61. function submit() {
  62. $('.tech-form').find('.intro').attr('readonly', 'true');
  63. $('#tech-avatar').attr('disabled', 'disabled');
  64. $('.tech-avatar-btn').addClass('am-disabled');
  65. }
  66. $('.intro').on('blur', function(event) {
  67. event.preventDefault();
  68. intro = $(this).val();
  69. });
  70. $('.tech-form').on('click', '.btn-edit', function(event) {
  71. event.preventDefault();
  72. edit();
  73. });
  74. $('.tech-form').on('click', '.btn-submit', function(event) {
  75. event.preventDefault();
  76. if (intro == '') {
  77. alert('介绍不能为空');
  78. } else if (avatar == '') {
  79. alert('请上传头像');
  80. } else {
  81. submit();
  82. $.ajax({
  83. url: apiUrl + '/index.php?r=o2o/techHome/updateInfo',
  84. jsonp: "callback",
  85. dataType: "jsonp",
  86. data: {
  87. tech_id: tech_id,
  88. desc: intro,
  89. avatar: avatar + cropImg
  90. }
  91. })
  92. .done(function(res) {
  93. alert(res.message);
  94. })
  95. .fail(function(res) {
  96. alert(res.message);
  97. })
  98. .always(function() {
  99. edit();
  100. });
  101. }
  102. });
  103. $('.tech-form').on('change', '#tech-avatar', function(event) {
  104. event.preventDefault();
  105. var files = event.target.files;
  106. var formData = new FormData();
  107. formData.append('token', token);
  108. formData.append('file', files[0]);
  109. var name = files[0].name;
  110. var point = name.lastIndexOf('.'),
  111. type = name.substr(point),
  112. key = Math.random().toString(16).substring(2) + (+new Date()) + type;
  113. formData.append('key', key);
  114. $.ajax({
  115. url: 'http://upload.qiniu.com',
  116. type: 'POST',
  117. data: formData,
  118. processData: false,
  119. contentType: false
  120. })
  121. .done(function(res) {
  122. avatar = url + res.key
  123. $('.img-preview').html('<img src="'+ url + res.key +'" alt="" class="cropimage">');
  124. crop();
  125. })
  126. .fail(function() {
  127. console.log("error");
  128. })
  129. .always(function() {
  130. console.log("complete");
  131. });
  132. });
  133. function crop() {
  134. $('.cropimage').cropbox({
  135. width: 200,
  136. height: 200,
  137. controls: ''
  138. }, function() {
  139. //on load
  140. }).on('cropbox', function(event, results) {
  141. var X = results.cropX;
  142. var Y = results.cropY;
  143. var W = results.cropW;
  144. var H = results.cropH;
  145. cropImg = '?imageMogr/v2/crop/!' + W + 'x' + H + 'a' + X + 'a' + Y;
  146. });
  147. }
  148. })
  149. </script>