selfBuildPick.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. {{ row.measureQuantity }} {{ row.measuringUnit }}
  118. </template>
  119. </el-table-column>
  120. <el-table-column
  121. label="领料仓库"
  122. prop="warehouseId"
  123. show-overflow-tooltip
  124. >
  125. <template slot-scope="{ row, $index }">
  126. <div>
  127. <el-select
  128. v-model="row.warehouseId"
  129. placeholder="请选择"
  130. filterable
  131. >
  132. <el-option
  133. v-for="item in row.warehouseList"
  134. :label="item.warehouse_name"
  135. :value="item.warehouse_id"
  136. :key="item.warehouse_id"
  137. >
  138. </el-option>
  139. </el-select>
  140. </div>
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="操作" fixed="right" width="100px">
  144. <template slot-scope="{ $index, row }">
  145. <el-link type="danger" @click="removeItem($index)">删除</el-link>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </el-form>
  150. </div>
  151. <template slot="footer">
  152. <el-button size="mini" @click="handleClose">取 消</el-button>
  153. <el-button size="mini" type="primary" @click="save()">确 定</el-button>
  154. </template>
  155. <newPickingList
  156. isType="pick"
  157. ref="pickingListRef"
  158. @allSelection="allSelection"
  159. ></newPickingList>
  160. </ele-modal>
  161. </template>
  162. <script>
  163. import { getCode } from '@/api/produce/workOrder';
  164. import newPickingList from './newPickingList.vue';
  165. import { typeName } from '@/views/produce/components/common.js';
  166. import { unproductive } from '@/api/produce/picking';
  167. export default {
  168. components: {
  169. newPickingList
  170. },
  171. data() {
  172. return {
  173. visible: true,
  174. typeName,
  175. pickForm: {
  176. pickCode: null,
  177. pickName: null
  178. },
  179. objPick: {
  180. pickList: []
  181. },
  182. selectionData: []
  183. };
  184. },
  185. created() {
  186. this.getOrderCode();
  187. },
  188. methods: {
  189. async getOrderCode() {
  190. this.pickForm.pickCode = await getCode('pick_order_code');
  191. },
  192. openPicking() {
  193. this.$refs.pickingListRef.open(null, this.objPick);
  194. },
  195. allSelection(id, list) {
  196. // this.objPick = {
  197. // pickList: list
  198. // };
  199. list.forEach((item) => {
  200. item.code = item.categoryCode;
  201. item.name = item.categoryName;
  202. item.modelType = item.categoryModel;
  203. item.measuringUnit = item.measuringUnit
  204. ? item.measuringUnit
  205. : item.measureUnit;
  206. item.unit = item.unit ? item.unit : item.measureUnit;
  207. });
  208. const newData = [];
  209. if (list.length != 0) {
  210. list.forEach((it) => {
  211. newData.push(this.deepCopy(it));
  212. });
  213. }
  214. this.objPick = {
  215. pickList: newData
  216. };
  217. this.$forceUpdate();
  218. },
  219. deepCopy(obj, hash = new WeakMap()) {
  220. if (obj === null) return null;
  221. if (obj instanceof Date) return new Date(obj);
  222. if (obj instanceof RegExp) return new RegExp(obj);
  223. if (typeof obj !== 'object' && typeof obj !== 'function') return obj;
  224. if (hash.has(obj)) return hash.get(obj);
  225. const result = Array.isArray(obj) ? [] : {};
  226. hash.set(obj, result);
  227. return Object.keys(obj).reduce((acc, key) => {
  228. acc[key] = this.deepCopy(obj[key], hash);
  229. return acc;
  230. }, result);
  231. },
  232. batchDelete() {
  233. if (this.selectionData.length == 0) {
  234. return this.$message.warning('请选择需要删除的领料数据!');
  235. }
  236. this.$confirm('此操作将删除领料数据, 是否继续?', '提示', {
  237. confirmButtonText: '确定',
  238. cancelButtonText: '取消',
  239. type: 'warning'
  240. })
  241. .then(() => {
  242. for (let item of this.selectionData) {
  243. const findIndex = this.objPick.pickList.findIndex(
  244. (it) => item.id == it.id
  245. );
  246. this.objPick.pickList.splice(findIndex, 1);
  247. }
  248. })
  249. .catch(() => {});
  250. },
  251. handleSelectionChange(val) {
  252. this.selectionData = val;
  253. },
  254. removeItem(index) {
  255. this.objPick.pickList.splice(index, 1);
  256. },
  257. save() {
  258. if (this.objPick.pickList.length == 0) {
  259. this.$message.warning('请选择物料');
  260. return false;
  261. }
  262. if (this.objPick.pickList.length > 0) {
  263. let name;
  264. let bol2;
  265. let _i;
  266. bol2 = this.objPick.pickList.every((e, i) => {
  267. _i = i;
  268. name = e.name;
  269. // e.categoryId = e.id;
  270. // e.id = e.categoryId
  271. return (
  272. Object.prototype.hasOwnProperty.call(e, 'demandQuantity') &&
  273. Number(e.demandQuantity) > 0 &&
  274. e.warehouseId
  275. );
  276. });
  277. if (!bol2) {
  278. this.$message.warning(
  279. `${this.objPick.pickList[_i].code}的${name}数据不能为空`
  280. );
  281. return false;
  282. }
  283. }
  284. let param = {
  285. detailList: this.objPick.pickList,
  286. name: this.pickForm.pickName,
  287. code: this.pickForm.pickCode
  288. };
  289. unproductive(param).then((res) => {
  290. this.$message.success('领料成功');
  291. this.$emit('close', true);
  292. });
  293. },
  294. handleClose() {
  295. this.$emit('close');
  296. }
  297. }
  298. };
  299. </script>
  300. <style lang="scss" scoped></style>