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

445 lines
13 KiB

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