addCombination.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div v-loading="loading">
  3. <div class="form-box">
  4. <el-form
  5. label-position="top"
  6. :model="form"
  7. ref="form"
  8. :rules="formRules"
  9. label-width="100px"
  10. >
  11. <div v-if="submitType === '10'">
  12. <el-row>
  13. <el-form-item label="组合名称" prop="productId">
  14. <el-select
  15. v-model="form.productId"
  16. placeholder="请选择"
  17. style="width: 100%"
  18. @change="handleGetCanQuantity"
  19. >
  20. <el-option
  21. v-for="item in combinationNameList"
  22. :key="item.id"
  23. :label="item.name"
  24. :value="item.id"
  25. >
  26. </el-option>
  27. </el-select>
  28. </el-form-item>
  29. </el-row>
  30. <!-- <el-row> 规格:xxxxxxxx </el-row> -->
  31. <el-form-item label="组合后放置仓库" prop="combinationWarehouseId">
  32. <el-select
  33. v-model="form.combinationWarehouseId"
  34. placeholder="请选择"
  35. style="width: 100%"
  36. >
  37. <el-option
  38. v-for="item in warehouseSelectList"
  39. :key="item.id"
  40. :label="item.name"
  41. :value="item.id"
  42. >
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="半成品所在仓库" prop="sourceWarehouseId">
  47. <el-select
  48. v-model="form.sourceWarehouseId"
  49. placeholder="请选择"
  50. style="width: 100%"
  51. @change="handleGetCanQuantity"
  52. >
  53. <el-option
  54. v-for="item in warehouseSelectList"
  55. :key="item.id"
  56. :label="item.name"
  57. :value="item.id"
  58. >
  59. </el-option>
  60. </el-select>
  61. </el-form-item>
  62. <el-row>
  63. <el-col :span="8">
  64. <el-form-item label="组合数量" prop="combinationQuantity">
  65. <el-input
  66. v-model="form.combinationQuantity"
  67. :disabled="canQuantity === 0"
  68. placeholder="请输入"
  69. >
  70. </el-input>
  71. </el-form-item>
  72. </el-col>
  73. </el-row>
  74. <div style="color: #999999">可组合数量:{{ canQuantity }}</div>
  75. </div>
  76. <div v-else>
  77. <el-row :gutter="10">
  78. <el-col :span="12">
  79. <el-form-item
  80. label="组合后放置仓库"
  81. prop="combinationWarehouseId"
  82. >
  83. <el-select
  84. v-model="form.combinationWarehouseId"
  85. placeholder="请选择"
  86. style="width: 100%"
  87. >
  88. <el-option
  89. v-for="item in warehouseSelectList"
  90. :key="item.id"
  91. :label="item.name"
  92. :value="item.id"
  93. >
  94. </el-option>
  95. </el-select>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="12">
  99. <el-form-item label="半成品所在仓库" prop="sourceWarehouseId">
  100. <el-select
  101. v-model="form.sourceWarehouseId"
  102. placeholder="请选择"
  103. style="width: 100%"
  104. @change="handleGetCanQuantity"
  105. >
  106. <el-option
  107. v-for="item in warehouseSelectList"
  108. :key="item.id"
  109. :label="item.name"
  110. :value="item.id"
  111. >
  112. </el-option>
  113. </el-select>
  114. </el-form-item>
  115. </el-col>
  116. </el-row>
  117. <div style="margin-top: 20px">
  118. <labelTitle content="组合明细"></labelTitle>
  119. </div>
  120. <div style="margin: 10px 0">
  121. <el-button size="small" @click="selectDialog = true">
  122. 添加产品</el-button
  123. >
  124. </div>
  125. <el-table :data="form.productList">
  126. <el-table-column label="产品名称" prop="productName">
  127. </el-table-column>
  128. <!-- <el-table-column label="可组合数量" prop="name"> </el-table-column> -->
  129. <el-table-column label="组合数量" prop="combinationQuantity">
  130. <template slot-scope="scope">
  131. <el-form-item
  132. :prop="'productList.' + scope.$index + '.combinationQuantity'"
  133. :rules="formRules.combinationQuantity"
  134. :inline-message="true"
  135. label-width="0"
  136. >
  137. <el-input
  138. v-model="scope.row.combinationQuantity"
  139. placeholder="请输入"
  140. size="mini"
  141. >
  142. </el-input>
  143. </el-form-item>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="操作" width="100" align="center">
  147. <template slot-scope="scope">
  148. <el-button type="text" @click="deleteRow(scope.$index)"
  149. >删除</el-button
  150. >
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. </div>
  155. </el-form>
  156. </div>
  157. <div style="text-align: center; margin-top: 15px">
  158. <el-button size="small" @click="handleCancel">取消 </el-button>
  159. <el-button type="primary" size="small" @click="handleSubmit">
  160. 确定</el-button
  161. >
  162. </div>
  163. <el-dialog
  164. title="组合选择"
  165. v-if="selectDialog"
  166. :visible.sync="selectDialog"
  167. width="80%"
  168. top="60px"
  169. >
  170. <selectProduct
  171. :isCombination="isCombination"
  172. @select="handleSelect"
  173. ></selectProduct>
  174. </el-dialog>
  175. </div>
  176. </template>
  177. <script>
  178. import labelTitle from "@/components/label-title/index.vue";
  179. import selectProduct from "@/components/select-product/index.vue";
  180. import {
  181. getCombinationNameList,
  182. getCanQuantity,
  183. } from "@/api/inventory-management/combination.js";
  184. import { warehouseSelectList } from "@/api/product-material/warehouse/index.js";
  185. export default {
  186. name: "addCombination",
  187. components: { labelTitle, selectProduct },
  188. props: {
  189. form: {
  190. type: Object,
  191. default: () => {},
  192. },
  193. submitType: {
  194. type: String,
  195. default: "10",
  196. },
  197. },
  198. data() {
  199. return {
  200. loading: false,
  201. warehouseSelectList: [],
  202. combinationNameList: [],
  203. canQuantity: 0,
  204. formRules: {
  205. productId: [
  206. {
  207. required: true,
  208. message: "请选择组合名称",
  209. trigger: "change",
  210. },
  211. ],
  212. combinationWarehouseId: [
  213. {
  214. required: true,
  215. message: "请选择组合后放置仓库",
  216. trigger: "change",
  217. },
  218. ],
  219. sourceWarehouseId: [
  220. {
  221. required: true,
  222. message: "请选择半成品所在仓库",
  223. trigger: "change",
  224. },
  225. ],
  226. combinationQuantity: [
  227. {
  228. required: true,
  229. message: "请输入组合数量",
  230. trigger: "blur",
  231. },
  232. ],
  233. },
  234. selectDialog: false,
  235. isCombination: true, //默认让选择产品组件请求是组合的产品
  236. };
  237. },
  238. created() {
  239. this.getData();
  240. },
  241. methods: {
  242. getData() {
  243. getCombinationNameList().then((res) => {
  244. this.combinationNameList = res.data.data;
  245. });
  246. warehouseSelectList().then((res) => {
  247. this.warehouseSelectList = res.data.data;
  248. });
  249. },
  250. handleGetCanQuantity() {
  251. if (this.form.productId && this.form.sourceWarehouseId) {
  252. getCanQuantity({
  253. productId: this.form.productId,
  254. sourceWarehouseId: this.form.sourceWarehouseId,
  255. }).then((res) => {
  256. this.canQuantity = res.data.data;
  257. });
  258. }
  259. },
  260. handleSubmit() {
  261. this.$refs.form.validate((valid) => {
  262. if (valid) {
  263. this.loading = true;
  264. if (this.submitType === "20") {
  265. this.form.productList = this.form.productList.map((x) => ({
  266. productId: x.productId,
  267. combinationQuantity: x.combinationQuantity,
  268. combinationWarehouseId: this.form.combinationWarehouseId,
  269. sourceWarehouseId: this.form.sourceWarehouseId,
  270. }));
  271. }
  272. this.$emit("submit");
  273. }
  274. });
  275. },
  276. handleCancel() {
  277. this.$emit("cancel");
  278. },
  279. handleSelect(row) {
  280. const flag = this.form.productList.some((x) => x.productId === row.id);
  281. if (flag) return this.msgInfo("该产品已经选择");
  282. const product = {
  283. productId: row.id,
  284. productName: row.name,
  285. combinationQuantity: "",
  286. };
  287. this.form.productList.push(product);
  288. this.msgSuccess("选择成功");
  289. },
  290. deleteRow(index) {
  291. this.form.productList.splice(index, 1);
  292. this.msgSuccess("删除成功");
  293. },
  294. },
  295. };
  296. </script>
  297. <style lang="scss" scoped>
  298. .form-box {
  299. height: calc(100vh - 280px);
  300. overflow: auto;
  301. box-sizing: border-box;
  302. padding: 10px;
  303. }
  304. ::v-deep {
  305. .el-form-item {
  306. margin-bottom: 3px;
  307. }
  308. .el-form--label-top .el-form-item__label {
  309. padding: 8px 0 0 0;
  310. }
  311. }
  312. </style>