BaseForm.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. <template>
  2. <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
  3. <a-row :gutter="48" slot="extra">
  4. <a-col :md="48" :sm="48">
  5. <span class="table-page-search-submitButtons" style="float: right" >
  6. <a-button style="margin-left: 8px" type="primary" @click="save()">保存</a-button>
  7. <a-button style="margin-left: 8px" @click="handleCancel()">返回列表</a-button>
  8. </span>
  9. </a-col>
  10. </a-row>
  11. <a-form :form="form">
  12. <a-form-item v-show="false" >
  13. <a-input v-decorator="['id']" type="hidden"/>
  14. <a-input v-decorator="['sbId']" type="hidden"/>
  15. <a-input v-decorator="['typeId']" type="hidden"/>
  16. </a-form-item>
  17. <a-form-item v-show="false" >
  18. <a-input v-decorator="['unit']" type="hidden"/>
  19. </a-form-item>
  20. <a-form-item v-show="false" >
  21. <a-input v-decorator="['unitBz']" type="hidden"/>
  22. </a-form-item>
  23. <a-form-item v-show="false">
  24. <a-input v-decorator="['producerId']" />
  25. </a-form-item>
  26. <a-form-item v-show="false">
  27. <a-input v-decorator="['supplierId']" />
  28. </a-form-item>
  29. <title-divider title="基础信息" width="100px"></title-divider>
  30. <row-list :col="2">
  31. <row-item>
  32. <a-form-item
  33. label="类别"
  34. :labelCol="BaseTool.Constant.labelCol"
  35. :wrapperCol="BaseTool.Constant.wrapperCol"
  36. >
  37. <a-tree-select
  38. style="width: 100%"
  39. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  40. :treeData="spareTypeData"
  41. :treeNodeFilterProp="'title'"
  42. :showSearch="true"
  43. v-decorator="['parentTypeId', {rules: [{required: true, message: '类别不能为空'}]}]"
  44. placeholder="请选择"
  45. >
  46. </a-tree-select>
  47. </a-form-item>
  48. </row-item>
  49. <row-item>
  50. <a-form-item
  51. label="备件名称"
  52. :labelCol="BaseTool.Constant.labelCol"
  53. :wrapperCol="BaseTool.Constant.wrapperCol"
  54. >
  55. <a-input
  56. v-decorator="['name', {rules: [{required: true, message: '设备名称不能为空'}]}]" />
  57. </a-form-item>
  58. </row-item>
  59. <row-item>
  60. <a-form-item
  61. label="规格型号"
  62. :labelCol="BaseTool.Constant.labelCol"
  63. :wrapperCol="BaseTool.Constant.wrapperCol"
  64. >
  65. <a-input
  66. v-decorator="['ggxh']" />
  67. </a-form-item>
  68. </row-item>
  69. <row-item>
  70. <a-form-item
  71. label="生产商"
  72. :labelCol="BaseTool.Constant.labelCol"
  73. :wrapperCol="BaseTool.Constant.wrapperCol"
  74. >
  75. <a-input
  76. style="width: 70%"
  77. disabled
  78. v-decorator="['producerName']" />
  79. <a-button style="width: 30%" type="primary" @click="handleProducerSelect">选择</a-button>
  80. </a-form-item>
  81. </row-item>
  82. <row-item>
  83. <a-form-item
  84. label="备件价值"
  85. :labelCol="BaseTool.Constant.labelCol"
  86. :wrapperCol="BaseTool.Constant.wrapperCol"
  87. >
  88. <a-input-number
  89. style="width: 100%"
  90. :min="0"
  91. :step="0.01"
  92. :formatter="BaseTool.Amount.formatter"
  93. :parser="BaseTool.Amount.parser"
  94. v-decorator="['initialValue', {rules: [{required: true, message: '备件价值不能为空'}]}]" />
  95. </a-form-item>
  96. </row-item>
  97. <row-item>
  98. <a-form-item
  99. label="采购供应商"
  100. :labelCol="BaseTool.Constant.labelCol"
  101. :wrapperCol="BaseTool.Constant.wrapperCol"
  102. >
  103. <a-input
  104. style="width: 70%"
  105. disabled
  106. v-decorator="['supplierName']" />
  107. <a-button style="width: 30%" type="primary" @click="handleSupplierSelect">选择</a-button>
  108. </a-form-item>
  109. </row-item>
  110. <row-item>
  111. <a-form-item
  112. label="备件编号"
  113. :labelCol="BaseTool.Constant.labelCol"
  114. :wrapperCol="BaseTool.Constant.wrapperCol"
  115. >
  116. <a-input
  117. v-decorator="['no', {rules: [{required: false, message: '备件编码不能为空'}]}]" />
  118. </a-form-item>
  119. </row-item>
  120. <row-item>
  121. <a-form-item
  122. label="原厂编号"
  123. :labelCol="BaseTool.Constant.labelCol"
  124. :wrapperCol="BaseTool.Constant.wrapperCol"
  125. >
  126. <a-input
  127. style="width: 100%"
  128. v-decorator="['initNo']" />
  129. </a-form-item>
  130. </row-item>
  131. <row-item>
  132. <a-form-item
  133. label="自编号"
  134. :labelCol="BaseTool.Constant.labelCol"
  135. :wrapperCol="BaseTool.Constant.wrapperCol"
  136. >
  137. <a-input
  138. v-decorator="['zbh', {rules: [{required: false, message: '自编号不能为空'}]}]" />
  139. </a-form-item>
  140. </row-item>
  141. <row-item>
  142. <a-form-item
  143. label="助记码"
  144. :labelCol="BaseTool.Constant.labelCol"
  145. :wrapperCol="BaseTool.Constant.wrapperCol"
  146. >
  147. <a-input
  148. v-decorator="['zjm']" />
  149. </a-form-item>
  150. </row-item>
  151. <row-item>
  152. <a-form-item
  153. label="备件等级"
  154. :labelCol="BaseTool.Constant.labelCol"
  155. :wrapperCol="BaseTool.Constant.wrapperCol"
  156. >
  157. <a-select v-decorator="['level', {initialValue: 1}]" placeholder="请选择">
  158. <a-select-option
  159. v-for="(label,value) in levelMap"
  160. :key="value"
  161. :label="label"
  162. :value="parseInt(value)">{{ label }}
  163. </a-select-option>
  164. </a-select>
  165. </a-form-item>
  166. </row-item>
  167. <row-item>
  168. <a-form-item
  169. label="计量单位"
  170. :labelCol="BaseTool.Constant.labelCol"
  171. :wrapperCol="BaseTool.Constant.wrapperCol"
  172. >
  173. <a-select
  174. show-search
  175. :value="unitName"
  176. :default-active-first-option="false"
  177. :show-arrow="true"
  178. :filter-option="true"
  179. :not-found-content="null"
  180. @search="handleSearch"
  181. @blur="handleBlur"
  182. @change="handleChange">
  183. <a-select-option
  184. v-for="(label,value) in unitMap"
  185. :key="value"
  186. :label="label"
  187. :value="label">{{ label }}
  188. </a-select-option>
  189. </a-select>
  190. </a-form-item>
  191. </row-item>
  192. <!-- <row-item>
  193. <a-form-item
  194. label="包装单位"
  195. :labelCol="BaseTool.Constant.labelCol"
  196. :wrapperCol="BaseTool.Constant.wrapperCol"
  197. >
  198. <a-select
  199. show-search
  200. :value="unitNameBz"
  201. :default-active-first-option="false"
  202. :show-arrow="true"
  203. :filter-option="true"
  204. :not-found-content="null"
  205. @search="handleSearchBz"
  206. @blur="handleBlurBz"
  207. @change="handleChangeBz">
  208. <a-select-option
  209. v-for="(label,value) in unitMap"
  210. :key="value"
  211. :label="label"
  212. :value="label">{{ label }}
  213. </a-select-option>
  214. </a-select>
  215. </a-form-item>
  216. </row-item>
  217. <row-item>
  218. <a-form-item
  219. label="折算系数"
  220. :labelCol="BaseTool.Constant.labelCol"
  221. :wrapperCol="BaseTool.Constant.wrapperCol"
  222. >
  223. <a-input
  224. placeholder="单位折算为包装单位,如24个单位包装为一箱"
  225. v-decorator="['unitRate']" />
  226. </a-form-item>
  227. </row-item>-->
  228. <row-item>
  229. <a-form-item
  230. label="采购周期"
  231. :labelCol="BaseTool.Constant.labelCol"
  232. :wrapperCol="BaseTool.Constant.wrapperCol"
  233. >
  234. <a-input suffix="天" v-decorator="['purchasePeriod']" />
  235. </a-form-item>
  236. </row-item>
  237. <row-item>
  238. <a-form-item
  239. label="使用周期"
  240. :labelCol="BaseTool.Constant.labelCol"
  241. :wrapperCol="BaseTool.Constant.wrapperCol"
  242. >
  243. <a-input suffix="月" v-decorator="['usePeriod']" />
  244. </a-form-item>
  245. </row-item>
  246. <row-item>
  247. <a-form-item
  248. label="寿命周期"
  249. :labelCol="BaseTool.Constant.labelCol"
  250. :wrapperCol="BaseTool.Constant.wrapperCol"
  251. >
  252. <a-input suffix="月" v-decorator="['agePeriod']" />
  253. </a-form-item>
  254. </row-item>
  255. <row-item>
  256. <a-form-item
  257. label="最高库存"
  258. :labelCol="BaseTool.Constant.labelCol"
  259. :wrapperCol="BaseTool.Constant.wrapperCol"
  260. >
  261. <a-input-number
  262. style="width: 100%"
  263. :min="1"
  264. v-decorator="['maxStock']" />
  265. </a-form-item>
  266. </row-item>
  267. <row-item>
  268. <a-form-item
  269. label="最低库存"
  270. :labelCol="BaseTool.Constant.labelCol"
  271. :wrapperCol="BaseTool.Constant.wrapperCol"
  272. >
  273. <a-input-number
  274. style="width: 100%"
  275. :min="1"
  276. v-decorator="['minStock']" />
  277. </a-form-item>
  278. </row-item>
  279. <row-item v-show="isAdd">
  280. <a-form-item
  281. label="初始库位"
  282. :labelCol="BaseTool.Constant.labelCol"
  283. :wrapperCol="BaseTool.Constant.wrapperCol"
  284. >
  285. <a-tree-select
  286. style="width: 100%"
  287. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  288. :treeData="storeTreeDate"
  289. :treeNodeFilterProp="'title'"
  290. :showSearch="true"
  291. v-decorator="['storeId', {rules: [{required: false, message: '仓库库位不能为空'}]}]"
  292. placeholder="请选择"
  293. >
  294. </a-tree-select>
  295. </a-form-item>
  296. </row-item>
  297. <row-item v-show="isAdd">
  298. <a-form-item
  299. label="初始库存"
  300. :labelCol="BaseTool.Constant.labelCol"
  301. :wrapperCol="BaseTool.Constant.wrapperCol"
  302. >
  303. <a-input-number
  304. style="width: 100%"
  305. :min="1"
  306. v-decorator="['initStock']" />
  307. </a-form-item>
  308. </row-item>
  309. <row-item>
  310. <a-form-item
  311. label="英文名称"
  312. :labelCol="BaseTool.Constant.labelCol"
  313. :wrapperCol="BaseTool.Constant.wrapperCol"
  314. >
  315. <a-input
  316. v-decorator="['englishName', {rules: [{required: false, message: '英文名称不能为空'}]}]" />
  317. </a-form-item>
  318. </row-item>
  319. <row-item>
  320. <a-form-item
  321. label="产地"
  322. :labelCol="BaseTool.Constant.labelCol"
  323. :wrapperCol="BaseTool.Constant.wrapperCol"
  324. >
  325. <a-select v-decorator="['cd']" placeholder="请选择">
  326. <a-select-option
  327. v-for="(label,value) in cdMap"
  328. :key="value"
  329. :label="label"
  330. :value="parseInt(value)">{{ label }}
  331. </a-select-option>
  332. </a-select>
  333. </a-form-item>
  334. </row-item>
  335. <row-item>
  336. <a-form-item
  337. label="备件图片"
  338. :labelCol="BaseTool.Constant.labelCol"
  339. :wrapperCol="BaseTool.Constant.wrapperCol"
  340. >
  341. <a-upload
  342. :action="uploadUrl"
  343. :multiple="true"
  344. list-type="picture"
  345. :file-list="this.defaultApplicationFileList"
  346. @change="handleApplicationFileChange"
  347. accept="image/*"
  348. :headers="headers"
  349. >
  350. <a-button> <a-icon type="upload" /> 上传图片 </a-button>
  351. </a-upload>
  352. </a-form-item>
  353. </row-item>
  354. <row-item>
  355. <a-form-item
  356. label="参数"
  357. :labelCol="BaseTool.Constant.labelCol"
  358. :wrapperCol="BaseTool.Constant.wrapperCol"
  359. >
  360. <a-textarea
  361. v-decorator="['params']" />
  362. </a-form-item>
  363. </row-item>
  364. <row-item>
  365. <a-form-item
  366. label="备注"
  367. :labelCol="BaseTool.Constant.labelCol"
  368. :wrapperCol="BaseTool.Constant.wrapperCol"
  369. >
  370. <a-textarea
  371. v-decorator="['remark']" />
  372. </a-form-item>
  373. </row-item>
  374. </row-list>
  375. </a-form>
  376. <title-divider title="设备信息" width="100px"></title-divider>
  377. <div class="table-operator">
  378. <a-button style="margin-left:8px;" type="primary" @click="handleSbSelect">
  379. <a-icon type="plus"/>
  380. 添加
  381. </a-button>
  382. <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
  383. <a-icon type="delete"/>
  384. 删除
  385. </a-button>
  386. </div>
  387. <a-table
  388. :data-source="data"
  389. :columns="columns"
  390. bordered
  391. tableLayout="auto"
  392. :row-selection="rowSelection"
  393. rowKey="id">
  394. <span slot="action" slot-scope="record">
  395. <template>
  396. <a v-if="$auth('sb-infos-edit')" @click="handleDetailSelect(record)">修改</a>
  397. <a-divider type="vertical" />
  398. <a-popconfirm v-if="$auth('sb-infos-del')" title="是否要删除该条数据?" @confirm="handleDelOne(record.id)">
  399. <a>删除</a>
  400. </a-popconfirm>
  401. </template>
  402. </span>
  403. </a-table>
  404. <p style="color: red">仓库数量初始化注意事项:<br/>
  405. 1:初始化库存仅能选择一个库位入库<br/>
  406. 2:初始化库存仅能新增,如需要修改请在仓库管理->仓库库存中修改数量<br/>
  407. </p>
  408. <template slot="footer">
  409. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  410. </template>
  411. <firm-producer-select-modal ref="producerSelectModal" @selected="handleProducerSelected"/>
  412. <supplier-select-modal ref="supplierSelectModal" @selected="handleSupplierSelected"/>
  413. <store-select-modal ref="storeSelectModal" @selected="handleStoreSelected"/>
  414. <sb-info-select-modal :type="'checkbox'" ref="sbInfoSelectModal" @selected="handleSbSelected"/>
  415. <base-form-spare ref="baseModal" @selected="handleDetailSelected"/>
  416. </a-card>
  417. </template>
  418. <script>
  419. import pick from 'lodash.pick'
  420. import { addSparePartInfo, querySparePartInfo, updateSparePartInfo } from '@/api/sqarepartmanage/sparepartinfo'
  421. import { querySpareType, fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
  422. import { fetchSbGuigeOptions } from '@/api/sb/guige'
  423. import FirmProducerSelectModal from '@/views/firm/producer/modules/FirmProducerSelectModal'
  424. import SupplierSelectModal from '@/views/purchase/supplier/modules/SupplierSelectModal'
  425. import UploadSpareFile from '@/components/Upload/UploadSpareFile'
  426. import Vue from 'vue'
  427. import StoreSelectModal from '@/views/store/store/modules/StoreSelectModal'
  428. import { uploadUrl } from '@/api/upms/file'
  429. import { ACCESS_TOKEN } from '@/store/mutation-types'
  430. import { fetchStoreTree } from '@/api/store/store'
  431. import { selectSbModelListBySpareId } from '@/api/sb/modelbom'
  432. import SbInfoSelectModal from '@/views/sb/info/modules/SbInfoSelectModal'
  433. import BaseFormSpare from '@/views/sb/modelbom/modules/BaseFormSpare'
  434. export default {
  435. name: 'BaseSparePartInfo',
  436. components: {
  437. FirmProducerSelectModal,
  438. SupplierSelectModal,
  439. UploadSpareFile,
  440. StoreSelectModal,
  441. SbInfoSelectModal,
  442. BaseFormSpare
  443. },
  444. data () {
  445. return {
  446. isAdd: false,
  447. unitName: null,
  448. unitNameBz: null,
  449. rowSelection: {
  450. onChange: (selectedRowKeys, selectedRows) => {
  451. this.selectedRowKeys = selectedRowKeys
  452. this.selectedRows = selectedRows
  453. }
  454. },
  455. gg: null,
  456. storeTreeDate: [],
  457. uploadUrl: uploadUrl,
  458. defaultApplicationFileList: [],
  459. applicationFileList: [], // 备件图片
  460. confirmLoading: false,
  461. modalTitle: null,
  462. form: this.$form.createForm(this),
  463. visible: false,
  464. // 下拉框map
  465. levelMap: {},
  466. periodTypeMap: {},
  467. unitMap: {},
  468. cdMap: {},
  469. ytMap: {},
  470. spareTypeData: [],
  471. spareTypeDataMiddle: [],
  472. spareTypeDataChild: [],
  473. producers: [],
  474. ggList: [],
  475. headers: {
  476. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  477. },
  478. // 表头
  479. columns: [
  480. {
  481. title: '型号',
  482. dataIndex: 'model'
  483. },
  484. {
  485. title: '名称',
  486. dataIndex: 'name'
  487. },
  488. {
  489. title: '新号',
  490. dataIndex: 'no'
  491. },
  492. {
  493. title: '旧号',
  494. dataIndex: 'zbh'
  495. },
  496. {
  497. title: '更换周期',
  498. dataIndex: 'period',
  499. customRender: (text, record, index) => {
  500. return text + this.BaseTool.Table.getMapText(this.periodTypeMap, record.periodType)
  501. }
  502. },
  503. {
  504. title: '数量',
  505. dataIndex: 'num'
  506. },
  507. {
  508. title: '操作',
  509. key: 'action',
  510. checked: true,
  511. align: 'center',
  512. // fixed: 'right',
  513. scopedSlots: { customRender: 'action' }
  514. }
  515. ],
  516. data: [],
  517. sbId: null,
  518. selectedRowKeys: [],
  519. selectedRows: [],
  520. options: {
  521. rowSelection: {
  522. selectedRowKeys: this.selectedRowKeys
  523. }
  524. }
  525. }
  526. },
  527. props: {
  528. },
  529. created () {
  530. // 下拉框map
  531. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_INFO_LEVEL)
  532. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  533. this.cdMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PRODUCER_AREA)
  534. this.ytMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_USE_TYPE)
  535. this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
  536. },
  537. methods: {
  538. base (record, sbId) {
  539. this.setTree(record)
  540. this.visible = true
  541. this.sbId = sbId
  542. console.log('sbId: ', sbId)
  543. // 如果是空标识添加
  544. if (this.BaseTool.Object.isBlank(record)) {
  545. this.modalTitle = '添加'
  546. this.isAdd = true
  547. return
  548. }
  549. this.modalTitle = '编辑'
  550. if (this.BaseTool.Object.isBlank(record.id)) {
  551. this.modalTitle = '复制'
  552. }
  553. selectSbModelListBySpareId({ id: record.id }).then(res => {
  554. this.data = res.data
  555. })
  556. const { form: { setFieldsValue } } = this
  557. this.applicationFileList = record.applicationFileList
  558. this.defaultApplicationFileList = this.BaseTool.UPLOAD.transImg(this.applicationFileList)
  559. this.unitName = record.unit
  560. this.unitNameBz = record.unitBz
  561. this.gg = record.ggxh
  562. // 日期处理
  563. this.$nextTick(() => {
  564. setFieldsValue(Object.assign(pick(record, [
  565. 'id',
  566. 'no',
  567. 'sbId',
  568. 'initNo',
  569. 'uniteNo',
  570. 'nameNo',
  571. 'ggNo',
  572. 'name',
  573. 'parentTypeId',
  574. 'middleTypeId',
  575. 'childTypeId',
  576. 'typeId',
  577. 'level',
  578. 'initialValue',
  579. 'producerId',
  580. 'producerName',
  581. 'supplierId',
  582. 'supplierName',
  583. 'unit',
  584. 'unitBz',
  585. 'unitRate',
  586. 'englishName',
  587. 'childNo',
  588. 'parentNo',
  589. 'parentName',
  590. 'childName',
  591. 'typeName',
  592. 'middleNo',
  593. 'middleName',
  594. 'cd',
  595. 'ggxh',
  596. // 'yt',
  597. 'zjm',
  598. 'zbh',
  599. 'maxStock',
  600. 'minStock',
  601. 'initStock',
  602. 'remark'
  603. ])))
  604. })
  605. },
  606. save () {
  607. const { form: { validateFieldsAndScroll, setFieldsValue } } = this
  608. this.confirmLoading = true
  609. console.log('sbId: ' + this.sbId)
  610. setFieldsValue({
  611. 'unit': this.unitName,
  612. 'unitBz': this.unitNameBz,
  613. 'sbId': this.sbId
  614. })
  615. validateFieldsAndScroll((errors, values) => {
  616. if (errors) {
  617. this.confirmLoading = false
  618. return
  619. }
  620. values.applicationFileList = this.applicationFileList
  621. values.detailList = this.data
  622. // 日期处理
  623. if (this.BaseTool.String.isBlank(values.id)) {
  624. addSparePartInfo(values)
  625. .then(() => {
  626. this.handleCancel(values)
  627. }).catch(() => {
  628. this.confirmLoading = false
  629. })
  630. } else {
  631. updateSparePartInfo(values)
  632. .then(() => {
  633. this.handleCancel(values)
  634. }).catch(() => {
  635. this.confirmLoading = false
  636. })
  637. }
  638. })
  639. },
  640. handleProducerSelect () {
  641. this.$refs.producerSelectModal.base({}, { type: 3 })
  642. },
  643. handleProducerSelected (record, selectedRowKeys, selectedRow) {
  644. const { form: { setFieldsValue } } = this
  645. const [ key ] = selectedRowKeys
  646. const [ row ] = selectedRow
  647. setFieldsValue({
  648. 'producerId': key,
  649. 'producerName': row.name
  650. })
  651. },
  652. handleSupplierSelect () {
  653. this.$refs.supplierSelectModal.base()
  654. },
  655. handleSupplierSelected (record, selectedRowKeys, selectedRow) {
  656. const { form: { setFieldsValue } } = this
  657. const [ key ] = selectedRowKeys
  658. const [ row ] = selectedRow
  659. setFieldsValue({
  660. 'supplierId': key,
  661. 'supplierName': row.name
  662. })
  663. },
  664. handleCancel (values) {
  665. this.visible = false
  666. this.confirmLoading = false
  667. this.form.resetFields()
  668. this.unitName = null
  669. this.unitNameBz = null
  670. this.gg = null
  671. this.isAdd = true
  672. this.data = []
  673. if (this.BaseTool.Object.isNotBlank(values)) {
  674. this.$emit('ok', values)
  675. } else {
  676. this.$emit('ok')
  677. }
  678. },
  679. /**
  680. * 设置仓库、备件类别树
  681. */
  682. setTree (record = {}) {
  683. fetchStoreTree().then(res => {
  684. this.storeTreeDate = res.data
  685. })
  686. fetchSpareTypeTree().then(res => {
  687. this.spareTypeData = res.data
  688. })
  689. /* querySpareType({ filter: 2, parentId: record.parentTypeId }).then(res => {
  690. this.spareTypeDataMiddle = res.data
  691. })
  692. querySpareType({ filter: 2, parentId: record.middleTypeId }).then(res => {
  693. this.spareTypeDataChild = res.data
  694. }) */
  695. fetchSbGuigeOptions().then(res => {
  696. this.ggList = res.data
  697. })
  698. },
  699. checkSpareNo () {
  700. const { form: { getFieldValue } } = this
  701. const typeId = getFieldValue('typeId')
  702. const name = getFieldValue('name')
  703. // const ggxh = getFieldValue('ggxh')
  704. if (typeId == null) {
  705. this.$message.error('请先设置大小类型')
  706. return
  707. }
  708. querySparePartInfo({
  709. typeId: typeId,
  710. name: name,
  711. dataScope: {
  712. sortBy: 'desc',
  713. sortName: 'name'
  714. }
  715. }).then(res => {
  716. this.data = res.data
  717. })
  718. },
  719. /**
  720. * @function 任务类型文本框的值变化时的回调
  721. * @author ***
  722. * @time 2020-08-17
  723. **/
  724. handleSearch (value) {
  725. this.handleChange(value)
  726. },
  727. /**
  728. * @function 任务类型改变时的回调
  729. * @author ***
  730. * @time 2020-08-17
  731. **/
  732. handleChange (value) {
  733. this.unitName = (!isNaN(value) && value !== '') ? this.BaseTool.Object.getField(this.unitMap, value) : value
  734. if (isNaN(this.unitName) || this.unitName === '') {
  735. this.unitName = value
  736. }
  737. },
  738. /**
  739. * @function 修改设备关联
  740. * @author ***
  741. * @time 2020-08-17
  742. **/
  743. handleDetailSelect (record) {
  744. const modal = this.$refs.baseModal
  745. modal.base(record)
  746. },
  747. handleDetailSelected (values) {
  748. const newData = [...this.data]
  749. for (let j = 0; j < newData.length; j++) {
  750. if (values.sbId === newData[j].sbId) {
  751. newData[j].num = values.num
  752. newData[j].period = values.period
  753. newData[j].periodType = values.periodType
  754. break
  755. }
  756. }
  757. this.data = newData
  758. },
  759. /**
  760. * @function 添加关联设备
  761. * @author ***
  762. * @time 2020-08-17
  763. **/
  764. handleSbSelect () {
  765. const modal = this.$refs.sbInfoSelectModal
  766. modal.base()
  767. },
  768. handleSbSelected (keys, rows) {
  769. const { data } = this
  770. for (let i = 0; i < rows.length; i++) {
  771. var find = false
  772. for (let j = 0; j < data.length; j++) {
  773. if (rows[i].id === data[j].sbId) {
  774. find = true
  775. break
  776. }
  777. }
  778. if (!find) {
  779. const sbId = rows[i].id
  780. const selectData = rows[i]
  781. selectData.num = 1
  782. selectData.sbId = sbId
  783. selectData.id = null
  784. selectData.period = 1
  785. selectData.periodType = 1
  786. data.push(selectData)
  787. }
  788. }
  789. },
  790. /**
  791. * @function 任务类型失焦事件
  792. * @author ***
  793. * @time 2020-08-17
  794. **/
  795. handleBlur (value) {
  796. this.unitName = value
  797. },
  798. /**
  799. * @function 任务类型文本框的值变化时的回调
  800. * @author ***
  801. * @time 2020-08-17
  802. **/
  803. handleSearchBz (value) {
  804. this.handleChange(value)
  805. },
  806. /**
  807. * @function 任务类型改变时的回调
  808. * @author ***
  809. * @time 2020-08-17
  810. **/
  811. handleChangeBz (value) {
  812. this.unitNameBz = (!isNaN(value) && value !== '') ? this.BaseTool.Object.getField(this.unitMap, value) : value
  813. if (isNaN(this.unitNameBz) || this.unitNameBz === '') {
  814. this.unitNameBz = value
  815. }
  816. },
  817. /**
  818. * @function 任务类型失焦事件
  819. * @author ***
  820. * @time 2020-08-17
  821. **/
  822. handleBlurBz (value) {
  823. this.unitNameBz = value
  824. },
  825. /**
  826. * @function 任务类型文本框的值变化时的回调
  827. * @author ***
  828. * @time 2020-08-17
  829. **/
  830. handleSearchG (value) {
  831. this.handleChangeG(value)
  832. },
  833. /**
  834. * @function 任务类型改变时的回调
  835. * @author ***
  836. * @time 2020-08-17
  837. **/
  838. handleChangeG (value) {
  839. this.gg = (!isNaN(this.ggList[value]) && this.ggList[value] !== '') ? this.ggList[value].label : value
  840. if (isNaN(this.gg) || this.gg === '') {
  841. this.gg = value
  842. }
  843. },
  844. handleStoreSelect () {
  845. this.$refs.storeSelectModal.base()
  846. },
  847. handleStoreSelected (record, keys, rows) {
  848. const [ key ] = keys
  849. const [ row ] = rows
  850. const { form: { setFieldsValue } } = this
  851. // 日期处理
  852. this.$nextTick(() => {
  853. setFieldsValue(Object.assign({
  854. 'storeId': key,
  855. 'storeName': row.name
  856. }))
  857. })
  858. },
  859. handleDel (id) {
  860. const data = [...this.data]
  861. if (this.selectedRowKeys.length === 0) {
  862. this.$message.error('请至少选择一条数据')
  863. return
  864. }
  865. this.data = data.filter(item => !this.selectedRowKeys.includes(item.id))
  866. },
  867. handleDelOne (id) {
  868. const data = [...this.data]
  869. this.data = data.filter(item => id !== item.id)
  870. },
  871. /**
  872. * @function 任务类型失焦事件
  873. * @author ***
  874. * @time 2020-08-17
  875. **/
  876. handleBlurG (value) {
  877. this.gg = value
  878. },
  879. parentChange (val, option) {
  880. querySpareType({ parentId: val, filter: 2 }).then(res => {
  881. this.spareTypeDataMiddle = res.data
  882. })
  883. const { form: { setFieldsValue } } = this
  884. setFieldsValue({ parentNo: option.data.key, typeId: val, middleTypeId: null, middleNo: null, childTypeId: null, childNo: null })
  885. },
  886. middleChange (val, option) {
  887. querySpareType({ parentId: val, filter: 2 }).then(res => {
  888. this.spareTypeDataChild = res.data
  889. })
  890. const { form: { setFieldsValue } } = this
  891. setFieldsValue({ middleNo: option.data.key, typeId: val, childTypeId: null, childNo: null })
  892. },
  893. childChange (val, option) {
  894. const { form: { setFieldsValue } } = this
  895. setFieldsValue({ childNo: option.data.key, typeId: val, childTypeId: val })
  896. },
  897. handleApplicationFileChange (info) {
  898. this.defaultApplicationFileList = info.fileList
  899. this.applicationFileList = this.setFileList(info, 14)
  900. },
  901. setFileList (info, type) {
  902. const file = info.file
  903. const fileList = info.fileList
  904. if (file.status === 'done') {
  905. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  906. } else if (file.status === 'removed') {
  907. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  908. } else if (file.status === 'error') {
  909. this.$message.error('上传失败')
  910. return []
  911. }
  912. }
  913. }
  914. }
  915. </script>