consumableList.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. <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 } 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 } 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. function getList(idx){
  133. if(dataInfo.keyWord.trim() === ''){
  134. dataInfo.list = [];
  135. uni.stopPullDownRefresh();
  136. return;
  137. }
  138. uni.showLoading({
  139. title: "加载中",
  140. mask: true,
  141. });
  142. dataInfo.idx = idx === undefined ? dataInfo.idx : idx;
  143. if(dataInfo.idx === 0){
  144. dataInfo.list = [];
  145. }
  146. let postData = {
  147. idx: dataInfo.idx,
  148. sum: 20,
  149. consumable: {
  150. keyWord: dataInfo.keyWord,
  151. dutyDTO: dataInfo.incidentData.duty,
  152. showZero: true,
  153. }
  154. }
  155. api_consumable(postData).then(res => {
  156. uni.hideLoading();
  157. uni.stopPullDownRefresh();
  158. if(res.status == 200){
  159. let list = res.list || [];
  160. if(list.length){
  161. dataInfo.hasMore = true;
  162. dataInfo.list = dataInfo.idx === 0 ? list : dataInfo.list.concat(list);
  163. }else{
  164. dataInfo.hasMore = false;
  165. }
  166. }else{
  167. uni.showToast({
  168. icon: 'none',
  169. title: res.msg || '请求数据失败!'
  170. });
  171. }
  172. })
  173. }
  174. onLoad((option) => {
  175. dataInfo.incidentId = option.incidentId;
  176. dataInfo.summaryId = option.summaryId;
  177. getIncidentDetail();
  178. })
  179. onPullDownRefresh(() => {
  180. getList(0)
  181. })
  182. onReachBottom(() => {
  183. dataInfo.idx += 1;
  184. if (dataInfo.hasMore) {
  185. getList(); // 当触底时加载更多数据
  186. }
  187. })
  188. </script>
  189. <style lang="scss" scoped>
  190. .consumableList{
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: space-between;
  194. .head{
  195. height: 88rpx;
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. padding: 0 24rpx;
  200. position: fixed;
  201. z-index: 99;
  202. width: 100%;
  203. box-sizing: border-box;
  204. background: linear-gradient( 90deg, #58CF66 0%, #DDE9FC 100%);
  205. }
  206. .body{
  207. margin-bottom: 140rpx;
  208. margin-top: 88rpx;
  209. font-size: 26rpx;
  210. .body_item{
  211. border-bottom: 1rpx solid #DEDEDE;
  212. padding: 24rpx;
  213. }
  214. }
  215. .zanwu{
  216. margin-bottom: 140rpx;
  217. margin-top: 88rpx;
  218. display: flex;
  219. justify-content: center;
  220. .newicon-zanwu{
  221. font-size: 256rpx;
  222. color: #D6D6D6;
  223. margin-top: 140rpx;
  224. }
  225. }
  226. .foot_common_btns{
  227. position: fixed;
  228. left: 0;
  229. bottom: 0;
  230. background-color: #fff;
  231. }
  232. }
  233. </style>