index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: '列表页面', 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. </template-page>
  8. <div v-if="~['add', 'edit', 'detail'].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 v-if="formDialogType !== 2" 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 { chargingStandardList2, getMainList, getMainDetail, saveMain, deleteMain, getTypeList, getBrandList } from "@/api/miniapp";
  27. import { getClassifyList } from '@/api/goods'
  28. import ImageUpload from '@/components/file-upload'
  29. import operation_mixin from '@/components/template/operation_mixin.js'
  30. export default {
  31. components: { TemplatePage, ImageUpload },
  32. mixins: [import_mixin,operation_mixin],
  33. data() {
  34. return {
  35. // 表格属性
  36. tableAttributes: {
  37. // 启用勾选列
  38. selectColumn: false
  39. },
  40. // 表格事件
  41. tableEvents: {
  42. 'selection-change': this.selectionChange
  43. },
  44. // 勾选选中行
  45. recordSelected: [],
  46. /** 表单变量 */
  47. formDialogType: 0,
  48. formDialogTitles: ["新增", "编辑", "查看"],
  49. formDialog: false,
  50. formData: {
  51. chargingStandardTypeId: "",
  52. brandId: "",
  53. oneCategoryId: "",
  54. twoCategoryId: "",
  55. status: true,
  56. imageUrl: [],
  57. },
  58. businessTypeList: [], // 业务类型列表
  59. brandList: [], // 品牌列表
  60. mainList: [], // 一级分类列表
  61. smallList: [], // 二级分类列表
  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-select',
  90. options: this.businessTypeList,
  91. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  92. formItemAttributes: {
  93. label: '业务类型',
  94. prop: 'chargingStandardTypeId',
  95. rules: [...required]
  96. }
  97. },
  98. {
  99. md: 6,
  100. isShow: true,
  101. name: 'el-select',
  102. options: this.brandList,
  103. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  104. formItemAttributes: {
  105. label: '服务品牌',
  106. prop: 'brandId',
  107. rules: [...required]
  108. }
  109. },
  110. {
  111. md: 6,
  112. isShow: true,
  113. name: 'el-select',
  114. options: this.mainList,
  115. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  116. formItemAttributes: {
  117. label: '一级分类',
  118. prop: 'oneCategoryId',
  119. rules: [...required]
  120. },
  121. events: {
  122. change: async val => {
  123. this.smallList = []
  124. this.formData.twoCategoryId = ""
  125. if (val) {
  126. this.smallList = this.mainList.find(item => {
  127. return item.value == val;
  128. })?.data?.children?.map(item => ({
  129. label: item.name,
  130. value: item.categoryId,
  131. data: item
  132. })) || [];
  133. }
  134. }
  135. }
  136. },
  137. {
  138. md: 6,
  139. isShow: true,
  140. name: 'el-select',
  141. options: this.smallList,
  142. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2, },
  143. formItemAttributes: {
  144. label: '二级分类',
  145. prop: 'twoCategoryId',
  146. rules: [...required]
  147. }
  148. },
  149. {
  150. md: 6,
  151. isShow: true,
  152. name: 'el-radio',
  153. options: [{ label: "开启", value: true }, { label: "禁用", value: false }],
  154. attributes: { filterable: true, placeholder: '请选择', disabled: this.formDialogType == 2 },
  155. formItemAttributes: {
  156. label: '状态',
  157. prop: 'status',
  158. rules: [...required]
  159. }
  160. },
  161. {
  162. md: 24,
  163. isShow: true,
  164. name: 'slot-component',
  165. formItemAttributes: {
  166. label: '图片',
  167. prop: 'imageUrl',
  168. rules: [...required]
  169. },
  170. render: (h, { props, onInput }) => {
  171. var { value } = props
  172. return (
  173. <ImageUpload fileList={this.formData.imageUrl} uid="imgSrc_chargingStandard_materials_drawing_images" limit={1} isEdit={this.formDialogType !== 2} />
  174. )
  175. }
  176. },
  177. ]
  178. }
  179. },
  180. methods: {
  181. // 列表请求函数
  182. getList: chargingStandardList2,
  183. // 列表导出函数
  184. exportList() { },
  185. // 表格列解析渲染数据更改
  186. columnParsing(item, defaultData) {
  187. if (item.jname === 'imageUrl') {
  188. defaultData.render = (h, { row, index, column }) => {
  189. return (
  190. <div style="padding:0 6px;cursor: pointer;">
  191. {row.imageUrl ? row.imageUrl.split(",").map(url => <el-image src={url} preview-src-list={[url]} style="width:80px;height:auto;" />) : null}
  192. </div>
  193. )
  194. }
  195. }
  196. return defaultData
  197. },
  198. // 监听勾选变化
  199. selectionChange(data) {
  200. this.recordSelected = data
  201. },
  202. // 表格操作列
  203. operation() {
  204. return this.operationBtn({
  205. detail: {
  206. btnType: 'text',
  207. click: ({ row, index, column }) => {
  208. this.openForm('detail',row.id)
  209. }
  210. },
  211. edit: {
  212. btnType: 'text',
  213. click: ({ row, index, column }) => {
  214. this.openForm('edit',row.id)
  215. }
  216. },
  217. del: {
  218. btnType: 'text',
  219. prompt: '确定删除吗?',
  220. click: ({ row, index, column }) => {
  221. deleteMain({ id: row.id }).then(res => {
  222. this.$message({
  223. type: 'success',
  224. message: `删除成功!`,
  225. })
  226. this.$refs.pageRef.refreshList()
  227. })
  228. }
  229. }
  230. })
  231. },
  232. // 取消 新增编辑
  233. formCancel() {
  234. this.formVisible = false
  235. this.$refs?.formRef?.resetFields()
  236. this.$data.formRef = this.$options.data().formRef
  237. },
  238. // 打开 新增编辑 网点表单
  239. openForm(type, id) {
  240. this.$refs.tabPage.addTab({
  241. // 对应显示的模块
  242. activeKey: type,
  243. // 唯一标识
  244. key: type,
  245. // 页签名称
  246. label: ({ edit: "编辑", add: "新增", detail: "查看" })[type],
  247. // 打开时事件
  248. triggerEvent: () => {
  249. this.formCancel()
  250. this.$nextTick(()=>{
  251. this.formType = type
  252. this.formVisible = true
  253. if (type == 'add') {
  254. this.formDialogType = 0
  255. } else if(type == 'edit'){
  256. this.formDialogType = 1
  257. getMainDetail({ id }).then(res => {
  258. Object.assign(this.formData, res.data, {
  259. imageUrl: res.data.imageUrl ? [{ url: res.data.imageUrl }] : [],
  260. })
  261. this.initData()
  262. })
  263. }else{
  264. this.formDialogType = 2
  265. getMainDetail({ id }).then(res => {
  266. Object.assign(this.formData, res.data, {
  267. imageUrl: res.data.imageUrl ? [{ url: res.data.imageUrl }] : [],
  268. })
  269. this.initData()
  270. })
  271. }
  272. })
  273. },
  274. // 关闭时事件
  275. closeEvent: () => {
  276. }
  277. })
  278. },
  279. initData() {
  280. Promise.all([
  281. getTypeList(),
  282. getBrandList(),
  283. getClassifyList({
  284. type: 2,
  285. name: '',
  286. })
  287. ]).then(([res1, res2, res3]) => {
  288. this.businessTypeList = res1.data.map(item => ({
  289. label: item.name,
  290. value: item.id,
  291. data: item
  292. }));
  293. this.brandList = res2.data.map(item => ({
  294. label: item.brandName,
  295. value: item.id,
  296. data: item
  297. }));
  298. this.mainList = res3.data.map(item => ({
  299. label: item.name,
  300. value: item.categoryId,
  301. data: item
  302. }));
  303. if (this.formData.oneCategoryId) {
  304. this.smallList = this.mainList.find(item => {
  305. return item.value == this.formData.oneCategoryId;
  306. })?.data?.children?.map(item => ({
  307. label: item.name,
  308. value: item.categoryId,
  309. data: item
  310. })) || [];
  311. }
  312. })
  313. },
  314. formConfirm(cancel) {
  315. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  316. if (valid) {
  317. var pam = {
  318. ...this.formData,
  319. imageUrl: this.formData.imageUrl.map(item => item.url).join(","),
  320. };
  321. saveMain({ ...pam, type: 1 }).then(res => {
  322. this.$message({
  323. type: 'success',
  324. message: this.formDialogTitles[this.formDialogType] + `成功!`,
  325. })
  326. cancel('list')
  327. this.$refs.pageRef.refreshList()
  328. })
  329. }
  330. })
  331. },
  332. }
  333. }
  334. </script>
  335. <style lang="scss" scoped></style>