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

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