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

260 lines
7.1 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. // #ifdef H5
  67. this.checked_list = prevPage.$data.material_list;
  68. // #endif
  69. // #ifdef MP-WEIXIN
  70. this.checked_list = prevPage.data.material_list;
  71. // #endif
  72. this.getData();
  73. },
  74. methods: {
  75. // 搜索
  76. search(event){
  77. this.is_search_ing = true;
  78. this.material_name = event.value;
  79. this.current = this.tab_list.length; // 搜索的数据放到最后一项
  80. this.tab_list.push({m_cate_name: '搜索', list: []});
  81. this.getData({keyword: event.value});
  82. },
  83. // 取消搜索
  84. cancelSearch(){
  85. this.is_search_ing = false;
  86. this.material_name = '';
  87. this.current = 0;
  88. this.tab_list.pop();
  89. },
  90. // 获取数据
  91. getData(options){
  92. let supplier_ids = Object.keys(this.checked_list);
  93. this.request_count++;
  94. this.$http(this.API.API_CANTEEN_MATERIALLIST, {
  95. supplier_ids: supplier_ids, // 供应商id
  96. ...options
  97. }).then(res => {
  98. if(this.request_count <= 1){
  99. let category = res.data.category || [];
  100. let tab_list = category.map(item => {
  101. item.list = [];
  102. return item;
  103. })
  104. let list = res.data.material.map(item => {
  105. if(this.checked_list[item.supplier_id]){
  106. item.checked = false;
  107. if(this.checked_list[item.supplier_id].material_list[item.item_id]){
  108. item.checked = true;
  109. }
  110. }else{
  111. item.checked = false;
  112. }
  113. return item;
  114. })
  115. tab_list[this.current].list = list;
  116. this.tab_list = tab_list;
  117. }else{
  118. let list = res.data.material.map(item => {
  119. if(this.checked_list[item.supplier_id]){
  120. item.checked = false;
  121. if(this.checked_list[item.supplier_id].material_list[item.item_id]){
  122. item.checked = true;
  123. }
  124. }else{
  125. item.checked = false;
  126. }
  127. return item;
  128. })
  129. this.tab_list[this.current].list = list;
  130. }
  131. })
  132. },
  133. // 切换tab
  134. switchTab(current){
  135. this.current = current;
  136. let item = this.tab_list[this.current];
  137. if(item && item.list.length <= 0){ // 已经有数据了,就不在请求了
  138. this.getData({cate_id: item.id});
  139. }
  140. },
  141. // 切换每个供应商的多选状态
  142. switchChecked(item){
  143. // 备用改变item.checked方案
  144. // let tabItem = this.tab_list[this.current];
  145. // let item = tabItem.list[index];
  146. // item.checked = !item.checked;
  147. // this.tab_list[this.current] = tabItem;
  148. // 新方案
  149. item.checked = !item.checked;
  150. if(this.is_search_ing){
  151. this.tab_list.forEach(t_item => {
  152. t_item.list.forEach(l_item => {
  153. if(l_item.item_id == item.item_id){
  154. l_item.checked = item.checked;
  155. }
  156. })
  157. })
  158. }
  159. if(item.checked){
  160. this.checked_list[item.supplier_id].material_list[item.item_id] = item;
  161. }else{
  162. delete this.checked_list[item.supplier_id].material_list[item.item_id];
  163. }
  164. uni.$emit('addMaterialList', this.checked_list);
  165. console.log("checked_list", this.checked_list)
  166. },
  167. // 全部选择完毕
  168. submit(){
  169. console.log("sssss",this.tab_list);
  170. console.log("kkkk", this.checked_list);
  171. let page_num = 2; // 默认跳回前两个页面
  172. if(this.type == 1){
  173. page_num = 1;
  174. }
  175. this.$toBack(page_num);
  176. },
  177. // 上一步
  178. prev(){
  179. let pages = getCurrentPages();
  180. let prevPage = pages[pages.length - 2]; // 上一页
  181. this.checked_list = prevPage.$data.checked_list;
  182. uni.$emit('addMaterialList', this.checked_list);
  183. this.$toBack();
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped="scoped">
  189. /deep/.uni-searchbar__box{
  190. border: none;
  191. }
  192. .head{
  193. padding: 14rpx 16rpx;
  194. }
  195. .scroll-left{
  196. width: 200rpx;
  197. background-color: #F6F6F6;
  198. .tab-item{
  199. height: 90rpx;
  200. width: 100%;
  201. text-align: center;
  202. line-height: 90rpx;
  203. font-size: 28rpx;
  204. color: #555555;
  205. }
  206. .activa{
  207. color: #11D189;
  208. }
  209. }
  210. .scroll-right{
  211. width: 550rpx;
  212. background-color: #FFFFFF;
  213. .supplier-item{
  214. padding: 30rpx 32rpx 30rpx 30rpx;
  215. width: 100%;
  216. height: max-content;
  217. box-sizing: border-box;
  218. border-bottom: 1rpx solid #e5e5e5;
  219. font-size: 28rpx;
  220. color: #222222;
  221. }
  222. }
  223. .fixed-bottom{
  224. position: fixed;
  225. bottom: 0rpx;
  226. left: 0rpx;
  227. z-index: 99;
  228. width: 750rpx;
  229. height: 98rpx;
  230. display: flex;
  231. justify-content: space-between;
  232. align-items: center;
  233. border-top: 1rpx solid #E5E5E5;
  234. background-color: #FFFFFF;
  235. box-sizing: border-box;
  236. padding: 0 32rpx;
  237. .btn{
  238. width: 320rpx;
  239. height: 82rpx;
  240. border-radius: 41rpx;
  241. margin: 0;
  242. padding: 0;
  243. font-size: 32rpx;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. }
  248. .btn1{
  249. border: 2rpx solid #555555;
  250. opacity: .5;
  251. }
  252. .btn2{
  253. background: #11D189;
  254. color: #FFFFFF;
  255. }
  256. }
  257. </style>