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

414 lines
12 KiB

5 years ago
5 years ago
  1. <template>
  2. <view>
  3. <view class="head">
  4. <view class="list" @click="addSupplier">
  5. <view class="lf-row-between">
  6. <view>供应商</view>
  7. <view class="lf-icon">
  8. <u-icon name="plus-circle" size="42"></u-icon>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="list" v-if="show_material" @click="$url('/pages/classification/material?type=1')">
  13. <view class="lf-row-between">
  14. <view>采购清单</view>
  15. <view class="lf-icon">
  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;">{{ '请选择收货时间...' }}</view> -->
  29. <view class="lf-color-555 lf-text-right" style="width: 400rpx;">{{ date }}</view>
  30. </picker>
  31. </view>
  32. <self-line></self-line>
  33. <!-- 物料table -->
  34. <view class="lf-p-32 lf-p-t-30 lf-p-b-30 lf-w-100 lf-h-maxcontent lf-border-box">
  35. <view class="lf-font-32 lf-font-bold">物资明细</view>
  36. <view v-for="(value, key) in render_material_list" :key="key" class="lf-m-t-20" v-if="value.material_list.length">
  37. <view class="lf-m-b-20 lf-row-between">
  38. <view>{{ value.supplier_name }}</view>
  39. <button @click="removeSupplier(key)" class="remove-btn">全部删除</button>
  40. </view>
  41. <wyb-table :headers="value.headers"
  42. :contents="value.material_list"
  43. contentBgColor="#ecfaf5"
  44. :first-line-fixed="true"
  45. @onInputChange="onInputChange"
  46. width="max-content" height="800rpx"
  47. @onButtonClick="onButtonClick"></wyb-table>
  48. </view>
  49. </view>
  50. <!-- 操作按钮 -->
  51. <view style="height: 140rpx;"></view>
  52. <view class="fixed-bottom">
  53. <button class="btn btn1" @click="save(0)">临时保存</button>
  54. <button class="btn btn2" @click="save(1)">保存并发单</button>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import wybTable from '@/components/wyb-table/wyb-table';
  60. export default {
  61. components: {
  62. wybTable
  63. },
  64. data(){
  65. return {
  66. date: this.$shared.recordTime(new Date(), '-', 'date'), // 选择时间, 默认今天
  67. // date: '',
  68. material_list: {}, // 供应商,物资列表,不被渲染,在底层逻辑运作
  69. show_material: false, // 是否显示采购清单按钮
  70. render_material_list: {}, // 渲染出来的物资列表
  71. show_count: 0, // 页面显示次数
  72. p_sn: '', // 订单号,如果有
  73. type: 0 ,// 类型, 1编辑, 2复用
  74. first_time: true
  75. }
  76. },
  77. onLoad(options){
  78. // 监听MaterialList被操作
  79. uni.$on('addMaterialList', res => {
  80. this.material_list = res;
  81. })
  82. if(options){
  83. this.p_sn = options.p_sn || '';
  84. this.type = options.enter_type || 0;
  85. if(options.enter_type == 1 || options.enter_type == 2){
  86. this.copyMaterialList(); // 复用采购单
  87. }
  88. }
  89. },
  90. onShow(){
  91. this.show_count++;
  92. if(this.show_count > 1){
  93. this.transformList();
  94. }
  95. },
  96. methods: {
  97. // 物资列表转换成页面可渲染的格式,material_list => render_material_list
  98. transformList(){
  99. let material_list = JSON.stringify(this.material_list);
  100. material_list = JSON.parse(material_list);
  101. for(let i in material_list){
  102. // table 标题处理
  103. material_list[i].headers = [{
  104. key: 'material_name',
  105. label: '物资名称'
  106. },{
  107. key: 'spec_name',
  108. label: '规格'
  109. },{
  110. label: '单位',
  111. key: 'unit'
  112. },{
  113. label: '分类',
  114. key: 'category'
  115. },{
  116. key: 'brand',
  117. label: '品牌'
  118. },{
  119. key: 'quality_level',
  120. label: '品级'
  121. },{
  122. label: '编号',
  123. key: 'm_sn'
  124. },{
  125. label: '供应商',
  126. key: 'supplier_name'
  127. },{
  128. key: 'tax_price',
  129. label: '含税价'
  130. },{
  131. key: 'non_tax_price',
  132. label: '不含税价'
  133. },{
  134. key: 'purchase_limit',
  135. label: '起购数'
  136. },{
  137. key: 'purchase_number',
  138. label: '采购数量'
  139. },{
  140. key: 'operation',
  141. label: '操作'
  142. }];
  143. // table 内容处理
  144. let list_arr = [];
  145. for(let j in material_list[i].material_list){
  146. material_list[i].material_list[j].purchase_number = {edit: true, value: material_list[i].material_list[j].purchase_number || ''};
  147. material_list[i].material_list[j].operation = {button: true, key: 'delete', value: '删除'};
  148. material_list[i].material_list[j].supplier_name = material_list[i].supplier_name;
  149. material_list[i].material_list[j].tax_price = material_list[i].material_list[j].tax_price;
  150. material_list[i].material_list[j].non_tax_price = material_list[i].material_list[j].non_tax_price;
  151. material_list[i].material_list[j].unit = material_list[i].material_list[j].unit.unit_name;
  152. material_list[i].material_list[j].category = material_list[i].material_list[j].category.m_cate_name;
  153. list_arr.push(material_list[i].material_list[j]);
  154. }
  155. material_list[i].material_list = list_arr;
  156. }
  157. this.render_material_list = material_list;
  158. this.show_material = Object.keys(this.material_list).length > 0;
  159. console.log("transform..material_list", this.material_list);
  160. console.log("transform...render_material_list", this.render_material_list)
  161. },
  162. // 复用采购单
  163. copyMaterialList(){
  164. this.$http(this.API.API_BUYREUSE, {
  165. p_sn: this.p_sn
  166. }).then(res => {
  167. let list = res.data || [];
  168. let material_list = {};
  169. list.map(item => {
  170. let items = item.purchase[0]?.items || [];
  171. let items_obj = {};
  172. items.map(i_item => {
  173. items_obj[i_item.quotation_item_id] = {
  174. brand: i_item?.material?.brand || '',
  175. checked: true,
  176. item_id: i_item.quotation_item_id,
  177. m_sn: i_item?.material?.m_sn || '',
  178. material_id: i_item?.material?.id || 0,
  179. material_name: i_item?.material?.m_name || '',
  180. non_tax_price: i_item.non_tax_price,
  181. purchase_limit: i_item?.p_order_item?.purchase_limit || '',
  182. quality_level: i_item?.material?.quality_level || '',
  183. spec_id: i_item?.spec?.id || 0,
  184. spec_name: i_item?.spec?.name || '',
  185. supplier_id: item.id,
  186. supplier_name: item.supplier_name,
  187. tax_price: i_item.tax_price,
  188. purchase_number: i_item.purchase_number,
  189. unit: i_item?.material?.unit || {},
  190. category: i_item?.material?.category || {}
  191. };
  192. if(i_item?.material?.state && i_item?.material?.state != '启用'){
  193. items_obj[i_item.quotation_item_id].disabled = true;
  194. }
  195. });
  196. item.material_list = items_obj;
  197. material_list[item.id] = item;
  198. this.date = item.purchase[0]?.deadline_text || '';
  199. })
  200. this.material_list = material_list;
  201. this.transformList();
  202. })
  203. },
  204. // table-input值被改变
  205. onInputChange(event){
  206. console.log("检测到table input被更改", event);
  207. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  208. let material_index = event.contentIndex; // 取出第二层,物资下标
  209. let detailValue = event.detailValue; // 取出table input被输入的值
  210. let supplier_item = this.render_material_list[supplier_id]; // 取出所在供应商
  211. let material_item = supplier_item.material_list[material_index]; // 取出物资
  212. if(material_item.purchase_limit <= detailValue){
  213. material_item.purchase_number.value = detailValue; // 将输入的值赋值给物资
  214. }else{
  215. this.$msg('采购数量须大于起购数量');
  216. material_item.purchase_number.value = material_item.purchase_limit;
  217. // uni.showModal({
  218. // title: '温馨提示',
  219. // content: '采购数量必须大于起购数量',
  220. // showCancel: false,
  221. // success: result => {
  222. // material_item.purchase_number.value = material_item.purchase_limit;
  223. // }
  224. // })
  225. }
  226. console.log("render_material_list_change", this.render_material_list);
  227. },
  228. // table 操作按钮被点击
  229. onButtonClick(event){
  230. if(event.content.key == 'delete'){
  231. let material_index = event.contentIndex;
  232. let material_name = event.lineData.material_name;
  233. let spec_name = event.lineData.spec_name;
  234. let supplier_id = event.lineData.supplier_id;
  235. let item_id = event.lineData.item_id;
  236. uni.showModal({
  237. title: '温馨提示',
  238. content: `确定删除 ${material_name}-${spec_name} 吗?`,
  239. cancelColor: '#11D189',
  240. confirmColor: '#FF0000',
  241. success: result => {
  242. if(result.confirm){
  243. this.render_material_list[supplier_id].material_list.splice(material_index, 1);
  244. delete this.material_list[supplier_id].material_list[item_id];
  245. }
  246. }
  247. })
  248. }
  249. },
  250. // 时间选择
  251. pickerChange(event){
  252. this.date = event.detail.value;
  253. this.first_time = false
  254. },
  255. // 移除供应商
  256. removeSupplier(key){
  257. uni.showModal({
  258. title: '温馨提示',
  259. content: '删除供应商后所添加的物资将随之移除,确定继续吗?',
  260. confirmColor: '#FF0000',
  261. cancelColor: '#11D189',
  262. success: result => {
  263. if(result.confirm){
  264. // 移除render_material_list
  265. let render_material_list = {...this.render_material_list};
  266. delete render_material_list[key];
  267. this.render_material_list = render_material_list;
  268. // 移除material_list
  269. delete this.material_list[key];
  270. // 校验还有没有供应商,没有则不能显示选择物资按钮
  271. this.show_material = Object.keys(this.material_list).length > 0;
  272. }
  273. }
  274. })
  275. },
  276. // 保存并发单
  277. save(_t){
  278. let material_list = this.render_material_list;
  279. let list = [];
  280. let is_empty = true; // 物资数据是否为空
  281. let is_right = true; // 采购份数为正常的情况
  282. for(let i in material_list){
  283. if(Object.keys(material_list[i].material_list).length){
  284. is_empty = false;
  285. let material = material_list[i].material_list;
  286. // 数组写法
  287. let arr = material.map(item => {
  288. if(item.purchase_limit > item.purchase_number.value){
  289. is_right = false;
  290. };
  291. return {
  292. m_id: item.material_id,
  293. quotation_item_id: item.item_id,
  294. m_spec_id: item.spec_id,
  295. tax_price: item.tax_price,
  296. non_tax_price: item.non_tax_price,
  297. purchase_number: Number(item.purchase_number.value) || item.purchase_limit
  298. }
  299. });
  300. list.push({
  301. supplier_id: material_list[i].id,
  302. material: arr
  303. })
  304. }
  305. }
  306. let deadline = this.date;
  307. if(!deadline){
  308. this.$msg('请选择收货时间');
  309. return;
  310. }
  311. if(is_empty){
  312. this.$msg('您未选择物资');
  313. return;
  314. }
  315. if(!is_right){
  316. this.$msg('采购数量需大于起购数量');
  317. return;
  318. }
  319. let _api = this.API.API_CANTEEN_PURCHASEAPPLY;
  320. let _data = {
  321. order: list,
  322. state: _t,
  323. deadline: deadline
  324. };
  325. if(this.type == 1){
  326. _api = this.API.API_CANTEEN_PURCHASESAVE;
  327. _data.p_sn = this.p_sn;
  328. }
  329. this.$http(_api, _data).then(res => {
  330. this.$msg('操作成功').then(()=>{this.$toBack()});
  331. })
  332. },
  333. // 页面跳转添加供应商
  334. addSupplier(){
  335. if(this.type == 1){
  336. return this.$msg('编辑时不可更换供应商');
  337. }
  338. this.$url('/pages/classification/supplier');
  339. }
  340. }
  341. }
  342. </script>
  343. <style lang="scss" scoped="scoped">
  344. .lf-m-t-5{
  345. margin-top: 5rpx;
  346. }
  347. .head{
  348. width: 750rpx;
  349. height: max-content;
  350. padding: 0 32rpx;
  351. box-sizing: border-box;
  352. .list{
  353. width: 100%;
  354. border-bottom: 1rpx solid #e5e5e5;
  355. padding: 30rpx 0;
  356. font-size: 28rpx;
  357. &:last-child{
  358. border-bottom: none;
  359. }
  360. .lf-icon{
  361. padding: 2rpx 10rpx;
  362. display: flex;
  363. align-items: center;
  364. justify-content: center;
  365. }
  366. }
  367. }
  368. .fixed-bottom{
  369. position: fixed;
  370. bottom: 0rpx;
  371. left: 0rpx;
  372. z-index: 99;
  373. width: 750rpx;
  374. height: 98rpx;
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. border-top: 1rpx solid #E5E5E5;
  379. background-color: #FFFFFF;
  380. .btn{
  381. width: 320rpx;
  382. height: 82rpx;
  383. border-radius: 41rpx;
  384. margin: 0;
  385. padding: 0;
  386. font-size: 32rpx;
  387. display: flex;
  388. justify-content: center;
  389. align-items: center;
  390. }
  391. .btn1{
  392. border: 2rpx solid #555555;
  393. opacity: .5;
  394. }
  395. .btn2{
  396. background: #11D189;
  397. color: #FFFFFF;
  398. margin-left: 50rpx;
  399. }
  400. }
  401. .remove-btn{
  402. margin: 0;
  403. padding: 6rpx 12rpx;
  404. font-size: 28rpx;
  405. line-height: initial;
  406. background-color: #FF0000;
  407. color: #FFFFFF;
  408. }
  409. </style>