orderv2 add fines about

This commit is contained in:
qianhy
2023-05-25 09:46:04 +08:00
parent 154972341a
commit 677d22900a
2 changed files with 240 additions and 12 deletions
+53 -2
View File
@@ -1876,14 +1876,45 @@ class Orders extends HD_Controller
}else{
$money_json[$val['key']] = 0;
}
# form改用vue后
if (in_array('checked', array_keys($val))){
$val['price'] = $val['money'];
$checked = $val['checked'] == 'true' ? true : false;#var_dump($checked);
unset($val['checked']);
unset($val['title']);
unset($val['money']);
$checked && $new_services[] = $val;
$money_json[$val['key']] = $checked ? floatval($val['price']) : 0;
}
}
}#var_dump($new_services);exit();
# form改用vue后 增加精品选装
$price_fine_select = 0;
$fines = [];
if(is_array($info['fines'])){
$fines = $info['fines'] ? $info['fines'] : [];
foreach ($fines as $key => $val){
if ($val['id'] == -1 && intval($val['price']) == 0){
unset($fines[$key]);
continue;
}
if ($val['txt'] == '' && intval($val['price']) == 0){
unset($fines[$key]);
continue;
}
$price_fine_select += intval($val['price']);
}
}
$money_json['price_fine_select'] = $price_fine_select;
$srv_ids = is_array($new_services) ? array_column($new_services,'id') : [];
$updata = [
'if_insure' => in_array(1,$srv_ids) ? 1 : 0,
'if_num' => in_array(2,$srv_ids) ? 1 : 0,
'srv_ids' => json_encode($new_services,JSON_UNESCAPED_UNICODE),
'money_json' => json_encode($money_json,JSON_UNESCAPED_UNICODE)
'money_json' => json_encode($money_json,JSON_UNESCAPED_UNICODE),
'fines' => json_encode($fines,JSON_UNESCAPED_UNICODE),
];
$res = $this->receiver_orders_v2_model->update($updata,['id'=>$id]);
if($res){
@@ -1913,10 +1944,30 @@ class Orders extends HD_Controller
$srv_ids = is_array($services) ? array_column($services,'id') : [];
foreach($lists as $key=>$val){
$lists[$key]['money'] = $money_json[$val['key']] ? $money_json[$val['key']] : 0;
$lists[$key]['checked'] = in_array($val['id'],$srv_ids) ? 'checked' : '';
//$lists[$key]['checked'] = in_array($val['id'],$srv_ids) ? 'checked' : '';
$lists[$key]['checked'] = in_array($val['id'],$srv_ids) ? true : false; // form 改 vue
}
$this->data['srv_info'] = $lists;
$this->data['id'] = $id;
// 0522增加精品选装(biz_type==1后台手工添加的均为自定义,biz_type!=1只能修改price)
/*$this->load->model('receiver/receiver_fine_model');
$where = [
'status' => 1
];
$where['biz_id'] = $row['biz_id'];
$fines_list = $this->receiver_fine_model->select($where,'id desc',0,0,'id,title,price');
$this->data['fines_list'] = $fines_list;*/
$biz = $this->biz_model->get(['id' => $row['biz_id']], 'id,city_id,type');
$this->data['biz_type'] = $biz['type'];
$this->data['fines'] = $row['fines'] ? json_decode($row['fines'], true) : [];
if (!$this->data['fines']){
if ($biz['type'] != 1){
$this->data['fines'] = [array("id"=>"-1", "txt"=>"服务费", "price"=>"0")];
}
}
$this->data['price_fine_select'] = sprintf("%.2f", $money_json['price_fine_select']);
return $this->show_view('receiver/orderv2/edit_srv');
}
+187 -10
View File
@@ -1,22 +1,199 @@
<form class="am-form am-form-horizontal" action="/receiver/orderv2/orders/edit_srv" data-auto="true" method="post"
<!--<form class="am-form am-form-horizontal" action="/receiver/orderv2/orders/edit_srv" data-auto="true" method="post"
style="width: 90%;padding-top: 10px">
<? foreach ($srv_info as $key=>$value) {?>
<?/* foreach ($srv_info as $key=>$value) {*/?>
<div class="am-form-group">
<input type="hidden" value="<?=$value['id']?>" name="money[<?=$key?>][id]"/>
<input type="hidden" value="<?=$value['key']?>" name="money[<?=$key?>][key]"/>
<input type="hidden" value="<?/*=$value['id']*/?>" name="money[<?/*=$key*/?>][id]"/>
<input type="hidden" value="<?/*=$value['key']*/?>" name="money[<?/*=$key*/?>][key]"/>
<label class="am-para-label">
<input type="checkbox" name="money[<?=$key?>][checkbox]" <?=$value['checked']?> value="1">
<?=$value['title']?>
<input type="checkbox" name="money[<?/*=$key*/?>][checkbox]" <?/*=$value['checked']*/?> value="1">
<?/*=$value['title']*/?>
</label>
<div class="am-para-input">
<input type="text" value="<?=$value['money']?>" name="money[<?=$key?>][price]" <?=$value['key']=='price_insure' ? 'readonly' : ''?>/>
<input type="text" value="<?/*=$value['money']*/?>" name="money[<?/*=$key*/?>][price]" <?/*=$value['key']=='price_insure' ? 'readonly' : ''*/?>/>
</div>
</div>
<?}?>
<?/*}*/?>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="id" value="<?/*=$id*/?>">
<button class="am-btn am-btn-secondary" type="submit">确定</button>
</div>
</div>
</form>
</form>-->
<div id="vue-edit-srv" class="am-form am-form-horizontal" style="width: 98%;padding-top: 10px">
<template v-for="(item,index) in srv_info">
<div class="am-form-group">
<input type="hidden" :id="'id_'+index" name="'id_'+index" v-model="item.id" />
<input type="hidden" :id="'key_'+index" name="'key_'+index" v-model="item.key" />
<label class="am-para-label">
<input type="checkbox" v-model="item.checked" />
{{item.title}}
</label>
<div class="am-para-input">
<input type="text" :id="'money_'+index" name="'money_'+index" v-model="item.money" :readonly="item.key=='price_insure'" />
</div>
</div>
</template>
<div class="am-form-group">
<label class="am-para-label">
精品选装:
</label>
<div class="am-para-input">
{{price_fine_select}}
</div>
<div id="options-modal" class="am-para-input">
<table class="table table-hover table-middle" style="table-layout:fixed">
<colgroup>
<col width="60%">
<col width="20%">
<col width="">
</colgroup>
<thead>
<tr>
<th class="text-center">项目</th>
<th class="text-center">金额(非服务费时,0为赠送)</th>
<th class="text-right">
<a v-if="biz_type==1" href="javascript:" style="margin-top: 2px;" class="btn btn-primary btn-sm" @click='addOptions()'>添加</a>
</th>
</tr>
</thead>
<tbody>
<template v-for="(item,index) in fines">
<tr>
<td class="text-center">
<input v-if="biz_type==1" :id="'txt_'+index" @blur="editTxt(index)" class="form-control" v-model="item.txt" placeholder="请输入项目">
<label v-else v-text="item.txt"></label>
</td>
<td class="text-center">
<input :id="'price_'+index" @blur="editPrice(index)" class="form-control"
v-model="item.price" type="number" placeholder="请输入金额" min="0" oninput="if(value<0)value=0;">
</td>
<td class="text-right">
<a v-if="biz_type==1" href="javascript:void(0);" style="margin-top:2px;"
class="btn btn-danger btn-sm" @click='delOptions(index)'>删除</a>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 2rem">
<div class="am-para-input">
<input type="hidden" id="o_id" name="o_id" v-model="o_id">
<button class="am-btn am-btn-secondary" type="submit" @click="saveEdit();">确定</button>
</div>
</div>
</div>
<script>
var vue_obj;
$(document).ready(function () {
vue_obj = new Vue({
el: '#vue-edit-srv',
data: {
srv_info: [],
fines: [],
o_id: 0,
biz_type: '',
price_fine_select: '',
},
mounted: function () {
var vm = this;
vm.srv_info = <?=json_encode($srv_info, JSON_UNESCAPED_UNICODE)?>;
vm.fines = <?=json_encode($fines, JSON_UNESCAPED_UNICODE)?>;
vm.o_id = <?=$id?>;
vm.biz_type = <?=$biz_type?>;
vm.price_fine_select = <?=$price_fine_select?>;
// alert(vm.o_id);
},
computed: {},
created: function () {
// var vm = this;
// alert(vm.o_id); // 在data初始化赋值才可
},
methods: {
saveEdit: function () {
var vm = this;
var post_data = {};
post_data['id'] = vm.o_id;
post_data['money'] = vm.srv_info;
post_data['fines'] = vm.fines;
$.ajax({
url: '/receiver/orderv2/orders/edit_srv',
type: 'post',
dataType: 'json',
data: post_data,
beforeSend: function () {
layer.load(1, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function (data) {
loading = false;
if (data['code']) {
layer.msg(data.msg, {
icon: 1,
time: 2000
}, function () {
if (data.url != '') {
// $.form.href(data.url);
window.location.href = data.url;
} else {
// $.form.reload();
window.location.reload();
}
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
complete: function () {
loading = false;
layer.closeAll('loading');
},
});
},
addOptions: function () {
var vm = this;
vm.fines.push({txt: '', price: '0'});
// vm.fines.push({id: 0, txt: '', price: '0'});
},
delOptions: function (index) {
var vm = this;
vm.fines.splice(index,1);
},
editTxt: function (index) {
var name = $("#txt_" + index).val();
if (name == '') {
layer.msg("项目不能为空!", {icon: 2});
return false;
}
},
editPrice: function (index) {
var vm = this;
var price = 0;
console.dir(vm.fines);
for (item in vm.fines){
console.dir(item);
console.dir(vm.fines[item]);
console.dir(vm.fines[item]['price']);
console.dir(parseInt(vm.fines[item]['price']));
if (vm.fines[item]['price'].length > 0){
price += parseInt(vm.fines[item]['price']);
}
}
console.dir(price);
vm.price_fine_select = price;
return true;
},
}
});
});
</script>