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

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