addByProduct.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <el-dialog
  3. title="新建"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="80%"
  10. >
  11. <div>
  12. <el-form :model="productForm" ref="productForm">
  13. <el-row :gutter="24">
  14. <el-col :span="6">
  15. <el-form-item label="回收单号" prop="code" label-width="90px">
  16. <el-input v-model="productForm.code" disabled=""></el-input>
  17. </el-form-item>
  18. </el-col>
  19. <el-col :span="6">
  20. <el-form-item label="回收单名称" prop="name" label-width="90px">
  21. <el-input v-model="productForm.name"></el-input>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-button type="primary" @click="categorySelect"
  26. >选择物料</el-button
  27. >
  28. </el-col>
  29. </el-row>
  30. </el-form>
  31. <div v-for="(item, idx) in materialList" :key="idx">
  32. <el-form
  33. :ref="`form22${idx}`"
  34. :model="{ pickList: item }"
  35. :rules="tableRules"
  36. size="mini"
  37. label-position="left"
  38. >
  39. <div class="tableZ_box">
  40. <div class="row">
  41. <div class="col">
  42. <div class="name">物料编码</div>
  43. <div class="content">{{ item.code }}</div>
  44. </div>
  45. <div class="col">
  46. <div class="name">物料名称</div>
  47. <div class="content">{{ item.name }}</div>
  48. </div>
  49. <div class="col">
  50. <div class="name">型号</div>
  51. <div class="content">{{ item.modelType }}</div>
  52. </div>
  53. <div class="col">
  54. <div class="name">规格</div>
  55. <div class="content">{{ item.specification }}</div>
  56. </div>
  57. <div class="col">
  58. <div class="name">牌号</div>
  59. <div class="content">{{ item.brandNum }}</div>
  60. </div>
  61. <div class="col">
  62. <div class="name">数量</div>
  63. <div class="content content_num">
  64. <el-input v-model="productWeight"></el-input>
  65. <div style="margin-left: 8px"> {{ item.measuringUnit }}</div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <div style="margin: 6px">
  71. <el-button type="primary" size="mini" @click="handWorkOrder()"
  72. >新增</el-button
  73. >
  74. </div>
  75. <div v-if="item.detailList && item.detailList.length > 0">
  76. <el-table
  77. :ref="`form222${idx}`"
  78. class="table_content"
  79. :max-height="300"
  80. :data="item.detailList"
  81. tooltip-effect="dark"
  82. style="width: 100%"
  83. stripe
  84. border
  85. >
  86. <el-table-column label="序号" type="index" width="60">
  87. <template slot-scope="{ row, $index }">
  88. {{ $index }}
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="编码" prop="categoryCode">
  92. </el-table-column>
  93. <el-table-column label="工单编码" prop="code"> </el-table-column>
  94. <el-table-column label="名称" prop="categoryName">
  95. </el-table-column>
  96. <el-table-column label="型号" prop="modelType"> </el-table-column>
  97. <el-table-column label="规格" prop="specification">
  98. </el-table-column>
  99. <el-table-column label="工序" prop="taskName"> </el-table-column>
  100. <el-table-column label="合格品数量" prop="formedNum">
  101. </el-table-column>
  102. <el-table-column label="不合格品数量" prop="notFormedNum">
  103. </el-table-column>
  104. <el-table-column label="回收" prop="quantity" width="180px">
  105. <template slot-scope="{ $index, row }">
  106. <el-input v-model="row.quantity" size="mini">
  107. <template slot="append">{{ row.unit }}</template>
  108. </el-input>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="操作" fixed="right" width="100px">
  112. <template slot-scope="{ $index, row }">
  113. <el-link type="danger" @click="removeItem(idx, $index)"
  114. >删除</el-link
  115. >
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. </div>
  120. </el-form>
  121. </div>
  122. </div>
  123. <template slot="footer">
  124. <el-button size="mini" @click="handleClose">取 消</el-button>
  125. <el-button size="mini" type="primary" @click="save()">确 定</el-button>
  126. </template>
  127. <ProductModal ref="productRefs" @changeProduct="determineChoose" />
  128. <produceOrder
  129. v-if="orderShow"
  130. @close="orderShow = false"
  131. @workSelect="workSelect"
  132. ></produceOrder>
  133. </el-dialog>
  134. </template>
  135. <script>
  136. import { getCode } from '@/api/produce/workOrder';
  137. import { listDisposeBy, disposeSave } from '@/api/byProduct/index';
  138. import ProductModal from './ProductModal.vue';
  139. import produceOrder from '@/views/pick/pickApply/components/produceOrder.vue';
  140. export default {
  141. components: {
  142. ProductModal,
  143. produceOrder
  144. },
  145. data() {
  146. return {
  147. visible: true,
  148. productForm: {
  149. code: null,
  150. name: null
  151. },
  152. materialList: [],
  153. tableRules: {},
  154. productWeight: null,
  155. orderShow: false,
  156. newWeightList: []
  157. };
  158. },
  159. created() {
  160. this.getOrderCode();
  161. },
  162. methods: {
  163. handleClose() {
  164. this.$emit('close');
  165. },
  166. async getOrderCode() {
  167. this.productForm.code = await getCode('dispose_code');
  168. },
  169. save() {
  170. let param = {
  171. detailList: this.materialList[0].detailList || [],
  172. ...this.productForm,
  173. categoryId: this.materialList[0].id,
  174. quantity: this.productWeight
  175. };
  176. console.log(param,'1111111111111111');
  177. disposeSave(param).then((res) => {
  178. this.$emit('close', true);
  179. });
  180. },
  181. categorySelect() {
  182. this.$refs.productRefs.open({}, '选择物料', '1', null);
  183. },
  184. determineChoose(title, row, idx) {
  185. if (title == '选择物料') {
  186. console.log(row, idx);
  187. this.materialList[0] = row;
  188. this.$forceUpdate();
  189. }
  190. },
  191. handWorkOrder() {
  192. if (!this.productWeight) {
  193. return this.$message.error('请输入数量');
  194. }
  195. this.orderShow = true;
  196. },
  197. workSelect(ids, taskId) {
  198. console.log(ids, taskId);
  199. let param = {
  200. categoryId: this.materialList[0].id,
  201. taskId: taskId,
  202. workOrderIds: ids
  203. };
  204. listDisposeBy(param).then((res) => {
  205. this.newWeightList = res;
  206. this.WeightListFN();
  207. this.$forceUpdate();
  208. });
  209. this.orderShow = false;
  210. },
  211. WeightListFN() {
  212. let _totalNum = 0;
  213. let _oneWeight = 0;
  214. let _arr = [];
  215. // 使用reduce方法求和
  216. _totalNum = this.newWeightList.reduce((acc, item) => {
  217. return acc + item.formedNum + item.notFormedNum;
  218. }, 0);
  219. _oneWeight = this.productWeight / _totalNum;
  220. this.newWeightList.forEach((item) => {
  221. _arr.push({
  222. ...item,
  223. quantity: (item.formedNum + item.notFormedNum) * _oneWeight
  224. });
  225. });
  226. this.$set(this.materialList[0], 'detailList', _arr);
  227. },
  228. removeItem(idx, index) {
  229. this.materialList[idx].detailList.splice(index, 1);
  230. }
  231. }
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. .content_num {
  236. display: flex;
  237. align-items: center;
  238. padding: 2px;
  239. --input-background-color: #f0f8f2;
  240. }
  241. .table_content {
  242. margin-bottom: 10px;
  243. }
  244. .tableZ_box {
  245. border: 1px solid #e3e5e5;
  246. margin: 6px 0;
  247. &:last-child {
  248. border-bottom: none;
  249. }
  250. .row {
  251. width: 100%;
  252. display: flex;
  253. }
  254. .col {
  255. width: 16.666%;
  256. display: flex;
  257. align-items: center;
  258. min-width: 200px;
  259. min-height: 32px;
  260. border-bottom: 1px solid #e3e5e5;
  261. border-right: 1px solid #e3e5e5;
  262. &:last-child {
  263. border-right: none;
  264. }
  265. .name {
  266. display: flex;
  267. align-items: center;
  268. padding: 4px;
  269. width: 80px;
  270. height: 100%;
  271. background-color: #ededed;
  272. color: #000;
  273. }
  274. .content {
  275. padding: 4px 6px;
  276. color: #000;
  277. }
  278. }
  279. .pd6 {
  280. padding: 0 6px;
  281. }
  282. }
  283. </style>
  284. <style>
  285. :v-deep .el-form-item__error {
  286. bottom: -6px !important;
  287. }
  288. </style>