categoryAllocation.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div style="width: 100%; height: 100%; box-sizing: border-box; padding: 20px">
  3. <zj-page-container direction="row">
  4. <div class="catalogue" style="padding-right: 0px">
  5. <zj-page-container>
  6. <div style="padding: 0 10px 10px; display: flex">
  7. <el-button icon="el-icon-refresh-right" size="small" @click="refreshDepartment"
  8. style="padding: 9px 10px; margin-right: 6px"></el-button>
  9. <el-input placeholder="输入关键字进行过滤" size="small" clearable v-model="filterText"> </el-input>
  10. </div>
  11. <zj-page-fill>
  12. <el-tree :data="listTree" :props="defaultProps" default-expand-all highlight-current
  13. :expand-on-click-node="false" :filter-node-method="filterNode" @node-click="handleNodeClick"
  14. node-key="categoryId" ref="listTree">
  15. <div class="custom-tree-node" slot-scope="{ node, data }">
  16. <span>
  17. <i :class="data.children && data.children.length > 0 ? 'el-icon-folder-opened' : 'el-icon-document-remove'
  18. "></i>
  19. <span>{{ node.label }}</span>
  20. </span>
  21. <span v-if="data.level == 2 || data.level == 3">
  22. <el-button v-if="data.level == 2" type="text" size="mini" @click="addChClass(data)"> 添加 </el-button>
  23. <el-button v-if="data.level == 3" type="text" size="mini" @click="editClass(data)"> 编辑 </el-button>
  24. <el-popconfirm v-if="data.level == 3" style="margin-left: 10px" title="确定删除吗?"
  25. @confirm="handleDelete(data)">
  26. <el-button v-if="data.level == 3" slot="reference" size="mini" type="text"> 删除 </el-button>
  27. </el-popconfirm>
  28. </span>
  29. </div>
  30. </el-tree>
  31. </zj-page-fill>
  32. </zj-page-container>
  33. </div>
  34. <zj-page-fill v-loading="!showList">
  35. <template-page v-if="showList && item && item.typeAttribute" ref="pageRef" :getList="getListRight"
  36. :exportList="exportList" :columnParsing="columnParsing" :optionsEvensGroup="optionsEvensGroup"
  37. :tableAttributes="tableAttributes" :tableEvents="tableEvents" :operationColumnWidth="200"
  38. :operation="operation()" :recordsHook="recordsHook" :replaceOrNotMap="true" :customModuleName="`${$route.meta.title}_${item ? ['规格', '其他'][typeAttribute[item.typeAttribute]] : ''
  39. }`" :setModuleId="`${$route.meta.moduleId}_${item ? item.typeAttribute : ''}`">
  40. </template-page>
  41. </zj-page-fill>
  42. </zj-page-container>
  43. <el-dialog :title="formData.categoryId ? '编辑' : '新建'" :modal="true" width="600px" :visible.sync="formDialog"
  44. :before-close="formCancel" :close-on-click-modal="false">
  45. <zj-form-container v-if="formDialog" ref="formRef" :form-data="formData" :styleSwitch="false">
  46. <zj-form-module label-width="120px" :showPackUp="false" :form-data="formData" :form-items="formItems">
  47. </zj-form-module>
  48. </zj-form-container>
  49. <div slot="footer" class="dialog-footer">
  50. <el-button size="mini" @click="formCancel">取 消</el-button>
  51. <el-button size="mini" @click="formConfirm" type="primary">确定</el-button>
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import import_mixin from '@/components/template/import_mixin.js'
  58. import TemplatePage from '@/components/template/template-page-1.vue'
  59. import { treeToList } from '@/utils/util'
  60. import {
  61. tradeList,
  62. tradeListPage,
  63. tradePageExport,
  64. tradeListOtherPage,
  65. tradePageOtherExport,
  66. serviceCategoryDetail,
  67. serviceCategoryItemAdd,
  68. serviceCategoryItemUpdate,
  69. serviceCategoryItemDel
  70. } from '@/api/tradeInConfig.js'
  71. import formItems from '../mixins/formItems.js'
  72. export default {
  73. mixins: [import_mixin, formItems],
  74. components: {
  75. TemplatePage
  76. },
  77. data() {
  78. return {
  79. // 事件组合
  80. optionsEvensGroup: [],
  81. // 表格属性
  82. tableAttributes: {},
  83. // 表格事件
  84. tableEvents: {},
  85. // 重新加载列表
  86. showList: true,
  87. //**部门树 */
  88. filterText: '',
  89. list: [],
  90. listTree: [],
  91. defaultProps: {
  92. children: 'children',
  93. label: 'name'
  94. },
  95. item: null,
  96. typeAttribute: {
  97. SPEC: 0,
  98. OTHER: 1
  99. }
  100. }
  101. },
  102. watch: {
  103. filterText(val) {
  104. this.$refs.listTree.filter(val)
  105. },
  106. item(val) {
  107. this.showList = false
  108. if (val) {
  109. this.$nextTick(() => {
  110. this.showList = true
  111. })
  112. }
  113. }
  114. },
  115. mounted() {
  116. this.getList()
  117. },
  118. methods: {
  119. getList() {
  120. tradeList().then(res => {
  121. this.list = treeToList(res.data)
  122. this.listTree = res.data
  123. this.listTree.map(item => {
  124. ; (item.children || []).map(item2 => {
  125. ; (item2.children || []).map(item3 => {
  126. if (!this.item) {
  127. this.item = item3
  128. serviceCategoryDetail({ categoryId: item3.categoryId }).then(res => {
  129. this.item = res.data
  130. this.$nextTick(() => {
  131. this.$refs.listTree.setCurrentKey(this.item?.categoryId || '')
  132. })
  133. })
  134. }
  135. })
  136. })
  137. })
  138. })
  139. },
  140. refreshDepartment() {
  141. this.getList()
  142. },
  143. filterNode(value, data) {
  144. if (!value) return true
  145. return data.name.indexOf(value) !== -1
  146. },
  147. // 选择部门
  148. handleNodeClick(data) {
  149. if (data.level === 3) {
  150. serviceCategoryDetail({ categoryId: data.categoryId }).then(res => {
  151. this.item = res.data
  152. })
  153. } else {
  154. this.$refs.listTree.setCurrentKey(this.item?.categoryId || '')
  155. }
  156. },
  157. exportList(...p) {
  158. return [tradePageExport, tradePageOtherExport][
  159. this.typeAttribute[this.item.typeAttribute]
  160. ](...p)
  161. },
  162. // 列表请求函数
  163. getListRight(p, cb) {
  164. p.params.push({ param: 'service_category_id', compare: '=', value: this.item.categoryId })
  165. cb && cb(p)
  166. return [tradeListPage, tradeListOtherPage][
  167. this.typeAttribute[this.item.typeAttribute]
  168. ](p)
  169. },
  170. recordsHook(list) {
  171. return [
  172. {
  173. "dictName": "",
  174. "price": 0,
  175. "companyName": JSON.parse(localStorage.getItem('greemall_user')).companyName,
  176. "categoryName": this.item?.name || '',
  177. "serviceCategoryId": this.item?.categoryId || '',
  178. "status": 'ON',
  179. "typeAttribute": this.item?.typeAttribute,
  180. "remark": "",
  181. isRowEdit: true
  182. },
  183. ...list.map(item => ({ ...item, isRowEdit: false }))
  184. ]
  185. },
  186. // 表格列解析渲染数据更改
  187. columnParsing(item, defaultData) {
  188. if (item.jname === 'dictName') {
  189. defaultData.render = (h, { row, index, column }) => {
  190. if (row.isRowEdit) {
  191. return (
  192. <div class="redbordererr">
  193. <el-input
  194. value={row[column.columnAttributes.prop]}
  195. onInput={val => {
  196. row[column.columnAttributes.prop] = val
  197. }}
  198. placeholder="请输入内容"
  199. ></el-input>
  200. </div>
  201. )
  202. } else {
  203. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  204. }
  205. }
  206. }
  207. if (item.jname === 'remark') {
  208. defaultData.render = (h, { row, index, column }) => {
  209. if (row.isRowEdit) {
  210. return (
  211. <div class="redbordererr">
  212. <el-input
  213. value={row[column.columnAttributes.prop]}
  214. onInput={val => {
  215. row[column.columnAttributes.prop] = val
  216. }}
  217. placeholder="请输入内容"
  218. ></el-input>
  219. </div>
  220. )
  221. } else {
  222. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  223. }
  224. }
  225. }
  226. if (item.jname === 'status') {
  227. defaultData.render = (h, { row, index, column }) => {
  228. if (row.isRowEdit) {
  229. return (
  230. <div class="redbordererr">
  231. <el-select
  232. value={row[column.columnAttributes.prop]}
  233. onInput={val => {
  234. row[column.columnAttributes.prop] = val
  235. }}
  236. placeholder="请选择"
  237. >
  238. {[
  239. { label: '有效', value: 'ON' },
  240. { label: '无效', value: 'OFF' }
  241. ].map((item, index_) => (
  242. <el-option key={index_} label={item.label} value={item.value}></el-option>
  243. ))}
  244. </el-select>
  245. </div>
  246. )
  247. } else {
  248. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  249. }
  250. }
  251. }
  252. if (item.jname === 'price') {
  253. defaultData.render = (h, { row, index, column }) => {
  254. if (row.isRowEdit) {
  255. return (
  256. <div class="redbordererr">
  257. <el-input
  258. value={row[column.columnAttributes.prop]}
  259. onInput={val => {
  260. row[column.columnAttributes.prop] = val
  261. }}
  262. placeholder="请输入内容"
  263. type="number"
  264. ></el-input>
  265. </div>
  266. )
  267. } else {
  268. return (
  269. <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  270. )
  271. }
  272. }
  273. }
  274. return defaultData
  275. },
  276. operation() {
  277. return (h, { row, index, column }) => {
  278. return (
  279. <div class="operation-btns">
  280. {index === 0 || row.isRowEdit ? (
  281. <zj-button
  282. useLoading={false}
  283. parameter={[row]}
  284. buttonAttributes={{
  285. size: 'mini',
  286. type: 'primary'
  287. }}
  288. buttonEvents={{
  289. click: row => {
  290. if (this.jiaoyan(row)) {
  291. ;[serviceCategoryItemAdd, serviceCategoryItemUpdate]
  292. [row.id ? 1 : 0]({
  293. ...row,
  294. status: row.status == '有效' ? 'ON' : row.status == '无效' ? 'OFF' : row.status
  295. })
  296. .then(res => {
  297. this.$message({
  298. type: 'success',
  299. message: `保存成功!`
  300. })
  301. this.$refs.pageRef.refreshList()
  302. })
  303. }
  304. }
  305. }}
  306. >
  307. 保存
  308. </zj-button>
  309. ) : null}
  310. {!row.isRowEdit ? (
  311. <zj-button
  312. useLoading={false}
  313. parameter={[row]}
  314. buttonAttributes={{
  315. size: 'mini',
  316. type: 'primary'
  317. }}
  318. buttonEvents={{
  319. click: row => {
  320. row.isRowEdit = true
  321. }
  322. }}
  323. >
  324. 编辑
  325. </zj-button>
  326. ) : null}
  327. {index !== 0 ? (
  328. <el-popconfirm
  329. icon="el-icon-info"
  330. icon-color="red"
  331. title="这是一段内容确定删除吗?"
  332. onConfirm={() => {
  333. serviceCategoryItemDel({
  334. categoryId: row.id
  335. }).then(res => {
  336. this.$message({
  337. type: 'success',
  338. message: `删除成功!`
  339. })
  340. this.$refs.pageRef.refreshList()
  341. })
  342. }}
  343. >
  344. <zj-button
  345. slot="reference"
  346. buttonAttributes={{
  347. size: 'mini',
  348. type: 'danger'
  349. }}
  350. >
  351. 删除
  352. </zj-button>
  353. </el-popconfirm>
  354. ) : null}
  355. </div>
  356. )
  357. }
  358. },
  359. jiaoyan(row) {
  360. try {
  361. ;['dictName', 'price'].map(key => {
  362. if (row[key] === undefined || row[key] === null || row[key] === '') {
  363. throw new Error(
  364. {
  365. dictName: '字典值',
  366. price: ["回收价格(元/台)", "增减费用(元/台)"][this.typeAttribute[this.item.typeAttribute]],
  367. }[key]
  368. )
  369. }
  370. })
  371. return true
  372. } catch (err) {
  373. this.$message({
  374. type: 'error',
  375. message: `缺少参数【${err.message}】!`
  376. })
  377. return false
  378. }
  379. }
  380. }
  381. }
  382. </script>
  383. <style lang="scss" scoped>
  384. .catalogue {
  385. width: 300px;
  386. height: 100%;
  387. box-sizing: border-box;
  388. padding: 20px;
  389. overflow-y: auto;
  390. overflow-x: hidden;
  391. }
  392. .custom-tree-node {
  393. flex: 1;
  394. display: flex;
  395. align-items: center;
  396. justify-content: space-between;
  397. font-size: 14px;
  398. padding-right: 8px;
  399. }
  400. </style>