cost.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div>
  3. <div class="title222">
  4. <van-sticky offset-top="-0.9rem">
  5. <van-cell :title="'选择日期:' + costDateTitle" @click="costDateShow = true" class="costDateSel" />
  6. <van-calendar v-model="costDateShow" type="range" :allow-same-day="true" :show-confirm="false" @confirm="dateConfirm" :min-date="minDate" :max-date="maxDate" />
  7. <van-tabs v-model="active" @change="activeChange" background="#20a0ff" title-active-color="#fff" title-inactive-color="#3c3c45" style="height:1.17333rem;">
  8. <van-tab title="项目"></van-tab>
  9. <van-tab title="项目分类" v-if="user.companyId != '1071'"></van-tab>
  10. </van-tabs>
  11. </van-sticky>
  12. </div>
  13. <div style="padding-top:2px;margin-bottom:1.33333rem">
  14. <van-cell v-if="listLoading" style="padding-top:2px;background-color: transparent;">
  15. <template #default>
  16. <van-loading color="#1989fa" size="24" text-size="12" style="text-align:center;">加载中...</van-loading>
  17. </template>
  18. </van-cell>
  19. <van-cell v-if="timeCostList.length == 0" style="padding-top:2px;background-color: transparent;">
  20. <template #default>
  21. <div style="text-align:center;color:#7d7e80;font-size:13px">暂无数据</div>
  22. </template>
  23. </van-cell>
  24. <template v-else>
  25. <span v-if="active == 0">
  26. <van-cell v-for="item in timeCostList" :key="item.id" style="padding: 2px 4px;background-color: transparent;">
  27. <div style="padding: 0.26667rem 0.42667rem;background-color: #fff;">
  28. <van-row>
  29. <van-col span="6" style="text-align:center;color:#969799">项目名称</van-col>
  30. <van-col span="18">{{item.project}}</van-col>
  31. </van-row>
  32. <van-row>
  33. <van-col span="6" style="text-align:center;color:#969799">项目编号</van-col>
  34. <van-col span="18">{{item.projectCode}}</van-col>
  35. </van-row>
  36. <van-row>
  37. <van-col v-if="countHours" span="4" style="text-align:center;color:#969799">工时</van-col>
  38. <van-col v-if="countHours" span="5" style="text-align:right">{{item.cost.toFixed(1)}} h</van-col>
  39. <van-col v-if="countCost" span="5" style="text-align:right;color:#969799">成本</van-col>
  40. <van-col v-if="countCost" span="8" style="text-align:right">¥ {{item.costMoney.toFixed(2)}}</van-col>
  41. </van-row>
  42. </div>
  43. </van-cell>
  44. </span>
  45. <span v-if="active == 1">
  46. <van-cell v-for="item in timeCostList" :key="item.category" style="padding: 2px 4px;background-color: transparent;">
  47. <div style="padding: 0.26667rem 0.42667rem;background-color: #fff;">
  48. <van-row>
  49. <van-col span="6" style="text-align:center;color:#969799">分类名称</van-col>
  50. <van-col span="18">{{item.categoryName}}</van-col>
  51. </van-row>
  52. <van-row>
  53. <van-col v-if="countHours" span="4" style="text-align:center;color:#969799">工时</van-col>
  54. <van-col v-if="countHours" span="5" style="text-align:right">{{item.cost.toFixed(1)}} h</van-col>
  55. <van-col v-if="countCost" span="5" style="text-align:right;color:#969799">成本</van-col>
  56. <van-col v-if="countCost" span="8" style="text-align:right">¥ {{item.costMoney.toFixed(2)}}</van-col>
  57. </van-row>
  58. </div>
  59. </van-cell>
  60. </span>
  61. </template>
  62. </div>
  63. <Footer page="cost"></Footer>
  64. </div>
  65. </template>
  66. <script>
  67. import Footer from "@/components/Footer";
  68. export default {
  69. components: {
  70. Footer
  71. },
  72. data() {
  73. return {
  74. countCost: false,
  75. countHours: false,
  76. active: 0,
  77. listLoading: false,
  78. minDate: new Date(2020,0,1),
  79. maxDate: new Date(2025,11,31),
  80. costDateTitle: '',
  81. costDate: [],
  82. costDateShow: false,
  83. timeCostList: [],
  84. user: JSON.parse(localStorage.userInfo),
  85. }
  86. },
  87. mounted() {
  88. let user = JSON.parse(localStorage.userInfo)
  89. for(let i in user.functionList){
  90. if(user.functionList[i].name == '查看工时统计'){
  91. this.countHours = true
  92. }
  93. if(user.functionList[i].name == '查看成本统计'){
  94. this.countCost = true
  95. }
  96. }
  97. let end = new Date()
  98. let start = new Date(end.getFullYear(),end.getMonth(),1)
  99. this.costDate = [this.formatDate(start),this.formatDate(end)]
  100. this.costDateTitle = this.dateToTitle(this.costDate)
  101. this.getTimeCost()
  102. },
  103. methods: {
  104. formatDate(date) {
  105. let mon = date.getMonth() + 1
  106. return `${date.getFullYear()}-${mon<10?'0'+mon:mon}-${date.getDate()<10?'0'+date.getDate():date.getDate()}`;
  107. },
  108. dateToTitle(dateArr){
  109. let start = dateArr[0].split('-')
  110. let end = dateArr[1].split('-')
  111. return `${start[0]}年${start[1]}月${start[2]}日\u3000至\u3000${end[0]}年${end[1]}月${end[2]}日`
  112. },
  113. activeChange(name,title){
  114. this.timeCostList = []
  115. this.getTimeCost()
  116. },
  117. dateConfirm(value,date){
  118. this.costDate = [this.formatDate(value[0]),this.formatDate(value[1])]
  119. this.costDateTitle = this.dateToTitle(this.costDate)
  120. this.costDateShow = false
  121. this.getTimeCost()
  122. },
  123. getTimeCost(){
  124. let url = this.active ? '/project/getTimeCostByCategory' : '/project/getTimeCost'
  125. this.listLoading = true
  126. this.$axios.post(url, {
  127. startDate: this.costDate[0],
  128. endDate: this.costDate[1],
  129. type: 0
  130. }).then(res => {
  131. if(res.code == "ok") {
  132. this.listLoading = false
  133. this.timeCostList = res.data.costList
  134. } else {
  135. this.listLoading = false
  136. this.$toast.clear();
  137. this.$toast.fail('获取失败');
  138. }
  139. }).catch(err=> {this.listLoading = false;this.$toast.clear();console.log(err)});
  140. }
  141. },
  142. }
  143. </script>
  144. <style>
  145. .title222 {
  146. background-color: #20a0ff;
  147. overflow: hidden;
  148. }
  149. .costDateSel {
  150. background-color: #20a0ff;
  151. color: #fff;
  152. font-size: 12px !important;
  153. padding-top: 0.14rem;
  154. padding-left: 0.43rem;
  155. padding-bottom: 0.3rem;
  156. height: 1.08rem;
  157. }
  158. .costDateSel::after{
  159. display: none;
  160. }
  161. .title222 .van-tabs__line{
  162. background-color: #f7f7f7;
  163. }
  164. </style>