自主项目,食堂系统,前端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.

327 lines
8.8 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="prev">上一步</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(){
  46. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  47. let pages = getCurrentPages();
  48. let prevPage = pages[pages.length - 3]; // 上上一页
  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.material_list;
  57. /*
  58. this.checked_list = {
  59. "1": {
  60. address: "广西南宁市青秀区青秀万达店",
  61. admin_uid: 1,
  62. area_id: 2165,
  63. checked: true,
  64. city_id: 2163,
  65. corporate_account: "6214456799861234",
  66. corporate_account_name: "刘淑怡粮油店",
  67. corporate_bank: "招商银行",
  68. corporate_bank_sub: "青秀区支行",
  69. corporate_name: "法人",
  70. corporate_phone: "15699896658",
  71. created_at: "2021-07-17 11:34:50",
  72. created_uid: 1,
  73. ctl_man: "刘淑怡",
  74. ctl_phone: "13397706896",
  75. deleted_at: null,
  76. deleted_uid: 0,
  77. id: 1,
  78. license_number: "11559896646",
  79. license_pic: "admin_images/5bbbc1e4f96bc5566c43bb006d36cc37.jpg",
  80. logo: "admin_images/83e16f0d0c9dd01f1bfd62ddf150607e.jpeg",
  81. material_list: {},
  82. private_account: "",
  83. private_account_name: "",
  84. private_bank: "",
  85. private_bank_sub: "",
  86. province_id: 2162,
  87. qualification_pic: "",
  88. remark: "测试备注,我只改个备注",
  89. s_cate_id: 1,
  90. state: "启用",
  91. subject_name: "主体名称",
  92. subject_type: "公司",
  93. supplier_name: "供应商001",
  94. updated_at: "2021-07-17 16:25:58",
  95. updated_uid: 1
  96. },
  97. "2": {
  98. address: "F座6楼",
  99. admin_uid: 3,
  100. area_id: 2165,
  101. checked: true,
  102. city_id: 2163,
  103. corporate_account: "",
  104. corporate_account_name: "",
  105. corporate_bank: "",
  106. corporate_bank_sub: "",
  107. corporate_name: "",
  108. corporate_phone: "",
  109. created_at: "2021-07-17 20:28:17",
  110. created_uid: 1,
  111. ctl_man: "芳芳",
  112. ctl_phone: "13397706896",
  113. deleted_at: null,
  114. deleted_uid: 0,
  115. id: 2,
  116. license_number: "",
  117. license_pic: "",
  118. logo: "admin_images/skyshareimg.jpeg",
  119. material_list: {},
  120. private_account: "",
  121. private_account_name: "",
  122. private_bank: "",
  123. private_bank_sub: "",
  124. province_id: 2162,
  125. qualification_pic: "",
  126. remark: "",
  127. s_cate_id: 2,
  128. state: "启用",
  129. subject_name: "",
  130. subject_type: "公司",
  131. supplier_name: "供应商002",
  132. updated_at: "2021-07-27 12:00:01",
  133. updated_uid: 1
  134. }
  135. };
  136. */
  137. this.getData();
  138. },
  139. methods: {
  140. // 搜索
  141. search(event){
  142. this.is_search_ing = true;
  143. this.material_name = event.value;
  144. this.current = this.tab_list.length; // 搜索的数据放到最后一项
  145. this.tab_list.push({m_cate_name: '搜索', list: []});
  146. this.getData({keyword: event.value});
  147. },
  148. // 取消搜索
  149. cancelSearch(){
  150. this.is_search_ing = false;
  151. this.material_name = '';
  152. this.current = 0;
  153. this.tab_list.pop();
  154. },
  155. // 获取数据
  156. getData(options){
  157. let supplier_ids = Object.keys(this.checked_list);
  158. this.request_count++;
  159. this.$http(this.API.API_CANTEEN_MATERIALLIST, {
  160. supplier_ids: supplier_ids, // 供应商id
  161. ...options
  162. }).then(res => {
  163. if(this.request_count <= 1){
  164. let category = res.data.category || [];
  165. let tab_list = category.map(item => {
  166. item.list = [];
  167. return item;
  168. })
  169. let list = res.data.material.map(item => {
  170. if(this.checked_list[item.supplier_id]){
  171. item.checked = false;
  172. if(this.checked_list[item.supplier_id].material_list[item.material_id]){
  173. item.checked = true;
  174. }
  175. }else{
  176. item.checked = false;
  177. }
  178. return item;
  179. })
  180. tab_list[this.current].list = list;
  181. this.tab_list = tab_list;
  182. }else{
  183. let list = res.data.material.map(item => {
  184. if(this.checked_list[item.supplier_id]){
  185. item.checked = false;
  186. if(this.checked_list[item.supplier_id].material_list[item.material_id]){
  187. item.checked = true;
  188. }
  189. }else{
  190. item.checked = false;
  191. }
  192. return item;
  193. })
  194. this.tab_list[this.current].list = list;
  195. }
  196. })
  197. },
  198. // 切换tab
  199. switchTab(current){
  200. this.current = current;
  201. let item = this.tab_list[this.current];
  202. if(item && item.list.length <= 0){ // 已经有数据了,就不在请求了
  203. this.getData({cate_id: item.id});
  204. }
  205. },
  206. // 切换每个供应商的多选状态
  207. switchChecked(item){
  208. // 备用改变item.checked方案
  209. // let tabItem = this.tab_list[this.current];
  210. // let item = tabItem.list[index];
  211. // item.checked = !item.checked;
  212. // this.tab_list[this.current] = tabItem;
  213. // 新方案
  214. item.checked = !item.checked;
  215. if(this.is_search_ing){
  216. this.tab_list.forEach(t_item => {
  217. t_item.list.forEach(l_item => {
  218. if(l_item.material_id == item.material_id){
  219. l_item.checked = item.checked;
  220. }
  221. })
  222. })
  223. }
  224. if(item.checked){
  225. this.checked_list[item.supplier_id].material_list[item.material_id] = item;
  226. }else{
  227. delete this.checked_list[item.supplier_id].material_list[item.material_id];
  228. }
  229. uni.$emit('addMaterialList', this.checked_list);
  230. console.log("checked_list", this.checked_list)
  231. },
  232. // 全部选择完毕
  233. submit(){
  234. console.log("sssss",this.tab_list);
  235. console.log("kkkk", this.checked_list);
  236. // todo关闭所有页面跳转
  237. // this.$url('/pages/canteen/purchase/launch', {type: 'launch'})
  238. // this.$toBack(2); // 跳回前两个页面
  239. },
  240. // 上一步
  241. prev(){
  242. let pages = getCurrentPages();
  243. let prevPage = pages[pages.length - 2]; // 上一页
  244. this.checked_list = prevPage.$data.checked_list;
  245. uni.$emit('addMaterialList', this.checked_list);
  246. this.$toBack();
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="scss" scoped="scoped">
  252. /deep/.uni-searchbar__box{
  253. border: none;
  254. }
  255. .head{
  256. padding: 14rpx 16rpx;
  257. }
  258. .scroll-left{
  259. width: 200rpx;
  260. background-color: #F6F6F6;
  261. .tab-item{
  262. height: 90rpx;
  263. width: 100%;
  264. text-align: center;
  265. line-height: 90rpx;
  266. font-size: 28rpx;
  267. color: #555555;
  268. }
  269. .activa{
  270. color: #11D189;
  271. }
  272. }
  273. .scroll-right{
  274. width: 550rpx;
  275. background-color: #FFFFFF;
  276. .supplier-item{
  277. padding: 30rpx 32rpx 30rpx 30rpx;
  278. width: 100%;
  279. height: max-content;
  280. box-sizing: border-box;
  281. border-bottom: 1rpx solid #e5e5e5;
  282. font-size: 28rpx;
  283. color: #222222;
  284. }
  285. }
  286. .fixed-bottom{
  287. position: fixed;
  288. bottom: 0rpx;
  289. left: 0rpx;
  290. z-index: 99;
  291. width: 750rpx;
  292. height: 98rpx;
  293. display: flex;
  294. justify-content: space-between;
  295. align-items: center;
  296. border-top: 1rpx solid #E5E5E5;
  297. background-color: #FFFFFF;
  298. box-sizing: border-box;
  299. padding: 0 32rpx;
  300. .btn{
  301. width: 320rpx;
  302. height: 82rpx;
  303. border-radius: 41rpx;
  304. margin: 0;
  305. padding: 0;
  306. font-size: 32rpx;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. }
  311. .btn1{
  312. border: 2rpx solid #555555;
  313. opacity: .5;
  314. }
  315. .btn2{
  316. background: #11D189;
  317. color: #FFFFFF;
  318. }
  319. }
  320. </style>