selfBuildPick.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <ele-modal
  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. :maxable="true"
  10. width="90%"
  11. >
  12. <div>
  13. <el-form :model="pickForm" ref="pickForm">
  14. <el-row :gutter="24">
  15. <el-col :span="6">
  16. <el-form-item label="领料单编号" prop="pickCode" label-width="90px">
  17. <el-input v-model="pickForm.pickCode" disabled=""></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="6">
  21. <el-form-item label="领料单名称" prop="pickName" label-width="90px">
  22. <el-input v-model="pickForm.pickName"></el-input>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="6">
  26. <el-button type="primary" @click="openPicking">添加物料</el-button>
  27. <el-button type="primary" @click="batchDelete">批量删除</el-button>
  28. </el-col>
  29. </el-row>
  30. </el-form>
  31. <el-form>
  32. <el-table
  33. ref="form222"
  34. class="table_content"
  35. :max-height="300"
  36. :data="objPick.pickList"
  37. tooltip-effect="dark"
  38. style="width: 100%"
  39. stripe
  40. border
  41. @selection-change="handleSelectionChange"
  42. >
  43. <el-table-column type="selection" width="55" align="center">
  44. </el-table-column>
  45. <el-table-column label="序号" type="index" width="60">
  46. <template slot-scope="{ row, $index }">
  47. {{ $index + 1 }}
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="类型" prop="rootCategoryLevelId" width="80">
  51. <template slot-scope="{ row, $index }">
  52. <el-tag size="mini">{{
  53. typeName[Number(row.rootCategoryLevelId)]
  54. }}</el-tag>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="编码" prop="assetCode" show-overflow-tooltip>
  58. <template slot-scope="{ row, $index }">
  59. <span
  60. v-if="
  61. Object.prototype.hasOwnProperty.call(row, 'isBom') &&
  62. row.isBom == 1
  63. "
  64. style="color: #faad14"
  65. >
  66. {{ row.categoryCode }}
  67. </span>
  68. <span>
  69. {{
  70. row.rootCategoryLevelId == 4 ? row.codeNumber : row.code
  71. }}</span
  72. >
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="批次号" prop="batchNo" show-overflow-tooltip>
  76. </el-table-column>
  77. <el-table-column label="名称" prop="name" show-overflow-tooltip>
  78. <template slot-scope="{ row, $index }">
  79. <span
  80. v-if="
  81. Object.prototype.hasOwnProperty.call(row, 'isBom') &&
  82. row.isBom == 1
  83. "
  84. >
  85. {{ row.categoryName }}
  86. </span>
  87. <span> {{ row.name }}</span>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="型号" prop="modelType" show-overflow-tooltip>
  91. </el-table-column>
  92. <el-table-column
  93. label="规格"
  94. prop="specification"
  95. show-overflow-tooltip
  96. >
  97. </el-table-column>
  98. <el-table-column label="数量" prop="demandQuantity">
  99. <template slot-scope="{ row, $index }">
  100. <el-form-item>
  101. <el-input
  102. v-model="row.demandQuantity"
  103. @input="
  104. row.demandQuantity > row.measureQuantity
  105. ? (row.demandQuantity = row.measureQuantity)
  106. : row.demandQuantity
  107. "
  108. size="mini"
  109. >
  110. <template slot="append">{{ row.measuringUnit }}</template>
  111. </el-input>
  112. </el-form-item>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="计量库存数量" prop="measureQuantity">
  116. <template slot-scope="{ row, $index }">
  117. <!-- 物品维度后端回填的是 measureQuantity(物品聚合库存),
  118. 批次维度回填的是 stockCountBase(批次库存),两者兜底展示 -->
  119. {{ row.stockCountBase ?? row.measureQuantity }} {{ row.measuringUnit }}
  120. </template>
  121. </el-table-column>
  122. <el-table-column
  123. label="领料仓库"
  124. prop="warehouseId"
  125. show-overflow-tooltip
  126. >
  127. <template slot-scope="{ row, $index }">
  128. <div>
  129. <el-select
  130. v-model="row.warehouseId"
  131. placeholder="请选择"
  132. filterable
  133. >
  134. <el-option
  135. v-for="item in row.warehouseList"
  136. :label="item.warehouse_name"
  137. :value="item.warehouse_id"
  138. :key="item.warehouse_id"
  139. >
  140. </el-option>
  141. </el-select>
  142. </div>
  143. </template>
  144. </el-table-column>
  145. <el-table-column label="操作" fixed="right" width="100px">
  146. <template slot-scope="{ $index, row }">
  147. <el-link type="danger" @click="removeItem($index)">删除</el-link>
  148. </template>
  149. </el-table-column>
  150. </el-table>
  151. </el-form>
  152. </div>
  153. <template slot="footer">
  154. <el-button size="mini" @click="handleClose">取 消</el-button>
  155. <el-button size="mini" type="primary" @click="save()">确 定</el-button>
  156. </template>
  157. <newPickingList
  158. isType="pick"
  159. ref="pickingListRef"
  160. @allSelection="allSelection"
  161. ></newPickingList>
  162. </ele-modal>
  163. </template>
  164. <script>
  165. import { getCode } from '@/api/produce/workOrder';
  166. import newPickingList from './newPickingList.vue';
  167. import { typeName } from '@/views/produce/components/common.js';
  168. import { unproductive } from '@/api/produce/picking';
  169. export default {
  170. components: {
  171. newPickingList
  172. },
  173. data() {
  174. return {
  175. visible: true,
  176. typeName,
  177. pickForm: {
  178. pickCode: null,
  179. pickName: null
  180. },
  181. objPick: {
  182. pickList: []
  183. },
  184. selectionData: []
  185. };
  186. },
  187. created() {
  188. this.getOrderCode();
  189. },
  190. methods: {
  191. async getOrderCode() {
  192. this.pickForm.pickCode = await getCode('pick_order_code');
  193. },
  194. openPicking() {
  195. this.$refs.pickingListRef.open(null, this.objPick);
  196. },
  197. allSelection(id, list) {
  198. // this.objPick = {
  199. // pickList: list
  200. // };
  201. list.forEach((item) => {
  202. item.code = item.categoryCode;
  203. item.name = item.categoryName;
  204. item.modelType = item.categoryModel;
  205. item.measuringUnit = item.measuringUnit
  206. ? item.measuringUnit
  207. : item.measureUnit;
  208. item.unit = item.unit ? item.unit : item.measureUnit;
  209. });
  210. const newData = [];
  211. if (list.length != 0) {
  212. list.forEach((it) => {
  213. newData.push(this.deepCopy(it));
  214. });
  215. }
  216. this.objPick = {
  217. pickList: newData
  218. };
  219. this.$forceUpdate();
  220. },
  221. deepCopy(obj, hash = new WeakMap()) {
  222. if (obj === null) return null;
  223. if (obj instanceof Date) return new Date(obj);
  224. if (obj instanceof RegExp) return new RegExp(obj);
  225. if (typeof obj !== 'object' && typeof obj !== 'function') return obj;
  226. if (hash.has(obj)) return hash.get(obj);
  227. const result = Array.isArray(obj) ? [] : {};
  228. hash.set(obj, result);
  229. return Object.keys(obj).reduce((acc, key) => {
  230. acc[key] = this.deepCopy(obj[key], hash);
  231. return acc;
  232. }, result);
  233. },
  234. batchDelete() {
  235. if (this.selectionData.length == 0) {
  236. return this.$message.warning('请选择需要删除的领料数据!');
  237. }
  238. this.$confirm('此操作将删除领料数据, 是否继续?', '提示', {
  239. confirmButtonText: '确定',
  240. cancelButtonText: '取消',
  241. type: 'warning'
  242. })
  243. .then(() => {
  244. for (let item of this.selectionData) {
  245. const findIndex = this.objPick.pickList.findIndex(
  246. (it) => item.id == it.id
  247. );
  248. this.objPick.pickList.splice(findIndex, 1);
  249. }
  250. })
  251. .catch(() => {});
  252. },
  253. handleSelectionChange(val) {
  254. this.selectionData = val;
  255. },
  256. removeItem(index) {
  257. this.objPick.pickList.splice(index, 1);
  258. },
  259. save() {
  260. if (this.objPick.pickList.length == 0) {
  261. this.$message.warning('请选择物料');
  262. return false;
  263. }
  264. if (this.objPick.pickList.length > 0) {
  265. let name;
  266. let bol2;
  267. let _i;
  268. bol2 = this.objPick.pickList.every((e, i) => {
  269. _i = i;
  270. name = e.name;
  271. // e.categoryId = e.id;
  272. // e.id = e.categoryId
  273. return (
  274. Object.prototype.hasOwnProperty.call(e, 'demandQuantity') &&
  275. Number(e.demandQuantity) > 0 &&
  276. e.warehouseId
  277. );
  278. });
  279. if (!bol2) {
  280. this.$message.warning(
  281. `${this.objPick.pickList[_i].code}的${name}数据不能为空`
  282. );
  283. return false;
  284. }
  285. }
  286. let param = {
  287. detailList: this.objPick.pickList,
  288. name: this.pickForm.pickName,
  289. code: this.pickForm.pickCode
  290. };
  291. unproductive(param).then((res) => {
  292. this.$message.success('领料成功');
  293. this.$emit('close', true);
  294. });
  295. },
  296. handleClose() {
  297. this.$emit('close');
  298. }
  299. }
  300. };
  301. </script>
  302. <style lang="scss" scoped></style>