edit.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <ele-modal :visible.sync="visible" :title="title" width="40vw" append-to-body>
  3. <div class="title">{{ title == '返工返修' ? '原' : '' }}产品信息</div>
  4. <el-table :data="poList" border>
  5. <el-table-column label="产品名称" align="center" prop="productName">
  6. </el-table-column>
  7. <el-table-column label="产品编号" align="center" prop="productCode">
  8. </el-table-column>
  9. <!-- <el-table-column label="刻码" align="center" prop="engravingCode">
  10. </el-table-column> -->
  11. <el-table-column label="规格" align="center" prop="specification">
  12. </el-table-column>
  13. <el-table-column label="数量" align="center" prop="unqualifiedQuantity">
  14. </el-table-column>
  15. <el-table-column label="创建时间" align="center" prop="createTime">
  16. </el-table-column>
  17. <el-table-column label="创建人" align="center" prop="reviewerName">
  18. </el-table-column>
  19. <el-table-column
  20. label="入库仓库"
  21. align="center"
  22. prop="depotId"
  23. v-if="title != '返工返修'"
  24. >
  25. <template slot-scope="scope">
  26. <el-select v-model="scope.row.depotId">
  27. <el-option
  28. v-for="item in warehouseList"
  29. :key="item.id"
  30. :value="item.id"
  31. :label="item.name"
  32. @click.native="handleChangeDepot(scope.row, item)"
  33. ></el-option>
  34. </el-select>
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. <div class="title" v-if="title == '返工返修'">返工返修产品信息</div>
  39. <el-form
  40. ref="form"
  41. label-width="90px"
  42. class="create-form"
  43. v-if="title == '返工返修'"
  44. >
  45. <el-table :data="newPoList" border height="20vh">
  46. <el-table-column label="序号" align="center" width="60">
  47. <template slot-scope="scope">
  48. <span>{{ scope.$index + 1 }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="产品名称" align="center" prop="productNameNew">
  52. </el-table-column>
  53. <el-table-column label="产品编号" align="center" prop="productCodeNew">
  54. </el-table-column>
  55. <!-- <el-table-column label="刻码" align="center" prop="engravingCode">
  56. </el-table-column> -->
  57. <!-- <el-table-column label="型号" align="center" prop="model">
  58. </el-table-column> -->
  59. <el-table-column label="规格" align="center" prop="specificationNew">
  60. </el-table-column>
  61. <el-table-column label="数量" align="center" prop="sumNew">
  62. <template slot-scope="scope">
  63. <el-form-item
  64. label-width="0px"
  65. :prop="'newPoList.' + scope.$index + '.sumNew'"
  66. >
  67. <el-input
  68. v-model.number="scope.row.sumNew"
  69. size="small"
  70. oninput="value=value.replace(/[^\d]/g,'')"
  71. style="width: 100%"
  72. placeholder="输入数量"
  73. @input="inputNumber(scope.row)"
  74. ></el-input>
  75. </el-form-item>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="操作" align="center" width="70">
  79. <template slot-scope="scope">
  80. <el-link
  81. type="danger"
  82. :underline="false"
  83. @click="handleDeleteItem(scope.$index)"
  84. >
  85. 删除
  86. </el-link>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </el-form>
  91. <div class="add-product" @click="addEquipment" v-if="title == '返工返修'">
  92. <i class="el-icon-circle-plus-outline"></i>
  93. </div>
  94. <template v-slot:footer>
  95. <el-button @click="cancel">取消</el-button>
  96. <el-button type="primary" @click="save" :loading="loading">
  97. 提交
  98. </el-button>
  99. </template>
  100. <!-- 选择产品 -->
  101. <EquipmentDialog ref="equipmentRefs" @choose="confirmChoose" :type="2">
  102. </EquipmentDialog>
  103. </ele-modal>
  104. </template>
  105. <script>
  106. import EquipmentDialog from './EquipmentDialog.vue';
  107. import {
  108. getWarehouseList
  109. // queryKilnXCH
  110. } from '@/api/mes';
  111. export default {
  112. components: {
  113. EquipmentDialog
  114. },
  115. data() {
  116. return {
  117. poList: [],
  118. newPoList: [],
  119. visible: false,
  120. loading: false,
  121. title: '返工返修',
  122. originLong: '',
  123. originHeight: '',
  124. type: '',
  125. warehouseList: []
  126. };
  127. },
  128. computed: {},
  129. created() {
  130. getWarehouseList().then((res) => {
  131. this.warehouseList = res;
  132. });
  133. },
  134. methods: {
  135. open(row, type) {
  136. this.visible = true;
  137. this.poList = row;
  138. this.title = type == 1 ? '返工返修' : type == 2 ? '报废' : '试销品';
  139. if (
  140. !row[0].productName.includes('板材') &&
  141. !row[0].productName.includes('砌块')
  142. ) {
  143. return;
  144. }
  145. this._calcVolume(this.poList[0].specification);
  146. },
  147. handleChangeDepot(row, item) {
  148. row.depotName = item.name;
  149. },
  150. cancel() {
  151. this.visible = false;
  152. },
  153. // 删除产品
  154. handleDeleteItem(index, id) {
  155. this.$confirm('确认删除吗?', '提示', {
  156. confirmButtonText: '确定',
  157. cancleButtonText: '取消',
  158. type: 'warning'
  159. })
  160. .then((res) => {
  161. this.newPoList.splice(index, 1);
  162. })
  163. .catch(() => {});
  164. },
  165. addEquipment() {
  166. this.$refs.equipmentRefs.open();
  167. },
  168. /* 保存编辑 */
  169. save() {
  170. let isSumNew = true,
  171. isDepotId = true;
  172. let data = this.title == '返工返修' ? this.newPoList : this.poList;
  173. data.forEach((item) => {
  174. if (this.title == '返工返修' && !item.sumNew) {
  175. isSumNew = false;
  176. }
  177. if (this.title != '返工返修' && !item.depotId) {
  178. isDepotId = false;
  179. }
  180. });
  181. if(data.length==0){
  182. this.$alert('产品列表不能为空');
  183. return;
  184. }
  185. if (!isSumNew) {
  186. this.$alert('数量不能为空');
  187. return;
  188. }
  189. if (!isDepotId) {
  190. this.$alert('请选择入库仓库');
  191. return;
  192. }
  193. this.$emit('success', data);
  194. this.cancel();
  195. },
  196. // 封装计算体积方法
  197. _calcVolume(string) {
  198. let modelArr = string.split('*');
  199. let originLong = Number(modelArr[0]);
  200. let originWide = Number(modelArr[1]);
  201. let originHeight = modelArr[2].substr(0, modelArr[2].indexOf('cm'));
  202. this.originLong = originLong;
  203. this.originHeight = originHeight;
  204. return originLong * originWide * originHeight;
  205. },
  206. // 封装计算修补信息规格*块数的总体积
  207. _calcModelVSWordcount() {
  208. // 计算修补规格体积
  209. let cutedVolume = 0;
  210. let sumVolume = 0;
  211. this.newPoList.map((item) => {
  212. if (item.sumNew > 0 && item.specificationNew) {
  213. cutedVolume =
  214. this._calcVolume(item.specificationNew) * Number(item.sumNew);
  215. sumVolume += cutedVolume;
  216. }
  217. });
  218. return sumVolume;
  219. },
  220. // 输入块数计算规格体积是否超出原规格体积
  221. inputNumber(row) {
  222. if (
  223. !row.productName.includes('板材') &&
  224. !row.productName.includes('砌块')
  225. ) {
  226. return;
  227. }
  228. // 计算原规格体积
  229. let originVolume = 0;
  230. let sumVolume = 0;
  231. originVolume = this._calcVolume(this.poList[0].specification);
  232. console.log(originVolume, 'originVolume');
  233. // 计算修补总体积
  234. sumVolume = this._calcModelVSWordcount();
  235. console.log(sumVolume, 'sumVolume');
  236. if (sumVolume > originVolume) {
  237. row.sumNew = 0;
  238. this.$alert('修补规格总体积不能大于原规格体积!');
  239. }
  240. },
  241. // 判断产品规格
  242. modelChange(row) {
  243. // 判断修补规格高度不能大于原规格高度
  244. if (!row.name.includes('板材') && !row.name.includes('砌块')) {
  245. return true;
  246. }
  247. let currentLong = Number(row.specification.split('*')[0]);
  248. let currentHeight = row.specification.split('*')[2];
  249. currentHeight = Number(
  250. currentHeight.substr(0, currentHeight.indexOf('cm'))
  251. );
  252. if (currentLong > this.originLong) {
  253. this.$alert('修补规格长度不能大于原规格长度!');
  254. return false;
  255. }
  256. if (currentHeight > this.originHeight) {
  257. this.$alert('修补规格高度不能大于原规格高度!');
  258. return false;
  259. }
  260. return true;
  261. },
  262. // 确定选择
  263. confirmChoose(data) {
  264. console.log(data, 'data');
  265. let list = [];
  266. let is = true;
  267. if (data.length > 0) {
  268. list = JSON.parse(JSON.stringify(data)).map((item) => {
  269. is = this.modelChange(item);
  270. return {
  271. productCodeNew: item.code,
  272. productNameNew: item.name,
  273. // productUnitWeight: item.netWeight,
  274. // weightUnit: item.weightUnit,
  275. specificationNew: item.specification,
  276. sumNew: ''
  277. };
  278. });
  279. if (!is) {
  280. return;
  281. }
  282. this.newPoList = this.newPoList.concat(list);
  283. }
  284. }
  285. }
  286. };
  287. </script>
  288. <style lang="scss" scoped>
  289. .basic-details-title {
  290. margin: 10px 0;
  291. }
  292. .title {
  293. font-size: 16px;
  294. line-height: 45px;
  295. }
  296. .add-product {
  297. width: 100%;
  298. display: flex;
  299. align-items: center;
  300. justify-content: flex-end;
  301. font-size: 30px;
  302. color: #1890ff;
  303. margin: 10px 0;
  304. cursor: pointer;
  305. }
  306. .create-form .el-form-item {
  307. // margin-bottom: 15px !important;
  308. }
  309. </style>