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

274 lines
8.0 KiB

  1. <template>
  2. <view>
  3. <view class="head">
  4. <view class="list">
  5. <view class="lf-row-between">
  6. <view>供应商</view>
  7. <view class="lf-icon" @click="$url('/pages/canteen/classification/supplier')">
  8. <u-icon name="plus-circle" size="42"></u-icon>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="list" v-if="show_material">
  13. <view class="lf-row-between">
  14. <view>采购清单</view>
  15. <view class="lf-icon" @click="$url('/pages/canteen/classification/material?type=1')">
  16. <u-icon name="plus-circle" size="42"></u-icon>
  17. </view>
  18. </view>
  19. <view class="lf-font-24 lf-color-gray">添加物资后可以编辑数量</view>
  20. </view>
  21. </view>
  22. <!-- 修饰条 -->
  23. <self-line></self-line>
  24. <!-- 收货时间 -->
  25. <view class="lf-row-between lf-p-30 lf-p-l-32 lf-p-r-32 lf-font-28">
  26. <view class="lf-color-black">收货时间</view>
  27. <picker mode="date" :value="date" @change="pickerChange">
  28. <view class="lf-color-555 lf-text-right" style="width: 400rpx;">{{ date }}</view>
  29. </picker>
  30. </view>
  31. <self-line></self-line>
  32. <!-- 物料table -->
  33. <view class="lf-p-32 lf-p-t-30 lf-p-b-30 lf-w-100 lf-h-maxcontent lf-border-box">
  34. <view class="lf-font-32 lf-font-bold">物资明细</view>
  35. <view v-for="(value, key) in render_material_list" :key="key" class="lf-m-t-20">
  36. <view class="lf-m-b-10 lf-row-between">
  37. <text>{{ value.supplier_name }}</text>
  38. <text @click="removeSupplier(key)">删除</text>
  39. </view>
  40. <wyb-table :headers="value.headers"
  41. :contents="value.material_list"
  42. contentBgColor="#ecfaf5"
  43. :first-line-fixed="true"
  44. @onInputChange="onInputChange"
  45. width="max-content" height="800rpx"
  46. @onButtonClick="onButtonClick"></wyb-table>
  47. </view>
  48. </view>
  49. <!-- 操作按钮 -->
  50. <view style="height: 100rpx;"></view>
  51. <view class="fixed-bottom">
  52. <button class="btn btn1" @click="save(0)">临时保存</button>
  53. <button class="btn btn2" @click="save(1)">保存并发单</button>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import wybTable from '@/components/wyb-table/wyb-table';
  59. export default {
  60. components: {
  61. wybTable
  62. },
  63. data(){
  64. return {
  65. date: this.$shared.recordTime(new Date(), '-', 'date'), // 选择时间
  66. material_list: {}, // 供应商,物资列表,不被渲染,在底层逻辑运作
  67. show_material: false, // 是否显示采购清单按钮
  68. render_material_list: {} // 渲染出来的物资列表
  69. }
  70. },
  71. onLoad(){
  72. // 监听MaterialList被操作
  73. uni.$on('addMaterialList', res => {
  74. this.material_list = res;
  75. })
  76. },
  77. onShow(){
  78. let material_list = JSON.stringify(this.material_list);
  79. material_list = JSON.parse(material_list);
  80. for(let i in material_list){
  81. // table 标题处理
  82. material_list[i].headers = [{
  83. key: 'material_name',
  84. label: '菜品名称'
  85. },{
  86. key: 'spec_name',
  87. label: '规格'
  88. },{
  89. key: 'unit',
  90. label: '单位'
  91. },{
  92. key: 'brand',
  93. label: '品牌'
  94. },{
  95. key: 'tax_price',
  96. label: '含税价'
  97. },{
  98. key: 'non_tax_price',
  99. label: '不含税价'
  100. },{
  101. key: 'purchase_number',
  102. label: '数量'
  103. },{
  104. key: 'operation',
  105. label: '操作'
  106. }];
  107. // table 内容处理
  108. let list_arr = [];
  109. for(let j in material_list[i].material_list){
  110. material_list[i].material_list[j].purchase_number = {edit: true, value: ''};
  111. material_list[i].material_list[j].operation = {button: true, key: 'delete', value: '删除'};
  112. list_arr.push(material_list[i].material_list[j]);
  113. }
  114. material_list[i].material_list = list_arr;
  115. }
  116. this.render_material_list = material_list;
  117. this.show_material = Object.keys(this.material_list).length > 0;
  118. console.log("show..material_list", this.material_list);
  119. console.log("show...render_material_list", this.render_material_list)
  120. },
  121. methods: {
  122. // table-input值被改变
  123. onInputChange(event){
  124. console.log("检测到table input被更改", event);
  125. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  126. let material_index = event.contentIndex; // 取出第二层,物资下标
  127. let detailValue = event.detailValue; // 取出table input被输入的值
  128. let supplier_item = this.render_material_list[supplier_id]; // 取出所在供应商
  129. let material_item = supplier_item.material_list[material_index]; // 取出物资
  130. material_item.purchase_number.value = detailValue; // 将输入的值赋值给物资
  131. console.log("render_material_list_change", this.render_material_list);
  132. },
  133. // table 操作按钮被点击
  134. onButtonClick(event){
  135. console.log("event", event);
  136. if(event.content.key == 'delete'){
  137. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  138. let material_id = event.lineData.material_id; // 取出第二层,物资id
  139. let material_index = event.lineData.contentIndex; // 取出第二层,物资下标
  140. this.render_material_list[supplier_id].material_list.splice(material_index, 1);
  141. delete this.material_list[supplier_id].material_list[material_id];
  142. }
  143. },
  144. // 时间选择
  145. pickerChange(event){
  146. this.date = event.detail.value;
  147. },
  148. // 移除供应商
  149. removeSupplier(key){
  150. // 移除render_material_list
  151. let render_material_list = {...this.render_material_list};
  152. delete render_material_list[key];
  153. this.render_material_list = render_material_list;
  154. // 移除material_list
  155. delete this.material_list[key];
  156. // 校验还有没有供应商,没有则不能显示选择物资按钮
  157. this.show_material = Object.keys(this.material_list).length > 0;
  158. },
  159. // 保存并发单
  160. save(_t){
  161. let material_list = this.render_material_list;
  162. let list = [];
  163. let is_empty = true; // 物资数据是否为空
  164. for(let i in material_list){
  165. if(Object.keys(material_list[i].material_list).length){
  166. is_empty = false;
  167. let material = material_list[i].material_list;
  168. // 数组写法
  169. let arr = material.map(item => {
  170. return {
  171. m_id: item.material_id,
  172. m_spec_id: item.spec_id,
  173. tax_price: item.tax_price,
  174. non_tax_price: item.non_tax_price,
  175. purchase_number: item.purchase_number.value || 0
  176. }
  177. });
  178. // 对象写法:
  179. // let arr = [];
  180. // for(let j in material){
  181. // arr.push({
  182. // m_id: material[j].material_id,
  183. // m_spec_id: material[j].spec_id,
  184. // tax_price: material[j].tax_price,
  185. // non_tax_price: material[j].non_tax_price,
  186. // purchase_number: material[j].purchase_number.value || 0
  187. // });
  188. // }
  189. list.push({
  190. supplier_id: material_list[i].id,
  191. material: arr
  192. })
  193. }
  194. }
  195. console.log("list", list)
  196. if(is_empty){
  197. this.$msg('您未选择物资');
  198. return;
  199. }
  200. let state = ['待发单', '待审核'][_t];
  201. this.$http(this.API.API_CANTEEN_PURCHASEAPPLY, {
  202. order: list,
  203. state: state
  204. }).then(res => {
  205. console.log("save", res);
  206. this.$msg('操作成功');
  207. })
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped="scoped">
  213. .lf-m-t-5{
  214. margin-top: 5rpx;
  215. }
  216. .head{
  217. width: 750rpx;
  218. height: max-content;
  219. padding: 0 32rpx;
  220. box-sizing: border-box;
  221. .list{
  222. width: 100%;
  223. border-bottom: 1rpx solid #e5e5e5;
  224. padding: 30rpx 0;
  225. font-size: 28rpx;
  226. &:last-child{
  227. border-bottom: none;
  228. }
  229. .lf-icon{
  230. padding: 2rpx 10rpx;
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. }
  235. }
  236. }
  237. .fixed-bottom{
  238. position: fixed;
  239. bottom: 0rpx;
  240. left: 0rpx;
  241. z-index: 99;
  242. width: 750rpx;
  243. height: 98rpx;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. border-top: 1rpx solid #E5E5E5;
  248. background-color: #FFFFFF;
  249. .btn{
  250. width: 320rpx;
  251. height: 82rpx;
  252. border-radius: 41rpx;
  253. margin: 0;
  254. padding: 0;
  255. font-size: 32rpx;
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. .btn1{
  261. border: 2rpx solid #555555;
  262. opacity: .5;
  263. }
  264. .btn2{
  265. background: #11D189;
  266. color: #FFFFFF;
  267. margin-left: 50rpx;
  268. }
  269. }
  270. </style>