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