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

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