fee.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. {extend name="common/common2" /}
  2. {block name="main"}
  3. <style>
  4. a.list-group-item.active, a.list-group-item.active:hover, a.list-group-item.active:focus{
  5. background-color: #148d8f !important;
  6. border-color: #148d8f !important;
  7. }
  8. </style>
  9. <div id="feeapp">
  10. <div class="panel panel-default">
  11. <div class="panel-heading">
  12. 收费科目
  13. <div class="btn-group pull-right">
  14. <a href="javascript:history.go(-1);">返回</a>
  15. </div>
  16. </div>
  17. <div class="panel-body">
  18. <div class="row">
  19. <div class="col-xs-12" style="padding-bottom: 20px;">
  20. 业主:{$owner['name']} &nbsp;&nbsp;
  21. 联系电话:{$owner['phone']} &nbsp;&nbsp;
  22. 类型:{if $owner['type'] == 1}住户{else}租户{/if}
  23. </div>
  24. <div class="col-xs-3" style="min-height: 200px">
  25. <div class="list-group">
  26. <a v-for="(item,index) in lists" :key="index" href="javascript:;" @click="selectData(item)" class="list-group-item" :class="curData&&curData.type == item.type&&curData.id == item.id?'active':''">
  27. <span v-if="item.cate == 1">[住房] </span>
  28. <span v-if="item.cate == 2">[商铺] </span>
  29. <span v-if="item.cate == 3">[营业房] </span>
  30. <span v-if="item.cate == 4">[储藏室] </span>
  31. <span v-if="item.cate == 5">[停车位] </span>
  32. {{item.title}}
  33. <span v-if="item.c_type > 0">({{item.c_type_name}})</span>
  34. </a>
  35. </div>
  36. </div>
  37. <div class="col-xs-3" style="min-height: 200px">
  38. <div class="list-group" v-if="curData && curData.fee.length > 0">
  39. <a v-for="(item,index) in curData.fee" :key="index" href="javascript:;" @click="selectFee(item)" class="list-group-item" :class="curFee&&curFee.id == item.id?'active':''">
  40. [{{item.parent_title}}] {{item.title}}
  41. </a>
  42. </div>
  43. </div>
  44. <div class="col-xs-6" style="min-height: 200px">
  45. <!-- <p><strong>收费详情</strong></p>-->
  46. <table class="table" v-if="curData && curFee">
  47. <tr v-if="curFee.area == 1">
  48. <td style="width: 100px;">产权面积</td>
  49. <td>{{curData.area}}</td>
  50. </tr>
  51. <tr>
  52. <td>基本单价</td>
  53. <td>{{curFee.price}}元</td>
  54. </tr>
  55. <tr v-if="curFee.area != 0 || curFee.cycle != 0">
  56. <td>计算公式</td>
  57. <td v-if="curFee.area == 1">基本单价*产权面积</td>
  58. <td v-if="curFee.area == 0">基本单价</td>
  59. </tr>
  60. <tr v-if="curFee.cycle == 1 && curFee.end">
  61. <td>最近缴费日期</td>
  62. <td>
  63. {{curFee.start}} ~ {{curFee.start}}
  64. </td>
  65. </tr>
  66. <tr v-if="curFee.cycle == 1 && curFee.end">
  67. <td>历史收费金额</td>
  68. <td>
  69. {{curFee.tmoney}}
  70. </td>
  71. </tr>
  72. <tr v-if="curFee.cycle == 1">
  73. <td>起止日期</td>
  74. <td>
  75. <input type="date" v-model="start" max="2100-01-01"> ~ <input type="date" v-model="end" max="2100-01-01">
  76. <!--<el-date-picker
  77. v-model="date"
  78. type="daterange"
  79. size="small"
  80. value-format="yyyy-MM-dd"
  81. @change="changeDate"
  82. range-separator="至"
  83. start-placeholder="开始日期"
  84. end-placeholder="结束日期">
  85. </el-date-picker>-->
  86. </td>
  87. </tr>
  88. <tr>
  89. <td>总金额</td>
  90. <td>{{totalPrice}}元</td>
  91. </tr>
  92. <tr>
  93. <td>备注</td>
  94. <td>
  95. <el-input
  96. type="textarea"
  97. :rows="2"
  98. placeholder="请输入"
  99. v-model="remark">
  100. </el-input>
  101. </td>
  102. </tr>
  103. <tr>
  104. <td></td>
  105. <td>
  106. <button type="button" @click="saveBtn" class="btn btn-sm btn-primary">保存数据</button>
  107. </td>
  108. </tr>
  109. </table>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. <div class="panel panel-default">
  115. <div class="panel-heading">收费明细</div>
  116. <div class="panel-body">
  117. <div class="row">
  118. <div class="col-xs-12">
  119. <table class="table">
  120. <tr>
  121. <th>资源名称</th>
  122. <th>科目名称</th>
  123. <th>应收金额</th>
  124. <th>起止日期</th>
  125. <th>备注</th>
  126. <th>操作</th>
  127. </tr>
  128. <tr v-for="(item,index) in selData" :key="index">
  129. <td>
  130. <span v-if="item.cate == 1">[住房] </span>
  131. <span v-if="item.cate == 2">[商铺] </span>
  132. <span v-if="item.cate == 3">[营业房] </span>
  133. <span v-if="item.cate == 4">[储藏室] </span>
  134. <span v-if="item.cate == 5">[停车位] </span>
  135. {{item.title}}
  136. </td>
  137. <td>[{{item.fee_parent_title}}] {{item.fee_title}}</td>
  138. <td>{{item.total_price}}</td>
  139. <td v-if="item.start">{{item.start}} ~ {{item.end}}</td>
  140. <td v-if="!item.start"></td>
  141. <td>{{item.remark}}</td>
  142. <td>
  143. <button type="button" @click="delSelectData(index)" class="btn btn-xs btn-danger">删除</button>
  144. </td>
  145. </tr>
  146. </table>
  147. <div>
  148. <form class="form-inline">
  149. <div class="form-group">
  150. <label>最晚缴费日期 <span class="text-danger">*</span></label>
  151. <el-date-picker
  152. v-model="lastDate"
  153. type="date"
  154. size="small"
  155. value-format="yyyy-MM-dd"
  156. placeholder="选择日期">
  157. </el-date-picker>
  158. </div>
  159. <button type="button" @click="submitOrder" class="btn btn-sm btn-primary">生成缴费单</button>
  160. </form>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. {/block}
  168. {block name="script"}
  169. <script>
  170. var lists = {:json_encode($lists)};
  171. var houseId = "{$houseId}";
  172. var vm = new Vue({
  173. el: '#feeapp',
  174. data: {
  175. lists: lists,
  176. curData: null,
  177. curFee: null,
  178. curRet: null,
  179. date: '',
  180. remark: '',
  181. totalPrice: 0,
  182. selData: [],
  183. lastDate: '',
  184. flag: false,
  185. houseId: houseId,
  186. start: '',
  187. end: '',
  188. },
  189. computed: {
  190. },
  191. watch: {
  192. start(val,oldVal){
  193. this.calculationPrice();
  194. },
  195. end(val, oldVal){
  196. this.calculationPrice();
  197. }
  198. },
  199. created: function () {
  200. this.initDate();
  201. },
  202. methods: {
  203. initDate(){
  204. var nowDate = new Date();
  205. var fullYear = nowDate.getFullYear();
  206. var month = nowDate.getMonth() + 1; // getMonth 方法返回 0-11,代表1-12月
  207. var endOfMonth = new Date(fullYear, month, 0).getDate(); // 获取本月最后一天
  208. var endDate = this.getFullDate(nowDate.setDate(endOfMonth));//当月最后一天
  209. var startDate = this.getFullDate(nowDate.setDate(1));//当月第一天
  210. this.date = [startDate,endDate];
  211. this.start = startDate;
  212. this.end = endDate;
  213. },
  214. calculationPrice(){ // 计算总金额
  215. this.date = [this.start,this.end];
  216. let price = Number(this.curFee.price);
  217. let tPrice = price;
  218. this.curFee.MONTHS = [];
  219. if(this.curFee.cycle == 1){ //按周期算
  220. tPrice = 0;
  221. if(this.date){
  222. let months = this.getMonthBetween(this.date[0],this.date[1]);
  223. console.log('months',months);
  224. if(months.length == 1){ //不跨月
  225. let day = this.getDaysBetween(this.date[0],this.date[1]);
  226. tPrice = Number(tPrice) + (Number(price)/months[0].days) * day;
  227. this.curFee.MONTHS.push({
  228. year: months[0].year,
  229. month: months[0].month,
  230. money: (Number(price)/months[0].days) * day
  231. });
  232. }else{
  233. for (let o in months){
  234. let start = this.date[0];
  235. let end = this.date[1];
  236. let pri = 0;
  237. if(start >= months[o].start){
  238. let sarr = start.split('-');
  239. let day = months[o].days - Number(sarr[2]) + 1;
  240. tPrice = Number(tPrice) + (Number(price)/months[o].days) * day;
  241. pri = (Number(price)/months[o].days) * day;
  242. }
  243. if(end <= months[o].end){
  244. let earr = end.split('-');
  245. let day = Number(earr[2]);
  246. tPrice = Number(tPrice) + (Number(price)/months[o].days) * day;
  247. pri = (Number(price)/months[o].days) * day;
  248. }
  249. if(start < months[o].start && end > months[o].end){
  250. tPrice = Number(tPrice) + Number(price);
  251. pri = Number(price);
  252. }
  253. this.curFee.MONTHS.push({
  254. year: months[o].year,
  255. month: months[o].month,
  256. money: pri.toFixed(2)
  257. });
  258. }
  259. }
  260. }else{
  261. tPrice = 0;
  262. }
  263. }
  264. if(this.curFee.area == 1){ //按面积算
  265. tPrice = Number(tPrice) * Number(this.curData.area);
  266. for(let o in this.curFee.MONTHS){
  267. this.curFee.MONTHS[o].money = (Number(this.curFee.MONTHS[o].money) * Number(this.curData.area)).toFixed(2);
  268. }
  269. }
  270. if(this.curFee.cycle == 0 && this.curFee.area == 0){
  271. tPrice = price;
  272. }
  273. this.totalPrice = Number(tPrice).toFixed(2);
  274. console.log('change',this.totalPrice,this.curFee);
  275. },
  276. selectData(item){
  277. this.curData = item;
  278. this.curFee = null;
  279. this.curRet = null;
  280. },
  281. selectFee(item){
  282. this.curFee = item;
  283. this.curRet = null;
  284. this.remark = '';
  285. if(item.cycle == 1){
  286. this.initDate();
  287. }else{
  288. this.date = '';
  289. }
  290. this.calculationPrice();
  291. },
  292. changeDate(){
  293. this.calculationPrice();
  294. },
  295. saveBtn(){
  296. // 先检查是否有该科目的单子,有提示错误
  297. for(let o in this.selData){
  298. if(this.curData.type == this.selData[o].type && this.curData.id == this.selData[o].id && this.curFee.id == this.selData[o].fee_id){
  299. this.$message.error('该科目已存在记录');
  300. return false;
  301. }
  302. }
  303. this.selData.push({
  304. type: this.curData.type,
  305. cate: this.curData.cate,
  306. id: this.curData.id,
  307. title: this.curData.title,
  308. area: this.curData.area,
  309. fee_id: this.curFee.id,
  310. fee_title: this.curFee.title,
  311. fee_parent_title: this.curFee.parent_title,
  312. price: this.curFee.price,
  313. months: this.curFee.MONTHS,
  314. total_price: this.totalPrice,
  315. start: this.start,
  316. end: this.end,
  317. remark: this.remark
  318. });
  319. },
  320. delSelectData(index){
  321. let oldoptions = JSON.parse(JSON.stringify(this.selData));
  322. let newoptions = [];
  323. for(let o in oldoptions){
  324. if(o != index){
  325. newoptions.push(oldoptions[o]);
  326. }
  327. }
  328. this.selData = JSON.parse(JSON.stringify(newoptions));
  329. },
  330. submitOrder(){ //生成欠费单
  331. if(this.selData.length == 0){
  332. this.$message.error('请选择收费科目');
  333. return false;
  334. }
  335. if(!this.lastDate){
  336. this.$message.error('请选择最晚缴费日期');
  337. return false;
  338. }
  339. if(this.flag){
  340. return false;
  341. }
  342. this.flag = true;
  343. let that = this;
  344. $.ajax({
  345. type: 'POST',
  346. url: '{:url("feeSave")}',
  347. dataType: 'json',
  348. data:{
  349. houseId: this.houseId,
  350. lastDate: this.lastDate,
  351. order: JSON.stringify(this.selData)
  352. },
  353. success: function(res){
  354. if(res.code == 1){
  355. window.location.href = '{:url("HousePay/detail",[],"")}/id/'+res.data.id;
  356. }else{
  357. that.$message.error(res.msg);
  358. that.flag = false;
  359. }
  360. },
  361. error: function(){
  362. that.$message.error('操作失败');
  363. that.flag = false;
  364. return false;
  365. }
  366. });
  367. },
  368. getFullDate(targetDate) { // 获取时间
  369. var D, y, m, d;
  370. if (targetDate) {
  371. D = new Date(targetDate);
  372. y = D.getFullYear();
  373. m = D.getMonth() + 1;
  374. d = D.getDate();
  375. } else {
  376. y = fullYear;
  377. m = month;
  378. d = date;
  379. }
  380. m = m > 9 ? m : '0' + m;
  381. d = d > 9 ? d : '0' + d;
  382. return y + '-' + m + '-' + d;
  383. },
  384. getDaysBetween(dateString1,dateString2){ // 获取两个日期之间的天数
  385. var startDate = Date.parse(dateString1);
  386. var endDate = Date.parse(dateString2);
  387. if (startDate>endDate){
  388. return 0;
  389. }
  390. if (startDate==endDate){
  391. return 1;
  392. }
  393. var days=(endDate - startDate)/(1*24*60*60*1000);
  394. return days + 1;
  395. },
  396. getMonthBetween (start, end) {
  397. var result = [];
  398. var s = start.split("-");
  399. var e = end.split("-");
  400. var min = new Date();
  401. var max = new Date();
  402. min.setFullYear(s[0], s[1] * 1 - 1, 1);//开始日期
  403. max.setFullYear(e[0], e[1] * 1 - 1, 1);//结束日期
  404. var curr = min;
  405. while (curr <= max) {
  406. let month = curr.getMonth() + 1;
  407. let year = curr.getFullYear();
  408. let endOfMonth = new Date(year, month, 0).getDate(); // 获取本月最后一天
  409. let endDate = this.getFullDate(curr.setDate(endOfMonth));//当月最后一天
  410. let startDate = this.getFullDate(curr.setDate(1));//当月第一天
  411. result.push({
  412. year: year,
  413. month: month,
  414. days: this.getMonthDay(year,month),
  415. start: startDate,
  416. end: endDate
  417. });
  418. curr.setMonth(month);
  419. }
  420. return result;
  421. },
  422. getMonthDay(year, month){
  423. var d = new Date(year, month, 0);
  424. return d.getDate();
  425. },
  426. }
  427. });
  428. </script>
  429. {/block}