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

390 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. key: 'brand',
  111. label: '品牌'
  112. },{
  113. key: 'quality_level',
  114. label: '品级'
  115. },{
  116. label: '编号',
  117. key: 'm_sn'
  118. },{
  119. label: '供应商',
  120. key: 'supplier_name'
  121. },{
  122. key: 'tax_price',
  123. label: '含税价'
  124. },{
  125. key: 'non_tax_price',
  126. label: '不含税价'
  127. },{
  128. key: 'purchase_limit',
  129. label: '起购数'
  130. },{
  131. key: 'purchase_number',
  132. label: '采购数量'
  133. },{
  134. key: 'operation',
  135. label: '操作'
  136. }];
  137. // table 内容处理
  138. let list_arr = [];
  139. for(let j in material_list[i].material_list){
  140. material_list[i].material_list[j].purchase_number = {edit: true, value: material_list[i].material_list[j].purchase_number || ''};
  141. material_list[i].material_list[j].operation = {button: true, key: 'delete', value: '删除'};
  142. material_list[i].material_list[j].supplier_name = material_list[i].supplier_name;
  143. material_list[i].material_list[j].tax_price = material_list[i].material_list[j].tax_price;
  144. material_list[i].material_list[j].non_tax_price = material_list[i].material_list[j].non_tax_price;
  145. list_arr.push(material_list[i].material_list[j]);
  146. }
  147. material_list[i].material_list = list_arr;
  148. }
  149. this.render_material_list = material_list;
  150. this.show_material = Object.keys(this.material_list).length > 0;
  151. console.log("transform..material_list", this.material_list);
  152. console.log("transform...render_material_list", this.render_material_list)
  153. },
  154. // 复用采购单
  155. copyMaterialList(){
  156. this.$http(this.API.API_BUYREUSE, {
  157. p_sn: this.p_sn
  158. }).then(res => {
  159. let list = res.data || [];
  160. let material_list = {};
  161. list.map(item => {
  162. let items = item.purchase[0]?.items || [];
  163. let items_obj = {};
  164. items.map(i_item => {
  165. items_obj[i_item.quotation_item_id] = {
  166. brand: i_item?.material?.brand || '',
  167. checked: true,
  168. item_id: i_item.quotation_item_id,
  169. m_sn: i_item?.material?.m_sn || '',
  170. material_id: i_item?.material?.id || 0,
  171. material_name: i_item?.material?.m_name || '',
  172. non_tax_price: i_item.non_tax_price,
  173. purchase_limit: i_item?.p_order_item?.purchase_limit || '',
  174. quality_level: i_item?.material?.quality_level || '',
  175. spec_id: i_item?.spec?.id || 0,
  176. spec_name: i_item?.spec?.name || '',
  177. supplier_id: item.id,
  178. supplier_name: item.supplier_name,
  179. tax_price: i_item.tax_price,
  180. purchase_number: i_item.purchase_number
  181. };
  182. });
  183. item.material_list = items_obj;
  184. material_list[item.id] = item;
  185. this.date = item.purchase[0]?.deadline_text || '';
  186. })
  187. this.material_list = material_list;
  188. this.transformList();
  189. })
  190. },
  191. // table-input值被改变
  192. onInputChange(event){
  193. console.log("检测到table input被更改", event);
  194. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  195. let material_index = event.contentIndex; // 取出第二层,物资下标
  196. let detailValue = event.detailValue; // 取出table input被输入的值
  197. let supplier_item = this.render_material_list[supplier_id]; // 取出所在供应商
  198. let material_item = supplier_item.material_list[material_index]; // 取出物资
  199. if(material_item.purchase_limit <= detailValue){
  200. material_item.purchase_number.value = detailValue; // 将输入的值赋值给物资
  201. }else{
  202. this.$msg('采购数量须大于起购数量');
  203. material_item.purchase_number.value = material_item.purchase_limit;
  204. // uni.showModal({
  205. // title: '温馨提示',
  206. // content: '采购数量必须大于起购数量',
  207. // showCancel: false,
  208. // success: result => {
  209. // material_item.purchase_number.value = material_item.purchase_limit;
  210. // }
  211. // })
  212. }
  213. console.log("render_material_list_change", this.render_material_list);
  214. },
  215. // table 操作按钮被点击
  216. onButtonClick(event){
  217. console.log("event", event);
  218. if(event.content.key == 'delete'){
  219. let supplier_id = event.lineData.supplier_id; // 取出第一层,供应商id
  220. let item_id = event.lineData.item_id; // 取出第二层,item_id
  221. let material_index = event.lineData.contentIndex; // 取出第二层,物资下标
  222. this.render_material_list[supplier_id].material_list.splice(material_index, 1);
  223. delete this.material_list[supplier_id].material_list[item_id];
  224. }
  225. },
  226. // 时间选择
  227. pickerChange(event){
  228. this.date = event.detail.value;
  229. this.first_time = false
  230. },
  231. // 移除供应商
  232. removeSupplier(key){
  233. uni.showModal({
  234. title: '温馨提示',
  235. content: '删除供应商后所添加的物资将随之移除,确定继续吗?',
  236. confirmColor: '#FF0000',
  237. cancelColor: '#11D189',
  238. success: result => {
  239. if(result.confirm){
  240. // 移除render_material_list
  241. let render_material_list = {...this.render_material_list};
  242. delete render_material_list[key];
  243. this.render_material_list = render_material_list;
  244. // 移除material_list
  245. delete this.material_list[key];
  246. // 校验还有没有供应商,没有则不能显示选择物资按钮
  247. this.show_material = Object.keys(this.material_list).length > 0;
  248. }
  249. }
  250. })
  251. },
  252. // 保存并发单
  253. save(_t){
  254. let material_list = this.render_material_list;
  255. let list = [];
  256. let is_empty = true; // 物资数据是否为空
  257. let is_right = true; // 采购份数为正常的情况
  258. for(let i in material_list){
  259. if(Object.keys(material_list[i].material_list).length){
  260. is_empty = false;
  261. let material = material_list[i].material_list;
  262. // 数组写法
  263. let arr = material.map(item => {
  264. if(item.purchase_limit > item.purchase_number.value){
  265. is_right = false;
  266. };
  267. return {
  268. m_id: item.material_id,
  269. quotation_item_id: item.item_id,
  270. m_spec_id: item.spec_id,
  271. tax_price: item.tax_price,
  272. non_tax_price: item.non_tax_price,
  273. purchase_number: Number(item.purchase_number.value) || item.purchase_limit
  274. }
  275. });
  276. list.push({
  277. supplier_id: material_list[i].id,
  278. material: arr
  279. })
  280. }
  281. }
  282. let deadline = this.date;
  283. if(!deadline){
  284. this.$msg('请选择收货时间');
  285. return;
  286. }
  287. if(is_empty){
  288. this.$msg('您未选择物资');
  289. return;
  290. }
  291. if(!is_right){
  292. this.$msg('采购数量需大于起购数量');
  293. return;
  294. }
  295. let _api = this.API.API_CANTEEN_PURCHASEAPPLY;
  296. let _data = {
  297. order: list,
  298. state: _t,
  299. deadline: deadline
  300. };
  301. if(this.type == 1){
  302. _api = this.API.API_CANTEEN_PURCHASESAVE;
  303. _data.p_sn = this.p_sn;
  304. }
  305. this.$http(_api, _data).then(res => {
  306. this.$msg('操作成功').then(()=>{this.$toBack()});
  307. })
  308. },
  309. // 页面跳转添加供应商
  310. addSupplier(){
  311. if(this.type == 1){
  312. return this.$msg('编辑时不可更换供应商');
  313. }
  314. this.$url('/pages/classification/supplier');
  315. }
  316. }
  317. }
  318. </script>
  319. <style lang="scss" scoped="scoped">
  320. .lf-m-t-5{
  321. margin-top: 5rpx;
  322. }
  323. .head{
  324. width: 750rpx;
  325. height: max-content;
  326. padding: 0 32rpx;
  327. box-sizing: border-box;
  328. .list{
  329. width: 100%;
  330. border-bottom: 1rpx solid #e5e5e5;
  331. padding: 30rpx 0;
  332. font-size: 28rpx;
  333. &:last-child{
  334. border-bottom: none;
  335. }
  336. .lf-icon{
  337. padding: 2rpx 10rpx;
  338. display: flex;
  339. align-items: center;
  340. justify-content: center;
  341. }
  342. }
  343. }
  344. .fixed-bottom{
  345. position: fixed;
  346. bottom: 0rpx;
  347. left: 0rpx;
  348. z-index: 99;
  349. width: 750rpx;
  350. height: 98rpx;
  351. display: flex;
  352. justify-content: center;
  353. align-items: center;
  354. border-top: 1rpx solid #E5E5E5;
  355. background-color: #FFFFFF;
  356. .btn{
  357. width: 320rpx;
  358. height: 82rpx;
  359. border-radius: 41rpx;
  360. margin: 0;
  361. padding: 0;
  362. font-size: 32rpx;
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. }
  367. .btn1{
  368. border: 2rpx solid #555555;
  369. opacity: .5;
  370. }
  371. .btn2{
  372. background: #11D189;
  373. color: #FFFFFF;
  374. margin-left: 50rpx;
  375. }
  376. }
  377. .remove-btn{
  378. margin: 0;
  379. padding: 6rpx 12rpx;
  380. font-size: 28rpx;
  381. line-height: initial;
  382. background-color: #FF0000;
  383. color: #FFFFFF;
  384. }
  385. </style>