自主产品,供应链食堂系统。将两个端拆开了。
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.

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