categoryAllocation.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. "maxPrice":"",
  182. "minPrice":"",
  183. isRowEdit: true
  184. },
  185. ...list.map(item => ({ ...item, isRowEdit: false }))
  186. ]
  187. },
  188. // 表格列解析渲染数据更改
  189. columnParsing(item, defaultData) {
  190. if (item.jname === 'dictName') {
  191. defaultData.render = (h, { row, index, column }) => {
  192. if (row.isRowEdit) {
  193. return (
  194. <div class="redbordererr">
  195. <el-input
  196. value={row[column.columnAttributes.prop]}
  197. onInput={val => {
  198. row[column.columnAttributes.prop] = val
  199. }}
  200. placeholder="请输入内容"
  201. ></el-input>
  202. </div>
  203. )
  204. } else {
  205. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  206. }
  207. }
  208. }
  209. if (item.jname === 'remark') {
  210. defaultData.render = (h, { row, index, column }) => {
  211. if (row.isRowEdit) {
  212. return (
  213. <div class="redbordererr">
  214. <el-input
  215. value={row[column.columnAttributes.prop]}
  216. onInput={val => {
  217. row[column.columnAttributes.prop] = val
  218. }}
  219. placeholder="请输入内容"
  220. ></el-input>
  221. </div>
  222. )
  223. } else {
  224. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  225. }
  226. }
  227. }
  228. if (item.jname === 'status') {
  229. defaultData.render = (h, { row, index, column }) => {
  230. if (row.isRowEdit) {
  231. return (
  232. <div class="redbordererr">
  233. <el-select
  234. value={row[column.columnAttributes.prop]}
  235. onInput={val => {
  236. row[column.columnAttributes.prop] = val
  237. }}
  238. placeholder="请选择"
  239. >
  240. {[
  241. { label: '有效', value: 'ON' },
  242. { label: '无效', value: 'OFF' }
  243. ].map((item, index_) => (
  244. <el-option key={index_} label={item.label} value={item.value}></el-option>
  245. ))}
  246. </el-select>
  247. </div>
  248. )
  249. } else {
  250. return <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  251. }
  252. }
  253. }
  254. if (item.jname === 'price') {
  255. defaultData.render = (h, { row, index, column }) => {
  256. if (row.isRowEdit) {
  257. return (
  258. <div class="redbordererr">
  259. <el-input
  260. value={row[column.columnAttributes.prop]}
  261. onInput={val => {
  262. row[column.columnAttributes.prop] = val
  263. }}
  264. placeholder="请输入内容"
  265. type="number"
  266. ></el-input>
  267. </div>
  268. )
  269. } else {
  270. return (
  271. <div style="padding:0 6px;">{row[column.columnAttributes.prop]}</div>
  272. )
  273. }
  274. }
  275. }
  276. return defaultData
  277. },
  278. operation() {
  279. return (h, { row, index, column }) => {
  280. return (
  281. <div class="operation-btns">
  282. {index === 0 || row.isRowEdit ? (
  283. <zj-button
  284. useLoading={false}
  285. parameter={[row]}
  286. buttonAttributes={{
  287. size: 'mini',
  288. type: 'primary'
  289. }}
  290. buttonEvents={{
  291. click: row => {
  292. if (this.jiaoyan(row)) {
  293. ;[serviceCategoryItemAdd, serviceCategoryItemUpdate]
  294. [row.id ? 1 : 0]({
  295. ...row,
  296. status: row.status == '有效' ? 'ON' : row.status == '无效' ? 'OFF' : row.status
  297. })
  298. .then(res => {
  299. this.$message({
  300. type: 'success',
  301. message: `保存成功!`
  302. })
  303. this.$refs.pageRef.refreshList()
  304. })
  305. }
  306. }
  307. }}
  308. >
  309. 保存
  310. </zj-button>
  311. ) : null}
  312. {!row.isRowEdit ? (
  313. <zj-button
  314. useLoading={false}
  315. parameter={[row]}
  316. buttonAttributes={{
  317. size: 'mini',
  318. type: 'primary'
  319. }}
  320. buttonEvents={{
  321. click: row => {
  322. row.isRowEdit = true
  323. }
  324. }}
  325. >
  326. 编辑
  327. </zj-button>
  328. ) : null}
  329. {index !== 0 ? (
  330. <el-popconfirm
  331. icon="el-icon-info"
  332. icon-color="red"
  333. title="这是一段内容确定删除吗?"
  334. onConfirm={() => {
  335. serviceCategoryItemDel({
  336. categoryId: row.id
  337. }).then(res => {
  338. this.$message({
  339. type: 'success',
  340. message: `删除成功!`
  341. })
  342. this.$refs.pageRef.refreshList()
  343. })
  344. }}
  345. >
  346. <zj-button
  347. slot="reference"
  348. buttonAttributes={{
  349. size: 'mini',
  350. type: 'danger'
  351. }}
  352. >
  353. 删除
  354. </zj-button>
  355. </el-popconfirm>
  356. ) : null}
  357. </div>
  358. )
  359. }
  360. },
  361. jiaoyan(row) {
  362. try {
  363. ;['dictName', 'price'].map(key => {
  364. if (row[key] === undefined || row[key] === null || row[key] === '') {
  365. throw new Error(
  366. {
  367. dictName: '字典值',
  368. price: ["回收价格(元/台)", "增减费用(元/台)"][this.typeAttribute[this.item.typeAttribute]],
  369. }[key]
  370. )
  371. }
  372. })
  373. return true
  374. } catch (err) {
  375. this.$message({
  376. type: 'error',
  377. message: `缺少参数【${err.message}】!`
  378. })
  379. return false
  380. }
  381. }
  382. }
  383. }
  384. </script>
  385. <style lang="scss" scoped>
  386. .catalogue {
  387. width: 300px;
  388. height: 100%;
  389. box-sizing: border-box;
  390. padding: 20px;
  391. overflow-y: auto;
  392. overflow-x: hidden;
  393. }
  394. .custom-tree-node {
  395. flex: 1;
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. font-size: 14px;
  400. padding-right: 8px;
  401. }
  402. </style>