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

323 lines
9.6 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/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/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)" class="lf-color-price">删除</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. date: '',
  67. material_list: {}, // 供应商,物资列表,不被渲染,在底层逻辑运作
  68. show_material: false, // 是否显示采购清单按钮
  69. render_material_list: {} // 渲染出来的物资列表
  70. }
  71. },
  72. onLoad(){
  73. // 监听MaterialList被操作
  74. uni.$on('addMaterialList', res => {
  75. this.material_list = res;
  76. })
  77. },
  78. onShow(){
  79. let material_list = JSON.stringify(this.material_list);
  80. material_list = JSON.parse(material_list);
  81. for(let i in material_list){
  82. // table 标题处理
  83. material_list[i].headers = [{
  84. key: 'material_name',
  85. label: '物资名称'
  86. },{
  87. key: 'spec_name',
  88. label: '规格'
  89. },{
  90. key: 'brand',
  91. label: '品牌'
  92. },{
  93. key: 'quality_level',
  94. label: '品级'
  95. },{
  96. label: '编号',
  97. key: 'm_sn'
  98. },{
  99. label: '供应商',
  100. key: 'supplier_name'
  101. },{
  102. key: 'tax_price',
  103. label: '含税价'
  104. },{
  105. key: 'non_tax_price',
  106. label: '不含税价'
  107. },{
  108. key: 'purchase_limit',
  109. label: '起购数'
  110. },{
  111. key: 'purchase_number',
  112. label: '采购数量'
  113. },{
  114. key: 'operation',
  115. label: '操作'
  116. }];
  117. // table 内容处理
  118. let list_arr = [];
  119. for(let j in material_list[i].material_list){
  120. material_list[i].material_list[j].purchase_number = {edit: true, value: ''};
  121. material_list[i].material_list[j].operation = {button: true, key: 'delete', value: '删除'};
  122. material_list[i].material_list[j].supplier_name = material_list[i].supplier_name;
  123. material_list[i].material_list[j].tax_price = material_list[i].material_list[j].tax_price;
  124. material_list[i].material_list[j].non_tax_price = material_list[i].material_list[j].non_tax_price;
  125. // material_list[i].material_list[j].star_num = material_list[i].material_list[j].purchase_limit;
  126. list_arr.push(material_list[i].material_list[j]);
  127. }
  128. material_list[i].material_list = list_arr;
  129. }
  130. this.render_material_list = material_list;
  131. this.show_material = Object.keys(this.material_list).length > 0;
  132. console.log("show..material_list", this.material_list);
  133. console.log("show...render_material_list", this.render_material_list)
  134. },
  135. methods: {
  136. // table-input值被改变
  137. onInputChange(event){
  138. console.log("检测到table input被更改", event);
  139. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  140. let material_index = event.contentIndex; // 取出第二层,物资下标
  141. let detailValue = event.detailValue; // 取出table input被输入的值
  142. let supplier_item = this.render_material_list[supplier_id]; // 取出所在供应商
  143. let material_item = supplier_item.material_list[material_index]; // 取出物资
  144. if(material_item.purchase_limit <= detailValue){
  145. material_item.purchase_number.value = detailValue; // 将输入的值赋值给物资
  146. }else{
  147. uni.showModal({
  148. title: '温馨提示',
  149. content: '采购数量必须大于起购数量',
  150. showCancel: false,
  151. success: result => {
  152. material_item.purchase_number.value = material_item.purchase_limit;
  153. }
  154. })
  155. }
  156. console.log("render_material_list_change", this.render_material_list);
  157. },
  158. // table 操作按钮被点击
  159. onButtonClick(event){
  160. console.log("event", event);
  161. if(event.content.key == 'delete'){
  162. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  163. let item_id = event.lineData.item_id; // 取出第二层,item_id
  164. let material_index = event.lineData.contentIndex; // 取出第二层,物资下标
  165. this.render_material_list[supplier_id].material_list.splice(material_index, 1);
  166. delete this.material_list[supplier_id].material_list[item_id];
  167. }
  168. },
  169. // 时间选择
  170. pickerChange(event){
  171. this.date = event.detail.value;
  172. },
  173. // 移除供应商
  174. removeSupplier(key){
  175. uni.showModal({
  176. title: '温馨提示',
  177. content: '删除供应商后所添加的物资将随之移除,确定继续吗?',
  178. confirmColor: '#FF0000',
  179. cancelColor: '#11D189',
  180. success: result => {
  181. if(result.confirm){
  182. // 移除render_material_list
  183. let render_material_list = {...this.render_material_list};
  184. delete render_material_list[key];
  185. this.render_material_list = render_material_list;
  186. // 移除material_list
  187. delete this.material_list[key];
  188. // 校验还有没有供应商,没有则不能显示选择物资按钮
  189. this.show_material = Object.keys(this.material_list).length > 0;
  190. }
  191. }
  192. })
  193. },
  194. // 保存并发单
  195. save(_t){
  196. let material_list = this.render_material_list;
  197. let list = [];
  198. let is_empty = true; // 物资数据是否为空
  199. let is_right = true; // 采购份数为正常的情况
  200. for(let i in material_list){
  201. if(Object.keys(material_list[i].material_list).length){
  202. is_empty = false;
  203. let material = material_list[i].material_list;
  204. // 数组写法
  205. let arr = material.map(item => {
  206. if(item.purchase_limit > item.purchase_number.value){
  207. is_right = false;
  208. };
  209. return {
  210. m_id: item.material_id,
  211. m_spec_id: item.spec_id,
  212. tax_price: item.tax_price,
  213. non_tax_price: item.non_tax_price,
  214. purchase_number: Number(item.purchase_number.value) || item.purchase_limit
  215. }
  216. });
  217. // 对象写法:
  218. // let arr = [];
  219. // for(let j in material){
  220. // arr.push({
  221. // m_id: material[j].material_id,
  222. // m_spec_id: material[j].spec_id,
  223. // tax_price: material[j].tax_price,
  224. // non_tax_price: material[j].non_tax_price,
  225. // purchase_number: material[j].purchase_number.value || 0
  226. // });
  227. // }
  228. list.push({
  229. supplier_id: material_list[i].id,
  230. material: arr
  231. })
  232. }
  233. }
  234. console.log("list", list)
  235. let deadline = this.date;
  236. if(!deadline){
  237. this.$msg('请选择收货时间');
  238. return;
  239. }
  240. if(is_empty){
  241. this.$msg('您未选择物资');
  242. return;
  243. }
  244. if(!is_right){
  245. this.$msg('采购数量需大于起购数量');
  246. return;
  247. }
  248. // let state = ['待发单', '待审核'][_t];
  249. this.$http(this.API.API_CANTEEN_PURCHASEAPPLY, {
  250. order: list,
  251. state: _t,
  252. deadline: deadline
  253. }).then(res => {
  254. console.log("save", res);
  255. this.$msg('操作成功');
  256. })
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped="scoped">
  262. .lf-m-t-5{
  263. margin-top: 5rpx;
  264. }
  265. .head{
  266. width: 750rpx;
  267. height: max-content;
  268. padding: 0 32rpx;
  269. box-sizing: border-box;
  270. .list{
  271. width: 100%;
  272. border-bottom: 1rpx solid #e5e5e5;
  273. padding: 30rpx 0;
  274. font-size: 28rpx;
  275. &:last-child{
  276. border-bottom: none;
  277. }
  278. .lf-icon{
  279. padding: 2rpx 10rpx;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  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: center;
  295. align-items: center;
  296. border-top: 1rpx solid #E5E5E5;
  297. background-color: #FFFFFF;
  298. .btn{
  299. width: 320rpx;
  300. height: 82rpx;
  301. border-radius: 41rpx;
  302. margin: 0;
  303. padding: 0;
  304. font-size: 32rpx;
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. }
  309. .btn1{
  310. border: 2rpx solid #555555;
  311. opacity: .5;
  312. }
  313. .btn2{
  314. background: #11D189;
  315. color: #FFFFFF;
  316. margin-left: 50rpx;
  317. }
  318. }
  319. </style>