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

336 lines
9.3 KiB

5 years ago
  1. <template>
  2. <view>
  3. <view class="list" @click="$url('/pages/classification/warehouse')">
  4. <view class="lf-font-28 lf-color-black lf-row-between">
  5. <view>出库清单</view>
  6. <view class="lf-icon">
  7. <u-icon name="plus-circle" size="42"></u-icon>
  8. </view>
  9. </view>
  10. <view class="lf-font-24 lf-color-gray lf-m-t-5">添加物资后可以编辑数量</view>
  11. </view>
  12. <!-- 修饰条 -->
  13. <self-line></self-line>
  14. <!-- 物料table -->
  15. <view class="list">
  16. <view class="lf-font-32 lf-color-black lf-font-bold lf-m-b-20">物资明细</view>
  17. <wyb-table :headers="headers" :contents="contents"
  18. contentBgColor="#ecfaf5"
  19. :scrollToInput="true"
  20. :first-line-fixed="true"
  21. @onInputChange="onInputChange"
  22. @onButtonClick="onButtonClick"
  23. width="max-content" height="80vh"
  24. v-if="contents.length"></wyb-table>
  25. </view>
  26. <view style="height: 140rpx;"></view>
  27. <!-- 操作按钮 -->
  28. <view class="fixed-bottom lf-p-l-32 lf-p-r-32" style="justify-content: space-between;" v-if="enter_type == 1">
  29. <view></view>
  30. <!-- <button class="btn btn2" @click="editOrder()">立即申请</button> -->
  31. <button class="btn btn2" @click="save(1)">立即申请</button>
  32. </view>
  33. <view class="fixed-bottom" v-else>
  34. <button class="btn btn1" @click="save(0)">临时保存</button>
  35. <button class="btn btn2" @click="save(1)">直接申请</button>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import wybTable from '@/components/wyb-table/wyb-table';
  41. export default {
  42. components: {
  43. wybTable
  44. },
  45. data(){
  46. return {
  47. headers: [{
  48. label: '物资名称',
  49. key: 'material_name'
  50. },{
  51. label: '规格',
  52. key: 'spec_name'
  53. },{
  54. label: '单位',
  55. key: 'unit'
  56. },{
  57. label: '分类',
  58. key: 'category'
  59. },{
  60. key: 'brand',
  61. label: '品牌'
  62. },{
  63. key: 'quality_level',
  64. label: '品级'
  65. },{
  66. label: '编号',
  67. key: 'm_sn'
  68. },{
  69. label: '供应商',
  70. key: 'supplier_name'
  71. },{
  72. label: '批次',
  73. key: 'batch_sn'
  74. },{
  75. key: 'stock_number',
  76. label: '库存数量'
  77. },{
  78. key: 'delivery_number',
  79. label: '出库数量'
  80. },{
  81. key: 'operation',
  82. label: '操作'
  83. }],
  84. contents: [],
  85. warehouse_list: {},
  86. enter_type: '', // 1 编辑,2 复用
  87. o_sn: '',
  88. isStock: true
  89. }
  90. },
  91. onLoad(e){
  92. // 监听warehouse_list被操作
  93. uni.$on('addWarehouseList', res => {
  94. this.warehouse_list = res;
  95. })
  96. if(e){
  97. this.o_sn = e.o_sn
  98. this.enter_type = e.enter_type
  99. if(e.enter_type == 1 || e.enter_type == 2){
  100. this.getData();
  101. }
  102. }
  103. },
  104. onShow(){
  105. this.transformList();
  106. },
  107. methods: {
  108. transformList(){
  109. let contents = [];
  110. let warehouse_list = JSON.stringify(this.warehouse_list);
  111. warehouse_list = JSON.parse(warehouse_list);
  112. for(let i in warehouse_list){
  113. warehouse_list[i].delivery_number = {edit: true, value: warehouse_list[i].delivery_number || 1};
  114. warehouse_list[i].operation = {button: true, key: 'delete', value: '删除'};
  115. warehouse_list[i].unit = warehouse_list[i].unit.unit_name;
  116. warehouse_list[i].category = warehouse_list[i].category.m_cate_name;
  117. warehouse_list[i].stock_number = warehouse_list[i].stock;
  118. contents.push(warehouse_list[i]);
  119. }
  120. this.contents = contents;
  121. console.log("show.warehouse_list...", this.warehouse_list)
  122. console.log("transformList...", contents);
  123. },
  124. // 复用 & 编辑
  125. getData(){
  126. // TODO 此处应该调此接口 出库单复用
  127. // this.$http(this.API.API_CANTEEN_WAREHOUSEOUTREUSE, {
  128. this.$http(this.API.API_CANTEEN_OUTDETAIL, {
  129. o_sn: this.o_sn
  130. }).then(res => {
  131. // let list = res.data || [];
  132. let list = res.data.sheet || [];
  133. let warehouse_list = {};
  134. list.map(item => {
  135. console.log('======',item)
  136. console.log('===库存===',item.warehouse.stock)
  137. warehouse_list[item.id] = {
  138. batch_sn: item?.purchase?.batch_sn || '',
  139. brand: item?.material?.brand || '',
  140. checked: true,
  141. stock: item.warehouse.stock,
  142. m_sn: item?.material?.m_sn || '',
  143. material_id: item?.material?.id || 0,
  144. material_name: item?.material?.m_name || '',
  145. order_id: item.id,
  146. purchase_id: item.purchase_id,
  147. quality_level: item?.material?.quality_level || '',
  148. spec_id: item?.spec?.id || 0,
  149. spec_name: item?.spec?.name || '',
  150. supplier_name: item?.purchase?.supplier?.supplier_name || '',
  151. delivery_number: item.out_number || 1,
  152. unit: item?.material?.unit || {},
  153. category: item?.material?.category || {}
  154. };
  155. })
  156. this.warehouse_list = warehouse_list;
  157. this.transformList();
  158. })
  159. },
  160. //编辑出库 todo
  161. editOrder() {
  162. this.$http(this.API.API_EDITOUTORDER, {
  163. data: list
  164. }).then(res => {
  165. console.log("save", res);
  166. this.$msg('操作成功').then(() => this.$toBack());
  167. })
  168. },
  169. // table输入框
  170. onInputChange(event){
  171. console.log("检测到table input被更改", event);
  172. this.contents[event.contentIndex][event.key].value = event.detailValue;
  173. },
  174. // table操作按钮被点击
  175. onButtonClick(event){
  176. if(event.content.key == 'delete'){
  177. let material_index = event.contentIndex;
  178. let material_name = event.lineData.material_name;
  179. let spec_name = event.lineData.spec_name;
  180. let order_id = event.lineData.order_id;
  181. uni.showModal({
  182. title: '温馨提示',
  183. content: `确定删除 ${material_name}-${spec_name} 吗?`,
  184. cancelColor: '#11D189',
  185. confirmColor: '#FF0000',
  186. success: result => {
  187. if(result.confirm){
  188. this.contents.splice(material_index, 1);
  189. delete this.warehouse_list[order_id];
  190. }
  191. }
  192. })
  193. }
  194. },
  195. // 保存,出库
  196. save(_t){
  197. if(this.contents.length <= 0) {
  198. return this.$msg('您未选择物资')
  199. }
  200. let is_empty = false;
  201. let list = this.contents.map(item => {
  202. if(!item.delivery_number.value){
  203. is_empty = true;
  204. }
  205. if(Number(item.delivery_number.value) > item.stock) {
  206. console.log('循环几次')
  207. uni.showModal({
  208. title: '温馨提示',
  209. content: `物资:${item.material_name},仅剩${item.stock}单位库存,已超出您申请的数量,是否直接修改成出库${item.stock}单位`,
  210. confirmColor: '#11D189',
  211. success: result => {
  212. if(result.confirm){
  213. this.isStock = true
  214. item.delivery_number.value = item.stock
  215. return {
  216. m_id: item.material_id,
  217. m_spec_id: item.spec_id,
  218. purchase_id: item.purchase_id,
  219. out_number: Number(item.delivery_number.value),
  220. warehouse_id: item.order_id || 0,
  221. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  222. non_tax_price: item.non_tax_price || '',
  223. m_unit_id: item.m_unit_id || 0
  224. }
  225. }else {
  226. item.delivery_number.value = 1
  227. this.isStock = true
  228. return {
  229. m_id: item.material_id,
  230. m_spec_id: item.spec_id,
  231. purchase_id: item.purchase_id,
  232. out_number: Number(item.delivery_number.value),
  233. warehouse_id: item.order_id || 0,
  234. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  235. non_tax_price: item.non_tax_price || '',
  236. m_unit_id: item.m_unit_id || 0
  237. }
  238. }
  239. }
  240. })
  241. this.isStock = false
  242. return
  243. }else {
  244. return {
  245. m_id: item.material_id,
  246. m_spec_id: item.spec_id,
  247. purchase_id: item.purchase_id,
  248. out_number: Number(item.delivery_number.value) || 1,
  249. warehouse_id: item.order_id || 0,
  250. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  251. non_tax_price: item.non_tax_price || '',
  252. m_unit_id: item.m_unit_id || 0
  253. }
  254. }
  255. });
  256. if(this.isStock) {
  257. if(is_empty){
  258. uni.showModal({
  259. title: '温馨提示',
  260. content: '您有物资未填写出库数量, 请填写',
  261. showCancel: false,
  262. confirmColor: '#11D189'
  263. })
  264. return;
  265. }
  266. let state = ['待确认', '已确认'][_t]; // 传入状态
  267. let _api = this.API.API_CANTEEN_WAREHOUSEOUT;
  268. let _data = {
  269. data: list,
  270. state: state
  271. }
  272. if(this.enter_type == 1){
  273. _api = this.API.API_EDITOUTORDER;
  274. _data.o_sn = this.o_sn;
  275. }
  276. this.$http(_api, _data).then(res => {
  277. this.$msg('操作成功').then(() => this.$toBack());
  278. })
  279. }
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped="scoped">
  285. .lf-m-t-5{
  286. margin-top: 5rpx;
  287. }
  288. .lf-icon{
  289. padding: 2rpx 10rpx;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. }
  294. .list{
  295. padding: 30rpx 32rpx;
  296. width: 100%;
  297. height: max-content;
  298. box-sizing: border-box;
  299. }
  300. .fixed-bottom{
  301. position: fixed;
  302. bottom: 0rpx;
  303. left: 0rpx;
  304. z-index: 99;
  305. width: 750rpx;
  306. height: 98rpx;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. border-top: 1rpx solid #E5E5E5;
  311. background-color: #fff;
  312. .btn{
  313. width: 320rpx;
  314. height: 82rpx;
  315. border-radius: 41rpx;
  316. margin: 0;
  317. padding: 0;
  318. font-size: 32rpx;
  319. display: flex;
  320. justify-content: center;
  321. align-items: center;
  322. }
  323. .btn1{
  324. border: 2rpx solid #555555;
  325. opacity: .5;
  326. }
  327. .btn2{
  328. background: #11D189;
  329. color: #FFFFFF;
  330. margin-left: 50rpx;
  331. }
  332. }
  333. </style>