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

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