medicine.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="category-container">
  3. <!-- 顶部搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-input">
  6. <text class="iconfont icon-search"></text>
  7. <input
  8. v-model="searchKeyword"
  9. placeholder="搜索药品名称或适应症"
  10. placeholder-class="search-placeholder"
  11. @confirm="searchDrugs"
  12. />
  13. </view>
  14. </view>
  15. <!-- 药品列表 -->
  16. <view class="medicine-list">
  17. <view
  18. class="medicine-item"
  19. v-for="medicine in medicineList.records"
  20. :key="medicine.id"
  21. @click="viewMedicineDetail(medicine)"
  22. >
  23. <image
  24. :src="medicine.imageUrl || '/static/default-drug.png'"
  25. mode="aspectFill"
  26. class="medicine-image"
  27. />
  28. <view class="medicine-info">
  29. <text class="medicine-name">{{ medicine.drugName }}</text>
  30. <text class="medicine-desc">适应症:{{ medicine.indication }}</text>
  31. <text class="medicine-spec">规格:{{ medicine.specification }}</text>
  32. </view>
  33. <view class="medicine-stock">库存:{{ medicine.stockQuantity }}件</view>
  34. </view>
  35. <!-- 加载状态 -->
  36. <view v-if="isLoading" class="loading-tip">
  37. <text class="iconfont icon-loading"></text>
  38. <text>加载中...</text>
  39. </view>
  40. <!-- 空数据提示 -->
  41. <view v-if="!isLoading && medicineList.total === 0" class="no-data-tip">
  42. <image src="/static/no-data.png" mode="aspectFit" class="no-data-img" />
  43. <text>暂无符合条件的药品</text>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. searchKeyword: '', // 搜索关键词
  53. medicineList: { records: [], total: 0 }, // 药品列表(包含分页信息)
  54. isLoading: false, // 加载状态
  55. pageNum: 1, // 当前页码
  56. pageSize: 10 // 每页显示数量
  57. };
  58. },
  59. methods: {
  60. /**
  61. * 搜索药品
  62. */
  63. searchDrugs() {
  64. this.pageNum = 1; // 重置页码
  65. this.fetchDrugs(); // 执行查询
  66. },
  67. /**
  68. * 获取药品列表
  69. */
  70. fetchDrugs() {
  71. if (this.isLoading) return; // 防止重复请求
  72. this.isLoading = true;
  73. uni.request({
  74. url: 'http://localhost:8080/drug/drugAll', // 后端接口地址
  75. method: 'POST',
  76. data: {
  77. pageNum: this.pageNum,
  78. pageSize: this.pageSize// 适应症和药名搜索合并到同一个关键词
  79. },
  80. success: (res) => {
  81. if (res.statusCode === 200 && res.data.code === 200) {
  82. this.medicineList = res.data.data; // 假设后端返回格式为{code: 200, data: PageInfo}
  83. } else {
  84. uni.showToast({
  85. title: res.data.msg || '查询失败',
  86. icon: 'none',
  87. duration: 1500
  88. });
  89. }
  90. },
  91. fail: (err) => {
  92. console.error('药品查询失败:', err);
  93. uni.showToast({
  94. title: '网络请求失败,请检查网络',
  95. icon: 'none',
  96. duration: 1500
  97. });
  98. },
  99. complete: () => {
  100. this.isLoading = false;
  101. }
  102. });
  103. },
  104. /**
  105. * 查看药品详情
  106. * @param {Object} medicine 药品信息
  107. */
  108. viewMedicineDetail(medicine) {
  109. uni.navigateTo({
  110. url: `/pages/medicine/detail?id=${medicine.id}`
  111. });
  112. }
  113. },
  114. // 页面加载时初始化查询
  115. onLoad() {
  116. this.fetchDrugs();
  117. }
  118. }
  119. </script>
  120. <style scoped>
  121. .category-container {
  122. background: #f5f5f5;
  123. min-height: 100vh;
  124. padding-bottom: 80rpx;
  125. }
  126. .search-bar {
  127. padding: 20rpx 30rpx;
  128. background-color: #fff;
  129. box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
  130. }
  131. .search-input {
  132. display: flex;
  133. align-items: center;
  134. height: 80rpx;
  135. background-color: #f8f8f8;
  136. border-radius: 40rpx;
  137. padding: 0 40rpx;
  138. }
  139. .search-input .iconfont {
  140. color: #999;
  141. font-size: 40rpx;
  142. margin-right: 30rpx;
  143. }
  144. .search-input input {
  145. flex: 1;
  146. font-size: 32rpx;
  147. color: #333;
  148. }
  149. .medicine-list {
  150. padding: 30rpx 20rpx;
  151. }
  152. .medicine-item {
  153. background-color: #fff;
  154. border-radius: 20rpx;
  155. padding: 30rpx;
  156. margin-bottom: 30rpx;
  157. box-shadow: 0 10rpx 20rpx rgba(0,0,0,0.05);
  158. display: flex;
  159. align-items: center;
  160. }
  161. .medicine-image {
  162. width: 160rpx;
  163. height: 160rpx;
  164. border-radius: 10rpx;
  165. margin-right: 40rpx;
  166. }
  167. .medicine-info {
  168. flex: 1;
  169. }
  170. .medicine-name {
  171. font-size: 36rpx;
  172. font-weight: bold;
  173. color: #333;
  174. margin-bottom: 20rpx;
  175. }
  176. .medicine-desc {
  177. font-size: 28rpx;
  178. color: #666;
  179. margin-bottom: 10rpx;
  180. }
  181. .medicine-spec {
  182. font-size: 24rpx;
  183. color: #999;
  184. }
  185. .medicine-stock {
  186. font-size: 30rpx;
  187. color: #4a90e2;
  188. margin-left: 40rpx;
  189. }
  190. .loading-tip {
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. height: 200rpx;
  195. font-size: 32rpx;
  196. color: #999;
  197. }
  198. .no-data-tip {
  199. text-align: center;
  200. padding: 200rpx 30rpx;
  201. color: #999;
  202. }
  203. .no-data-img {
  204. width: 400rpx;
  205. height: 400rpx;
  206. margin: 0 auto 40rpx;
  207. opacity: 0.6;
  208. }
  209. </script>