list.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <a-card size="small" :bordered="false" class="shoppingManagementList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 操作按钮 -->
  5. <div ref="tableSearch" class="table-operator" style="border: 0;">
  6. <a-button id="shoppingManagementList-addType" type="primary" @click="addCategory('add')">新增类目</a-button>
  7. </div>
  8. <!-- 列表 -->
  9. <a-table
  10. class="sTable fixPagination"
  11. ref="table"
  12. :style="{ height: tableHeight+70+'px'}"
  13. size="small"
  14. :rowKey="(record) => record.id"
  15. :columns="columns"
  16. :pagination="false"
  17. :dataSource="loadDataList"
  18. :scroll="{ y: tableHeight }"
  19. @expand="expandChild"
  20. bordered>
  21. <!-- 图片 -->
  22. <template slot="imgs" slot-scope="text, record">
  23. <div class="addType-img">
  24. <img :src="record.iconUrl" alt="图片走丢啦" width="60" height="60" :id="'shoppingManagementList-img-'+record.id"/>
  25. </div>
  26. </template>
  27. <!-- 状态 -->
  28. <template slot="enabledFlag" slot-scope="text, record">
  29. <a-switch
  30. :id="'shoppingManagementList-enableFlag-'+record.id"
  31. v-if="$hasPermissions('B_supplierInfo_enabled')"
  32. checkedChildren="启用"
  33. unCheckedChildren="禁用"
  34. v-model="record.enableFlag"
  35. @click="e=>changeFlagHandle(e,record)"/>
  36. <span v-else :style="{color:(record.enableFlag?'#00aa00':'#999')}"> {{ record.enableFlag? '已启用': '已禁用' }} </span>
  37. </template>
  38. <!-- 操作 -->
  39. <template slot="action" slot-scope="text, record">
  40. <a-button
  41. size="small"
  42. type="link"
  43. class="button-info"
  44. @click="handleEdit(record,'edit')"
  45. :id="'shoppingManagementList-edit-btn'+record.id">编辑</a-button>
  46. <a-button
  47. size="small"
  48. type="link"
  49. class="button-info"
  50. v-if="record.type && record.type == 'root'"
  51. @click="handleEdit(record,'addChild')"
  52. :id="'shoppingManagementList-addChild-btn'+record.id">添加子类目</a-button>
  53. <a-button
  54. size="small"
  55. type="link"
  56. class="button-success"
  57. v-else
  58. @click="handleAddProduct(record)"
  59. :id="'shoppingManagementList-addProduct-btn'+record.id">添加产品</a-button>
  60. <a-button
  61. size="small"
  62. type="link"
  63. class="button-error"
  64. @click="handleDel(record)"
  65. :id="'shoppingManagementList-del-btn'+record.id">删除</a-button>
  66. </template>
  67. </a-table>
  68. </a-spin>
  69. <!-- 新增类目 -->
  70. <addCategoryModal
  71. v-drag
  72. ref="categoryModal"
  73. :pageType="pageType"
  74. :openModal="openCategoryModal"
  75. :parentData="parentData"
  76. @ok="$refs.table.refresh()"
  77. @close="openCategoryModal=false"></addCategoryModal>
  78. </a-card>
  79. </template>
  80. <script>
  81. import { commonMixin } from '@/utils/mixin'
  82. // 组件
  83. import { VSelect } from '@/components'
  84. import addCategoryModal from './addCategoryModal.vue'
  85. // 接口
  86. import { shopCategoryList, getChildList, shopCategoryUpdateStatus, shopCategoryDel } from '@/api/shopCategory'
  87. export default {
  88. name: 'ShoppingManagementList',
  89. mixins: [commonMixin],
  90. components: { VSelect, addCategoryModal },
  91. data () {
  92. return {
  93. spinning: false,
  94. tableHeight: 0, // 表格高度
  95. openCategoryModal: false, // 打开新增类目弹窗
  96. // 表头
  97. columns: [
  98. { title: '类目名称', dataIndex: 'categoryName', width: '20%', align: 'left', customRender: function (text) { return text || '--' } },
  99. { title: '图片', scopedSlots: { customRender: 'imgs' }, width: '15%', align: 'center' },
  100. { title: '优先级', dataIndex: 'sort', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  101. { title: '创建时间', dataIndex: 'createDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  102. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: '15%', align: 'center' },
  103. { title: '操作', scopedSlots: { customRender: 'action' }, width: '20%', align: 'center' }
  104. ],
  105. parentData: null, // 父级类目一行数据
  106. loadDataList: [], // 表格数据
  107. pageType: null// 按钮类型
  108. }
  109. },
  110. methods: {
  111. // 展开子级 获取子级数据
  112. expandChild (expanded, record) {
  113. if (expanded) {
  114. const _this = this
  115. _this.spinning = true
  116. getChildList({ categorySn: record.categorySn }).then(res => {
  117. if (res.status == 200) {
  118. const pos = this.loadDataList.findIndex(item => item.categorySn === record.categorySn)
  119. _this.loadDataList[pos].children = pos != -1 ? (res.data.shopCategoryList && res.data.shopCategoryList.length > 0) ? res.data.shopCategoryList : [] : []
  120. }
  121. _this.spinning = false
  122. })
  123. }
  124. },
  125. // 新增类目
  126. addCategory (typeVal) {
  127. this.pageType = typeVal
  128. this.openCategoryModal = true
  129. },
  130. // 编辑 添加子类目
  131. handleEdit (row, typeVal) {
  132. this.pageType = typeVal
  133. this.openCategoryModal = true
  134. this.parentData = row
  135. if (typeVal === 'edit') {
  136. this.$refs.categoryModal.getDetailData({ categorySn: row.categorySn })
  137. }
  138. },
  139. // 更新状态
  140. changeFlagHandle (e, row) {
  141. const _this = this
  142. const tipWord = row.status == 1 ? '禁用后,关联的产品会同步下架,确认禁用吗?' : '启用后,关联的产品不会同步上架,确认启用吗?'
  143. this.$confirm({
  144. title: '提示',
  145. content: tipWord,
  146. centered: true,
  147. onOk () {
  148. _this.spinning = true
  149. const params = { sn: row.categorySn }
  150. params.status = row.status == 1 ? '0' : '1'
  151. shopCategoryUpdateStatus(params).then(res => {
  152. if (res.status == 200) {
  153. _this.$message.success(res.message)
  154. _this.spinning = false
  155. } else {
  156. _this.spinning = false
  157. }
  158. })
  159. },
  160. onCancel () {
  161. }
  162. })
  163. },
  164. // 添加产品
  165. handleAddProduct (row) {
  166. this.$router.push({ name: 'chooseProductList', params: { sn: row.shopProductSn } })
  167. },
  168. // 删除
  169. handleDel (row) {
  170. const _this = this
  171. this.$confirm({
  172. title: '提示',
  173. content: '删除后,关联的产品会同步删除,确认删除吗?',
  174. centered: true,
  175. onOk () {
  176. _this.spinning = true
  177. shopCategoryDel({ categorySn: row.categorySn }).then(res => {
  178. if (res.status == 200) {
  179. _this.$message.success(res.message)
  180. _this.$refs.table.refresh()
  181. _this.spinning = false
  182. } else {
  183. _this.spinning = false
  184. }
  185. })
  186. }
  187. })
  188. },
  189. // 获取表格数据
  190. getTabData () {
  191. this.spinning = true
  192. shopCategoryList({}).then(res => {
  193. let data
  194. if (res.status == 200) {
  195. data = res.data
  196. for (var i = 0; i < data.length; i++) {
  197. data[i].enableFlag = data[i].status === 1
  198. data[i].children = []
  199. data[i].type = 'root'
  200. }
  201. }
  202. this.loadDataList = res.data
  203. this.spinning = false
  204. })
  205. },
  206. // 初始化
  207. pageInit () {
  208. const _this = this
  209. _this.getTabData()
  210. this.$nextTick(() => { // 页面渲染完成后的回调
  211. _this.setTableH()
  212. })
  213. },
  214. // 计算表格高度
  215. setTableH () {
  216. const tableSearchH = this.$refs.tableSearch.offsetHeight
  217. this.tableHeight = window.innerHeight - tableSearchH - 230
  218. }
  219. },
  220. watch: {
  221. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  222. this.setTableH()
  223. }
  224. },
  225. mounted () {
  226. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  227. this.pageInit()
  228. }
  229. },
  230. activated () {
  231. // 如果是新页签打开,则重置当前页面
  232. if (this.$store.state.app.isNewTab) {
  233. this.pageInit()
  234. }
  235. // 仅刷新列表,不重置页面
  236. if (this.$store.state.app.updateList) {
  237. this.pageInit()
  238. }
  239. },
  240. beforeRouteEnter (to, from, next) {
  241. next(vm => {})
  242. }
  243. }
  244. </script>
  245. <style lang="less">
  246. .shoppingManagementList-wrap{
  247. height: 100%;
  248. .addType-img{
  249. img{
  250. object-fit: cover;
  251. }
  252. }
  253. }
  254. </style>