workHourManagementTwo.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="workHourManagementTwo">
  3. <view class="head">
  4. <text class="one">{{dataInfo.parentName}}<uni-icons class="right" type="right" :size="16" :color="primaryColor"></uni-icons></text>
  5. <text class="two ellipsis">{{dataInfo.workHourManagementSelectedList.filter(v => v.parent.id == dataInfo.parentId).map(v => v.workName).join(';')}}</text>
  6. </view>
  7. <view class="body" v-if="dataInfo.list.length">
  8. <uni-data-checkbox v-model="dataInfo.workHourManagementList" multiple :localdata="dataInfo.list" mode="list" wrap icon="right" :map="{text:'workName',value:'id'}" @change="selectItem"></uni-data-checkbox>
  9. </view>
  10. <view class="zanwu" v-else>
  11. <text class="newicon newicon-zanwu"></text>
  12. </view>
  13. <view class="foot_common_btns">
  14. <button @click="goBack" type="default" class="primaryButton btn">上一级</button>
  15. <button @click="confirm" type="default" class="primaryButton btn">确认</button>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { ref, reactive} from 'vue'
  21. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  22. import { api_workHourManagement, api_querySummaryDoc, api_addSummaryDoc } from "@/http/api.js"
  23. import { defaultColor } from '@/static/js/theme.js'
  24. import { useSetTitle } from '@/share/useSetTitle.js'
  25. import { useLoginUserStore } from '@/stores/loginUser'
  26. import { useGoBack } from '@/share/useGoBack.js'
  27. useSetTitle();
  28. const loginUserStore = useLoginUserStore();
  29. const { goBack } = useGoBack();
  30. // 主题颜色
  31. const primaryColor = ref(defaultColor)
  32. // 数据
  33. const dataInfo = reactive({
  34. list: [],//工单列表
  35. idx: 0,//页码
  36. hasMore: true,//是否有更多数据
  37. incidentId: undefined,//事件ID
  38. summaryId: undefined,//汇总单ID
  39. parentId: undefined,//一级工时管理id
  40. parentName: '',//一级工时管理名称
  41. workHourManagementList: [],//二级工时管理列表-回显
  42. workHourManagementSelectedList: [],//二级工时管理列表-已选择
  43. })
  44. // 获取汇总单信息
  45. function getQuerySummaryDoc(){
  46. uni.showLoading({
  47. title: "加载中",
  48. mask: true,
  49. });
  50. let postData = {
  51. incidentId: dataInfo.incidentId,
  52. };
  53. api_querySummaryDoc(postData).then(res => {
  54. uni.hideLoading();
  55. if(res.status == 200){
  56. dataInfo.workHourManagementSelectedList = res.workHourManagementList || [];
  57. dataInfo.workHourManagementList = dataInfo.workHourManagementSelectedList.map(v => v.id);
  58. getList(0);
  59. }else{
  60. uni.showToast({
  61. icon: 'none',
  62. title: res.msg || '请求数据失败!'
  63. });
  64. }
  65. })
  66. }
  67. // 选择
  68. function selectItem(e){
  69. let workHourManagementSelectedList = dataInfo.workHourManagementSelectedList.filter(v => v.parent.id != dataInfo.parentId);
  70. dataInfo.workHourManagementSelectedList = workHourManagementSelectedList.concat(e.detail.data);
  71. }
  72. // 确认
  73. function confirm(){
  74. if(dataInfo.workHourManagementSelectedList.length === 0){
  75. uni.showToast({
  76. icon: 'none',
  77. title: '请选择二级工时管理'
  78. });
  79. return;
  80. }
  81. uni.showLoading({
  82. title: "加载中",
  83. mask: true,
  84. });
  85. let postData = {
  86. "workHourManagementList": dataInfo.workHourManagementSelectedList.map(v => ({workHourId: v.id, workHourNum: v.workHourNum2 || 1})),
  87. "summaryId": dataInfo.summaryId
  88. };
  89. api_addSummaryDoc(postData).then(res => {
  90. uni.hideLoading();
  91. if(res.status == 200){
  92. uni.showToast({
  93. icon: 'none',
  94. title: '添加工时成功',
  95. mask: true,
  96. });
  97. setTimeout(() => {
  98. uni.navigateTo({
  99. url: `/pages/handler/handler?incidentId=${dataInfo.incidentId}`,
  100. })
  101. }, 1500)
  102. }else{
  103. uni.showToast({
  104. icon: 'none',
  105. title: res.msg || '请求数据失败!'
  106. });
  107. }
  108. })
  109. }
  110. // 获取列表信息
  111. function getList(idx){
  112. uni.showLoading({
  113. title: "加载中",
  114. mask: true,
  115. });
  116. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  117. if(dataInfo.idx === 0){
  118. dataInfo.list = [];
  119. }
  120. let postData = {
  121. idx: dataInfo.idx,
  122. sum: 20,
  123. workHourManagement: {
  124. parent: {
  125. id: dataInfo.parentId,
  126. }
  127. }
  128. }
  129. api_workHourManagement(postData).then(res => {
  130. uni.hideLoading();
  131. uni.stopPullDownRefresh();
  132. if(res.status == 200){
  133. let list = res.list || [];
  134. if(list.length){
  135. dataInfo.hasMore = true;
  136. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  137. }else{
  138. dataInfo.hasMore = false;
  139. }
  140. }else{
  141. uni.showToast({
  142. icon: 'none',
  143. title: res.msg || '请求数据失败!'
  144. });
  145. }
  146. })
  147. }
  148. onLoad((option) => {
  149. dataInfo.incidentId = option.incidentId;
  150. dataInfo.summaryId = option.summaryId;
  151. dataInfo.parentId = option.parentId;
  152. dataInfo.parentName = option.parentName;
  153. getQuerySummaryDoc();
  154. })
  155. onPullDownRefresh(() => {
  156. getList(0)
  157. })
  158. onReachBottom(() => {
  159. dataInfo.idx += 1;
  160. if (dataInfo.hasMore) {
  161. getList(); // 当触底时加载更多数据
  162. }
  163. })
  164. </script>
  165. <style lang="scss" scoped>
  166. .workHourManagementTwo{
  167. display: flex;
  168. flex-direction: column;
  169. justify-content: space-between;
  170. .head{
  171. height: 88rpx;
  172. display: flex;
  173. align-items: center;
  174. padding: 0 24rpx;
  175. position: fixed;
  176. z-index: 99;
  177. width: 100%;
  178. box-sizing: border-box;
  179. background: #fff;
  180. font-size: 26rpx;
  181. color: $uni-primary;
  182. .right{
  183. margin-top: 2rpx;
  184. }
  185. .two{
  186. flex: 1;
  187. }
  188. }
  189. .body{
  190. border-top: 1rpx solid #DEDEDE;
  191. margin-bottom: 140rpx;
  192. margin-top: 88rpx;
  193. font-size: 26rpx;
  194. .body_item{
  195. border-bottom: 1rpx solid #DEDEDE;
  196. padding: 24rpx;
  197. }
  198. }
  199. .zanwu{
  200. margin-bottom: 140rpx;
  201. margin-top: 88rpx;
  202. display: flex;
  203. justify-content: center;
  204. .newicon-zanwu{
  205. font-size: 256rpx;
  206. color: #D6D6D6;
  207. margin-top: 140rpx;
  208. }
  209. }
  210. .foot_common_btns{
  211. position: fixed;
  212. left: 0;
  213. bottom: 0;
  214. background-color: #fff;
  215. }
  216. }
  217. </style>