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

222 lines
5.8 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 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" :contents="value.material_list" contentBgColor="#ecfaf5" :first-line-fixed="true" @onInputChange="onInputChange" width="max-content" height="800rpx"></wyb-table>
  41. </view>
  42. </view>
  43. <!-- 操作按钮 -->
  44. <view style="height: 100rpx;"></view>
  45. <view class="fixed-bottom">
  46. <button class="btn btn1" @click="save(0)">临时保存</button>
  47. <button class="btn btn2" @click="save(1)">保存并发单</button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import wybTable from '@/components/wyb-table/wyb-table';
  53. export default {
  54. components: {
  55. wybTable
  56. },
  57. data(){
  58. return {
  59. date: this.$shared.recordTime(new Date(), '-', 'date'), // 选择时间
  60. material_list: {}, // 供应商,物资列表
  61. show_material: false,
  62. render_material_list: []
  63. }
  64. },
  65. onLoad(){
  66. // todo 验证table有没有问题,因为它是从对象转为数组的
  67. // todo 选择供应商但未选择物资,点进去选择物资,选完回到当前页面,table没有显示
  68. // 监听MaterialList被操作
  69. uni.$on('addMaterialList', res => {
  70. this.material_list = res;
  71. })
  72. },
  73. onShow(){
  74. let material_list = this.material_list;
  75. for(let i in material_list){
  76. // table 标题处理
  77. material_list[i].headers = [{
  78. key: 'material_name',
  79. label: '菜品名称'
  80. },{
  81. key: 'spec_name',
  82. label: '规格'
  83. },{
  84. key: 'purchase_number',
  85. label: '采购数量'
  86. },{
  87. key: 'tax_price',
  88. label: '税前价'
  89. },{
  90. key: 'non_tax_price',
  91. label: '税后价'
  92. }];
  93. // table 内容处理
  94. for(let j in material_list[i].material_list){
  95. material_list[i].material_list[j].purchase_number = {edit: true, value: ''};
  96. }
  97. }
  98. this.material_list = material_list;
  99. this.show_material = Object.keys(this.material_list).length > 0;
  100. },
  101. methods: {
  102. // table-input值被改变 todo
  103. onInputChange(event){
  104. console.log("检测到table input被更改", event);
  105. // this.contents[event.contentIndex][event.key].value = event.detailValue;
  106. },
  107. // 时间选择
  108. pickerChange(event){
  109. this.date = event.detail.value;
  110. },
  111. // 移除供应商
  112. removeSupplier(key){
  113. let material_list = {...this.material_list};
  114. delete material_list[key];
  115. this.material_list = material_list;
  116. },
  117. // 保存并发单
  118. save(_t){
  119. let material_list = this.material_list;
  120. let list = [];
  121. let is_empty = true; // 物资数据是否为空
  122. for(let i in material_list){
  123. if(Object.keys(material_list[i].material_list).length){
  124. is_empty = false;
  125. let material = material_list[i].material_list;
  126. let arr = [];
  127. for(let j in material){
  128. arr.push({
  129. m_id: material[j].material_id,
  130. m_spec_id: material[j].spec_id,
  131. tax_price: material[j].tax_price,
  132. non_tax_price: material[j].non_tax_price,
  133. purchase_number: material[j].purchase_number.value || 0
  134. });
  135. }
  136. list.push({
  137. supplier_id: material_list[i].id,
  138. material: arr
  139. })
  140. }
  141. }
  142. console.log("list", list)
  143. if(is_empty){
  144. this.$msg('您未选择物资');
  145. return;
  146. }
  147. let state = ['待发单', '待审核'][_t];
  148. this.$http(this.API.API_CANTEEN_PURCHASEAPPLY, {
  149. order: list,
  150. state: state
  151. }).then(res => {
  152. console.log("save", res);
  153. this.$msg('操作成功');
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped="scoped">
  160. .lf-m-t-5{
  161. margin-top: 5rpx;
  162. }
  163. .head{
  164. width: 750rpx;
  165. height: max-content;
  166. padding: 0 32rpx;
  167. box-sizing: border-box;
  168. .list{
  169. width: 100%;
  170. border-bottom: 1rpx solid #e5e5e5;
  171. padding: 30rpx 0;
  172. font-size: 28rpx;
  173. &:last-child{
  174. border-bottom: none;
  175. }
  176. .lf-icon{
  177. padding: 2rpx 10rpx;
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. }
  182. }
  183. }
  184. .fixed-bottom{
  185. position: fixed;
  186. bottom: 0rpx;
  187. left: 0rpx;
  188. z-index: 99;
  189. width: 750rpx;
  190. height: 98rpx;
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. border-top: 1rpx solid #E5E5E5;
  195. background-color: #FFFFFF;
  196. .btn{
  197. width: 320rpx;
  198. height: 82rpx;
  199. border-radius: 41rpx;
  200. margin: 0;
  201. padding: 0;
  202. font-size: 32rpx;
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. }
  207. .btn1{
  208. border: 2rpx solid #555555;
  209. opacity: .5;
  210. }
  211. .btn2{
  212. background: #11D189;
  213. color: #FFFFFF;
  214. margin-left: 50rpx;
  215. }
  216. }
  217. </style>