SippliersClassify.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. }).catch((err) => { });
  164. },
  165. handleSet () {
  166. this.type = 1
  167. this.showModal = true
  168. this.form.code = ''
  169. this.form.title = ''
  170. },
  171. renderContent (h, { root, node, data }) {
  172. return h('span', {
  173. style: {
  174. display: 'inline-block',
  175. width: '100%'
  176. }
  177. }, [
  178. h('span', [
  179. h('Icon', {
  180. props: {
  181. type: 'ios-paper-outline'
  182. },
  183. style: {
  184. marginRight: '8px'
  185. }
  186. }),
  187. h('span', `${data.title}(${data.code})`)
  188. ]),
  189. h('span', {
  190. style: {
  191. display: 'inline-block',
  192. float: 'right',
  193. marginRight: '32px'
  194. }
  195. }, [
  196. h('Button', {
  197. props: { type: 'primary', size: 'small' },
  198. style: {
  199. marginRight: '8px'
  200. },
  201. on: {
  202. click: () => {
  203. this.type = 2
  204. this.form.parent_id = data.parent_id
  205. this.form.code = data.code
  206. this.form.title = data.title
  207. this.form.id = data.id
  208. this.showModal = true
  209. }
  210. }
  211. }, '编辑'),
  212. h('Button', {
  213. props: { type: 'error', size: 'small' },
  214. on: {
  215. click: () => {
  216. this.handleNodeDele(root, node, data)
  217. }
  218. },
  219. }, '删除')
  220. ])
  221. ]);
  222. },
  223. append (data) {
  224. const children = data.children || [];
  225. children.push({
  226. code: this.form.code,
  227. title: this.form.title,
  228. expand: true
  229. });
  230. this.$set(data, 'children', children);
  231. },
  232. remove (root, node, data) {
  233. if (node.children && node.children.length > 0) {
  234. this.$Message.error('有子集时不可删除')
  235. } else {
  236. const parentKey = root.find(el => el === node).parent;
  237. const parent = root.find(el => el.nodeKey === parentKey).node;
  238. const index = parent.children.indexOf(data);
  239. parent.children.splice(index, 1);
  240. }
  241. },
  242. handleCodeRuleModalCancel () {
  243. this.showCodeRuleModal = false
  244. this.isAllowEdit = false
  245. this.codeRuleList = this.tempRuleList
  246. },
  247. handleCodeRuleModalOk () {
  248. this.isAllowEdit = !this.isAllowEdit
  249. if (!this.isAllowEdit) {
  250. this.axios({
  251. method: 'post',
  252. url: '/api/basic_code_rule_edit',
  253. data: {
  254. uid: this.codeRuleList[0].uid,
  255. rule: this.codeRuleList
  256. }
  257. }).then((res) => {
  258. this.$Message.success(res.msg)
  259. }).catch((err) => { });
  260. }
  261. },
  262. handleNodeDele (root, node, data) {
  263. if (data.sub && data.sub.length > 0) {
  264. this.$Message.error('有子集时不可删除')
  265. } else {
  266. this.$Modal.confirm({
  267. title: '确认删除?',
  268. content: '此操作无法恢复,请确认!',
  269. onOk: () => {
  270. this.axios({
  271. method: 'get',
  272. url: '/api/basic_supply_del',
  273. params: {
  274. id: data.id
  275. }
  276. }).then((res) => {
  277. if (res.code == 200) {
  278. this.$Message.success(res.msg)
  279. this.initData()
  280. }
  281. }).catch((err) => { });
  282. },
  283. onCancel: () => { }
  284. })
  285. }
  286. },
  287. handleModalOk () {
  288. if (this.type == 1) {
  289. this.axios({
  290. method: 'post',
  291. url: '/api/basic_supply_add',
  292. data: {
  293. code: this.form.code,
  294. title: this.form.title
  295. }
  296. }).then((res) => {
  297. // this.$Message.success(res.msg)
  298. this.initData()
  299. }).catch((err) => { });
  300. } else {
  301. this.axios({
  302. method: 'post',
  303. url: '/api/basic_supply_edit',
  304. data: {
  305. id: this.form.id,
  306. code: this.form.code,
  307. title: this.form.title
  308. }
  309. }).then((res) => {
  310. // this.$Message.success(res.msg)
  311. this.initData()
  312. }).catch((err) => { });
  313. }
  314. },
  315. openChildrenNode (arr) {
  316. arr.forEach(element => {
  317. element.expand = true
  318. if (element.sub && element.sub.length > 0) {
  319. return this.openChildrenNode(element.sub)
  320. }
  321. });
  322. },
  323. handleCodeRule () {
  324. this.tempRuleList = JSON.parse(JSON.stringify(this.codeRuleList))
  325. this.showCodeRuleModal = true
  326. },
  327. },
  328. // 监听属性 类似于data概念
  329. computed: {},
  330. // 监控data中的数据变化
  331. watch: {},
  332. beforeCreate () { }, // 生命周期 - 创建之前
  333. beforeMount () { }, // 生命周期 - 挂载之前
  334. beforeUpdate () { }, // 生命周期 - 更新之前
  335. updated () { }, // 生命周期 - 更新之后
  336. beforeDestroy () { }, // 生命周期 - 销毁之前
  337. destroyed () { }, // 生命周期 - 销毁完成
  338. activated () { }, // 如果页面有keep-alive缓存功能,这个函数会触发
  339. }
  340. </script>
  341. <style lang='scss' scoped>
  342. .content {
  343. width: 100%;
  344. .content_left {
  345. width: 70%;
  346. }
  347. }
  348. .demo-tree-render {
  349. width: 100%;
  350. }
  351. /deep/.ivu-tree-title {
  352. width: 100%;
  353. }
  354. .modal_content {
  355. div {
  356. display: flex;
  357. justify-content: space-around;
  358. align-items: center;
  359. padding: 10px 0;
  360. }
  361. }
  362. </style>