index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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">
  7. <div slot="moreSearch">
  8. <el-radio-group v-model="type" size="mini" @change="changeType">
  9. <el-radio-button :label="''">全部</el-radio-button>
  10. <el-radio-button :label="true">开启</el-radio-button>
  11. <el-radio-button :label="false">禁用</el-radio-button>
  12. </el-radio-group>
  13. <br><br>
  14. </div>
  15. </template-page>
  16. <div v-if="~['add', 'edit', 'detail'].indexOf(activeKey)">
  17. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  18. <zj-form-module title="" label-width="110px" :showPackUp="false"
  19. :form-data="formData" :form-items="formItems">
  20. </zj-form-module>
  21. </zj-form-container>
  22. <div slot="footer" class="dialog-footer">
  23. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  24. <el-button v-if="formDialogType !== 2" size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
  25. </div>
  26. </div>
  27. </template>
  28. </zj-tab-page>
  29. </template>
  30. <script>
  31. import TemplatePage from '@/components/template/template-page-1.vue'
  32. import import_mixin from '@/components/template/import_mixin.js'
  33. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  34. import { chargingStandardList3, chargingStandardList3PageExport, chargingStandardImport, getMainList, getMainDetail, saveMain, deleteMain, getBrandList } from "@/api/miniapp";
  35. import { getClassifyList } from '@/api/goods'
  36. import { downloadFiles } from '@/utils/util'
  37. import operation_mixin from '@/components/template/operation_mixin.js'
  38. export default {
  39. components: { TemplatePage },
  40. mixins: [import_mixin,operation_mixin],
  41. data() {
  42. return {
  43. type: "",
  44. // 表格属性
  45. tableAttributes: {
  46. // 启用勾选列
  47. selectColumn: false
  48. },
  49. // 表格事件
  50. tableEvents: {
  51. 'selection-change': this.selectionChange
  52. },
  53. // 勾选选中行
  54. recordSelected: [],
  55. /** 表单变量 */
  56. formDialogType: 0,
  57. formDialogTitles: ["新增", "编辑", "查看"],
  58. formDialog: false,
  59. formData: {
  60. brandId: "",
  61. oneCategoryId: "",
  62. twoCategoryId: "",
  63. content1: "",
  64. content2: "",
  65. status: true,
  66. },
  67. brandList: [], // 品牌列表
  68. mainList: [], // 一级分类列表
  69. smallList: [], // 二级分类列表
  70. formType: 'add',
  71. formVisible: false,
  72. }
  73. },
  74. computed: {
  75. // 事件组合
  76. optionsEvensGroup() {
  77. return [
  78. [
  79. [
  80. this.optionsEvensAuth("add", {
  81. click: () => {
  82. this.openForm('add')
  83. }
  84. })
  85. ],
  86. ],
  87. [
  88. [
  89. this.optionsEvensAuth("template", {
  90. click: () => {
  91. this.handleDownload()
  92. }
  93. })
  94. ],
  95. ],
  96. [
  97. [
  98. this.optionsEvensAuth("imp", {
  99. render: () => {
  100. return this.importButton(chargingStandardImport, '导入模板')
  101. }
  102. })
  103. ],
  104. ]
  105. ]
  106. },
  107. // 更多参数
  108. moreParameters() {
  109. return []
  110. },
  111. formItems() {
  112. return [
  113. {
  114. md: 6,
  115. isShow: true,
  116. name: 'el-select',
  117. options: this.brandList,
  118. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  119. formItemAttributes: {
  120. label: '服务品牌',
  121. prop: 'brandId',
  122. rules: [...required]
  123. }
  124. },
  125. {
  126. md: 6,
  127. isShow: true,
  128. name: 'el-select',
  129. options: this.mainList,
  130. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  131. formItemAttributes: {
  132. label: '一级分类',
  133. prop: 'oneCategoryId',
  134. rules: [...required]
  135. },
  136. events: {
  137. change: async val => {
  138. this.smallList = []
  139. this.formData.twoCategoryId = ""
  140. if (val) {
  141. this.smallList = this.mainList.find(item => {
  142. return item.value == val;
  143. })?.data?.children?.map(item => ({
  144. label: item.name,
  145. value: item.categoryId,
  146. data: item
  147. })) || [];
  148. }
  149. }
  150. }
  151. },
  152. {
  153. md: 6,
  154. isShow: true,
  155. name: 'el-select',
  156. options: this.smallList,
  157. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  158. formItemAttributes: {
  159. label: '二级分类',
  160. prop: 'twoCategoryId',
  161. rules: [...required]
  162. }
  163. }, {
  164. md: 6,
  165. isShow: true,
  166. name: 'el-input',
  167. attributes: { placeholder: '请输入', disabled: this.formDialogType == 2, },
  168. formItemAttributes: {
  169. label: '故障内容',
  170. prop: 'content1',
  171. rules: [...required]
  172. }
  173. },
  174. {
  175. md: 6,
  176. isShow: true,
  177. name: 'el-radio',
  178. options: [{ label: "开启", value: true }, { label: "禁用", value: false }],
  179. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2 },
  180. formItemAttributes: {
  181. label: '状态',
  182. prop: 'status',
  183. rules: [...required]
  184. }
  185. },
  186. {
  187. md: 24,
  188. isShow: true,
  189. name: 'el-input',
  190. attributes: { placeholder: '请输入', type: "textarea", rows: 5, disabled: this.formDialogType == 2, },
  191. formItemAttributes: {
  192. label: '故障排除指引',
  193. prop: 'content2',
  194. rules: [...required]
  195. }
  196. }
  197. ]
  198. }
  199. },
  200. methods: {
  201. // 切换状态
  202. changeType(val) {
  203. this.$refs.pageRef.refreshList()
  204. },
  205. // 列表请求函数
  206. getList(p) {
  207. try {
  208. var pam = JSON.parse(JSON.stringify(p))
  209. if (this.type !== '') {
  210. pam.params.push({ "param": "a.status", "compare": "=", "value": this.type })
  211. }
  212. return chargingStandardList3(pam)
  213. } catch (error) {
  214. console.log(error)
  215. } finally {
  216. }
  217. },
  218. // 列表导出函数
  219. exportList: chargingStandardList3PageExport,
  220. // 表格列解析渲染数据更改
  221. columnParsing(item, defaultData) {
  222. return defaultData
  223. },
  224. // 监听勾选变化
  225. selectionChange(data) {
  226. this.recordSelected = data
  227. },
  228. // 表格操作列
  229. operation() {
  230. return this.operationBtn({
  231. detail: {
  232. btnType: 'text',
  233. click: ({ row, index, column }) => {
  234. this.openForm('detail',row.id)
  235. }
  236. },
  237. edit: {
  238. btnType: 'text',
  239. click: ({ row, index, column }) => {
  240. this.openForm('edit',row.id)
  241. }
  242. },
  243. del: {
  244. btnType: 'text',
  245. prompt: '确定删除吗?',
  246. click: ({ row, index, column }) => {
  247. deleteMain({ id: row.id }).then(res => {
  248. this.$message({
  249. type: 'success',
  250. message: `删除成功!`,
  251. })
  252. this.$refs.pageRef.refreshList()
  253. })
  254. }
  255. }
  256. })
  257. },
  258. // 取消 新增编辑
  259. formCancel() {
  260. this.formVisible = false
  261. this.$refs?.formRef?.resetFields()
  262. this.$data.formData = this.$options.data().formData
  263. },
  264. // 打开 新增编辑 网点表单
  265. openForm(type, id) {
  266. this.$refs.tabPage.addTab({
  267. // 对应显示的模块
  268. activeKey: type,
  269. // 唯一标识
  270. key: type,
  271. // 页签名称
  272. label: ({ edit: "编辑", add: "新增", detail: "查看" })[type],
  273. // 打开时事件
  274. triggerEvent: () => {
  275. this.formCancel()
  276. this.$nextTick(()=>{
  277. this.formType = type
  278. this.formVisible = true
  279. if (type == 'add') {
  280. this.formDialogType = 0
  281. this.initData()
  282. } else if(type == 'edit'){
  283. this.formDialogType = 1
  284. getMainDetail({ id }).then(res => {
  285. Object.assign(this.formData, res.data)
  286. this.initData()
  287. })
  288. }else{
  289. this.formDialogType = 2
  290. getMainDetail({ id }).then(res => {
  291. Object.assign(this.formData, res.data)
  292. this.initData()
  293. })
  294. }
  295. })
  296. },
  297. // 关闭时事件
  298. closeEvent: () => {
  299. }
  300. })
  301. },
  302. initData() {
  303. Promise.all([
  304. getBrandList(),
  305. getClassifyList({
  306. type: 2,
  307. name: '',
  308. })
  309. ]).then(([res2, res3]) => {
  310. this.brandList = res2.data.map(item => ({
  311. label: item.brandName,
  312. value: item.id,
  313. data: item
  314. }));
  315. this.mainList = res3.data.map(item => ({
  316. label: item.name,
  317. value: item.categoryId,
  318. data: item
  319. }));
  320. if (this.formData.oneCategoryId) {
  321. this.smallList = this.mainList.find(item => {
  322. return item.value == this.formData.oneCategoryId;
  323. })?.data?.children?.map(item => ({
  324. label: item.name,
  325. value: item.categoryId,
  326. data: item
  327. })) || [];
  328. }
  329. this.formDialog = true;
  330. })
  331. },
  332. formConfirm(cancel) {
  333. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  334. if (valid) {
  335. saveMain({...this.formData, type:2}).then(res => {
  336. this.$message({
  337. type: 'success',
  338. message: this.formDialogTitles[this.formDialogType] + `成功!`,
  339. })
  340. cancel('list')
  341. this.$refs.pageRef.refreshList()
  342. })
  343. }
  344. })
  345. },
  346. // 下载导入模版
  347. handleDownload() {
  348. downloadFiles('charging/standard/download');
  349. },
  350. }
  351. }
  352. </script>
  353. <style lang="scss" scoped></style>