activitycoupon.html 16.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
{php define('MUI', true);}
{template 'common/header'}
{if $activity_type == 'coupon'}
{if $op == 'display'}
<div class="mui-content activity-exchange" style="padding-bottom:55px;">
	<div class="mui-table nav">
		<a href="{php echo $this->createMobileurl('activity')}" class="mui-table-cell mui-active">
			卡券
		</a>
		<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'goods'))}" class="mui-table-cell">
			实物
		</a>
	</div>
	<div class="discount-voucher mui-content-padded">
		{if !empty($exchange_lists)}
		{loop $exchange_lists $item}
		{php echo tpl_app_coupon_item($item);}
		{/loop}
		{else}
		<div class="mui-input-row mui-text-center">暂无可兑换卡券</div>
		{/if}
	</div>
</div>
<script type="text/javascript">
$('.js-scan-rules').click(function() {
	$(this).parent().parent().next().toggle();
	$(this).find('span').toggleClass('fa-angle-up');
	$(this).find('span').toggleClass('fa-angle-down');
})
$('.js-coupon-exchange').click(function(){
	var id = $.trim($(this).data('id'));
	var source = $(this).data('source');
	var href = $(this).data('href');
	var cancel_href = $(this).data('cancel-href');
	var exchange_href = $(this).data('exchange-href');
	if(!id) {
		return false;
	}
	$.post(href, {'id' : id}, function(data) {
		data = $.parseJSON(data);
		console.dir(data)
		if (data.message.errno < 0) {
			util.toast(data.message.message, '', 'error');
		} else {
			util.toast(data.message.message, data.redirect, 'error');
		}
	});
});
</script>
{elseif $op == 'mine'}
<div class="mui-content pay-select-coupon">
	<div id="voucher" class="mui-control-content mui-active">
		{if !empty($coupon_records)}
		{loop $coupon_records $row}
		<div class="mui-input-row">
			{if COUPON_TYPE == WECHAT_COUPON}
			<a href="javascript:;" class="js-coupon-info" data-ajax={$row['extra_ajax']} data-id="{$row['id']}" data-code="{$row['code']}">
			{else}
			<a href="{php echo $this->createMobileurl('activity', array('op' => 'use', 'activity_type' => 'coupon', 'recid' => $row['recid']))}">
			{/if}
			<label>
				<div class="coupon-panel">
					<div class="mui-row">
						<div class="mui-col-xs-4 mui-text-center">
							<div class="coupon-panel-left">
								{$row['icon']}
							</div>
						</div>
						<div class="mui-col-xs-8">
							<div class="store-title mui-ellipsis mui-mb10">{$row['title']}</div>
							<div class="date">{$row['extra_date_info']}</div>
							<span class="use-token" data-id="{$row['id']}">
								<span class="mui-block icon-use-token">⇌</span>
								<span class="mui-block">使用</span>
							</span>
						</div>
					</div>
				</div>
			</label>
			</a>
			<ol class="coupon-rules" style="display:none;">
				{$row['description']}
			</ol>
			<div class="scan-rules js-scan-rules">{$type_names[$row['type']][0]}使用规则<span class="fa fa-angle-up"></span></div>
		</div>
		{/loop}
		{else}
		<div class="mui-input-row">
			<div class="mui-input-row mui-text-center">
				<div>暂无卡券
					{if $exchange_enable['exchange_enable'] == 1}
					,<a href="{php echo $this->createMobileurl('activity')}">点击兑换</a>
					{/if}
				</div>
			</div>
		</div>
		{/if}
	</div>
</div>
<script> 
{if COUPON_TYPE == WECHAT_COUPON}
$(document).on('click', '.js-coupon-info', function() {
	id = $(this).data('id');
	code = $(this).data('code');
	href = $(this).data('ajax');
	if (!code) {
		$.post(href, {'id' : id}, function(data){
			var data = $.parseJSON(data);
			if(data.message.errno < 0) {
				util.toast(data.message.error, '', 'error');
			} else {
				wx.ready(function(){
					wx.addCard({
						cardList:[
							{
								cardId : data.message.message.card_id,
								cardExt : data.message.message.card_ext
							}
						],
						success: function (res) {
						location.href = data.redirect;
						}
					});
				});
			}
			return false;
		});
	} else {
		$.post(href, {'id' : id, 'code' : code}, function(data) {
		var data = $.parseJSON(data);
		if(data.message.errno < 0) {
			u.message(data.message.error, '', 'error');
		} else {
			wx.ready(function(){
				wx.openCard({
					cardList:[
						{
							cardId : data.message.message.card_id,
							code : data.message.message.code
						}
					],
				});
			});
		}
		return false;
	});
	}
})
{/if}
	$(document).on('click', '.js-use-coupon-now', function() {
		code = $(this).data('code');
		url = "{php echo $this->createMobileurl('activity', array('op' => 'use', 'activity_type' => 'coupon'))}";
		$.post(url, {code: code}, function(data) {
			data = $.parseJSON(data);
			$('.pay-select-coupon img').attr('src', data.thumb);
			$('.pay-select-coupon .js-use-code').html(data.code)
			qrcodeShow(data.code);
		});
	});
	var qrcodeShow = function(code) {
		require(['jquery.qrcode'], function(){
			url = "{php echo url('entry', array('i' => $_W['uniacid'],'do' => 'home', 'm' => 'paycenter'));}";
			$('.js-qrcode-show').show();
			$('.qrcode-block').html('').qrcode({
				render: 'canvas',
				width: 150,
				height: 150,
				text: url
			});
		})
	};
	$(document).on('click', '.js-scan-rules', function() {
		$(this).prev().toggle();
		$(this).find('span').toggleClass('fa-angle-up');
		$(this).find('span').toggleClass('fa-angle-down');
	});
</script>
{/if}
{if $op == 'use'}
	<div class="mui-content activity-wx-card" style="background-color:{$coupon_info['color']}">
		<div class="wx-card-panel">
			<img src="{php echo tomedia($coupon_info['logo_url'])}" alt="" class="mui-img-circle"/>
			<div class="mui-text-muted mui-text-center">{$_W['account']['name']}</div>
			<div class="title mui-text-center">{$coupon_info['title']}</div>
			<div class="btn-used mui-text-center">
				{if $starttime > strtotime(date('Ymd'))}
				<a href="javascript:;" class="mui-btn mui-btn-block mui-disabled" style="background-color:{$coupon_info['color']};color:#fff;border-color:{$coupon_info['color']}">未到可用时间</a>
				{else}
				<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'coupon', 'op' => 'qrcode', 'couponid' => $coupon_info['id'], 'recid' => $recid))}" class="mui-btn mui-btn-block" style="background-color:{$coupon_info['color']};color:#fff;border-color:{$coupon_info['color']}">立即使用</a>
				{/if}
			</div>
			<div class="sub-title mui-text-center">{$coupon_info['sub_title']}</div>
			<div class="date mui-text-center">{$coupon_info['exp_date']}</div>
			<ul class="mui-table-view mui-table-view-chevron">
				<li class="mui-table-view-cell">
					<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'coupon', 'op' => 'detail', 'couponid' => $coupon_info['id'], 'recid' => $recid))}" class="mui-navigate-right">{if $coupon_info['type'] == '1'}折扣{else}代金{/if}券详情</a>
				</li>
				<li class="mui-table-view-cell">
				<a href="{php echo url('entry', array('m' => 'paycenter', 'do' => 'consume', 'encrypt_code' => $coupon_record['code'], 'card_id' => $coupon_info['id'], 'openid' => $_W['openid'], 'source' => $coupon_info['source']))}" class="mui-navigate-right">立即使用</a>
				</li>
				<li class="mui-table-view-cell">
					<a href="{php echo url('mc/home')}" class="mui-navigate-right">
						个人中心
						<span class="mui-pull-right">点击进入</span>
					</a>
				</li>
			</ul>
		</div>
	</div>
{/if}
{if $op == 'detail'}
	<div class="mui-content">
		<div class="mui-pl10 mui-mt15">{if $coupon_info['type'] == '1'}折扣{else}代金{/if}券详情</div>
		<hr />
		<div class="mui-content-padded">
			<dl class="mui-dl-horizontal">
				<dt>优惠说明</dt>
				<dd>{$coupon_info['discount_info']}</dd>
				<dt>有效日期</dt>
				<dd>{$coupon_info['detail_date_info']}</dd>
				<dt>使用须知</dt>
				<dd>{$coupon_info['description']}</dd>
			</dl>
		</div>
	</div>
{/if}
{if $op == 'qrcode'}
	<div class="mui-content activity-wx-card-detail" style="background-color:{php echo $coupon_info['color']}">
		<div class="mui-card mui-text-center">
			<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'coupon', 'op' => 'use', 'couponid' => $coupon_info['couponid'], 'recid' => $recid))}" class="cancel">取消</a>
			<div class="mui-text-muted">{$_W['account']['name']}</div>
			<div class="title">{$coupon_info['title']}</div>
			<div class="hr"></div>
			<div class="img">
				<div class="qrcode-block" data-url="{php echo murl('entry', array('m' => 'paycenter', 'do' => 'cardconsume', 'op' => 'consume', 'code' => $coupon_info['code']), true, true);}" style="margin-top:20px"></div>
			</div>
			<div class="bar-code">{$coupon_info['code']}</div>
			<div class="mui-text-muted">请在付款时出示此券</div>
		</div>
	</div>
	<script>
	require(['jquery.qrcode'], function(){
		var url = $('.qrcode-block').data('url');
		$('.qrcode-block').html('').qrcode({
			render: 'canvas',
			width: 150,
			height: 150,
			text: url
		});
	})
	</script>
{/if}
{/if}

{if $activity_type == 'goods'}
{if $op == 'display'}
<div class="mui-content activity-exchange">
	<div class="mui-table nav">
		<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'coupon'))}" class="mui-table-cell">
			卡券
		</a>
		<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'goods'))}" class="mui-table-cell mui-active">
			实物
		</a>
	</div>
	<div class="entity">
		<div class="mui-row">
			{loop $lists $row}
			<div class="mui-col-xs-6">
				<div class="mui-card mui-border-radius0 mui-mt10">
					<div class="img-container"><img class="mui-card-img-top mui-border-radius0" src="{php echo tomedia($row['thumb'])}"></div>
					<div class="mui-card-block">
						<div class="mui-card-title mui-small">{$row['title']}</div>
						<div class="mui-row exchange-action">
							<div class="mui-col-xs-6 mui-text-info"><img src="resource/images/icon-signed.png" alt=""/><span>{$row['credit']}</span></div>
							<div class="mui-col-xs-6 mui-text-right"><a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'deliver', 'id' => $row['id']))}" class="mui-badge mui-badge-blue">兑换 <span class="fa fa-angle-right"></span></a></div>
						</div>
					</div>
				</div>
			</div>
			{/loop}
		</div>
	</div>
</div>
{elseif $op == 'deliver'}
<div class="mui-content activity-entity-content">
	<div class="img-container">
		<img class="mui-card-img-top mui-border-radius0" src="{php echo tomedia($goods_info['thumb'])}"/>
		<div class="title">{$goods_info['title']}</div>
	</div>
	<div class="mui-row mui-bg-white mui-pa10">
		<div class="mui-col-xs-4">
			<span class="fa fa-database"></span>
			{$goods_info['credit']}
		</div>
		<div class="mui-col-xs-4 mui-text-muted">(剩余{$goods_info['reside']}件)</div>
		<div class="mui-col-xs-4 mui-text-center"><a href="javascript:;" class="mui-btn mui-btn-green mui-btn-outlined js-address-info">{$is_exchange['name']}</a></div>
	</div>
	<div class="mui-content-padded">
		<div class="mui-segmented-control mui-segmented-control-info">
			<a class="mui-control-item mui-active" href="#exchange-info">兑换说明</a>
			<a class="mui-control-item" href="#address-info">收货信息</a>
		</div>
	</div>
	<div id="exchange-info" class="mui-control-content mui-active">
		<div class="mui-bg-white mui-mt10 mui-pa10">
			<div class="mui-big mui-mt10 mui-mb10">兑换说明</div>
			<div class="mui-text-muted state">
				<div>{$goods_info['exp_date']}</div>
				<div>每人只可兑换{$goods_info['pretotal']}件此商品</div>
			</div>
			<div class="mui-big mui-mt10 mui-mb10">产品简介</div>
			<div class="mui-text-muted introduction">{$goods_info['description']}</div>
		</div>
	</div>
	<div id="address-info" class="mui-control-content">
		<div class="mui-bg-white mui-mt10 mui-pa10">
			<div class="mui-big mui-mt10 mui-mb10">收货信息</div>
			<div class="state">
				<label for="">收货人姓名:</label>
				{php echo tpl_app_fans_form('username', $address_data['username'], '收货人姓名');}
				<label for="">收货人电话:</label>
				{php echo tpl_app_fans_form('mobile', $address_data['mobile'], '收货人电话');}
				<label for="">收货人邮编:</label>
				{php echo tpl_app_fans_form('zipcode', $address_data['zipcode'], '收货人邮编');}
				<label>收货人地址:</label>
				{php echo tpl_app_form_field_district('address',array('province' => $address_data['province'],'city' => $address_data['city'],'district' => $address_data['district']));}
				{php echo tpl_app_fans_form('address[address]', $address_data['address'], '收货人地址');}
			</div>
			</div>
			<div class="mui-content-padded">
				{if $is_exchange['error'] == '1'}
				<button class="mui-btn mui-btn-success mui-btn-block js-exchange" type="button" data-id="{$goods_info['id']}" data-tid="{$tid}">提交</button>
				{elseif $is_exchange['error'] == '-1'}
				<button class="mui-btn mui-btn-block mui-btn-danger">{$is_exchange['name']}</button>
				{/if}
			</div>
		</div>
		
	</div>
</div>
<script type="text/javascript">
	$(document).on('click', '.js-address-info', function() {
		$('#exchange-info').removeClass('mui-active');
		$('#address-info').addClass('mui-active');
		$('a[href="#exchange-info"]').removeClass('mui-active');
		$('a[href="#address-info"]').addClass('mui-active');
	});
	$(document).on('click', '.js-exchange', function() {
		$(this).addClass('mui-disabled');
		username = $('input[name="username"]').val();
		mobile = $('input[name="mobile"]').val();
		zipcode = $('input[name="zipcode"]').val();
		address_province = $('input[name="address[province]"]').val();
		address_city = $('input[name="address[city]"]').val();
		address_district = $('input[name="address[district]"]').val();
		address_addr = $('input[name="address[address]"]').val();
		type = "{$type}";
		id = $(this).data('id');
		tid = $(this).data('tid');
		if (!(username && mobile && zipcode && address_province && address_city && address_district && address_addr)) {
			util.toast('请填写收货人信息', '', 'error');
			return;
		}
		if (type == 'edit') {
			ajax_url = "{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'deliver'))}";
		} else {
			ajax_url = "{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'post'))}";
		}
		$.post(ajax_url, {'username' : username, 'mobile' : mobile, 'zipcode' : zipcode, 'address_province' : address_province, 'address_city' : address_city, 'address_district' : address_district, 'address_addr' : address_addr, 'id' : id, 'tid' : tid}, function(data) {
			data = $.parseJSON(data);
			if (data.message.errno < 0) {
				util.toast(data.message.message, '', 'error');
			} else {
				util.toast(data.message.message, data.redirect, 'success');
			}
		});
	});
</script>
{elseif $op == 'mine'} 
<div class="mui-content activity-exchange">
	<div class="entity">
		<div class="mui-row">
			{loop $lists $row}
			{if ($row['status'] == '' || $row['status'] == 0)}
			<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'deliver', 'id' => $row['gid'], 'type' => 'edit', 'tid' => $row['tid']))}">
			{/if}
			<div class="mui-col-xs-6">
				<div class="mui-card mui-border-radius0 mui-mt10">
					<div class="img-container"><img class="mui-card-img-top mui-border-radius0" src="{php echo tomedia($row['thumb'])}"></div>
					<div class="mui-card-block">
						<div class="mui-card-title mui-small">{$row['title']}</div>
						<div class="mui-row exchange-action">
							<div class="mui-col-xs-12 mui-text-right">
							{if $row['status'] == '1'}
							<a href="javascript:;" class="mui-badge mui-badge-blue js-shipping-confirm" data-tid="{$row['tid']}">确认收货<span class="fa fa-angle-right"></span>
							{elseif ($row['status'] == '' || $row['status'] == 0)}
							<a href="{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'deliver', 'id' => $row['gid'], 'type' => 'edit', 'tid' => $row['tid']))}" class="mui-badge mui-badge-blue">待发货<span class="fa fa-angle-right"></span>
							{elseif $row['status'] == '2'}
							<a href="javascript:;" class="mui-badge mui-badge-disabled">已完成<span class="fa fa-angle-right"></span>
							{/if}
							</a>
							</div>
						</div>
					</div>
				</div>
			</div>
			{if ($row['status'] == '' || $row['status'] == 0)}
			</a>
			{/if}
			{/loop}
		</div>
	</div>
</div>
<script type="text/javascript">
	$(document).on('click', '.js-shipping-confirm', function() {
		tid = $(this).data('tid');
		$.post("{php echo $this->createMobileurl('activity', array('activity_type' => 'goods', 'op' => 'confirm'))}", {'tid' : tid}, function(data) {
			data = $.parseJSON(data);
			if (data.message.errno > 0) {
				util.toast(data.message.message, data.redirect, 'success');
			} else {
				util.toast(data.message.message, '', 'error');
			}
		})
	})
</script>
{/if}

{/if}
{template 'common/footer'}