selectLab.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!-- 选择实验室 -->
  2. <template>
  3. <view id="gasCylinderSelectLab">
  4. <view class="top-input-max-box">
  5. <view class="input-box">
  6. <uni-icons type="search" class="icon-box" color="#7C7C7C" size="25"></uni-icons>
  7. <input class="uni-input input-min" confirm-type="search" @confirm="getList()" v-model="inputData" maxlength="20"
  8. placeholder="搜索实验室" />
  9. <view class="button-p" @click="resetButton()">重置</view>
  10. </view>
  11. <view class="picker-box">
  12. <picker @change="bindPickerChangeA" :value="indexA" :range="arrayA">
  13. <view class="picker-min-box">
  14. <view>{{indexA==null?'学院':arrayA[indexA]}}</view>
  15. <uni-icons type="down" class="icon-box" size="15"></uni-icons>
  16. </view>
  17. </picker>
  18. <picker mode="multiSelector" @change="bindPickerChangeB" @columnchange="bindColumnChangeB" :value="multiIndexB"
  19. :range="multiArrayB" range-key="name"> <!-- ⚠️ 请替换为你接口中实际用于展示的字段名 -->
  20. <view class="picker-min-box">
  21. <!-- 展示当前选中的 校区-楼栋-楼层 -->
  22. <view v-if="multiIndexB[0]==null && multiIndexB[1]==null && multiIndexB[2]==null">请选择楼层</view>
  23. <!-- <view v-else>
  24. {{ multiArrayB[0][multiIndexB[0]].name }} -
  25. {{ multiArrayB[1][multiIndexB[1]].name }} -
  26. {{ multiArrayB[2][multiIndexB[2]].name }}
  27. </view> -->
  28. <view v-else>
  29. {{ multiArrayB[2][multiIndexB[2]].name }}
  30. </view>
  31. <uni-icons type="down" class="icon-box" size="15"></uni-icons>
  32. </view>
  33. </picker>
  34. <!-- <picker @change="bindPickerChangeB" :value="indexB" :range="arrayB" mode="multiSelector"
  35. range-key="buildFloorVoList">
  36. <view class="picker-min-box">
  37. <view>{{indexB==null?'楼栋':arrayB[indexB]}}</view>
  38. <uni-icons type="down" class="icon-box" size="15"></uni-icons>
  39. </view>
  40. </picker> -->
  41. <!-- <picker @change="bindPickerChangeC" :value="indexC" :range="arrayC">
  42. <view class="picker-min-box">
  43. <view>{{indexC==null?'楼层':arrayC[indexC]}}</view>
  44. <uni-icons type="down" class="icon-box" size="15"></uni-icons>
  45. </view>
  46. </picker> -->
  47. </view>
  48. </view>
  49. <scroll-view scroll-y @scrolltolower="scrollGet" class="content-box">
  50. <view class="null-p" v-if="!dataList[0]">暂无数据</view>
  51. <view class="for-max-big-box" @click="checkButton(item)" v-for="(item,index) in dataList" :key="index">
  52. <view class="for-title-box">
  53. <view>实验室名称:</view>
  54. <view>{{item.subName}}</view>
  55. </view>
  56. <view class="for-text-box">
  57. <view>楼栋:</view>
  58. <view>{{item.buildName}}</view>
  59. </view>
  60. <view class="for-text-box">
  61. <view>楼层:</view>
  62. <view>{{item.floorName}}</view>
  63. </view>
  64. <view class="for-text-box">
  65. <view>房间号:</view>
  66. <view>{{item.roomNum}}</view>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. <uni-icons class="sao-code-box" type="scan" color="#fff" size="25"></uni-icons>
  71. </view>
  72. </template>
  73. <script>
  74. import {
  75. getDeptDropList,
  76. systemBuildingGetTreeList,
  77. airbottleNewQpAppletBottleSubjectsPage,
  78. } from '@/pages_supplierCylinderManagement/api/index.js'
  79. export default {
  80. data() {
  81. return {
  82. fromPage: '',
  83. inputData: '',
  84. listA: [],
  85. arrayA: [],
  86. indexA: null,
  87. // 三维数组:[ [所有校区], [当前选中校区下的楼栋], [当前选中楼栋下的楼层] ]
  88. multiArrayB: [
  89. [],
  90. [],
  91. []
  92. ],
  93. // 当前选中的索引,初始为 null 表示未选择
  94. multiIndexB: [null, null, null],
  95. // 存储完整的原始树形数据
  96. optionListB: [],
  97. dataList: [],
  98. // 查询参数
  99. getDataType: false,
  100. queryParams: {
  101. page: 1,
  102. pageSize: 10,
  103. },
  104. total: 0,
  105. }
  106. },
  107. onLoad(options) {
  108. this.fromPage = options.from;
  109. },
  110. onShow() {
  111. this.getDeptDropList();
  112. this.systemBuildingGetTreeList();
  113. this.getList();
  114. },
  115. methods: {
  116. bindPickerChangeA(e) {
  117. this.indexA = e.detail.value
  118. this.$set(this.queryParams, 'page', 1);
  119. this.getList();
  120. },
  121. //滚动加载事件
  122. scrollGet() {
  123. let self = this;
  124. if (self.total / self.queryParams.pageSize <= self.queryParams.page) {
  125. this.$set(this, 'getDataType', true);
  126. } else {
  127. this.queryParams.page += 1;
  128. this.$nextTick(() => {
  129. this.getList();
  130. })
  131. }
  132. },
  133. //搜索用户
  134. async getList() {
  135. let self = this;
  136. let obj = {
  137. page: this.queryParams.page,
  138. pageSize: this.queryParams.pageSize,
  139. searchValue: this.inputData,
  140. deptId: this.indexA == null ? '' : this.listA[this.indexA].deptId,
  141. buildId: this.multiIndexB[1] == null ? '' : this.multiArrayB[1][this.multiIndexB[1]].id,
  142. floorId: this.multiIndexB[2] == null ? '' : this.multiArrayB[2][this.multiIndexB[2]].id,
  143. };
  144. const {
  145. data
  146. } = await airbottleNewQpAppletBottleSubjectsPage(obj);
  147. if (data.code == 200) {
  148. if (self.queryParams.page == 1) {
  149. this.dataList = data.data.records;
  150. this.total = data.data.total;
  151. if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
  152. this.$set(this, 'getDataType', true);
  153. }
  154. } else {
  155. this.dataList = [...this.dataList, ...data.data.records]
  156. this.total = data.data.total;
  157. if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
  158. this.$set(this, 'getDataType', true);
  159. }
  160. }
  161. }
  162. },
  163. async getDeptDropList() {
  164. const {
  165. data
  166. } = await getDeptDropList({
  167. deptName: '',
  168. level: 2,
  169. deptType: 1
  170. });
  171. if (data.code == 200) {
  172. let list = [];
  173. for (let i = 0; i < data.data.length; i++) {
  174. list.push(data.data[i].deptName);
  175. }
  176. this.$set(this, 'listA', data.data);
  177. this.$set(this, 'arrayA', list);
  178. }
  179. },
  180. async systemBuildingGetTreeList() {
  181. const {
  182. data
  183. } = await systemBuildingGetTreeList({});
  184. if (data.code == 200) {
  185. let list = JSON.parse(JSON.stringify(data.data));
  186. // 执行你原有的过滤逻辑
  187. this.pushNode(list);
  188. this.optionListB = list;
  189. // ✅ 核心:将树形结构转换为 multiSelector 需要的三维数组
  190. if (list.length > 0) {
  191. // 第一列:提取所有校区
  192. const campuses = list.map(item => item);
  193. // 第二列:默认取第一个校区下的楼栋列表
  194. const buildings = list[0].buildFloorVoList || [];
  195. // 第三列:默认取第一个楼栋下的楼层列表
  196. const floors = (buildings.length > 0) ? buildings[0].buildFloorVoList || [] : [];
  197. this.multiArrayB = [campuses, buildings, floors];
  198. // 重置选中索引为 null,实现默认不选中
  199. this.multiIndexB = [null, null, null];
  200. }
  201. }
  202. },
  203. // 辅助方法:你原有的树形节点过滤逻辑
  204. pushNode(list) {
  205. for (let i = 0; i < list.length; i++) {
  206. if (list[i].type != 3 && (!list[i].buildFloorVoList || list[i].buildFloorVoList.length === 0)) {
  207. list.splice(i, 1);
  208. i--;
  209. } else if (list[i].type == 3) {
  210. delete list[i].buildFloorVoList;
  211. } else {
  212. this.pushNode(list[i].buildFloorVoList);
  213. }
  214. }
  215. },
  216. // 2. 监听列变化(联动核心)
  217. bindColumnChangeB(e) {
  218. const column = e.detail.column; // 改变的列号 (0:校区, 1:楼栋, 2:楼层)
  219. const value = e.detail.value; // 改变后的索引
  220. // 更新当前列的索引
  221. this.multiIndexB[column] = value;
  222. if (column === 0) {
  223. // --- 第一列(校区)变化 ---
  224. // 1. 更新第二列(楼栋)的数据
  225. const currentCampus = this.optionListB[value];
  226. this.$set(this.multiArrayB, 1, currentCampus.buildFloorVoList || []);
  227. // 2. 更新第三列(楼层)的数据(基于新的楼栋列表的第一个)
  228. const newBuildings = this.multiArrayB[1];
  229. const newFloors = (newBuildings.length > 0) ? newBuildings[0].buildFloorVoList || [] : [];
  230. this.$set(this.multiArrayB, 2, newFloors);
  231. // 3. 重置后续列的索引
  232. this.multiIndexB[1] = 0;
  233. this.multiIndexB[2] = 0;
  234. } else if (column === 1) {
  235. // --- 第二列(楼栋)变化 ---
  236. // 1. 更新第三列(楼层)的数据
  237. const currentBuilding = this.multiArrayB[1][value];
  238. this.$set(this.multiArrayB, 2, currentBuilding.buildFloorVoList || []);
  239. // 2. 重置后续列的索引
  240. this.multiIndexB[2] = 0;
  241. }
  242. // 如果是第三列(楼层)变化,则无需更新其他列
  243. },
  244. // 3. 确认选择
  245. bindPickerChangeB(e) {
  246. this.multiIndexB = e.detail.value;
  247. // 获取最终选中的完整对象
  248. const selectedCampus = this.multiArrayB[0][this.multiIndexB[0]];
  249. const selectedBuilding = this.multiArrayB[1][this.multiIndexB[1]];
  250. const selectedFloor = this.multiArrayB[2][this.multiIndexB[2]];
  251. this.$set(this.queryParams, 'page', 1);
  252. this.getList();
  253. // 在这里将值赋值给表单字段
  254. // this.newData.campusId = selectedCampus.id;
  255. // this.newData.buildingId = selectedBuilding.id;
  256. // this.newData.floorId = selectedFloor.id;
  257. },
  258. //重置
  259. resetButton() {
  260. this.$set(this, 'inputData', '');
  261. this.$set(this, 'indexA', null);
  262. this.$set(this, 'multiIndexB', [null, null, null]);
  263. this.$set(this, 'dataList', []);
  264. this.$set(this, 'getDataType', false);
  265. this.$set(this, 'queryParams', {
  266. page: 1,
  267. pageSize: 10,
  268. });
  269. this.$set(this, 'total', 0);
  270. this.getList();
  271. },
  272. checkButton(item) {
  273. let obj = {
  274. subId:item.subId,
  275. deptId:item.deptId,
  276. subName:item.subName,
  277. buildName:item.buildName,
  278. floorName:item.floorName,
  279. roomNum:item.roomNum,
  280. }
  281. if (this.fromPage == 1) {
  282. uni.redirectTo({
  283. url: '/pages_supplierCylinderManagement/views/gasCylinderManagement/inbound?form=' + encodeURIComponent(
  284. JSON.stringify(obj)) + '&pageType=2'
  285. });
  286. } else if (this.fromPage == 2) {
  287. uni.redirectTo({
  288. url: '/pages_supplierCylinderManagement/views/gasCylinderManagement/outbound?form=' + encodeURIComponent(
  289. JSON.stringify(obj)) + '&pageType=2'
  290. });
  291. }
  292. },
  293. }
  294. }
  295. </script>
  296. <style lang="stylus" scoped>
  297. #gasCylinderSelectLab {
  298. height: 100%;
  299. width: 100%;
  300. display flex;
  301. flex-direction column;
  302. overflow: hidden;
  303. position: relative;
  304. .top-input-max-box {
  305. background-color: #fff;
  306. .input-box {
  307. display: flex;
  308. border-radius: 40rpx;
  309. background-color: #eeeeee;
  310. margin: 20rpx 20rpx 0 20rpx;
  311. color: #7C7C7C;
  312. .icon-box {
  313. margin: 15rpx;
  314. }
  315. .input-min {
  316. height: 80rpx;
  317. line-height: 80rpx;
  318. flex: 1;
  319. }
  320. .button-p {
  321. line-height: 80rpx;
  322. width: 120rpx;
  323. text-align: center;
  324. color: #333;
  325. font-size: 28rpx;
  326. background-color: #D4D4D4;
  327. border-top-right-radius: 40rpx;
  328. border-bottom-right-radius: 40rpx;
  329. }
  330. }
  331. .picker-box {
  332. display: flex;
  333. .picker-min-box {
  334. height: 80rpx;
  335. line-height: 80rpx;
  336. display: flex;
  337. padding: 0 30rpx;
  338. .icon-box {
  339. margin-left: 10rpx;
  340. }
  341. }
  342. }
  343. }
  344. .content-box {
  345. flex: 1;
  346. display flex;
  347. flex-direction column;
  348. overflow: scroll;
  349. padding-bottom: 40rpx;
  350. .null-p {
  351. text-align: center;
  352. line-height: 300rpx;
  353. color: #999;
  354. }
  355. .for-max-big-box {
  356. padding: 20rpx 30rpx;
  357. background-color: #fff;
  358. border-radius: 10rpx;
  359. margin: 25rpx 25rpx 0;
  360. .for-title-box {
  361. display: flex;
  362. margin-bottom: 20rpx;
  363. view {
  364. padding-bottom: 20rpx;
  365. line-height: 60rpx;
  366. border-bottom: 1rpx solid #dedede;
  367. font-weight: 700;
  368. }
  369. view:nth-child(1) {
  370. color: #666666;
  371. }
  372. view:nth-child(2) {
  373. flex: 1;
  374. text-align: right;
  375. }
  376. }
  377. .for-text-box {
  378. display: flex;
  379. view {
  380. line-height: 60rpx;
  381. font-weight: 700;
  382. }
  383. view:nth-child(1) {
  384. color: #666666;
  385. }
  386. view:nth-child(2) {
  387. flex: 1;
  388. text-align: right;
  389. }
  390. }
  391. }
  392. }
  393. .sao-code-box {
  394. width: 100rpx;
  395. height: 100rpx;
  396. line-height: 100rpx;
  397. text-align: center;
  398. background-color: #266FFF;
  399. border-radius: 50%;
  400. position: absolute;
  401. bottom: 60rpx;
  402. left: 50%;
  403. margin-left: -50rpx;
  404. }
  405. }
  406. </style>