index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  3. :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
  4. :operation="operation()" :exportList="exportList" :operationColumnWidth="160">
  5. <el-dialog title="" width="500px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog"
  6. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
  7. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  8. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
  9. :form-data="formData" :form-items="formItems">
  10. </zj-form-module>
  11. </zj-form-container>
  12. <div slot="footer" class="dialog-footer">
  13. <el-button size="mini" @click="formCancel">取 消</el-button>
  14. <el-button size="mini" @click="formConfirm" type="primary">确 定</el-button>
  15. </div>
  16. </el-dialog>
  17. </template-page>
  18. </template>
  19. <script>
  20. import TemplatePage from '@/components/template/template-page-1.vue'
  21. import import_mixin from '@/components/template/import_mixin.js'
  22. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  23. import {
  24. goodsNewsCategoryListPageV2,
  25. goodsNewsCategoryPageExport,
  26. addNewclassify,
  27. getNewclassifyDetail,
  28. editNewclassifyDetail,
  29. changeNewclassify,
  30. deleteNewclassify
  31. } from "@/api/goods";
  32. import operation_mixin from '@/components/template/operation_mixin.js'
  33. export default {
  34. components: { TemplatePage },
  35. mixins: [import_mixin,operation_mixin],
  36. data() {
  37. return {
  38. // 表格属性
  39. tableAttributes: {
  40. // 启用勾选列
  41. selectColumn: false
  42. },
  43. // 表格事件
  44. tableEvents: {
  45. 'selection-change': this.selectionChange
  46. },
  47. // 勾选选中行
  48. recordSelected: [],
  49. /** 表单变量 */
  50. formDialogType: 0,
  51. formDialogTitles: ["新增", "编辑"],
  52. formDialog: false,
  53. formData: {
  54. mainTitle: '',
  55. subTitle: '',
  56. type: '',
  57. sortNum: '',
  58. },
  59. }
  60. },
  61. computed: {
  62. // 事件组合
  63. optionsEvensGroup() {
  64. return [
  65. [
  66. [
  67. this.optionsEvensAuth("add", {
  68. click: () => {
  69. this.addData()
  70. }
  71. })
  72. ]
  73. ]
  74. ]
  75. },
  76. // 更多参数
  77. moreParameters() {
  78. return []
  79. },
  80. formItems() {
  81. return [{
  82. md: 24,
  83. isShow: true,
  84. name: 'el-input',
  85. attributes: { placeholder: '请输入' },
  86. formItemAttributes: {
  87. label: '主标题',
  88. prop: 'mainTitle',
  89. rules: [...required]
  90. }
  91. }, {
  92. md: 24,
  93. isShow: true,
  94. name: 'el-input',
  95. attributes: { placeholder: '请输入' },
  96. formItemAttributes: {
  97. label: '副标题',
  98. prop: 'subTitle',
  99. rules: [...required]
  100. }
  101. },
  102. {
  103. md: 24,
  104. isShow: true,
  105. name: 'el-radio',
  106. options: [
  107. { label: "普通商品", value: 1 },
  108. { label: "套购商品", value: 2 },
  109. ],
  110. attributes: { filterable: true, placeholder: '请选择', disabled: this.formData.flag === 'START' || this.formDialogType == 2 },
  111. formItemAttributes: {
  112. label: '商品类别',
  113. prop: 'type',
  114. rules: [...required]
  115. }
  116. }, {
  117. md: 24,
  118. isShow: true,
  119. name: 'el-input',
  120. attributes: { placeholder: '请输入' },
  121. formItemAttributes: {
  122. label: '排序',
  123. prop: 'sortNum',
  124. rules: []
  125. }
  126. }]
  127. }
  128. },
  129. methods: {
  130. // 列表请求函数
  131. getList: goodsNewsCategoryListPageV2,
  132. // 列表导出函数
  133. exportList: goodsNewsCategoryPageExport,
  134. // 表格列解析渲染数据更改
  135. columnParsing(item, defaultData) {
  136. return defaultData
  137. },
  138. // 监听勾选变化
  139. selectionChange(data) {
  140. this.recordSelected = data
  141. },
  142. // 表格操作列
  143. operation() {
  144. return this.operationBtn({
  145. disposition: {
  146. btnType: 'text',
  147. click: ({ row, index, column }) => {
  148. this.$router.push({
  149. name: "newclassify_set",
  150. query: {
  151. item: row
  152. },
  153. });
  154. }
  155. },
  156. edit: {
  157. btnType: 'text',
  158. click: ({ row, index, column }) => {
  159. getNewclassifyDetail({ newsCategoryId: row.goodsNewsCategoryId }).then(res => {
  160. Object.assign(this.formData, res.data)
  161. this.formDialogType = 1
  162. this.openForm()
  163. })
  164. }
  165. },
  166. del: {
  167. btnType: 'text',
  168. prompt: '确定删除吗?',
  169. click: ({ row, index, column }) => {
  170. deleteNewclassify({ goodsNewsCategoryId: row.goodsNewsCategoryId }).then(() => {
  171. this.$message({ type: 'success', message: '删除成功!' })
  172. this.$refs.pageRef.refreshList()
  173. })
  174. }
  175. },
  176. status: {
  177. btnType: 'text',
  178. name: ({ row, index, column }) => {
  179. return Number(row.status) ? "关闭" : "开启"
  180. },
  181. prompt: ({ row, index, column }) => {
  182. return `是否确定${Number(row.status) ? "关闭" : "开启"}?`
  183. },
  184. click: ({ row, index, column }) => {
  185. changeNewclassify({
  186. goodsNewsCategoryId: row.goodsNewsCategoryId,
  187. status: Number(row.status) ? 0 : 1,
  188. }).then(res => {
  189. this.$message({ type: 'success', message: `${Number(row.status) ? "关闭" : "开启"}成功!` })
  190. this.$refs.pageRef.refreshList()
  191. })
  192. }
  193. },
  194. })
  195. },
  196. addData() {
  197. this.formDialogType = 0
  198. this.openForm()
  199. },
  200. openForm() {
  201. this.formDialog = true;
  202. },
  203. formCancel() {
  204. this.$refs.formRef.$refs.inlineForm.clearValidate()
  205. this.$data.formData = this.$options.data().formData
  206. this.formDialog = false
  207. },
  208. formConfirm() {
  209. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  210. if (valid) {
  211. ([addNewclassify, editNewclassifyDetail][this.formDialogType])(this.formData).then(res => {
  212. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  213. this.formCancel()
  214. this.$refs.pageRef.refreshList()
  215. })
  216. }
  217. })
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="scss" scoped></style>