index.vue 9.7 KB

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