add_service.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <tr>
  2. <td class="layui-td-gray" colspan="6" style="text-align:left; color:#666"><strong>服务信息</strong> <span class="layui-btn layui-btn-sm" type="button" id="serviceAdd">+ 添加服务</span></td>
  3. </tr>
  4. <tr>
  5. <td colspan="6">
  6. <table id="serviceTable" class="layui-table layui-table-min" style="margin:0">
  7. <tr>
  8. <th width="200">服务名称</th>
  9. <th width="200">服务周期</th>
  10. <th width="100">服务单价</th>
  11. <th width="100">服务次数</th>
  12. <th width="100">小计</th>
  13. <th>备注信息</th>
  14. <th width="60">操作</th>
  15. </tr>
  16. <tr class="service-tr">
  17. {eq name="is_service" value="1"}
  18. <td><input type="text" name="service_title[]" value="" class="layui-input service-picker" readonly lay-verify="required" lay-reqText="请完善服务名称"><input type="hidden" name="service_id[]" value="0"></td>
  19. {else/}
  20. <td><input type="text" name="service_title[]" value="" class="layui-input" lay-verify="required" lay-reqText="请完善服务名称"><input type="hidden" name="service_id[]" value="0"></td>
  21. {/eq}
  22. <td><input type="text" name="service_date[]" value="" class="layui-input layui-input-readonly tool-time" data-range="到" lay-verify="required" lay-reqText="请选择服务周期" readonly></td>
  23. <td><input type="text" name="service_price[]" value="0.00" class="layui-input input-num" lay-verify="required|number" lay-reqText="请输入服务单价"></td>
  24. <td><input type="text" name="service_num[]" value="1" class="layui-input input-num" lay-verify="required|number" lay-reqText="请输入服务次数"></td>
  25. <td><input type="text" name="service_subtotal[]" value="0.00" class="layui-input layui-input-readonly" readonly></td>
  26. <td><input type="text" name="service_remark[]" value="" class="layui-input"></td>
  27. <td><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></td>
  28. </tr>
  29. </table>
  30. </td>
  31. </tr>
  32. <script>
  33. const is_service={$is_service};
  34. function product_fun(layui){
  35. let form = layui.form,oaPicker = layui.oaPicker;
  36. //选择物品弹窗
  37. $('body').on('click','.service-picker',function () {
  38. let that = $(this),ids = [],titles=[],price=[],map = {},types = 'services',type = 1;
  39. let callback = function(data){
  40. for ( var i = 0; i <data.length; i++){
  41. ids.push(data[i].id);
  42. titles.push(data[i].title);
  43. price.push(data[i].price);
  44. }
  45. that.val(titles.join(','));
  46. that.next().val(ids.join(','));
  47. that.parents('.service-tr').find('input').eq(3).val(price.join(','));
  48. that.parents('.service-tr').find('input').eq(5).val(price.join(','));
  49. count_cost();
  50. }
  51. oaPicker.picker(types,type,callback,map);
  52. });
  53. //添加服务信息表格
  54. $('#serviceAdd').on('click',function(){
  55. var html = '',service_title=' class="layui-input"';
  56. if(is_service==1){
  57. service_title=' class="layui-input service-picker" readonly';
  58. }
  59. html += '<tr class="service-tr">\
  60. <td><input type="text" name="service_title[]" value="" '+service_title+' lay-verify="required" lay-reqText="请完善服务名称"><input type="hidden" name="service_id[]" value="0"></td>\
  61. <td><input type="text" name="service_date[]" value="" class="layui-input layui-input-readonly tool-time" data-range="到" lay-verify="required" lay-reqText="请选择服务周期" readonly></td>\
  62. <td><input type="text" name="service_price[]" value="0.00" class="layui-input input-num" lay-verify="required|number" lay-reqText="请输入服务单价"></td>\
  63. <td><input type="text" name="service_num[]" value="1" class="layui-input input-num" lay-verify="required|number" lay-reqText="请输入服务次数"></td>\
  64. <td><input type="text" name="service_subtotal[]" value="0.00" class="layui-input layui-input-readonly" readonly></td>\
  65. <td><input type="text" name="service_remark[]" value="" class="layui-input"></td>\
  66. <td><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></td>\
  67. </tr>';
  68. $('#serviceTable').append(html).find('.tr-none').remove();
  69. form.render();
  70. });
  71. $('#serviceTable').on('click', '[lay-event="del"]', function() {
  72. if($('.service-tr').length<2){
  73. layer.msg('至少保留一个服务选项');
  74. return false;
  75. }
  76. $(this).parents('.service-tr').remove();
  77. count_cost();
  78. });
  79. //计算价格
  80. $('#serviceTable').on('input', '.input-num', function() {
  81. var inputs = $(this).parents('.service-tr').find("input");
  82. var service_price = inputs.eq(3).val();
  83. var service_num = inputs.eq(4).val();
  84. var service_amount = (service_price*service_num).toFixed(2);
  85. if(isNaN(service_amount)){
  86. service_amount = 0.00;
  87. }
  88. inputs.eq(5).val(service_amount);
  89. count_cost();
  90. });
  91. //计算总价
  92. function count_cost(){
  93. var service_subtotal = $('#serviceTable').find('[name="service_subtotal[]"]');
  94. var total = 0;
  95. for (var m = 0; m < service_subtotal.length; m++) {
  96. total+=$(service_subtotal[m]).val()*1000;
  97. }
  98. if(isNaN(total)){
  99. total = 0;
  100. }
  101. $('[name="cost"]').val((total/1000).toFixed(2));
  102. }
  103. }
  104. </script>