tpl.func.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function _tpl_form_field_date($name, $values = '', $withtime = false) {
  8. $html = '';
  9. $html .= '<input class="mui-calendar-picker" type="text" placeholder="请选择日期" readonly value="' . $values . '" name="' . $name . '" />';
  10. $html .= '<input type="hidden" value="' . $values . '" name="' . $name . '"/>';
  11. if (!defined('TPL_INIT_CALENDAR')) {
  12. $html .= '
  13. <script type="text/javascript">
  14. $(document).on("tap", ".mui-calendar-picker", function(){
  15. var $this = $(this);
  16. util.datepicker({type: "date", beginYear: 1960, endYear: 2050}, function(rs){
  17. $this.val(rs.value)
  18. .next().val(rs.value)
  19. });
  20. });
  21. </script>';
  22. define('TPL_INIT_CALENDAR', true);
  23. }
  24. return $html;
  25. }
  26. function tpl_app_fans_form($field, $value = '', $placeholder = '') {
  27. $placeholders[$field] = '请填写' . $placeholder;
  28. if(in_array($field, array('birth', 'reside', 'gender', 'education', 'constellation', 'zodiac', 'bloodtype'))) {
  29. $placeholders[$field] = '请选择' . $placeholder;
  30. }
  31. if($field == 'height') {
  32. $placeholders[$field] = '请填写' . $placeholder . '(单位:cm)';
  33. } elseif ($field == 'weight') {
  34. $placeholders[$field] = '请填写' . $placeholder . '(单位:kg)';
  35. }
  36. switch ($field) {
  37. case 'avatar':
  38. $html = tpl_app_form_field_avatar('avatar', $value);
  39. break;
  40. case 'birth':
  41. case 'birthyear':
  42. case 'birthmonth':
  43. case 'birthday':
  44. $html = tpl_app_form_field_calendar('birth', $value);
  45. break;
  46. case 'reside':
  47. case 'resideprovince':
  48. case 'residecity':
  49. case 'residedist':
  50. $html = tpl_app_form_field_district('reside', $value);
  51. break;
  52. case 'bio':
  53. case 'interest':
  54. $html = '<textarea name="' . $field . '" rows="3" placeholder="' . $placeholders[$field] . '">' . $value . '</textarea>';
  55. break;
  56. case 'gender':
  57. case 'education':
  58. case 'constellation':
  59. case 'zodiac':
  60. case 'bloodtype':
  61. if($field == 'gender') {
  62. $options = array(
  63. '0' => '保密',
  64. '1' => '男',
  65. '2' => '女',
  66. );
  67. $text_value = $options[$value];
  68. } else {
  69. if ($field == 'bloodtype') {
  70. $options = array('A', 'B', 'AB', 'O', '其它');
  71. } elseif ($field == 'zodiac') {
  72. $options = array('鼠', '牛', '虎', '兔', '龙', '蛇', '马', '羊', '猴', '鸡', '狗', '猪');
  73. } elseif ($field == 'constellation') {
  74. $options = array('水瓶座', '双鱼座', '白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座');
  75. } elseif ($field == 'education') {
  76. $options = array('博士', '硕士', '本科', '专科', '中学', '小学', '其它');
  77. }
  78. $text_value = $value;
  79. }
  80. $data = array();
  81. foreach($options as $key => $option) {
  82. if(!$option) {
  83. continue;
  84. }
  85. if($field == 'gender') {
  86. $data[] = array(
  87. 'text' => $option,
  88. 'value' => $key
  89. );
  90. } else {
  91. $data[] = array(
  92. 'text' => $option,
  93. 'value' => $option
  94. );
  95. }
  96. }
  97. if($field != 'gender') {
  98. $text_value = $value;
  99. unset($options);
  100. }
  101. $html = '
  102. <input class="mui-'. $field .'-picker" type="text" value="'. $text_value .'" readonly placeholder="' . $placeholders[$field] . '"/>
  103. <input type="hidden" name="'. $field .'" value="'. $value .'"/>
  104. <script type="text/javascript">
  105. $(".mui-'. $field .'-picker").on("tap", function(){
  106. var $this = $(this);
  107. util.poppicker({data: '. json_encode($data) .'}, function(items){
  108. $this.val(items[0].text).next().val(items[0].value);
  109. });
  110. });
  111. </script>';
  112. break;
  113. case 'nickname':
  114. case 'realname':
  115. case 'address':
  116. case 'mobile':
  117. case 'qq':
  118. case 'msn':
  119. case 'email':
  120. case 'telephone':
  121. case 'taobao':
  122. case 'alipay':
  123. case 'studentid':
  124. case 'grade':
  125. case 'graduateschool':
  126. case 'idcard':
  127. case 'zipcode':
  128. case 'site':
  129. case 'affectivestatus':
  130. case 'lookingfor':
  131. case 'nationality':
  132. case 'height':
  133. case 'weight':
  134. case 'company':
  135. case 'occupation':
  136. case 'position':
  137. case 'revenue':
  138. default:
  139. $html = '<input type="text" name="' . $field . '" value="' . $value . '" placeholder="' . $placeholders[$field] . '"/>';
  140. break;
  141. }
  142. return $html;
  143. }
  144. function tpl_app_form_field_calendar($name, $values = array()) {
  145. $value = (empty($values['year']) || empty($values['month']) || empty($values['day'])) ? '' : implode('-', $values);
  146. $html = '';
  147. $html .= '<input class="mui-calendar-picker" type="text" placeholder="请选择日期" readonly value="' . $value . '" name="' . $name . '" />';
  148. $html .= '<input type="hidden" value="' . $values['year'] . '" name="' . $name . '[year]"/>';
  149. $html .= '<input type="hidden" value="' . $values['month'] . '" name="' . $name . '[month]"/>';
  150. $html .= '<input type="hidden" value="' . $values['day'] . '" name="' . $name . '[day]"/>';
  151. if (!defined('TPL_INIT_CALENDAR')) {
  152. $html .= '
  153. <script type="text/javascript">
  154. $(document).on("tap", ".mui-calendar-picker", function(){
  155. var $this = $(this);
  156. util.datepicker({
  157. type: "date",
  158. beginYear: 1910,
  159. endYear: 2060,
  160. selected : {
  161. year : "' . $values['year'] . '", month : "' . $values['month'] . '", day : "' . $values['day'] . '"}
  162. }, function(rs){
  163. $this.val(rs.value)
  164. .next().val(rs.y.text)
  165. .next().val(rs.m.text)
  166. .next().val(rs.d.text)
  167. });
  168. });
  169. </script>';
  170. define('TPL_INIT_CALENDAR', true);
  171. }
  172. return $html;
  173. }
  174. function tpl_app_form_field_district($name, $values = array()) {
  175. $value = (empty($values['province']) || empty($values['city']) || empty($values['district'])) ? '' : implode(' ', $values);
  176. $html = '';
  177. $html .= '<input class="mui-district-picker-' . $name .'" placeholder="请选择地区" type="text" readonly value="' . $value . '"/>';
  178. $html .= '<input type="hidden" value="' . $values['province'] . '" name="' . $name . '[province]"/>';
  179. $html .= '<input type="hidden" value="' . $values['city'] . '" name="' . $name . '[city]"/>';
  180. $html .= '<input type="hidden" value="' . $values['district'] . '" name="' . $name . '[district]"/>';
  181. $html .= '
  182. <script type="text/javascript">
  183. $(document).on("tap", ".mui-district-picker-' . $name . '", function(){
  184. var $this = $(this);
  185. util.districtpicker(function(item){
  186. $this.val(item[0].text+" "+item[1].text+" "+item[2].text)
  187. .next().val(item[0].text)
  188. .next().val(item[1].text)
  189. .next().val(item[2].text);
  190. }, {province : "' . $values['province'] . '", city : "' . $values['city'] . '", district : "' . $values['district'] . '"});
  191. });
  192. </script>';
  193. return $html;
  194. }
  195. function tpl_app_form_field_avatar($name, $value = '') {
  196. $val = './resource/images/nopic.jpg';
  197. if (!empty($value)) {
  198. $val = tomedia($value);
  199. }
  200. $html = '<ul class="mui-table-view mui-table-view-chevron">
  201. <li class="mui-table-view-cell avatar js-avatar-'.$name.'">
  202. <a href="javascript:;" class="mui-navigate-right">头像
  203. <div class="mui-pull-right mui-navigate-right">
  204. <img class="mui-avatar-select mui-pull-left" src="' . $val. '" width="40" height="40">
  205. </div>
  206. </a>
  207. </li>
  208. </ul>
  209. ';
  210. $href = url('mc/profile/avatar');
  211. $html .= "<script>
  212. util.image($('.js-avatar-{$name}'), function(url){
  213. $('.js-avatar-{$name} img').attr('src', url.url);
  214. $.post('" . $href . "', {'avatar' : url.attachment}, function(data) {
  215. data = $.parseJSON(data);
  216. if (data.type == 'success') {
  217. util.toast(data.message);
  218. } else {
  219. util.toast('更新失败');
  220. }
  221. })
  222. }, {
  223. crop : true
  224. });
  225. </script>";
  226. return $html;
  227. }
  228. function tpl_app_form_field_image($name, $value = '') {
  229. $thumb = empty($value) ? 'images/global/nopic.jpg' : $value;
  230. $thumb = tomedia($thumb);
  231. $html = <<<EOF
  232. <div class="mui-table-view-chevron">
  233. <div class="mui-image-uploader">
  234. <a href="javascript:;" class="mui-upload-btn mui-pull-right js-image-{$name}"></a>
  235. <div class="mui-image-preview js-image-preview mui-pull-right"></div>
  236. </div>
  237. </div>
  238. <script>
  239. util.image($('.js-image-{$name}'), function(url){
  240. $('.js-image-{$name}').parent().find('.js-image-preview').append('<input type="hidden" value="'+url.attachment+'" name="{$name}[]" /><img src="'+url.url+'" data-id="'+url.id+'" data-preview-src="" data-preview-group="__IMG_UPLOAD_{$name}" />');
  241. }, {
  242. crop : false,
  243. multiple : true,
  244. preview : '__IMG_UPLOAD_{$name}'
  245. });
  246. </script>
  247. EOF;
  248. return $html;
  249. }
  250. function tpl_app_coupon_item($item) {
  251. load()->model('activity');
  252. $type_names = activity_coupon_type_label();
  253. if ($item['type'] == COUPON_TYPE_DISCOUNT) {
  254. $icon = '<div class="price">'.$item['extra']['discount'] * 0.1.'<span>折</span></div>';
  255. } elseif ($item['type'] == COUPON_TYPE_CASH) {
  256. $icon = '<div class="price">' . $item['extra']['reduce_cost'] * 0.01 . '<span>元</span></div><div class="condition">满' . $item['extra']['least_cost'] * 0.01 . '元可用</div>';
  257. } elseif ($item['type'] == COUPON_TYPE_GROUPON) {
  258. $icon = '<img src="resource/images/groupon.png" alt="" />';
  259. } elseif ($item['type'] == COUPON_TYPE_GIFT) {
  260. $icon = '<img src="resource/images/wx_gift.png" alt="" />';
  261. } elseif ($item['type'] == COUPON_TYPE_GENERAL) {
  262. $icon = '<img src="resource/images/general_coupon.png" alt="" />';
  263. }
  264. $extra_func = '<div class="mui-col-xs-5 mui-text-info integral-info"><img src="' . $item['extra_func']['pic'] .'" alt=""/><span>' . $item['extra_func']['credit'] . '</span></div>';
  265. $html .= '
  266. <div class="coupon-panel-info mui-mb10">
  267. <div class="mui-row">
  268. <div class="mui-col-xs-4 mui-text-center">
  269. <div class="coupon-panel-left">'
  270. . $icon .
  271. '</div>
  272. </div>
  273. <div class="mui-col-xs-8">
  274. <div class="mui-row">
  275. <div class="mui-col-xs-7 store-title mui-ellipsis">' . $item['title']. '</div>
  276. ' . $extra_func . '
  277. </div>
  278. <div class="date">' . $item['extra_date_info'] . '</div>
  279. <div class="coupon-rules mui-text-muted js-scan-rules">' . $type_names[$item['type']][0] . '使用规则<span class="fa fa-angle-down"></span></div>
  280. <a class="use-token js-coupon-exchange" data-id="' . $item['id'] . '" data-source="' . $item['source'] . '" data-href="' . $item['extra_href'] . '">
  281. <span class="mui-block icon-use-token">⇌</span>
  282. <span class="mui-block">兑换</span>
  283. </a>
  284. </div>
  285. </div>
  286. <div class="coupon-rules-con js-rules-show" style="display:none;">
  287. <div>' . $item['description'] . '</div>
  288. </div>
  289. </div>
  290. ';
  291. return $html;
  292. }
  293. function tpl_form_field_image($name, $value) {
  294. $thumb = empty($value) ? 'images/global/nopic.jpg' : $value;
  295. $thumb = tomedia($thumb);
  296. $html = <<<EOF
  297. <style>
  298. .webuploader-pick {color:#333;}
  299. </style>
  300. <div class="input-group">
  301. <input type="hidden" name="$name" value="$value" class="form-control" autocomplete="off" readonly="readonly">
  302. <a class="btn btn-default js-image-{$name}">上传图片</a>
  303. </div>
  304. <span class="help-block">
  305. <img src="$thumb" >
  306. </span>
  307. <script>
  308. util.image($('.js-image-{$name}'), function(url){
  309. $('.js-image-{$name}').prev().val(url.attachment);
  310. $('.js-image-{$name}').parent().next().find('img').attr('src',url.url);
  311. }, {
  312. crop : false,
  313. multiple : false
  314. });
  315. </script>
  316. EOF;
  317. return $html;
  318. }