workHourManagementTwo.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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: 9999,
  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. dataInfo.list = list
  135. // if(list.length){
  136. // dataInfo.hasMore = true;
  137. // dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  138. // }else{
  139. // dataInfo.hasMore = false;
  140. // }
  141. }else{
  142. uni.showToast({
  143. icon: 'none',
  144. title: res.msg || '请求数据失败!'
  145. });
  146. }
  147. })
  148. }
  149. onLoad((option) => {
  150. dataInfo.incidentId = option.incidentId;
  151. dataInfo.summaryId = option.summaryId;
  152. dataInfo.parentId = option.parentId;
  153. dataInfo.parentName = option.parentName;
  154. getQuerySummaryDoc();
  155. })
  156. onPullDownRefresh(() => {
  157. getList(0)
  158. })
  159. onReachBottom(() => {
  160. // dataInfo.idx += 1;
  161. // if (dataInfo.hasMore) {
  162. // getList(); // 当触底时加载更多数据
  163. // }
  164. })
  165. </script>
  166. <style lang="scss" scoped>
  167. .workHourManagementTwo{
  168. display: flex;
  169. flex-direction: column;
  170. justify-content: space-between;
  171. .head{
  172. height: 88rpx;
  173. display: flex;
  174. align-items: center;
  175. padding: 0 24rpx;
  176. position: fixed;
  177. z-index: 99;
  178. width: 100%;
  179. box-sizing: border-box;
  180. background: #fff;
  181. font-size: 26rpx;
  182. color: $uni-primary;
  183. .right{
  184. margin-top: 2rpx;
  185. }
  186. .two{
  187. flex: 1;
  188. }
  189. }
  190. .body{
  191. border-top: 1rpx solid #DEDEDE;
  192. margin-bottom: 140rpx;
  193. margin-top: 88rpx;
  194. font-size: 26rpx;
  195. .body_item{
  196. border-bottom: 1rpx solid #DEDEDE;
  197. padding: 24rpx;
  198. }
  199. }
  200. .zanwu{
  201. margin-bottom: 140rpx;
  202. margin-top: 88rpx;
  203. display: flex;
  204. justify-content: center;
  205. .newicon-zanwu{
  206. font-size: 256rpx;
  207. color: #D6D6D6;
  208. margin-top: 140rpx;
  209. }
  210. }
  211. .foot_common_btns{
  212. position: fixed;
  213. left: 0;
  214. bottom: 0;
  215. background-color: #fff;
  216. }
  217. }
  218. </style>