Authored by cailing

取消订单优化样式

... ... @@ -10191,6 +10191,7 @@ define("js/home/order-block", ["jquery","handlebars","source-map"], function(req
*/
var $ = require("jquery");
var Handlebars = require("handlebars");
var dialog = require("js/common/dialog");
... ... @@ -10203,9 +10204,13 @@ var html = $tpl.html();
var active;
var dialogMessage = '<p class="message-title"><i class="order-icon {{messageIcon}}"></i>{{messageTitle}}</p><p class="message-summary">{{messageSummary}}</p>';
var $dialogEdit = $('#edit-dialog-tpl');
var $addressManage, $province, $city, $county, $selectList, $name, $phone, $address, $telCode, $tel;
function cancelFactory(id) {
var options = {
mask: false,
mask: true,
btns: [
{
id: 'cancel-sure',
... ... @@ -10214,23 +10219,31 @@ function cancelFactory(id) {
cb: function() {
var $checked = $('.cancel-dialog :checked');
var $tip = $('.cancel-dialog .cancel-tip');
var text = '';
if ($checked.val() === '10') {
text = $checked.parent().find('#reason_other').val();
} else {
text = $checked.siblings('label').text();
}
if ($checked.length === 0) {
$tip.html('请选择要取消订单的原因');
return;
}
$.ajax({
type: 'POST',
url: '/home/orders/cancelorder',
data: {
orderCode: id,
reason: $checked.val()
reasonId: $checked.val(),
reason: text
}
}).then(function(data) {
if (data.code === 200) {
active.close();
history.go(0);
active = showMessgaeDialog('icon-success', '订单修改', '您已成功取消了该订单', function() {
location.reload(true);
});
active.show();
} else {
$tip.html(data.message);
}
... ... @@ -10239,7 +10252,7 @@ function cancelFactory(id) {
},
{
id: 'cancel-no',
name: '取消',
name: '暂不取消',
btnClass: ['cancel-no'],
cb: function() {
active.close();
... ... @@ -10253,7 +10266,61 @@ function cancelFactory(id) {
return new Dialog(options);
}
function showMessgaeDialog(message_icon, message_title, message_summary, cb) {
var template = Handlebars.compile(dialogMessage);
var html = template({messageIcon: message_icon, messageTitle: message_title, messageSummary: message_summary});
var options = {
mask: true,
btns: [
{
id: 'message-sure',
name: '确定',
btnClass: ['message-sure'],
cb: function() {
active.close();
cb && cb();
}
}
],
content: html,
className: 'message-dialog',
};
return new Dialog(options);
}
// 编辑订单
function editOrder(id) {
var options = {
mask: true,
btns: [
{
id: 'edit-sure',
name: '确定',
btnClass: ['edit-sure'],
cb: function() {
saveAddress(id);
}
},
{
id: 'edit-no',
name: '取消',
btnClass: ['edit-no'],
cb: function() {
active.close();
}
}
],
content: $dialogEdit.html(),
className: 'edit-order-dialog'
};
return new Dialog(options);
}
$tpl.remove();
$dialogEdit.remove();
//查看物流
$('.check-logistics').click(function() {
... ... @@ -10293,7 +10360,270 @@ $('.me-orders, .order-detail').on('click', '.cancel-order', function(e) {
content: '您确定要确认收货吗?'
});
active.show();
}).on('click', '.edit-order', function() {
active = editOrder($(this).closest('.order, .order-detail').data('id'))
active.show();
newAddress(0);
});
// 地址操作
function newAddress(id) {
var code, codeId;
var pId = id || 0; //如果没有传id则获取所有省列表
var addressCodeReg = /[0-9]{2}/gi;
$addressManage = $('.edit-order-dialog');
$province = $addressManage.find('select[name="province"]');
$city = $addressManage.find('select[name="city"]');
$county = $addressManage.find('select[name="county"]');
$selectList = $addressManage.find('select[name="province"], select[name="city"]');
$name = $addressManage.find('.inp[name="name"]');
$phone = $addressManage.find('.inp[name="phone"]');
$address = $addressManage.find('.inp[name="address"]');
$telCode = $addressManage.find('.inp[name="tel-code"]');
$tel = $addressManage.find('.inp[name="tel"]');
code = $province.data("areacode") + '';
codeId = !!code && code.match(addressCodeReg);
//获取省
getAddress({
id: pId,
type: 'getProvince',
selectId: codeId[0]
}, function() {
var provinceId = $province.val();
if (provinceId !== '0') {
//如果获取的省有默认选中项则获取市
getAddress({
id: provinceId,
type: 'getCity',
selectId: '' + codeId[0] + codeId[1]
}, function() {
var cityId = $city.val();
//如果获取的市有默认选中项则获取县
if (cityId !== '0') {
getAddress({
id: cityId,
type: 'getCounty',
selectId: code
});
}
});
} else {
$addressManage.find('select[name="city"]').html('<option value="0">请选择城市</option>');
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
}
});
// 发生change事件时获取下一级地址
$selectList.change(function() {
var $this = $(this);
if ($this.attr('name') === 'province') {
if ($this.val() === '0') {
$addressManage.find('select[name="city"]').html('<option value="0">请选择城市</option>');
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
} else {
getAddress({
id: $this.val(),
type: 'getCity'
}, function() {
isProvinceChecked = true;
});
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
}
}
if ($this.attr('name') === 'city' && isProvinceChecked) {
if ($this.val() === '0') {
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
} else {
getAddress({
id: $this.val(),
type: 'getCounty'
});
}
}
});
}
/**
* @description: 改函数会返回地址信息
* d {Object} type: 'getProvince'获取省 type: 'getCity'获取城市 type: 'getCounty'获取县
* id: 0 && type: 'getProvince' 获取所有省,默认没有选中项
* id !== 0 && type: 'getProvince' 获取所有省,默认选中用户所在的省
*/
function getAddress(d, callback) {
var $obj;
var selectId = d.selectId;
if (d.type === 'getProvince') {
//url = 'getProvince';
$obj = $province;
} else if (d.type === 'getCity') {
//url = 'getCity';
$obj = $city;
} else if (d.type === 'getCounty') {
//url = 'getCounty';
$obj = $county;
}
$.ajax({
type: 'GET',
url: '/cart/index/getAreaList',
dataType: 'json',
data: {
id: d.id * 1
}
}).then(function(d) {
structureOption($obj, d.data, selectId);
if (typeof callback === 'function') {
callback();
}
});
}
// 构建select下拉选项
function structureOption($obj, data, selectId) {
var i,
optionHtml = '',
defaultOption,
isStar = '';
for (i = 0; i < data.length; i++) {
if (data[i].is_support_express === 'Y') {
isStar = '*';
} else {
isStar = '';
}
if (data[i].id === selectId) {
optionHtml += '<option selected value="' + data[i].id + '">' + isStar + data[i].caption + '</option>';
} else {
optionHtml += '<option value="' + data[i].id + '">' + isStar + data[i].caption + '</option>';
}
}
if ($obj.attr('name') === 'province') {
defaultOption = '<option value="0">请选择省份</option>';
} else if ($obj.attr('name') === 'city') {
defaultOption = '<option value="0">请选择城市</option>';
} else if ($obj.attr('name') === 'county') {
defaultOption = '<option value="0">请选择区县</option>';
}
$obj.html(defaultOption + optionHtml);
}
// 保存地址
function saveAddress(id) {
var name = $name.val(),
province = $province.val(),
city = $city.val(),
county = $county.val(),
address = $address.val(),
phone = $phone.val(),
telCode = $telCode.val(),
tel = $tel.val();
var $err_name = $name.siblings('.error'),
$err_province = $province.siblings('.error'),
$err_address = $address.siblings('.error'),
$err_phone = $phone.siblings('.error'),
$err_tel = $tel.siblings('.error');
var postData = {
orderCode: id,
userName: name,
areaCode: county,
address: address,
mobile: phone,
phoneCode: telCode,
phoneNum: tel
};
var nameReg = /^[\u4e00-\u9fa5]{2,5}$/;
var addressReg = /^[\s\S]{2,100}$/;
var phoneReg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
var telCodeReg = /^[0-9]{3,5}$/;
var telReg = /^[0-9]{5,10}$/;
if (!nameReg.test(name)) {
$err_name.find('b').html('真实姓名至少2个中文,最多5个中文');
$err_name.show();
return;
} else {
$err_name.hide();
}
if (province === '0' || city === '0' || county === '0') {
$err_province.show();
return;
} else {
$err_province.hide();
}
if (!addressReg.test(address)) {
$err_address.find('b').html('你输入的地址格式不正确');
$err_address.show();
return;
} else {
$err_address.hide();
}
if (!phoneReg.test(phone)) {
$err_phone.find('b').html('你输入的联系电话格式不正确');
$err_phone.show();
return;
} else {
$err_phone.hide();
}
if ((!!telCode && !telCodeReg.test(telCode)) || (!!tel && !telReg.test(tel)) ||
(telCodeReg.test(telCode) && !telReg.test(tel)) ||
(!telCodeReg.test(telCode) && telReg.test(tel))) {
$err_tel.find('b').html('你输入的电话格式不正确');
$err_tel.show();
return;
} else {
$err_tel.hide();
}
$.ajax({
type: 'post',
url: '/home/orders/modifyAddress',
data: postData
}).then(function(d) {
if (d.code === 200) {
active.close();
active = showMessgaeDialog('icon-waiting', '订单修改', '您的订单正在尝试修改,请耐心等待。稍后可在订单详情页查看修改情况!', function() {
location.reload(true);
});
active.show();
} else {
new dialog.Alert(d.message).show();
}
})
}
});
define("js/home/orders", ["jquery","handlebars","source-map"], function(require, exports, module){
/**
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.