index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :export-list="exportList" :column-parsing="columnParsing"
  3. :more-parameters="moreParameters" :operation="operation()" :operation-column-width="240" :replace-or-not-map="false"
  4. :optionsEvensGroup="optionsEvensGroup" :tableAttributes="tableAttributes" :tableEvents="tableEvents">
  5. <div class="cartographer_big">
  6. <el-dialog title="编辑" width="100%" :modal="false" :visible.sync="visible" :before-close="handleClose">
  7. <Form v-if="visible" :detail-id="detailId" @back="handleClose" />
  8. </el-dialog>
  9. </div>
  10. </template-page>
  11. </template>
  12. <script>
  13. import TemplatePage from '@/components/template/template-page-1.vue'
  14. import import_mixin from '@/components/template/import_mixin.js'
  15. import operation_mixin from '@/components/template/operation_mixin.js'
  16. import Form from './form.vue'
  17. import { esGoodsList, esGoodsListExport, esGoodsDel, esGoodsTop, esGoodsBatchUpdateStatus } from '@/api/commodityManagement'
  18. export default {
  19. components: { TemplatePage, Form },
  20. mixins: [import_mixin, operation_mixin],
  21. props: {},
  22. data() {
  23. return {
  24. // 事件组合
  25. optionsEvensGroup: [
  26. [
  27. [
  28. this.optionsEvensAuth('batchListing', {
  29. click: () => {
  30. if (this.recordSelected.length === 0) {
  31. this.$message.warning('请勾选')
  32. return
  33. }
  34. esGoodsBatchUpdateStatus({
  35. ids:this.recordSelected.map(item=>item.id).join(","),
  36. status:"ON"
  37. }).then(res => {
  38. this.$message({ type: 'success', message: `设置成功!` })
  39. this.$refs.pageRef.refreshList()
  40. })
  41. }
  42. })
  43. ],
  44. [
  45. this.optionsEvensAuth('batchDelist', {
  46. click: () => {
  47. if (this.recordSelected.length === 0) {
  48. this.$message.warning('请勾选')
  49. return
  50. }
  51. esGoodsBatchUpdateStatus({
  52. ids:this.recordSelected.map(item=>item.id).join(","),
  53. status:"OFF"
  54. }).then(res => {
  55. this.$message({ type: 'success', message: `设置成功!` })
  56. this.$refs.pageRef.refreshList()
  57. })
  58. }
  59. })
  60. ]
  61. ]
  62. ],
  63. visible: false,
  64. detailId: '',
  65. // 表格属性
  66. tableAttributes: {
  67. // 启用勾选列
  68. selectColumn: true,
  69. selectable: this.selectable
  70. },
  71. // 表格事件
  72. tableEvents: {
  73. 'selection-change': this.selectionChange
  74. },
  75. recordSelected: []
  76. }
  77. },
  78. computed: {
  79. moreParameters() {
  80. return [
  81. {
  82. name: '状态',
  83. key: 'orderType',
  84. value: '',
  85. conditions: [
  86. {
  87. label: `全部`,
  88. value: ''
  89. },
  90. {
  91. label: `上架`,
  92. value: 'ON'
  93. },
  94. {
  95. label: `下架`,
  96. value: 'OFF'
  97. },
  98. {
  99. label: `已卖出`,
  100. value: 'SALE'
  101. }
  102. ]
  103. }
  104. ]
  105. }
  106. },
  107. methods: {
  108. selectable(row, index) {
  109. return ["ON", "OFF"].includes(Object.entries(row.selectMapData.status).find(([key, val]) => val == row.status)?.[0])
  110. },
  111. // 监听勾选变化
  112. selectionChange(data) {
  113. this.recordSelected = data
  114. },
  115. // 列表请求函数
  116. getList(p, cb) {
  117. if (p.orderType) {
  118. p.params.push({ param: 'a.status', compare: '=', value: p.orderType })
  119. }
  120. cb && cb(p)
  121. return esGoodsList(p)
  122. },
  123. // 列表导出函数
  124. exportList: esGoodsListExport,
  125. // 表格列解析渲染数据更改
  126. columnParsing(item, defaultData) {
  127. if (item.jname === 'imgUrl') {
  128. defaultData.render = (h, { row, index, column }) => {
  129. return (
  130. <div style="padding:0 6px;cursor: pointer;">
  131. {row.imgUrl
  132. ? row.imgUrl
  133. .split(',')
  134. .map(url => (
  135. <el-image src={url} preview-src-list={[url]} fit="fit" style="width:80px;height:80px;" />
  136. ))
  137. : null}
  138. </div>
  139. )
  140. }
  141. }
  142. return defaultData
  143. },
  144. operation() {
  145. return this.operationBtn({
  146. edit: {
  147. click: ({ row, index, column }) => {
  148. this.detailId = row.id
  149. this.visible = true
  150. }
  151. },
  152. del: {
  153. prompt: "是否确定删除?",
  154. conditions: ({ row, index, column }) => {
  155. return row.status == "SALE"
  156. },
  157. click: ({ row, index, column }) => {
  158. esGoodsDel({ id: row.id }).then(res => {
  159. this.$message({ type: 'success', message: `删除成功!` })
  160. this.$refs.pageRef.refreshList()
  161. })
  162. }
  163. },
  164. topFix: {
  165. prompt: "是否确定置顶?",
  166. conditions: ({ row, index, column }) => {
  167. return !row.isTop
  168. },
  169. click: ({ row, index, column }) => {
  170. esGoodsTop({ id: row.id, isTop: true }).then(res => {
  171. this.$message({ type: 'success', message: `设置成功!` })
  172. this.$refs.pageRef.refreshList()
  173. })
  174. }
  175. },
  176. unTopFix: {
  177. prompt: "是否确定取消置顶?",
  178. conditions: ({ row, index, column }) => {
  179. return row.isTop
  180. },
  181. click: ({ row, index, column }) => {
  182. esGoodsTop({ id: row.id, isTop: false }).then(res => {
  183. this.$message({ type: 'success', message: `设置成功!` })
  184. this.$refs.pageRef.refreshList()
  185. })
  186. }
  187. }
  188. })
  189. },
  190. handleClose(obj) {
  191. this.detailId = ''
  192. this.visible = false
  193. this.$refs.pageRef.refreshList()
  194. if(obj && obj.detailId){
  195. this.$nextTick(()=>{
  196. this.detailId = obj.detailId
  197. this.visible = true
  198. })
  199. }
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped></style>