自主项目,食堂系统,前端uniapp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
5.7 KiB

  1. <template>
  2. <view>
  3. <view class="head" v-if="tab_list.length">
  4. <uni-search-bar @confirm="search" @cancel="cancelSearch" placeholder="搜索物资" radius="90" bgColor="#f6f6f6" ></uni-search-bar>
  5. </view>
  6. <view class="lf-flex content" v-if="tab_list.length">
  7. <scroll-view :scroll-y="true" class="scroll-left"
  8. v-if="!is_search_ing"
  9. :style="{height: 'calc('+ windowHeight +'px - 222rpx)'}">
  10. <view class="tab-item" :class="{'activa': index == current}" v-for="(item, index) in tab_list" :key="index" @click="switchTab(index)">{{ item.m_cate_name }}</view>
  11. </scroll-view>
  12. <scroll-view :scroll-y="true" class="scroll-right"
  13. :style="{height: 'calc('+ windowHeight +'px - 222rpx)', width:is_search_ing?'100%':'550rpx'}">
  14. <view class="supplier-item" v-for="(item, index) in tab_list[current].list" :key="index">
  15. <label class="lf-row-between" @click="switchChecked(item)">
  16. <view style="height: 40rpx;">{{ item.material_name }}</view>
  17. <u-icon name="checkmark-circle-fill" size="40" color="#11D189" v-if="item.checked"></u-icon>
  18. </label>
  19. </view>
  20. <view class="loading-more">
  21. <lf-nocontent v-if="!tab_list[current].list.length"></lf-nocontent>
  22. </view>
  23. </scroll-view>
  24. </view>
  25. <!-- 操作按钮 -->
  26. <view class="fixed-bottom">
  27. <button class="btn btn1" @click="cancel">取消</button>
  28. <button class="btn btn2" @click="submit">确定</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data(){
  35. return {
  36. windowHeight: 0,
  37. tab_list: [],
  38. current: 0, // tab下标
  39. material_name: '', // 当前搜索值,搜索的是物资
  40. checked_list: {},
  41. is_search_ing: false, // 是否处于搜索中
  42. request_count: 0, // 请求次数
  43. }
  44. },
  45. onLoad(options){
  46. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  47. let pages = getCurrentPages();
  48. let prevPage = pages[pages.length - 2];
  49. if(!prevPage){
  50. let path_url = '/pages/canteen/index/index';
  51. this.$msg('页面异常, 即将跳转').then(result => {
  52. this.$url(path_url, {type: 'launch'});
  53. })
  54. return;
  55. }
  56. this.checked_list = prevPage.$data.warehouse_list;
  57. this.getData();
  58. },
  59. methods: {
  60. // 搜索
  61. search(event){
  62. this.is_search_ing = true;
  63. this.material_name = event.value;
  64. this.current = this.tab_list.length; // 搜索的数据放到最后一项
  65. this.tab_list.push({m_cate_name: '搜索', list: []});
  66. this.getData({keyword: event.value});
  67. },
  68. // 取消搜索
  69. cancelSearch(){
  70. this.is_search_ing = false;
  71. this.material_name = '';
  72. this.current = 0;
  73. this.tab_list.pop();
  74. },
  75. // 获取数据
  76. getData(options){
  77. this.request_count++;
  78. this.$http(this.API.API_CANTEEN_MATERIALLISTBYWAREHOUSE, {
  79. ...options
  80. }).then(res => {
  81. if(this.request_count <= 1){
  82. let category = res.data.category || [];
  83. let tab_list = category.map(item => {
  84. item.list = [];
  85. return item;
  86. })
  87. let list = res.data.material.map(item => {
  88. if(this.checked_list[item.material_id]){
  89. item.checked = true;
  90. }else{
  91. item.checked = false;
  92. }
  93. return item;
  94. })
  95. tab_list[this.current].list = list;
  96. this.tab_list = tab_list;
  97. }else{
  98. let list = res.data.material.map(item => {
  99. if(this.checked_list[item.material_id]){
  100. item.checked = true;
  101. }else{
  102. item.checked = false;
  103. }
  104. return item;
  105. })
  106. this.tab_list[this.current].list = list;
  107. }
  108. })
  109. },
  110. // 切换tab
  111. switchTab(current){
  112. this.current = current;
  113. let item = this.tab_list[this.current];
  114. if(item && item.list.length <= 0){ // 已经有数据了,就不在请求了
  115. this.getData({cate_id: item.id});
  116. }
  117. },
  118. // 切换每个供应商的多选状态
  119. switchChecked(item){
  120. item.checked = !item.checked;
  121. if(this.is_search_ing){
  122. this.tab_list.forEach(t_item => {
  123. t_item.list.forEach(l_item => {
  124. if(l_item.material_id == item.material_id){
  125. l_item.checked = item.checked;
  126. }
  127. })
  128. })
  129. }
  130. if(item.checked){
  131. this.checked_list[item.material_id] = item;
  132. }else{
  133. delete this.checked_list[item.material_id];
  134. }
  135. uni.$emit('addWarehouseList', this.checked_list);
  136. console.log("checked_list", this.checked_list)
  137. },
  138. // 全部选择完毕
  139. submit(){
  140. this.$toBack();
  141. },
  142. // 取消
  143. cancel(){
  144. this.checked_list = {};
  145. uni.$emit('addWarehouseList', this.checked_list);
  146. this.$toBack();
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped="scoped">
  152. /deep/.uni-searchbar__box{
  153. border: none;
  154. }
  155. .head{
  156. padding: 14rpx 16rpx;
  157. }
  158. .scroll-left{
  159. width: 200rpx;
  160. background-color: #F6F6F6;
  161. .tab-item{
  162. height: 90rpx;
  163. width: 100%;
  164. text-align: center;
  165. line-height: 90rpx;
  166. font-size: 28rpx;
  167. color: #555555;
  168. }
  169. .activa{
  170. color: #11D189;
  171. }
  172. }
  173. .scroll-right{
  174. width: 550rpx;
  175. background-color: #FFFFFF;
  176. .supplier-item{
  177. padding: 30rpx 32rpx 30rpx 30rpx;
  178. width: 100%;
  179. height: max-content;
  180. box-sizing: border-box;
  181. border-bottom: 1rpx solid #e5e5e5;
  182. font-size: 28rpx;
  183. color: #222222;
  184. }
  185. }
  186. .fixed-bottom{
  187. position: fixed;
  188. bottom: 0rpx;
  189. left: 0rpx;
  190. z-index: 99;
  191. width: 750rpx;
  192. height: 98rpx;
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. border-top: 1rpx solid #E5E5E5;
  197. background-color: #FFFFFF;
  198. box-sizing: border-box;
  199. padding: 0 32rpx;
  200. .btn{
  201. width: 320rpx;
  202. height: 82rpx;
  203. border-radius: 41rpx;
  204. margin: 0;
  205. padding: 0;
  206. font-size: 32rpx;
  207. display: flex;
  208. justify-content: center;
  209. align-items: center;
  210. }
  211. .btn1{
  212. border: 2rpx solid #555555;
  213. opacity: .5;
  214. }
  215. .btn2{
  216. background: #11D189;
  217. color: #FFFFFF;
  218. }
  219. }
  220. </style>