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

344 lines
9.7 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. 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. warehouse_id: item?.warehouse_id || 0
  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. console.log("this.contents", this.contents);
  205. let is_empty = false;
  206. let list = this.contents.map(item => {
  207. if(!item.delivery_number.value){
  208. is_empty = true;
  209. }
  210. if(Number(item.delivery_number.value) > item.stock) {
  211. console.log('循环几次')
  212. uni.showModal({
  213. title: '温馨提示',
  214. content: `物资:${item.material_name},仅剩${item.stock}单位库存,已超出您申请的数量,是否直接修改成出库${item.stock}单位`,
  215. confirmColor: '#11D189',
  216. success: result => {
  217. if(result.confirm){
  218. this.isStock = true
  219. item.delivery_number.value = item.stock
  220. return {
  221. m_id: item.material_id,
  222. m_spec_id: item.spec_id,
  223. purchase_id: item.purchase_id,
  224. out_number: Number(item.delivery_number.value),
  225. warehouse_id: item.warehouse_id || item.order_id || 0,
  226. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  227. non_tax_price: item.non_tax_price || '',
  228. m_unit_id: item.m_unit_id || 0
  229. }
  230. }else {
  231. item.delivery_number.value = 1
  232. this.isStock = true
  233. return {
  234. m_id: item.material_id,
  235. m_spec_id: item.spec_id,
  236. purchase_id: item.purchase_id,
  237. out_number: Number(item.delivery_number.value),
  238. warehouse_id: item.warehouse_id || item.order_id || 0,
  239. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  240. non_tax_price: item.non_tax_price || '',
  241. m_unit_id: item.m_unit_id || 0
  242. }
  243. }
  244. }
  245. })
  246. this.isStock = false
  247. return
  248. }else {
  249. return {
  250. m_id: item.material_id,
  251. m_spec_id: item.spec_id,
  252. purchase_id: item.purchase_id,
  253. out_number: Number(item.delivery_number.value) || 1,
  254. warehouse_id: item.warehouse_id || item.order_id || 0,
  255. tax_price: item.tax_price || '', // TODO 添加物资页面未返回价格,默认空
  256. non_tax_price: item.non_tax_price || '',
  257. m_unit_id: item.m_unit_id || 0
  258. }
  259. }
  260. });
  261. if(this.isStock) {
  262. if(is_empty){
  263. uni.showModal({
  264. title: '温馨提示',
  265. content: '您有物资未填写出库数量, 请填写',
  266. showCancel: false,
  267. confirmColor: '#11D189'
  268. })
  269. this.button_click = false;
  270. return;
  271. }
  272. let state = ['待确认', '申请中'][_t]; // 传入状态
  273. let _api = this.API.API_CANTEEN_WAREHOUSEOUT;
  274. let _data = {
  275. data: list,
  276. state: state
  277. }
  278. if(this.enter_type == 1){
  279. _api = this.API.API_EDITOUTORDER;
  280. _data.o_sn = this.o_sn;
  281. }
  282. this.$http(_api, _data).then(res => {
  283. this.$msg('操作成功').then(() => this.$toBack());
  284. }).catch(err => this.button_click = false);
  285. }else{
  286. this.button_click = false;
  287. }
  288. }
  289. }
  290. }
  291. </script>
  292. <style lang="scss" scoped="scoped">
  293. .lf-m-t-5{
  294. margin-top: 5rpx;
  295. }
  296. .lf-icon{
  297. padding: 2rpx 10rpx;
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. }
  302. .list{
  303. padding: 30rpx 32rpx;
  304. width: 100%;
  305. height: max-content;
  306. box-sizing: border-box;
  307. }
  308. .fixed-bottom{
  309. position: fixed;
  310. bottom: 0rpx;
  311. left: 0rpx;
  312. z-index: 99;
  313. width: 750rpx;
  314. height: 98rpx;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. border-top: 1rpx solid #E5E5E5;
  319. background-color: #fff;
  320. .btn{
  321. width: 320rpx;
  322. height: 82rpx;
  323. border-radius: 41rpx;
  324. margin: 0;
  325. padding: 0;
  326. font-size: 32rpx;
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. }
  331. .btn1{
  332. border: 2rpx solid #555555;
  333. opacity: .5;
  334. }
  335. .btn2{
  336. background: #11D189;
  337. color: #FFFFFF;
  338. margin-left: 50rpx;
  339. }
  340. }
  341. </style>