consumableList.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="consumableList">
  3. <view class="head" v-if="isFlag">
  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" :class="{ mt0: !isFlag }">
  7. <view class="body_item ellipsis" v-for="data in dataInfo.list" :key="data.id" @click="numberClick(data, 'addConsumable')">
  8. {{data.name}}
  9. <template v-if="data.brandModel">({{data.brandModel}})</template>
  10. <template v-if="data.unit">({{data.unit}})</template>
  11. </view>
  12. </view>
  13. <view class="zanwu" v-else>
  14. <text class="newicon newicon-zanwu"></text>
  15. </view>
  16. <view class="foot_common_btns">
  17. <button @click="goBack" type="default" class="primaryButton btn">返回</button>
  18. </view>
  19. <NumberModal v-if="dataInfo.isNumber" @cancelEmit="cancelNumber" @confirmEmit="conformNumber" :selectData="dataInfo.selectData" :selectType="dataInfo.selectType"></NumberModal>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { debounce, uniqBy } from 'lodash-es'
  24. import { ref, reactive} from 'vue'
  25. import NumberModal from '@/components/NumberModal.vue';
  26. import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
  27. import { api_consumable, api_incidentDetail, api_addSummaryDoc, api_incidentCategoryConsumable } from "@/http/api.js"
  28. import { defaultColor } from '@/static/js/theme.js'
  29. import { useSetTitle } from '@/share/useSetTitle.js'
  30. import { useLoginUserStore } from '@/stores/loginUser'
  31. import { useGoBack } from '@/share/useGoBack.js'
  32. useSetTitle();
  33. const loginUserStore = useLoginUserStore();
  34. const { goBack } = useGoBack();
  35. // 主题颜色
  36. const primaryColor = ref(defaultColor)
  37. // 数据
  38. const dataInfo = reactive({
  39. list: [],//工单列表
  40. idx: 0,//页码
  41. hasMore: true,//是否有更多数据
  42. incidentId: undefined,//事件ID
  43. summaryId: undefined,//汇总单ID
  44. incidentData: {},//事件对象
  45. keyWord: '',//搜索的关键词
  46. isNumber: false,//修改数量弹窗
  47. evtNumber: 1,//弹窗返回的数量
  48. selectData: {},//选择的对象
  49. selectType: {},//选择的对象类型
  50. })
  51. // 点击修改数量
  52. function numberClick(data, type){
  53. console.log(data)
  54. dataInfo.isNumber = true;
  55. dataInfo.selectData = {
  56. consumableBrandModel: data.brandModel,
  57. consumableUnit: data.unit,
  58. consumableEndPrice: data.endPrice,
  59. consumableId: data.id,
  60. consumableName: data.name,
  61. };
  62. dataInfo.selectType = type;
  63. }
  64. // 确认修改数量
  65. function conformNumber(evtNumber){
  66. dataInfo.evtNumber = evtNumber;
  67. dataInfo.isNumber = false;
  68. addSummaryDoc();
  69. }
  70. // 关闭修改数量
  71. function cancelNumber(){
  72. dataInfo.isNumber = false;
  73. }
  74. // 添加耗材
  75. function addSummaryDoc(){
  76. uni.showLoading({
  77. title: "加载中",
  78. mask: true,
  79. });
  80. let postData = {
  81. "consumableList": [
  82. {
  83. "consumablesId": dataInfo.selectData.consumableId,
  84. "consumablesNum": dataInfo.evtNumber
  85. }
  86. ],
  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 getIncidentDetail(){
  112. uni.showLoading({
  113. title: "加载中",
  114. mask: true,
  115. });
  116. api_incidentDetail(dataInfo.incidentId).then(res => {
  117. uni.hideLoading();
  118. if(res.status == 200){
  119. dataInfo.incidentData = res.data || {};
  120. getList(0);
  121. }else{
  122. uni.showToast({
  123. icon: 'none',
  124. title: res.msg || '请求数据失败!'
  125. });
  126. }
  127. })
  128. }
  129. // 搜索
  130. const search = debounce(getList.bind(null, 0), 500);
  131. // 是否没有故障耗材配置
  132. const isFlag = ref(false);
  133. // 获取故障耗材配置
  134. async function getIncidentCategoryConsumable(){
  135. uni.showLoading({
  136. title: "加载中",
  137. mask: true,
  138. });
  139. let postData = {
  140. idx: 0,
  141. sum: 20,
  142. incidentCategoryConsumable: {
  143. duty: dataInfo.incidentData.duty.id,
  144. category: dataInfo.incidentData.category,
  145. }
  146. }
  147. let res = await api_incidentCategoryConsumable(postData);
  148. uni.hideLoading();
  149. uni.stopPullDownRefresh();
  150. if(res.status == 200){
  151. let list = res.list || [];
  152. if(list.length){
  153. isFlag.value = false;
  154. let arr = list.map(v => v.consumableDTOS).flat();
  155. dataInfo.list = uniqBy(arr, 'id');
  156. }else{
  157. isFlag.value = true;
  158. }
  159. }else{
  160. isFlag.value = false;
  161. uni.showToast({
  162. icon: 'none',
  163. title: res.msg || '请求数据失败!'
  164. });
  165. }
  166. }
  167. // 获取列表信息
  168. async function getList(idx){
  169. // 判断是否满足故障耗材配置
  170. await getIncidentCategoryConsumable();
  171. if(!isFlag.value){
  172. return;
  173. }
  174. if(dataInfo.keyWord.trim() === ''){
  175. dataInfo.list = [];
  176. uni.stopPullDownRefresh();
  177. return;
  178. }
  179. uni.showLoading({
  180. title: "加载中",
  181. mask: true,
  182. });
  183. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  184. if(dataInfo.idx === 0){
  185. dataInfo.list = [];
  186. }
  187. let postData = {
  188. idx: dataInfo.idx,
  189. sum: 20,
  190. consumable: {
  191. keyWord: dataInfo.keyWord,
  192. dutyDTO: dataInfo.incidentData.duty,
  193. showZero: true,
  194. }
  195. }
  196. api_consumable(postData).then(res => {
  197. uni.hideLoading();
  198. uni.stopPullDownRefresh();
  199. if(res.status == 200){
  200. let list = res.list || [];
  201. if(list.length){
  202. dataInfo.hasMore = true;
  203. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  204. }else{
  205. dataInfo.hasMore = false;
  206. }
  207. }else{
  208. uni.showToast({
  209. icon: 'none',
  210. title: res.msg || '请求数据失败!'
  211. });
  212. }
  213. })
  214. }
  215. onLoad((option) => {
  216. dataInfo.incidentId = option.incidentId;
  217. dataInfo.summaryId = option.summaryId;
  218. getIncidentDetail();
  219. })
  220. onPullDownRefresh(() => {
  221. getList(0)
  222. })
  223. onReachBottom(() => {
  224. dataInfo.idx += 1;
  225. if (dataInfo.hasMore) {
  226. getList(); // 当触底时加载更多数据
  227. }
  228. })
  229. </script>
  230. <style lang="scss" scoped>
  231. .consumableList{
  232. display: flex;
  233. flex-direction: column;
  234. justify-content: space-between;
  235. .head{
  236. height: 88rpx;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. padding: 0 24rpx;
  241. position: fixed;
  242. z-index: 99;
  243. width: 100%;
  244. box-sizing: border-box;
  245. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  246. }
  247. .body{
  248. margin-bottom: 140rpx;
  249. margin-top: 88rpx;
  250. font-size: 26rpx;
  251. .body_item{
  252. border-bottom: 1rpx solid #DEDEDE;
  253. padding: 24rpx;
  254. }
  255. }
  256. .zanwu{
  257. margin-bottom: 140rpx;
  258. margin-top: 88rpx;
  259. display: flex;
  260. justify-content: center;
  261. .newicon-zanwu{
  262. font-size: 256rpx;
  263. color: #D6D6D6;
  264. margin-top: 140rpx;
  265. }
  266. }
  267. .foot_common_btns{
  268. position: fixed;
  269. left: 0;
  270. bottom: 0;
  271. background-color: #fff;
  272. }
  273. }
  274. </style>