edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <div id="equipment_edit" class="ele-body baseinfo-container">
  3. <el-card shadow="never">
  4. <div class="page-title" v-if="showTitle">
  5. <el-page-header @back="$router.go(-1)">
  6. <div slot="content" class="pageContent">
  7. <div>{{ title }}</div>
  8. </div>
  9. </el-page-header>
  10. <div>
  11. <el-button type="primary" @click="submit" :loading="btnLoading"
  12. >确定</el-button
  13. >
  14. </div>
  15. </div>
  16. <div v-if="pageType == 'add'">
  17. <el-button type="primary" plain @click="handlwpbm">选择物品</el-button>
  18. </div>
  19. <el-form
  20. label-width="120px"
  21. :model="{ ...form, ...positionInfo }"
  22. ref="form"
  23. :rules="rules"
  24. >
  25. <div class="content">
  26. <basicInfoVue ref="basicInfoVueRef" />
  27. <businessInformation ref="businessInformationRef" :form="form" />
  28. <assetInformation ref="assetInformationRef" :form="form" />
  29. <turnoverCarInformation ref="turnoverCarInformationRef" />
  30. <warehouseConfigVue ref="warehouseConfigRef" class="ims" />
  31. <productInfoVue ref="productInfoRef" />
  32. <planVue ref="planRef" />
  33. <qualityConfig ref="qualityConfigRef" />
  34. <footerVue ref="footerVueRef" />
  35. <documentInformation ref="documentInformationRef" type="周转车" />
  36. <div class="basic-details-title border-none">
  37. <span class="border-span">物联参数</span>
  38. </div>
  39. <el-row>
  40. <el-col>
  41. <el-form-item label="是否启用物联">
  42. <el-switch
  43. v-model="isIotEnable"
  44. active-text="开"
  45. inactive-text="关"
  46. :active-value="1"
  47. :inactive-value="0"
  48. >
  49. </el-switch>
  50. </el-form-item>
  51. </el-col>
  52. <el-col>
  53. <el-form-item label="物联ID">{{ iotId }}</el-form-item>
  54. </el-col>
  55. </el-row>
  56. <div class="basic-details-title border-none">
  57. <span class="border-span">扩展信息</span>
  58. </div>
  59. <div class="kzzd">
  60. <el-row>
  61. <el-col
  62. :span="24"
  63. v-for="(item, index) in form.extInfoSelf"
  64. :key="index"
  65. style="margin-bottom: 20px"
  66. >
  67. <el-form-item
  68. label-width="0"
  69. :prop="'extInfoSelf.' + index + '.key'"
  70. :rules="{
  71. required: true,
  72. message: '自定义参数名称不能为空',
  73. trigger: 'blur'
  74. }"
  75. >
  76. <div class="add-col">
  77. <el-input
  78. class="col-input"
  79. v-model="item.key"
  80. placeholder="参数名称"
  81. ></el-input>
  82. <el-input
  83. class="col-input"
  84. v-model="item.value"
  85. placeholder="参数值"
  86. ></el-input>
  87. <el-button
  88. class="del"
  89. type="text"
  90. @click="delt(item, index)"
  91. >
  92. 删除
  93. </el-button>
  94. </div>
  95. </el-form-item>
  96. </el-col>
  97. <el-col :span="24" v-if="form.extInfoSelf.length < 10">
  98. <el-form-item label-width="0">
  99. <el-button
  100. class="primarybutton"
  101. type="primary"
  102. @click="addItem"
  103. >增加自定义参数</el-button
  104. >
  105. </el-form-item>
  106. </el-col>
  107. </el-row>
  108. </div>
  109. </div>
  110. </el-form>
  111. <DialogGoods
  112. ref="DialogGoods"
  113. @succeed="cbDialogGoods"
  114. width="1200px"
  115. ></DialogGoods>
  116. </el-card>
  117. </div>
  118. </template>
  119. <script>
  120. import turnoverCarInformation from './components/turnoverCarInformation.vue';
  121. import warehouseConfigVue from '../components/warehouseConfig.vue';
  122. import productInfoVue from '../components/productInfo.vue';
  123. import planVue from '../components/plan.vue';
  124. import qualityConfig from '../components/qualityConfig.vue';
  125. import footerVue from '../components/footer.vue';
  126. import documentInformation from '../components/documentInformation.vue';
  127. import basicInfoVue from '../components/basicInfo.vue';
  128. import DialogGoods from '../components/DialogGoods';
  129. import assetInformation from '../components/assetInformation.vue';
  130. import businessInformation from '../components/businessInformation.vue';
  131. import { getDetails } from '@/api/classifyManage/itemInformation';
  132. import {
  133. saveOrEdit,
  134. getAssetInfo,
  135. getCode,
  136. getAssetNum
  137. } from '@/api/ledgerAssets';
  138. export default {
  139. components: {
  140. warehouseConfigVue,
  141. productInfoVue,
  142. planVue,
  143. qualityConfig,
  144. footerVue,
  145. documentInformation,
  146. DialogGoods,
  147. assetInformation,
  148. businessInformation,
  149. basicInfoVue,
  150. turnoverCarInformation
  151. },
  152. data() {
  153. return {
  154. labelStyle: {
  155. width: '200px'
  156. },
  157. contentStyle: {
  158. width: '400px'
  159. },
  160. isLink: true,
  161. title: '新建周转车信息',
  162. pageType: 'add',
  163. btnLoading: false,
  164. // 周转车主键id
  165. id: '',
  166. form: {
  167. extInfoSelf: [],
  168. // 基本信息
  169. code: '',
  170. name: '',
  171. productTime: '',
  172. workstation: {}
  173. },
  174. rules: {
  175. name: [
  176. { required: true, message: '请输入周转车名称', trigger: 'blur' }
  177. ],
  178. // location: [{ validator: addressValidation, trigger: 'change' }],
  179. code: [
  180. { required: true, message: '请输入周转车编码', trigger: 'blur' }
  181. ]
  182. },
  183. // 基本信息
  184. basicInfo: {},
  185. positionInfo: {
  186. // 详细地址
  187. deviceDetailAddress: '',
  188. // 请选择产线
  189. lineCode: '',
  190. lineName: '',
  191. // 请选择车间
  192. workshopCode: '',
  193. workshopName: '',
  194. // 请选择工厂
  195. factoryCode: '',
  196. factoryName: ''
  197. },
  198. // 图片
  199. imageUrl: null,
  200. // 文档信息
  201. attUrl: {
  202. operatingManual: {
  203. value: [],
  204. sort: 1
  205. },
  206. productionLicence: {
  207. value: [],
  208. sort: 2
  209. },
  210. explosionProofCertificate: {
  211. value: [],
  212. sort: 3
  213. },
  214. surveyReport: {
  215. value: [],
  216. sort: 4
  217. },
  218. inspectionCycleManual: {
  219. value: [],
  220. sort: 5
  221. },
  222. informationDrawing: {
  223. value: [],
  224. sort: 6
  225. },
  226. productCertificate: {
  227. value: [],
  228. sort: 7
  229. }
  230. },
  231. // 是否开始物联
  232. isIotEnable: true,
  233. // 物联ID
  234. iotId: '',
  235. // 回显过保时间
  236. cbexpirationTime: '',
  237. // 生命周期
  238. sourceDICT: '',
  239. // 网络状态
  240. networkStatus: '',
  241. id: ''
  242. };
  243. },
  244. props: {
  245. showTitle: {
  246. type: Boolean,
  247. default: true
  248. }
  249. },
  250. watch: {},
  251. computed: {
  252. // 过保时间
  253. expirationTime() {
  254. if (this.form.productTime && this.basicInfo.expirationDate) {
  255. return this.setGbTime(
  256. this.form.productTime,
  257. this.basicInfo.expirationDate,
  258. this.basicInfo.expirationDateUnit
  259. );
  260. } else {
  261. return '';
  262. }
  263. }
  264. },
  265. async created() {
  266. if (this.$route.query.id) {
  267. this.pageType = 'edit';
  268. this.id = this.$route.query.id;
  269. await this.getInfo();
  270. this.title = '编辑周转车信息';
  271. // this.getgys();
  272. // await this._getWarehouseChildren();
  273. } else {
  274. this.pageType = 'add';
  275. this.title = '新增周转车信息';
  276. }
  277. },
  278. methods: {
  279. handlwpbm() {
  280. this.$refs.DialogGoods.open('7');
  281. },
  282. async cbDialogGoods(data) {
  283. let res = await getDetails(data.id);
  284. if (!data.extInfoSelf) {
  285. data.extInfoSelf = [];
  286. }
  287. if (!data.workstation) {
  288. data.workstation = {};
  289. }
  290. if (!data.isPublic) {
  291. data.isPublic = 0;
  292. }
  293. this.form = data;
  294. this.form.category = res;
  295. this.basicInfo = data;
  296. this.form.rootCategoryLevelId = this.basicInfo.categoryLevelPathId
  297. .split(',')[0]
  298. .replace('[', '');
  299. this.form.categoryId = this.basicInfo.id;
  300. this.form.name = this.basicInfo.name;
  301. this.form.code = data.code; //Date.now(); //res.data[0].onlyCode;
  302. this.initOtherMsg();
  303. },
  304. // 计算过保时间
  305. setGbTime(basic, value, type) {
  306. basic = Date.parse(basic);
  307. let time;
  308. switch (type) {
  309. case 'minute':
  310. time = value * 1000 * 60;
  311. break;
  312. case 'hour':
  313. time = value * 1000 * 60 * 60;
  314. break;
  315. case 'day':
  316. time = value * 1000 * 60 * 60 * 24;
  317. break;
  318. case 'month':
  319. time = value * 1000 * 60 * 60 * 24 * 30;
  320. break;
  321. case 'year':
  322. time = value * 1000 * 60 * 60 * 24 * 365;
  323. break;
  324. default:
  325. break;
  326. }
  327. let num = basic + time;
  328. return parseTime(num);
  329. },
  330. // 添加自定义参数
  331. addItem() {
  332. if (this.form.extInfoSelf.length < 10) {
  333. let item = { key: '', value: '' };
  334. this.form.extInfoSelf.push(item);
  335. } else {
  336. this.$message.warning('自定义参数最多添加10条');
  337. }
  338. },
  339. // 删除自定义参数
  340. delt(item, index) {
  341. this.form.extInfoSelf.splice(index, 1);
  342. },
  343. // 提交
  344. submit() {
  345. if (JSON.stringify(this.basicInfo) === '{}' && this.pageType == 'add') {
  346. return this.$message.error('请选择物品');
  347. }
  348. this.$refs.form.validate(async (valid) => {
  349. if (valid) {
  350. let par = {
  351. //基本信息
  352. ...this.form,
  353. assetType: 1,
  354. // 资产信息
  355. positionIds: '1,1,1,1',
  356. position: {
  357. detailPosition: this.positionInfo.deviceDetailAddress,
  358. pathIds: `${
  359. this.positionInfo.factoryCode
  360. ? this.positionInfo.factoryCode + ','
  361. : ''
  362. }${
  363. this.positionInfo.workshopCode
  364. ? this.positionInfo.workshopCode + ','
  365. : ''
  366. }${this.positionInfo.lineCode}`,
  367. pathName: `${
  368. this.positionInfo.factoryName
  369. ? this.positionInfo.factoryName + ','
  370. : ''
  371. }${
  372. this.positionInfo.workshopName
  373. ? this.positionInfo.workshopName + ','
  374. : ''
  375. }${this.positionInfo.lineName}`,
  376. type: '1',
  377. num: 1
  378. },
  379. // 文档信息
  380. attUrl: this.setWd() || [],
  381. // 周转车图片
  382. imageUrl: this.imageUrl || {},
  383. // 是否启用物联
  384. isIotEnable: this.isIotEnable
  385. // 扩展字段
  386. // extInfoSelf: this.setKz()
  387. };
  388. par.deviceLocationName = par.location
  389. ? par.location.toString()
  390. : '';
  391. par.extInfo = { ...this.form.category.categoryVehicle };
  392. let obj = {};
  393. par.extInfoSelf.forEach((item) => {
  394. obj[item.key] = item.value;
  395. });
  396. par.extInfoSelf = obj;
  397. if (this.pageType == 'edit') {
  398. par.id = this.id;
  399. } else {
  400. const batchNo = await getCode('lot_number_code');
  401. const res = await getAssetNum({
  402. assetCode: par.code,
  403. batchNum: batchNo,
  404. num: 1
  405. });
  406. console.log(res);
  407. par.code = res.data.shift().onlyCode;
  408. par.id = '';
  409. }
  410. this.btnLoading = true;
  411. console.log('sasasasa', par);
  412. saveOrEdit(par)
  413. .then((res) => {
  414. this.$message.success('操作成功');
  415. this.$router.go(-1);
  416. })
  417. .finally(() => {
  418. this.btnLoading = false;
  419. });
  420. } else {
  421. console.log('error submit!!');
  422. return false;
  423. }
  424. });
  425. },
  426. // 处理扩展字段
  427. setKz() {
  428. return this.form.extInfoSelf || [];
  429. },
  430. // 处理文档信息
  431. setWd() {
  432. return Object.values(this.attUrl).map((item) => ({
  433. ...(item.value[0] || {}),
  434. sort: item.sort
  435. }));
  436. },
  437. // 获取周转车详情
  438. async getInfo() {
  439. const data = await getAssetInfo(this.id);
  440. // 扩展字段
  441. data.extInfoSelf = data.extInfoSelf || [];
  442. // 权属人相关信息
  443. if (!data.workstation) {
  444. data.workstation = {};
  445. }
  446. // 资产信息类型默认专用
  447. if (!data.isPublic) {
  448. data.isPublic = 0;
  449. }
  450. this.form = data;
  451. this.form.location = data.deviceLocationName.split(',');
  452. this.basicInfo = data;
  453. this.cbexpirationTime = data.expirationTime;
  454. this.sourceDICT = data.sourceDICT;
  455. this.networkStatus = data.networkStatus;
  456. this.positionInfo.deviceDetailAddress = data.deviceDetailAddress;
  457. this.initOtherMsg();
  458. // 周转车图片
  459. this.imageUrl = data.imageUrl;
  460. // 物联参数
  461. this.isIotEnable = data.isIotEnable;
  462. this.iotId = data.iotId;
  463. },
  464. async initOtherMsg() {
  465. // 基本信息
  466. this.$refs.basicInfoVueRef.getDetailInfoAugr(
  467. this.form.category.category
  468. );
  469. // 仓储配置
  470. this.$refs.warehouseConfigRef.getDetailInfoAugr(
  471. this.form.category.categoryWms
  472. );
  473. // 生产信息
  474. this.$refs.productInfoRef.getDetailInfoAugr(
  475. this.form.category.categoryMes
  476. );
  477. // 计划配置
  478. this.$refs.planRef.getDetailInfoAugr(this.form.category.categoryAps);
  479. // 质量配置
  480. this.$refs.qualityConfigRef.getDetailInfoAugr(
  481. this.form.category.categoryQms
  482. );
  483. // 周转车信息
  484. this.$refs.turnoverCarInformationRef.getDetailInfoAugr(
  485. this.form.category.categoryVehicle
  486. );
  487. // 其他和关联信息
  488. this.$refs.footerVueRef.getDetailInfoAugr(this.form.category.category);
  489. // 文档信息
  490. if (this.form.attUrl && this.form.attUrl.length > 0) {
  491. Object.keys(this.attUrl).forEach((n, index) => {
  492. this.attUrl[n].value =
  493. (this.form.attUrl[index]?.storePath && [
  494. this.form.attUrl[index]
  495. ]) ||
  496. [];
  497. });
  498. this.$refs.documentInformationRef.getDetailInfoAugr(this.attUrl);
  499. }
  500. },
  501. // 设置标准产能
  502. setbzcn(val) {
  503. if (!val) {
  504. return '';
  505. }
  506. let item = JSON.parse(val);
  507. return item.standardCapacity || '';
  508. }
  509. }
  510. };
  511. </script>
  512. <style lang="scss" scoped>
  513. ::v-deep .descriptions {
  514. margin-bottom: 10px;
  515. }
  516. .baseinfo-container .basic-details-title {
  517. font-size: 16px;
  518. margin: 15px 0;
  519. }
  520. .upload-container {
  521. display: flex;
  522. justify-content: flex-start;
  523. .file-list {
  524. margin-left: 50px;
  525. flex: 1;
  526. }
  527. }
  528. .equipment-container {
  529. .label-none {
  530. .el-form-item__content {
  531. margin-left: 0 !important;
  532. }
  533. }
  534. }
  535. .sbwz {
  536. .item {
  537. width: 120px !important;
  538. }
  539. .item + .item {
  540. margin-left: 10px;
  541. }
  542. .item-input {
  543. width: 350px !important;
  544. }
  545. }
  546. .input {
  547. width: 100%;
  548. }
  549. .kzzd {
  550. width: 500px;
  551. .add-col {
  552. display: flex;
  553. .col-input {
  554. & + .col-input {
  555. margin-left: 10px;
  556. }
  557. }
  558. .del {
  559. margin-left: 10px;
  560. }
  561. }
  562. }
  563. ::v-deep .el-descriptions {
  564. .el-form-item {
  565. margin-bottom: 0px;
  566. }
  567. }
  568. </style>