add.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <div id="addDivision">
  3. <el-card style="height: calc(100vh - 15vh);position: relative;overflow: scroll;">
  4. <span>基本信息</span>
  5. <el-form :model="basicForm" :rules="basicRules" ref="basic" label-width="auto">
  6. <el-row :gutter="10">
  7. <el-col :span="1.5">
  8. <el-form-item label="物料分类编码">
  9. <el-input :disabled="disable" size="mini" style="width: 200px" readonly v-model="basicForm.materialClassify">
  10. <el-button slot="append" icon="el-icon-more" @click="chooseFourClass"></el-button>
  11. </el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="1.5">
  15. <el-form-item label="物料分类名称">
  16. <el-input
  17. v-model="basicForm.materialClassifyName"
  18. size="mini"
  19. disabled
  20. clearable
  21. style="width: 200px"
  22. />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="1.5">
  26. <el-form-item label="一级分类编码">
  27. <el-input
  28. v-model="basicForm.materialClassifyOne"
  29. size="mini"
  30. disabled
  31. clearable
  32. style="width: 200px"
  33. />
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-form-item label="一级分类名称">
  38. <el-input
  39. v-model="basicForm.materialClassifyOneName"
  40. size="mini"
  41. disabled
  42. clearable
  43. style="width: 200px"
  44. />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-form-item label="二级分类名称">
  49. <el-input
  50. v-model="basicForm.materialClassifyTwoName"
  51. size="mini"
  52. disabled
  53. clearable
  54. style="width: 200px"
  55. />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="1.5">
  59. <el-form-item label="三级分类名称">
  60. <el-input
  61. v-model="basicForm.materialClassifyThreeName"
  62. size="mini"
  63. disabled
  64. clearable
  65. style="width: 200px"
  66. />
  67. </el-form-item>
  68. </el-col>
  69. <el-col :span="1.5">
  70. <el-form-item label="四级分类名称">
  71. <el-input
  72. v-model="basicForm.materialClassifyFourName"
  73. size="mini"
  74. disabled
  75. clearable
  76. style="width: 200px"
  77. />
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="1.5">
  81. <el-form-item label="物料编码">
  82. <el-input :disabled="disable" style="width: 200px" size="mini" readonly v-model="basicForm.materialCode">
  83. <el-button slot="append" icon="el-icon-more" @click="test01"></el-button>
  84. </el-input>
  85. <el-input v-show="false" style="width: 200px" size="mini" v-model="basicForm.material"></el-input>
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="1.5">
  89. <el-form-item label="物料名称">
  90. <el-input
  91. v-model="basicForm.materialName"
  92. size="mini"
  93. disabled
  94. clearable
  95. style="width: 200px"
  96. />
  97. </el-form-item>
  98. </el-col>
  99. <el-col :span="1.5">
  100. <el-form-item label="生产厂家">
  101. <el-input
  102. v-model="basicForm.manufacturer"
  103. size="mini"
  104. :disabled="disable"
  105. clearable
  106. style="width: 200px"
  107. />
  108. </el-form-item>
  109. </el-col>
  110. <el-col :span="1.5">
  111. <el-form-item label="所属组织">
  112. <el-select
  113. ref="organizations"
  114. v-model="basicForm.org"
  115. size="mini"
  116. style="width: 200px"
  117. :disabled="disable"
  118. clearable
  119. @focus="chooseRefer('ORG_PARAM', true, '选择所属组织')"
  120. >
  121. <el-option
  122. v-for="item in organizationsOptions"
  123. :key="item.id"
  124. :label="item.name"
  125. :value="item.id"
  126. />
  127. </el-select>
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="1.5">
  131. <el-form-item label="订单员">
  132. <el-select
  133. ref="staffs"
  134. size="mini"
  135. style="width: 200px"
  136. :disabled="disable"
  137. v-model="basicForm.orderPersonal"
  138. clearable
  139. @clear="clean('订单员')"
  140. @focus="chooseRefer('CONTACTS_PARAM', true, '订单员')"
  141. >
  142. <el-option
  143. v-for="item in staffOptions"
  144. :key="item.id"
  145. :label="item.name"
  146. :value="item.code"
  147. />
  148. </el-select>
  149. </el-form-item>
  150. </el-col>
  151. <el-col :span="1.5">
  152. <el-form-item label="订单部门">
  153. <el-input
  154. v-model="basicForm.orderDeptName"
  155. size="mini"
  156. disabled
  157. style="width: 200px"
  158. />
  159. </el-form-item>
  160. </el-col>
  161. <el-col :span="1.5">
  162. <el-form-item label="采购员">
  163. <el-select
  164. ref="staffs2"
  165. size="mini"
  166. style="width: 200px"
  167. :disabled="disable"
  168. v-model="basicForm.buyer"
  169. clearable
  170. @clear="clean('采购员')"
  171. @focus="chooseRefer('CONTACTS_PARAM', true, '采购员')"
  172. >
  173. <el-option
  174. v-for="item in staff2Options"
  175. :key="item.id"
  176. :label="item.name"
  177. :value="item.code"
  178. />
  179. </el-select>
  180. </el-form-item>
  181. </el-col>
  182. <el-col :span="1.5">
  183. <el-form-item label="采购部门">
  184. <el-input
  185. v-model="basicForm.puDeptName"
  186. size="mini"
  187. disabled
  188. style="width: 200px"
  189. />
  190. </el-form-item>
  191. </el-col>
  192. <el-col :span="1.5">
  193. <el-form-item label="同步状态">
  194. <el-select disabled v-model="basicForm.sendStatus" size="mini" style="width: 200px">
  195. <el-option
  196. v-for="item in options"
  197. :key="item.value"
  198. :label="item.label"
  199. :value="item.value">
  200. </el-option>
  201. </el-select>
  202. </el-form-item>
  203. </el-col>
  204. <el-col :span="1.5">
  205. <el-form-item label="备注">
  206. <el-input
  207. v-model="basicForm.remark"
  208. size="mini"
  209. :disabled="disable"
  210. clearable
  211. style="width: 200px"
  212. />
  213. </el-form-item>
  214. </el-col>
  215. </el-row>
  216. </el-form>
  217. <div class="btn_group">
  218. <el-col :span="1.5" style="margin: 0 10px;">
  219. <el-button type="primary" size="mini" plain @click="save" v-if="pageStu == 'add' || pageStu == 'edit'">保存</el-button>
  220. </el-col>
  221. <!-- <el-col :span="1.5" style="margin: 0 10px;">
  222. <el-button type="primary" size="mini" plain @click="submit" v-if="pageStu == 'edit'">提交</el-button>
  223. </el-col> -->
  224. <el-col :span="1.5">
  225. <el-button size="mini" plain @click="back">返回</el-button>
  226. </el-col>
  227. </div>
  228. </el-card>
  229. <fourClass
  230. ref="fourClass"
  231. @doSubmit="acceptFourClass"
  232. :single="true"
  233. />
  234. <popDialog
  235. ref="contractSelect"
  236. @doSubmit="selectionsToInput"
  237. :single="true"
  238. />
  239. <Refers ref="refer" @doSubmit="selectionsRefer" :single="true"/>
  240. </div>
  241. </template>
  242. <script>
  243. import {addDivision, getDivisions, editDivision} from '@/api/purchase/basic.js'
  244. // 物料分类
  245. import fourClass from '@/components/PopDialog/fourClass.vue'
  246. // 调用物料分类详情接口用于数据回显
  247. import { getDetail } from '@/api/classify/basic';
  248. // 物料编码
  249. import popDialog from '@/components/PopDialog/index.vue'
  250. // 公用一个树形(组织部门传值不同)
  251. import Refers from '@/components/Refers/refers.vue'
  252. // 用于回显参照框数据
  253. import { getRefer } from '@/api/purchase/basic.js'
  254. export default {
  255. name: 'addDivision',
  256. components: {
  257. fourClass,
  258. popDialog,
  259. Refers,
  260. },
  261. props: ['pageStu','row', 'disable'],
  262. model: {
  263. prop: 'isList',
  264. event: 'jugislist'
  265. },
  266. data() {
  267. return {
  268. basicForm: {
  269. materialClassify: '',
  270. materialClassifyName: '',
  271. materialClassifyOne: '',
  272. materialClassifyOneName: '',
  273. materialClassifyTwoName: '',
  274. materialClassifyThreeName: '',
  275. materialClassifyFourName: '',
  276. material: '',
  277. materialCode: '',
  278. materialName: '',
  279. manufacturer: '',
  280. org: '',
  281. orgName: '',
  282. orderPersonal: '',
  283. orderPersonalName: '',
  284. orderDept: '',
  285. orderDeptName: '',
  286. buyer: '',
  287. buyerName: '',
  288. puDept: '',
  289. puDeptName: '',
  290. sendStatus: 'N',
  291. remark: ''
  292. },
  293. options: [{
  294. value: 'Y', label: '已同步',
  295. }, {
  296. value: 'N', label: '未同步'
  297. }],
  298. referCondition: {
  299. type: '',
  300. isPage: true,
  301. title: ''
  302. },
  303. organizationsOptions: [],
  304. staffOptions: [],
  305. staff2Options: [],
  306. basicRules: {}
  307. }
  308. },
  309. mounted() {
  310. if(this.pageStu == 'check') {
  311. console.log('数据', this.row)
  312. this.getDetails(this.row)
  313. } else if(this.pageStu == 'edit') {
  314. this.getDetails(this.row)
  315. }
  316. },
  317. methods: {
  318. save() {
  319. if(this.pageStu == 'add') {
  320. this.$modal.loading("保存中...");
  321. addDivision(this.basicForm).then(res => {
  322. if (res.code === 200) {
  323. this.$modal.notifySuccess("保存成功");
  324. this.$modal.closeLoading();
  325. this.back()
  326. }
  327. }).catch(err => {
  328. this.$modal.closeLoading();
  329. })
  330. } else if(this.pageStu == 'edit') {
  331. this.$modal.loading("保存中...");
  332. editDivision(this.basicForm).then(res => {
  333. this.$modal.notifySuccess("编辑成功");
  334. this.$modal.closeLoading();
  335. this.back()
  336. }).catch(err => {
  337. this.$modal.closeLoading();
  338. })
  339. }
  340. },
  341. submit() {},
  342. back() {
  343. this.$emit('jugislist', true)
  344. // let queryParams = {
  345. // pageNum: 1,
  346. // pageSize: 10
  347. // }
  348. this.$emit('refresh')
  349. },
  350. // 如果需要回显则调用详情接口
  351. getDetails(row) {
  352. getDivisions(row.id).then(res => {
  353. if (res.code === 200) {
  354. this.basicForm = res.data
  355. if (this.basicForm.org) { this.reBackRefer('ORG_PARAM', this.basicForm.org) }
  356. if (this.basicForm.orderPersonal) { this.reBackRefer('CONTACTS_PARAM', this.basicForm.orderPersonal, '订单员') }
  357. if (this.basicForm.buyer) { this.reBackRefer('CONTACTS_PARAM', this.basicForm.buyer, '采购员') }
  358. }
  359. })
  360. },
  361. // 选择物料分类
  362. acceptFourClass(selections) {
  363. console.log('收到的四级分类',selections)
  364. this.basicForm.materialClassify = selections.code
  365. this.basicForm.materialClassifyName = selections.materialType
  366. this.getTreeDetails(selections.id)
  367. },
  368. // 物料分类显示列表
  369. chooseFourClass() {
  370. this.$refs.fourClass.init()
  371. },
  372. // 选择物料分类后需要根据id再次查询一下123级分类
  373. getTreeDetails(id) {
  374. getDetail(id).then(res => {
  375. if (res.code === 200) {
  376. this.basicForm.materialClassifyOneName = res.data.oneClass
  377. this.basicForm.materialClassifyTwoName = res.data.twoClass
  378. this.basicForm.materialClassifyThreeName = res.data.threeClass
  379. this.basicForm.materialClassifyFourName = res.data.fourClass
  380. }
  381. })
  382. },
  383. selectionsToInput (selections) {
  384. console.log('父组件拿到的:', selections)
  385. this.basicForm.material = selections[0].id
  386. this.basicForm.materialCode = selections[0].code
  387. this.basicForm.materialName = selections[0].name
  388. },
  389. // 显示物料编码列表
  390. test01() {
  391. console.log('测试点击')
  392. this.$refs.contractSelect.init()
  393. },
  394. // 选择默认采购组织
  395. chooseRefer(type, isPage, title) {
  396. this.referCondition.type = type
  397. this.referCondition.isPage = isPage
  398. this.referCondition.title = title
  399. this.$refs.refer.init(this.referCondition)
  400. },
  401. selectionsRefer(selection) {
  402. if (this.referCondition.title == '选择所属组织') {
  403. this.organizationsOptions = selection
  404. this.basicForm.org = selection[0].id
  405. this.basicForm.orgName = selection[0].name
  406. }
  407. if (this.referCondition.title == '订单员') {
  408. this.staffOptions = selection
  409. this.basicForm.orderPersonal = selection[0].code
  410. this.basicForm.orderPersonalName = selection[0].name
  411. this.basicForm.orderDept = selection[0].deptId
  412. this.basicForm.orderDeptName = selection[0].deptName
  413. }
  414. if (this.referCondition.title == '采购员') {
  415. this.staff2Options = selection
  416. this.basicForm.buyer = selection[0].code
  417. this.basicForm.buyerName = selection[0].name
  418. this.basicForm.puDept = selection[0].deptId
  419. this.basicForm.puDeptName = selection[0].deptName
  420. }
  421. },
  422. // 回显参照框 加title解决判断重复提交问题
  423. reBackRefer(type, id, title) {
  424. getRefer({ type: type, id: id, title: title }).then(res => {
  425. if (type == 'ORG_PARAM') {
  426. this.organizationsOptions = res.rows
  427. }
  428. if (type == 'CONTACTS_PARAM' && title == '订单员') {
  429. this.staffOptions = res.rows
  430. }
  431. if (type == 'CONTACTS_PARAM' && title == '采购员') {
  432. this.staff2Options = res.rows
  433. }
  434. })
  435. },
  436. // 清空采购员,订单员
  437. clean(title) {
  438. if (title == '订单员') {
  439. this.basicForm.orderPersonal = ''
  440. this.basicForm.orderPersonalName = ''
  441. }
  442. if (title == '采购员') {
  443. this.basicForm.buyer = ''
  444. this.basicForm.buyerName = ''
  445. }
  446. }
  447. }
  448. }
  449. </script>
  450. <style lang="scss" scoped>
  451. .btn_group {
  452. // width: 100%;
  453. // margin: 20px 0;
  454. display: flex;
  455. // justify-content: center;
  456. position: absolute;
  457. top: 10px;right: 20px;
  458. }
  459. </style>