edit.vue 16 KB

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