tpl.func.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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'])) ? '' : 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. item[2].text = item[2].text || "";
  187. $this.val(item[0].text+" "+item[1].text+" "+item[2].text)
  188. .next().val(item[0].text)
  189. .next().val(item[1].text)
  190. .next().val(item[2].text);
  191. }, {province : "' . $values['province'] . '", city : "' . $values['city'] . '", district : "' . $values['district'] . '"});
  192. });
  193. </script>';
  194. return $html;
  195. }
  196. function tpl_app_form_field_avatar($name, $value = '', $type = 0) {
  197. $val = './resource/images/nopic.jpg';
  198. if (!empty($value)) {
  199. $val = tomedia($value);
  200. }
  201. $html = '<ul class="mui-table-view mui-table-view-chevron">
  202. <li class="mui-table-view-cell avatar js-avatar-'.$name.'">
  203. <a href="javascript:;" class="mui-navigate-right">头像
  204. <div class="mui-pull-right mui-navigate-right">
  205. <img class="mui-avatar-select mui-pull-left" src="' . $val. '" width="40" height="40">
  206. </div>
  207. </a>
  208. </li>
  209. </ul>
  210. ';
  211. if ($type) {
  212. $html = '<div class="mui-pull-right mui-navigate-right js-avatar-'.$name.'" style="padding-right: 50px;">
  213. <img class="mui-avatar-select mui-pull-left" src="' . $val. '" width="40" height="40">
  214. </div>
  215. ';
  216. }
  217. $href = url('mc/profile/avatar');
  218. $html .= "<script>
  219. util.image($('.js-avatar-{$name}'), function(url){
  220. $('.js-avatar-{$name} img').attr('src', url.url);
  221. $.post('" . $href . "', {'avatar' : url.attachment}, function(data) {
  222. data = $.parseJSON(data);
  223. if (data.type == 'success') {
  224. util.toast(data.message);
  225. } else {
  226. util.toast('更新失败');
  227. }
  228. })
  229. }, {
  230. crop : true
  231. });
  232. </script>";
  233. return $html;
  234. }
  235. function tpl_app_form_field_image($name, $value = '') {
  236. $thumb = empty($value) ? 'images/global/nopic.jpg' : $value;
  237. $thumb = tomedia($thumb);
  238. $html = <<<EOF
  239. <div class="mui-table-view-chevron">
  240. <div class="mui-image-uploader">
  241. <a href="javascript:;" class="mui-upload-btn mui-pull-right js-image-{$name}"></a>
  242. <div class="mui-image-preview js-image-preview mui-pull-right"></div>
  243. </div>
  244. </div>
  245. <script>
  246. util.image($('.js-image-{$name}'), function(url){
  247. $('.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}" />');
  248. }, {
  249. crop : false,
  250. multiple : true,
  251. preview : '__IMG_UPLOAD_{$name}'
  252. });
  253. </script>
  254. EOF;
  255. return $html;
  256. }
  257. function tpl_app_coupon_item($item) {
  258. load()->model('activity');
  259. $type_names = activity_coupon_type_label();
  260. if ($item['type'] == COUPON_TYPE_DISCOUNT) {
  261. $icon = '<div class="price">'.$item['extra']['discount'] * 0.1.'<span>折</span></div>';
  262. } elseif ($item['type'] == COUPON_TYPE_CASH) {
  263. $icon = '<div class="price">' . $item['extra']['reduce_cost'] * 0.01 . '<span>元</span></div><div class="condition">满' . $item['extra']['least_cost'] * 0.01 . '元可用</div>';
  264. } elseif ($item['type'] == COUPON_TYPE_GROUPON) {
  265. $icon = '<img src="resource/images/groupon.png" alt="" />';
  266. } elseif ($item['type'] == COUPON_TYPE_GIFT) {
  267. $icon = '<img src="resource/images/wx_gift.png" alt="" />';
  268. } elseif ($item['type'] == COUPON_TYPE_GENERAL) {
  269. $icon = '<img src="resource/images/general_coupon.png" alt="" />';
  270. }
  271. $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>';
  272. $html .= '
  273. <div class="coupon-panel-info mui-mb10">
  274. <div class="mui-row">
  275. <div class="mui-col-xs-4 mui-text-center">
  276. <div class="coupon-panel-left">'
  277. . $icon .
  278. '</div>
  279. </div>
  280. <div class="mui-col-xs-8">
  281. <div class="mui-row">
  282. <div class="mui-col-xs-7 store-title mui-ellipsis">' . $item['title']. '</div>
  283. ' . $extra_func . '
  284. </div>
  285. <div class="date">' . $item['extra_date_info'] . '</div>
  286. <div class="coupon-rules mui-text-muted js-scan-rules">' . $type_names[$item['type']][0] . '使用规则<span class="fa fa-angle-down"></span></div>
  287. <a class="use-token js-coupon-exchange" data-id="' . $item['id'] . '" data-source="' . $item['source'] . '" data-href="' . $item['extra_href'] . '">
  288. <span class="mui-block icon-use-token">⇌</span>
  289. <span class="mui-block">兑换</span>
  290. </a>
  291. </div>
  292. </div>
  293. <div class="coupon-rules-con js-rules-show" style="display:none;">
  294. <div>' . $item['description'] . '</div>
  295. </div>
  296. </div>
  297. ';
  298. return $html;
  299. }
  300. function tpl_form_field_image($name, $value) {
  301. $thumb = empty($value) ? 'images/global/nopic.jpg' : $value;
  302. $thumb = tomedia($thumb);
  303. $html = <<<EOF
  304. <style>
  305. .webuploader-pick {color:#333;}
  306. </style>
  307. <div class="input-group">
  308. <input type="hidden" name="$name" value="$value" class="form-control" autocomplete="off" readonly="readonly">
  309. <a class="btn btn-default js-image-{$name}">上传图片</a>
  310. </div>
  311. <span class="help-block">
  312. <img src="$thumb" >
  313. </span>
  314. <script>
  315. util.image($('.js-image-{$name}'), function(url){
  316. $('.js-image-{$name}').prev().val(url.attachment);
  317. $('.js-image-{$name}').parent().next().find('img').attr('src',url.url);
  318. }, {
  319. crop : false,
  320. multiple : false
  321. });
  322. </script>
  323. EOF;
  324. return $html;
  325. }