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

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