SippliersClassify.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="SippliersClassify">
  3. <Toptitle title="供应商分类">
  4. <slot name="titleButton">
  5. <Button @click="handleCodeRule"
  6. type="primary"
  7. ghost
  8. style="margin-right:10px;">编码规则</Button>
  9. <Button @click="handleSet()"
  10. type="primary"
  11. style="margin-right:10px;">新增分类</Button>
  12. </slot>
  13. </Toptitle>
  14. <div class="content">
  15. <div class="content_left">
  16. <Tree :data="treeData"
  17. children-key='sub'
  18. :render="renderContent"
  19. style="width:100%;"
  20. class="demo-tree-render"></Tree>
  21. </div>
  22. <div class="content_right"></div>
  23. </div>
  24. <Modal v-model="showModal"
  25. :title="type==1?'新增分类':'编辑分类'"
  26. @on-ok="handleModalOk"
  27. @on-cancel="showModal = false">
  28. <div class="modal_content">
  29. <div>
  30. <span>分类编码: </span>
  31. <Input type="text"
  32. size="small"
  33. placeholder="请输入"
  34. :disabled="type==2"
  35. v-model="form.code"
  36. style="width: 220px" />
  37. </div>
  38. <div>
  39. <span>分类名称: </span>
  40. <Input type="text"
  41. size="small"
  42. placeholder="请输入"
  43. v-model="form.title"
  44. style="width: 220px" />
  45. </div>
  46. </div>
  47. </Modal>
  48. <Modal v-model="showCodeRuleModal"
  49. title='编码规则'>
  50. <div class="modal_content">
  51. <div v-for="item in codeRuleList"
  52. :key="item.level">
  53. <span>{{item.level}}级(编码长度): </span>
  54. <Input type="number"
  55. size="small"
  56. placeholder="请输入"
  57. :disabled="!isAllowEdit"
  58. v-model="item.num"
  59. style="width: 220px" />
  60. </div>
  61. </div>
  62. <div slot="footer">
  63. <Button @click="handleCodeRuleModalCancel"
  64. type="primary"
  65. ghost
  66. style="margin-right:10px;">取消</Button>
  67. <Button @click="handleCodeRuleModalOk"
  68. type="primary"
  69. ghost
  70. style="margin-right:10px;">{{isAllowEdit == false?'修改':'确认'}}</Button>
  71. </div>
  72. </Modal>
  73. </div>
  74. </template>
  75. <script>
  76. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  77. // 例如:import 《组件名称》 from '《组件路径》';
  78. export default {
  79. name: 'SippliersClassify',
  80. components: {
  81. },
  82. props: {},
  83. // import引入的组件需要注入到对象中才能使用
  84. data () {
  85. // 这里存放数据
  86. return {
  87. showModal: false,
  88. showCodeRuleModal: false,
  89. isAllowEdit: false,
  90. type: '',
  91. form: {
  92. parent_id: '',
  93. id: '',
  94. code: '',
  95. title: ''
  96. },
  97. codeRuleList: [],
  98. treeData: [
  99. {
  100. title: '供应商分类',
  101. expand: true,
  102. sub: [],
  103. render: (h, { root, node, data }) => {
  104. return h('span', {
  105. style: {
  106. display: 'inline-block',
  107. width: '100%'
  108. }
  109. }, [
  110. h('span', [
  111. h('Icon', {
  112. props: {
  113. type: 'ios-folder-outline'
  114. },
  115. style: {
  116. marginRight: '8px'
  117. }
  118. }),
  119. h('span', data.title)
  120. ]),
  121. h('span', {
  122. style: {
  123. display: 'inline-block',
  124. // float: 'right',
  125. marginRight: '32px'
  126. }
  127. })
  128. ]);
  129. },
  130. }
  131. ],
  132. buttonProps: {
  133. type: 'default',
  134. size: 'small',
  135. },
  136. tempRuleList: [],
  137. }
  138. },
  139. // 生命周期 - 创建完成(可以访问当前this实例)
  140. created () {
  141. this.axios({
  142. method: 'get',
  143. url: '/api/basic_code_rule',
  144. params: {
  145. uid: 2
  146. }
  147. }).then((res) => {
  148. this.codeRuleList = res.data
  149. }).catch((err) => { });
  150. },
  151. // 生命周期 - 挂载完成(可以访问DOM元素)
  152. mounted () {
  153. this.initData()
  154. },
  155. methods: {
  156. initData () {
  157. this.axios({
  158. method: 'get',
  159. url: '/api/basic_supply_list',
  160. }).then((res) => {
  161. this.treeData[0].sub = res.data
  162. // this.openChildrenNode(this.treeData)
  163. // this.ergodic(this.treeData)
  164. this.treeData.forEach(item=>{
  165. item.expand=true;
  166. if(item.sub.length!=0)
  167. item.sub.forEach(_item=>{
  168. _item.expand=true;
  169. if(_item.sub.length!=0){
  170. _item.sub.forEach(__item=>{
  171. __item.expand=true
  172. })
  173. }
  174. })
  175. })
  176. }).catch((err) => { });
  177. },
  178. ergodic(row){
  179. row.forEach(item=>{
  180. if(item.sub.length==0){
  181. item.expand = true
  182. }else{
  183. item.expand = true
  184. this.ergodic(item)
  185. }
  186. })
  187. },
  188. handleSet () {
  189. this.type = 1
  190. this.showModal = true
  191. this.form.code = ''
  192. this.form.title = ''
  193. },
  194. renderContent (h, { root, node, data }) {
  195. return h('span', {
  196. style: {
  197. display: 'inline-block',
  198. width: '100%'
  199. }
  200. }, [
  201. h('span', [
  202. h('Icon', {
  203. props: {
  204. type: 'ios-paper-outline'
  205. },
  206. style: {
  207. marginRight: '8px'
  208. }
  209. }),
  210. h('span', `${data.title}(${data.code})`)
  211. ]),
  212. h('span', {
  213. style: {
  214. display: 'inline-block',
  215. float: 'right',
  216. marginRight: '32px'
  217. }
  218. }, [
  219. h('Button', {
  220. props: { type: 'primary', size: 'small' },
  221. style: {
  222. marginRight: '8px'
  223. },
  224. on: {
  225. click: () => {
  226. this.type = 2
  227. this.form.parent_id = data.parent_id
  228. this.form.code = data.code
  229. this.form.title = data.title
  230. this.form.id = data.id
  231. this.showModal = true
  232. }
  233. }
  234. }, '编辑'),
  235. h('Button', {
  236. props: { type: 'error', size: 'small' },
  237. on: {
  238. click: () => {
  239. this.handleNodeDele(root, node, data)
  240. }
  241. },
  242. }, '删除')
  243. ])
  244. ]);
  245. },
  246. append (data) {
  247. const children = data.children || [];
  248. children.push({
  249. code: this.form.code,
  250. title: this.form.title,
  251. expand: true
  252. });
  253. this.$set(data, 'children', children);
  254. },
  255. remove (root, node, data) {
  256. if (node.children && node.children.length > 0) {
  257. this.$Message.error('有子集时不可删除')
  258. } else {
  259. const parentKey = root.find(el => el === node).parent;
  260. const parent = root.find(el => el.nodeKey === parentKey).node;
  261. const index = parent.children.indexOf(data);
  262. parent.children.splice(index, 1);
  263. }
  264. },
  265. handleCodeRuleModalCancel () {
  266. this.showCodeRuleModal = false
  267. this.isAllowEdit = false
  268. this.codeRuleList = this.tempRuleList
  269. },
  270. handleCodeRuleModalOk () {
  271. this.isAllowEdit = !this.isAllowEdit
  272. if (!this.isAllowEdit) {
  273. this.axios({
  274. method: 'post',
  275. url: '/api/basic_code_rule_edit',
  276. data: {
  277. uid: this.codeRuleList[0].uid,
  278. rule: this.codeRuleList
  279. }
  280. }).then((res) => {
  281. this.$Message.success(res.msg)
  282. }).catch((err) => { });
  283. }
  284. },
  285. handleNodeDele (root, node, data) {
  286. if (data.sub && data.sub.length > 0) {
  287. this.$Message.error('有子集时不可删除')
  288. } else {
  289. this.$Modal.confirm({
  290. title: '确认删除?',
  291. content: '此操作无法恢复,请确认!',
  292. onOk: () => {
  293. this.axios({
  294. method: 'get',
  295. url: '/api/basic_supply_del',
  296. params: {
  297. id: data.id
  298. }
  299. }).then((res) => {
  300. if (res.code == 200) {
  301. this.$Message.success(res.msg)
  302. this.initData()
  303. }
  304. }).catch((err) => { });
  305. },
  306. onCancel: () => { }
  307. })
  308. }
  309. },
  310. handleModalOk () {
  311. if (this.type == 1) {
  312. this.axios({
  313. method: 'post',
  314. url: '/api/basic_supply_add',
  315. data: {
  316. code: this.form.code,
  317. title: this.form.title
  318. }
  319. }).then((res) => {
  320. // this.$Message.success(res.msg)
  321. this.initData()
  322. }).catch((err) => { });
  323. } else {
  324. this.axios({
  325. method: 'post',
  326. url: '/api/basic_supply_edit',
  327. data: {
  328. id: this.form.id,
  329. code: this.form.code,
  330. title: this.form.title
  331. }
  332. }).then((res) => {
  333. // this.$Message.success(res.msg)
  334. this.initData()
  335. }).catch((err) => { });
  336. }
  337. },
  338. openChildrenNode (arr) {
  339. arr.forEach(element => {
  340. element.expand = true
  341. if (element.sub && element.sub.length > 0) {
  342. return this.openChildrenNode(element.sub)
  343. }
  344. });
  345. },
  346. handleCodeRule () {
  347. this.tempRuleList = JSON.parse(JSON.stringify(this.codeRuleList))
  348. this.showCodeRuleModal = true
  349. },
  350. },
  351. // 监听属性 类似于data概念
  352. computed: {},
  353. // 监控data中的数据变化
  354. watch: {},
  355. beforeCreate () { }, // 生命周期 - 创建之前
  356. beforeMount () { }, // 生命周期 - 挂载之前
  357. beforeUpdate () { }, // 生命周期 - 更新之前
  358. updated () { }, // 生命周期 - 更新之后
  359. beforeDestroy () { }, // 生命周期 - 销毁之前
  360. destroyed () { }, // 生命周期 - 销毁完成
  361. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  362. }
  363. </script>
  364. <style lang='scss' scoped>
  365. .content {
  366. width: 100%;
  367. .content_left {
  368. width: 70%;
  369. }
  370. }
  371. .demo-tree-render {
  372. width: 100%;
  373. }
  374. /deep/.ivu-tree-title {
  375. width: 100%;
  376. }
  377. .modal_content {
  378. div {
  379. display: flex;
  380. justify-content: space-around;
  381. align-items: center;
  382. padding: 10px 0;
  383. }
  384. }
  385. </style>