consumableList.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="consumableList">
  3. <view class="head">
  4. <uni-search-bar v-model="dataInfo.keyWord" placeholder="请搜索耗材" bgColor="#F8F8F8" @input="search" cancelButton="none" focus :radius="18" />
  5. </view>
  6. <view class="body" v-if="dataInfo.list.length">
  7. <view class="body_item ellipsis" v-for="data in dataInfo.list" :key="data.id" @click="numberClick(data, 'addConsumable')">
  8. {{data.name}}
  9. </view>
  10. </view>
  11. <view class="zanwu" v-else>
  12. <text class="newicon newicon-zanwu"></text>
  13. </view>
  14. <view class="foot_common_btns">
  15. <button @click="goBack" type="default" class="primaryButton btn">返回</button>
  16. </view>
  17. <NumberModal v-if="dataInfo.isNumber" @cancelEmit="cancelNumber" @confirmEmit="conformNumber" :selectData="dataInfo.selectData" :selectType="dataInfo.selectType"></NumberModal>
  18. </view>
  19. </template>
  20. <script setup>
  21. import { debounce } from 'lodash-es'
  22. import { ref, reactive} from 'vue'
  23. import NumberModal from '@/components/NumberModal.vue';
  24. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  25. import { api_consumable, api_incidentDetail, api_addSummaryDoc } from "@/http/api.js"
  26. import { defaultColor } from '@/static/js/theme.js'
  27. import { useSetTitle } from '@/share/useSetTitle.js'
  28. import { useLoginUserStore } from '@/stores/loginUser'
  29. import { useGoBack } from '@/share/useGoBack.js'
  30. useSetTitle();
  31. const loginUserStore = useLoginUserStore();
  32. const { goBack } = useGoBack();
  33. // 主题颜色
  34. const primaryColor = ref(defaultColor)
  35. // 数据
  36. const dataInfo = reactive({
  37. list: [],//工单列表
  38. idx: 0,//页码
  39. hasMore: true,//是否有更多数据
  40. incidentId: undefined,//事件ID
  41. summaryId: undefined,//汇总单ID
  42. incidentData: {},//事件对象
  43. keyWord: '',//搜索的关键词
  44. isNumber: false,//修改数量弹窗
  45. evtNumber: 1,//弹窗返回的数量
  46. selectData: {},//选择的对象
  47. selectType: {},//选择的对象类型
  48. })
  49. // 点击修改数量
  50. function numberClick(data, type){
  51. dataInfo.isNumber = true;
  52. dataInfo.selectData = data;
  53. dataInfo.selectType = type;
  54. }
  55. // 确认修改数量
  56. function conformNumber(evtNumber){
  57. dataInfo.evtNumber = evtNumber;
  58. dataInfo.isNumber = false;
  59. addSummaryDoc();
  60. }
  61. // 关闭修改数量
  62. function cancelNumber(){
  63. dataInfo.isNumber = false;
  64. }
  65. // 添加耗材
  66. function addSummaryDoc(){
  67. uni.showLoading({
  68. title: "加载中",
  69. mask: true,
  70. });
  71. let postData = {
  72. "consumableList": [
  73. {
  74. "consumablesId": dataInfo.selectData.id,
  75. "consumablesNum": dataInfo.evtNumber
  76. }
  77. ],
  78. "summaryId": dataInfo.summaryId
  79. };
  80. api_addSummaryDoc(postData).then(res => {
  81. uni.hideLoading();
  82. if(res.status == 200){
  83. uni.showToast({
  84. icon: 'none',
  85. title: '添加耗材成功',
  86. mask: true,
  87. });
  88. setTimeout(() => {
  89. uni.navigateTo({
  90. url: `/pages/handler/handler?incidentId=${dataInfo.incidentId}`,
  91. })
  92. }, 1500)
  93. }else{
  94. uni.showToast({
  95. icon: 'none',
  96. title: res.msg || '请求数据失败!'
  97. });
  98. }
  99. })
  100. }
  101. // 获取事件详情
  102. function getIncidentDetail(){
  103. uni.showLoading({
  104. title: "加载中",
  105. mask: true,
  106. });
  107. api_incidentDetail(dataInfo.incidentId).then(res => {
  108. uni.hideLoading();
  109. if(res.status == 200){
  110. dataInfo.incidentData = res.data || {};
  111. getList(0);
  112. }else{
  113. uni.showToast({
  114. icon: 'none',
  115. title: res.msg || '请求数据失败!'
  116. });
  117. }
  118. })
  119. }
  120. // 搜索
  121. const search = debounce(getList.bind(null, 0), 500);
  122. // 获取列表信息
  123. function getList(idx){
  124. if(dataInfo.keyWord.trim() === ''){
  125. dataInfo.list = [];
  126. uni.stopPullDownRefresh();
  127. return;
  128. }
  129. uni.showLoading({
  130. title: "加载中",
  131. mask: true,
  132. });
  133. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  134. if(dataInfo.idx === 0){
  135. dataInfo.list = [];
  136. }
  137. let postData = {
  138. idx: dataInfo.idx,
  139. sum: 20,
  140. consumable: {
  141. keyWord: dataInfo.keyWord,
  142. dutyDTO: dataInfo.incidentData.duty,
  143. showZero: true,
  144. }
  145. }
  146. api_consumable(postData).then(res => {
  147. uni.hideLoading();
  148. uni.stopPullDownRefresh();
  149. if(res.status == 200){
  150. let list = res.list || [];
  151. if(list.length){
  152. dataInfo.hasMore = true;
  153. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  154. }else{
  155. dataInfo.hasMore = false;
  156. }
  157. }else{
  158. uni.showToast({
  159. icon: 'none',
  160. title: res.msg || '请求数据失败!'
  161. });
  162. }
  163. })
  164. }
  165. onLoad((option) => {
  166. dataInfo.incidentId = option.incidentId;
  167. dataInfo.summaryId = option.summaryId;
  168. getIncidentDetail();
  169. })
  170. onPullDownRefresh(() => {
  171. getList(0)
  172. })
  173. onReachBottom(() => {
  174. dataInfo.idx += 1;
  175. if (dataInfo.hasMore) {
  176. getList(); // 当触底时加载更多数据
  177. }
  178. })
  179. </script>
  180. <style lang="scss" scoped>
  181. .consumableList{
  182. display: flex;
  183. flex-direction: column;
  184. justify-content: space-between;
  185. .head{
  186. height: 88rpx;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. padding: 0 24rpx;
  191. position: fixed;
  192. z-index: 99;
  193. width: 100%;
  194. box-sizing: border-box;
  195. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  196. }
  197. .body{
  198. margin-bottom: 140rpx;
  199. margin-top: 88rpx;
  200. font-size: 26rpx;
  201. .body_item{
  202. border-bottom: 1rpx solid #DEDEDE;
  203. padding: 24rpx;
  204. }
  205. }
  206. .zanwu{
  207. margin-bottom: 140rpx;
  208. margin-top: 88rpx;
  209. display: flex;
  210. justify-content: center;
  211. .newicon-zanwu{
  212. font-size: 256rpx;
  213. color: #D6D6D6;
  214. margin-top: 140rpx;
  215. }
  216. }
  217. .foot_common_btns{
  218. position: fixed;
  219. left: 0;
  220. bottom: 0;
  221. background-color: #fff;
  222. }
  223. }
  224. </style>