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

231 lines
6.1 KiB

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