product-source-category.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="product-source-category">
  3. <div class="porListBox">
  4. <div class="addProduct">
  5. <div v-if="!productData.categoryName" class="addProBtn addImgBtn" @click="addProductCls"><span class="iconfont">&#xe685;</span>添加类别</div>
  6. <div v-else class="categoryName">
  7. <span>{{productData.categoryName}}</span>
  8. <div class="operation">
  9. <span class="iconfont" @click="replaceCategory">&#xe66c;</span>
  10. <span class="iconfont" @click="deleteCategory">&#xe633;</span>
  11. </div>
  12. </div>
  13. </div>
  14. </div>
  15. <el-dialog title="选择类别" :visible.sync="dialogCategory" width="600px">
  16. <el-cascader style="width: 100%"
  17. ref="cascader"
  18. :options="categoryList"
  19. :props="{ checkStrictly: true,label: 'categoryName',value: 'id',children: 'childs' }"
  20. clearable></el-cascader>
  21. <span slot="footer" class="dialog-footer">
  22. <el-button @click="dialogCategory = false">取 消</el-button>
  23. <el-button type="primary" @click="addCategoryData">确 定</el-button>
  24. </span>
  25. </el-dialog>
  26. </div>
  27. </template>
  28. <script>
  29. import api from '@@/components/canvasShow/config/api'
  30. import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
  31. import {checkEmptyChild} from '@@/config/common'
  32. import { mapMutations } from 'vuex'
  33. export default {
  34. name: "product-source-category",
  35. mixins: [sendReqMixin],
  36. data () {
  37. return {
  38. categoryList: [],
  39. dialogCategory: false,
  40. }
  41. },
  42. props: {
  43. productData: {
  44. type: Object,
  45. default: () => {}
  46. },
  47. type: {
  48. type: String,
  49. default: ''
  50. }
  51. },
  52. mounted () {
  53. this.selsectValue = this.linkValue // props 不能直接修改
  54. },
  55. methods: {
  56. ...mapMutations({
  57. setNewProductNum: 'SET_NEWPRODUCTNUM',
  58. setProductNum: 'SET_PRODUCTNUM'
  59. }),
  60. // 获取类别
  61. getCategory () {
  62. var _this = this
  63. let params = {
  64. url: api.getClassify,
  65. method: 'GET'
  66. }
  67. this.sendReq(params, (res) => {
  68. _this.categoryList = res.data
  69. checkEmptyChild(_this.categoryList)
  70. _this.dialogCategory = true
  71. })
  72. },
  73. // 添加类别
  74. addProductCls () {
  75. this.getCategory()
  76. },
  77. // 替换类别
  78. replaceCategory () {
  79. this.getCategory()
  80. },
  81. // 删除已选类别
  82. deleteCategory () {
  83. this.productData.categoryName = ''
  84. this.productData.categoryId = ''
  85. this.viewRefresh()
  86. },
  87. // 添加类别
  88. addCategoryData () {
  89. let nodesObj = this.$refs['cascader'].getCheckedNodes()
  90. if (nodesObj) {
  91. var categoryId = nodesObj[0].value
  92. var categoryName = nodesObj[0].label
  93. this.productData.categoryId = categoryId
  94. this.productData.categoryName = categoryName
  95. this.dialogCategory = false
  96. this.viewRefresh()
  97. }
  98. },
  99. // 通知画布刷新
  100. viewRefresh(){
  101. if(this.type === 'newProduct'){
  102. this.setNewProductNum()
  103. } else {
  104. this.setProductNum()
  105. }
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .product-source-category{
  112. .porListBox {
  113. padding: 10px;
  114. background: #F0F3F4;
  115. .addProduct {
  116. .categoryName {
  117. height: 35px;
  118. display: flex;
  119. align-items: center;
  120. background: #e9e9e9;
  121. border-radius: 4px;
  122. padding: 0 10px;
  123. justify-content: space-between;
  124. span {
  125. color: #333333;
  126. }
  127. span {
  128. color: #333333;
  129. }
  130. .operation {
  131. display: flex;
  132. span {
  133. width: 35px;
  134. display: block;
  135. height: 35px;
  136. line-height: 35px;
  137. text-align: center;
  138. cursor: pointer;
  139. }
  140. }
  141. }
  142. .addImgBtn {
  143. border-radius: 4px;
  144. background: $mainColor;
  145. text-align: center;
  146. height: 36px;
  147. color: #ffffff;
  148. font-size: 14px;
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. cursor: pointer;
  153. span {
  154. font-size: 20px;
  155. margin-right: 5px;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. </style>