CustomerClassify.vue 9.8 KB

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