index.vue 7.0 KB

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