categoryThree.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="categoryThree">
  3. <view class="head">
  4. <view class="one">{{dataInfo.grandParentName}}<uni-icons class="right" type="right" :size="16" :color="primaryColor"></uni-icons>{{dataInfo.parentName}}<uni-icons class="right" type="right" :size="16" :color="primaryColor"></uni-icons></view>
  5. <text class="two ellipsis">{{dataInfo.categoryThreeObj.category}}</text>
  6. </view>
  7. <view class="body" v-if="dataInfo.list.length">
  8. <uni-data-checkbox v-model="dataInfo.categoryThree" :localdata="dataInfo.list" mode="list" wrap icon="right" :map="{text:'category',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_incidentcategory } 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 { useHandlerStore } from '@/stores/handler'
  27. import { useGoBack } from '@/share/useGoBack.js'
  28. useSetTitle();
  29. const loginUserStore = useLoginUserStore();
  30. const handlerStore = useHandlerStore();
  31. const { goBack } = useGoBack();
  32. // 主题颜色
  33. const primaryColor = ref(defaultColor)
  34. // 数据
  35. const dataInfo = reactive({
  36. list: [],//工单列表
  37. idx: 0,//页码
  38. hasMore: true,//是否有更多数据
  39. incidentId: undefined,//事件ID
  40. paramData: {},//传参
  41. grandParentName: undefined,//二级故障现象名称
  42. parentId: undefined,//三级故障现象id
  43. parentName: '',//三级故障现象名称
  44. categoryThree: undefined,//三级故障现象-回显
  45. categoryThreeObj: {},//三级故障现象列表-已选择
  46. })
  47. // 选择
  48. function selectItem(e){
  49. dataInfo.categoryThreeObj = e.detail.data;
  50. }
  51. // 确认
  52. function confirm(){
  53. if(!dataInfo.categoryThree){
  54. uni.showToast({
  55. icon: 'none',
  56. title: '请选择三级故障现象'
  57. });
  58. return;
  59. }
  60. dataInfo.paramData.category = dataInfo.categoryThreeObj;
  61. handlerStore.setHandlerData(dataInfo.paramData);
  62. uni.navigateTo({
  63. url: `/pages/handler/handler?incidentId=${dataInfo.incidentId}`,
  64. })
  65. }
  66. // 获取传递的数据
  67. function getParamData(){
  68. dataInfo.paramData = handlerStore.handler.data || {};
  69. dataInfo.categoryThree = dataInfo.paramData.category ? dataInfo.paramData.category.id : undefined;
  70. dataInfo.categoryThreeObj = dataInfo.paramData.category || {};
  71. getList(0);
  72. }
  73. // 获取列表信息
  74. function getList(idx){
  75. uni.showLoading({
  76. title: "加载中",
  77. mask: true,
  78. });
  79. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  80. if(dataInfo.idx === 0){
  81. dataInfo.list = [];
  82. }
  83. let postData = {
  84. idx: dataInfo.idx,
  85. sum: 20,
  86. incidentcategory: {
  87. parent: {
  88. id: dataInfo.parentId,
  89. },
  90. }
  91. }
  92. // 当前所属院区或责任科室
  93. if(loginUserStore.loginUser.user.duty){
  94. postData.incidentcategory.duty = loginUserStore.loginUser.user.duty.id;
  95. }else if(loginUserStore.loginUser.user.branch){
  96. postData.incidentcategory.branch = loginUserStore.loginUser.user.branch.id;
  97. }
  98. api_incidentcategory(postData).then(res => {
  99. uni.hideLoading();
  100. uni.stopPullDownRefresh();
  101. if(res.status == 200){
  102. let list = res.list || [];
  103. if(list.length){
  104. dataInfo.hasMore = true;
  105. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  106. }else{
  107. dataInfo.hasMore = false;
  108. }
  109. }else{
  110. uni.showToast({
  111. icon: 'none',
  112. title: res.msg || '请求数据失败!'
  113. });
  114. }
  115. })
  116. }
  117. onLoad((option) => {
  118. dataInfo.incidentId = option.incidentId;
  119. dataInfo.grandParentName = option.grandParentName;
  120. dataInfo.parentId = option.parentId;
  121. dataInfo.parentName = option.parentName;
  122. getParamData();
  123. })
  124. onPullDownRefresh(() => {
  125. getList(0)
  126. })
  127. onReachBottom(() => {
  128. dataInfo.idx += 1;
  129. if (dataInfo.hasMore) {
  130. getList(); // 当触底时加载更多数据
  131. }
  132. })
  133. </script>
  134. <style lang="scss" scoped>
  135. .categoryThree{
  136. display: flex;
  137. flex-direction: column;
  138. justify-content: space-between;
  139. .head{
  140. height: 88rpx;
  141. display: flex;
  142. align-items: center;
  143. padding: 0 24rpx;
  144. position: fixed;
  145. z-index: 99;
  146. width: 100%;
  147. box-sizing: border-box;
  148. background: #fff;
  149. font-size: 26rpx;
  150. color: $uni-primary;
  151. .right{
  152. margin-top: 2rpx;
  153. }
  154. .two{
  155. flex: 1;
  156. }
  157. }
  158. .body{
  159. border-top: 1rpx solid #DEDEDE;
  160. margin-bottom: 140rpx;
  161. margin-top: 88rpx;
  162. font-size: 26rpx;
  163. .body_item{
  164. border-bottom: 1rpx solid #DEDEDE;
  165. padding: 24rpx;
  166. }
  167. }
  168. .zanwu{
  169. margin-bottom: 140rpx;
  170. margin-top: 88rpx;
  171. display: flex;
  172. justify-content: center;
  173. .newicon-zanwu{
  174. font-size: 256rpx;
  175. color: #D6D6D6;
  176. margin-top: 140rpx;
  177. }
  178. }
  179. .foot_common_btns{
  180. position: fixed;
  181. left: 0;
  182. bottom: 0;
  183. background-color: #fff;
  184. }
  185. }
  186. </style>