addClass.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div>
  3. <el-button type="primary" size="small" @click="dialogFormVisible=true" >{{$t(`设置分类`)}}</el-button>
  4. <el-dialog append-to-body :title="$t(`设置分类`)" :visible.sync="dialogFormVisible" width="900px">
  5. <el-input style="width:200px;" :placeholder="$t('搜索')" :suffix-icon="condition?condition.length > 0?'':'':'el-icon-search'" v-model="condition" @keyup.native.enter="getClassList()" @clear="getClassList" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
  6. </el-input>
  7. <el-table
  8. :data="classList"
  9. stripe
  10. row-key="itemclassid"
  11. size="small"
  12. height="500px"
  13. default-expand-all
  14. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  15. <el-table-column width="100">
  16. </el-table-column>
  17. <el-table-column
  18. prop="itemclassnum"
  19. :label="$t(`分类编号`)">
  20. </el-table-column>
  21. <el-table-column
  22. prop="itemclassname"
  23. :label="$t(`分类名称`)">
  24. </el-table-column>
  25. <el-table-column
  26. :label="$t('操作')"
  27. width="50">
  28. <template slot-scope="scope">
  29. <el-button type="text" size="mini" v-if="scope.row.disabled" @click="onSubmit(scope.row)">{{$t('添 加')}}</el-button>
  30. </template>
  31. </el-table-column>
  32. </el-table>
  33. <!-- <el-tree
  34. ref="tree"
  35. :data="classList"
  36. show-checkbox
  37. node-key="itemclassid"
  38. :default-expand-all="true"
  39. :default-checked-keys="data.checkArr">
  40. </el-tree> -->
  41. <!-- <div slot="footer" class="dialog-footer">
  42. <el-button size="small" @click="dialogFormVisible=false" class="normal-btn-width">{{$t('取 消')}}</el-button>
  43. <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">{{$t('确 定')}}</el-button>
  44. </div> -->
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script>
  49. import selectTable from '@/components/selectTable/index'
  50. import { log } from '@antv/g2plot/lib/utils'
  51. export default {
  52. props:['data'],
  53. components:{selectTable},
  54. data () {
  55. return {
  56. dialogFormVisible:false,
  57. classList:[],
  58. disabledId:[],
  59. tableList:[],
  60. tablecols:[],
  61. result:[],
  62. condition:''
  63. }
  64. },
  65. methods:{
  66. // async onSubmit () {
  67. // let arr = this.$refs.tree.getCheckedNodes().map(item => item.itemclassid)
  68. // let res = await this.$api.requested({
  69. // "id": 20220927090102,
  70. // "content": {
  71. // "itemclassids":arr,
  72. // "itemid": this.data.data.itemid,
  73. // "itemno":this.data.data.itemno
  74. // },
  75. // })
  76. // this.tool.showMessage(res,() => {
  77. // this.$emit('onSuccess')
  78. // this.dialogFormVisible = false
  79. // })
  80. // },
  81. async onSubmit (data) {
  82. let res = await this.$api.requested({
  83. "id": 20220927090102,
  84. "content": {
  85. "itemclassids":[data.itemclassid],
  86. "itemid": this.data.data.itemid,
  87. "itemno":this.data.data.itemno
  88. },
  89. })
  90. this.tool.showMessage(res,() => {
  91. this.$emit('onSuccess')
  92. this.getClassList()
  93. })
  94. },
  95. async getClassList () {
  96. let res = await this.$api.requested({
  97. "id": "20230325141103",
  98. "content": {
  99. "sa_brandid":0,
  100. "itemid": this.$route.query.id,
  101. "where": {
  102. istool: this.data.data.istool ? 1 : 0,
  103. condition:this.condition
  104. }
  105. }
  106. })
  107. console.log(res.data);
  108. res.data = res.data.map((item,index) => {
  109. return {
  110. itemclassname:item.brandname,
  111. itemclassid:index + 1,
  112. subdep: item.ttemclass,
  113. }
  114. })
  115. this.classList = this.createDeep(res.data)
  116. console.log(this.classList);
  117. },
  118. // createDeep (data) {
  119. // let arr = []
  120. // function createNodes (node) {
  121. // let elNode = {
  122. // label:node.itemclassname,
  123. // itemclassid:node.itemclassid,
  124. // disabled:node.disabled ? true : false,
  125. // children:[]
  126. // }
  127. // if (node.subdep && node.subdep.length > 0) {
  128. // for (let index = 0; index < node.subdep.length; index++) {
  129. // elNode.children.push(createNodes(node.subdep[index]))
  130. // }
  131. // }
  132. // return elNode
  133. // }
  134. // data.forEach(item => {
  135. // this.disabledId.push(item.itemclassid)
  136. // arr.push(createNodes(item))
  137. // })
  138. // return arr
  139. // },
  140. createDeep (data) {
  141. let arr = []
  142. function createNodes (node,first) {
  143. let elNode = {
  144. itemclassname:node.itemclassfullname ? node.itemclassfullname : node.itemclassname,
  145. itemclassid:node.itemclassid,
  146. itemclassnum:node.itemclassnum,
  147. children:[],
  148. disabled:first ? false : true
  149. }
  150. if (node.subdep && node.subdep.length > 0) {
  151. for (let index = 0; index < node.subdep.length; index++) {
  152. elNode.children.push(createNodes(node.subdep[index]))
  153. }
  154. }
  155. return elNode
  156. }
  157. data.forEach(item => {
  158. this.disabledId.push(item.itemclassid)
  159. arr.push(createNodes(item,true))
  160. })
  161. return arr
  162. },
  163. },
  164. created () {
  165. this.getClassList()
  166. this.tablecols = this.tool.tabelCol(this.$route.name)['selectClassTable'].tablecols
  167. }
  168. }
  169. </script>
  170. <style scoped>
  171. /deep/.el-dialog__body {
  172. padding-bottom: 0 !important;
  173. }
  174. </style>