edit.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <ele-modal :visible.sync="visible" :title="title" width="40vw" append-to-body :maxable="true">
  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. console.log(row,'row')
  137. this.visible = true;
  138. this.poList = row;
  139. this.type=type
  140. this.title = type == 1 ? '返工返修' : type == 2 ? '报废' : '试销品';
  141. if (
  142. !row[0].productName.includes('板材') &&
  143. !row[0].productName.includes('砌块')
  144. ) {
  145. return;
  146. }
  147. this._calcVolume(this.poList[0].specification);
  148. },
  149. handleChangeDepot(row, item) {
  150. row.depotName = item.name;
  151. },
  152. cancel() {
  153. this.visible = false;
  154. },
  155. // 删除产品
  156. handleDeleteItem(index, id) {
  157. this.$confirm('确认删除吗?', '提示', {
  158. confirmButtonText: '确定',
  159. cancleButtonText: '取消',
  160. type: 'warning'
  161. })
  162. .then((res) => {
  163. this.newPoList.splice(index, 1);
  164. })
  165. .catch(() => {});
  166. },
  167. addEquipment() {
  168. this.$refs.equipmentRefs.open();
  169. },
  170. /* 保存编辑 */
  171. save() {
  172. let isSumNew = true,
  173. isDepotId = true;
  174. let data = this.title == '返工返修' ? this.newPoList : this.poList;
  175. data.forEach((item) => {
  176. if (this.title == '返工返修' && !item.sumNew) {
  177. isSumNew = false;
  178. }
  179. if (this.title != '返工返修' && !item.depotId) {
  180. isDepotId = false;
  181. }
  182. });
  183. if(data.length==0){
  184. this.$alert('产品列表不能为空');
  185. return;
  186. }
  187. if (!isSumNew) {
  188. this.$alert('数量不能为空');
  189. return;
  190. }
  191. if (!isDepotId) {
  192. this.$alert('请选择入库仓库');
  193. return;
  194. }
  195. this.$emit('success', {data,type:this.type});
  196. this.cancel();
  197. },
  198. // 封装计算体积方法
  199. _calcVolume(string) {
  200. let modelArr = string.split('*');
  201. let originLong = Number(modelArr[0]);
  202. let originWide = Number(modelArr[1]);
  203. let originHeight = modelArr[2].substr(0, modelArr[2].indexOf('cm'));
  204. this.originLong = originLong;
  205. this.originHeight = originHeight;
  206. return originLong * originWide * originHeight;
  207. },
  208. // 封装计算修补信息规格*块数的总体积
  209. _calcModelVSWordcount() {
  210. // 计算修补规格体积
  211. let cutedVolume = 0;
  212. let sumVolume = 0;
  213. this.newPoList.map((item) => {
  214. if (item.sumNew > 0 && item.specificationNew) {
  215. cutedVolume =
  216. this._calcVolume(item.specificationNew) * Number(item.sumNew);
  217. sumVolume += cutedVolume;
  218. }
  219. });
  220. return sumVolume;
  221. },
  222. // 输入块数计算规格体积是否超出原规格体积
  223. inputNumber(row) {
  224. if (
  225. !row.productNameNew.includes('板材') &&
  226. !row.productNameNew.includes('砌块')
  227. ) {
  228. return;
  229. }
  230. // 计算原规格体积
  231. let originVolume = 0;
  232. let sumVolume = 0;
  233. originVolume = this._calcVolume(this.poList[0].specification);
  234. console.log(originVolume, 'originVolume');
  235. // 计算修补总体积
  236. sumVolume = this._calcModelVSWordcount();
  237. console.log(sumVolume, 'sumVolume');
  238. if (sumVolume > originVolume) {
  239. row.sumNew = 0;
  240. this.$alert('修补规格总体积不能大于原规格体积!');
  241. }
  242. },
  243. // 判断产品规格
  244. modelChange(row) {
  245. // 判断修补规格高度不能大于原规格高度
  246. if (!row.name.includes('板材') && !row.name.includes('砌块')) {
  247. return true;
  248. }
  249. let currentLong = Number(row.specification.split('*')[0]);
  250. let currentHeight = row.specification.split('*')[2];
  251. currentHeight = Number(
  252. currentHeight.substr(0, currentHeight.indexOf('cm'))
  253. );
  254. if (currentLong > this.originLong) {
  255. this.$alert('修补规格长度不能大于原规格长度!');
  256. return false;
  257. }
  258. if (currentHeight > this.originHeight) {
  259. this.$alert('修补规格高度不能大于原规格高度!');
  260. return false;
  261. }
  262. return true;
  263. },
  264. // 确定选择
  265. confirmChoose(data) {
  266. console.log(data, 'data');
  267. let list = [];
  268. let is = true;
  269. if (data.length > 0) {
  270. list = JSON.parse(JSON.stringify(data)).map((item) => {
  271. is = this.modelChange(item);
  272. return {
  273. productCodeNew: item.code,
  274. productNameNew: item.name,
  275. // productUnitWeight: item.netWeight,
  276. // weightUnit: item.weightUnit,
  277. specificationNew: item.specification,
  278. sumNew: ''
  279. };
  280. });
  281. if (!is) {
  282. return;
  283. }
  284. this.newPoList = this.newPoList.concat(list);
  285. }
  286. }
  287. }
  288. };
  289. </script>
  290. <style lang="scss" scoped>
  291. .basic-details-title {
  292. margin: 10px 0;
  293. }
  294. .title {
  295. font-size: 16px;
  296. line-height: 45px;
  297. }
  298. .add-product {
  299. width: 100%;
  300. display: flex;
  301. align-items: center;
  302. justify-content: flex-end;
  303. font-size: 30px;
  304. color: #1890ff;
  305. margin: 10px 0;
  306. cursor: pointer;
  307. }
  308. .create-form .el-form-item {
  309. // margin-bottom: 15px !important;
  310. }
  311. </style>