classify_index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div class="app-container">
  3. <div class="mymain-container">
  4. <div class="btn-group clearfix">
  5. <div class="fl">
  6. <el-button size="small" type="primary" icon="el-icon-plus" @click="addOrEditParent('add')">添加分类</el-button>
  7. </div>
  8. <div class="fr">
  9. <el-input placeholder="请输入分类名称进行搜索" v-model="screenForm.keyword" size="small" style="width: 240px;" clearable>
  10. <el-button slot="append" icon="el-icon-search" size="small" @click="getListByScreen"></el-button>
  11. </el-input>
  12. </div>
  13. </div>
  14. <div class="table">
  15. <el-table :data="dataList" row-key="categoryId" border default-expand-all :tree-props="{children: 'children'}">
  16. <el-table-column prop="name" label="分类名称" min-width="150"></el-table-column>
  17. <el-table-column align="center" label="分类图片" prop="imgUrl" width="80">
  18. <template slot-scope="scope">
  19. <el-image style="width: 40px; height: 40px; display: block; margin: 0 auto;" :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]" fit="cover">
  20. <div slot="error" style="height: 100%;font-size: 40px;">
  21. <i class="el-icon-picture-outline"></i>
  22. </div>
  23. </el-image>
  24. </template>
  25. </el-table-column>
  26. <el-table-column align="center" prop="createTime" label="创建时间" min-width="160"></el-table-column>
  27. <!-- <el-table-column align="center" prop="goodsNum" label="商品数"></el-table-column> -->
  28. <el-table-column align="center" prop="sortNum" label="排序"></el-table-column>
  29. <el-table-column align="center" prop="companyName" label="商户" min-width="120"></el-table-column>
  30. <el-table-column align="center" label="状态" class-name="status-col">
  31. <template slot-scope="scope">
  32. <el-tag :type="scope.row.status ? 'success':'danger'">{{ scope.row.status ? '显示':'隐藏' }}</el-tag>
  33. </template>
  34. </el-table-column>
  35. <el-table-column align="right" label="操作" width="150" fixed="right">
  36. <template slot-scope="scope">
  37. <el-button type="primary" size="mini" icon="el-icon-plus" v-if="scope.row.level == 1" @click="addOrEditChild('add', scope.row.categoryId)"></el-button>
  38. <el-button type="primary" size="mini" icon="el-icon-edit" v-if="scope.row.level == 1" @click="addOrEditParent('edit', scope.row.categoryId)"></el-button>
  39. <el-button type="primary" size="mini" icon="el-icon-edit" v-if="scope.row.level == 2" @click="addOrEditChild('edit', scope.row.categoryId)"></el-button>
  40. <el-popconfirm style="margin-left: 10px;" title="确定删除吗?" @onConfirm="handleDelete(scope.row.categoryId)" >
  41. <el-button slot="reference" size="mini" icon="el-icon-delete"></el-button>
  42. </el-popconfirm>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </div>
  47. </div>
  48. <!-- 新增编辑 一级分类 -->
  49. <el-dialog :title="addParentFormType == 'add' ? '添加一级分类':'编辑一级分类'" :visible.sync="addParentFormVisible" :show-close="false" width="40%" :close-on-click-modal="false">
  50. <el-form ref="addParentForm" :model="addParentForm" :rules="addParentFormRules" label-position="left" label-width="80px">
  51. <el-form-item label="一级分类" prop="oneClassify">
  52. <el-input type="text" placeholder="请输入一级分类名称" v-model="addParentForm.oneClassify" maxlength="10" show-word-limit style="width: 250px;"></el-input>
  53. </el-form-item>
  54. <el-form-item label="分类图片" prop="imgUrl">
  55. <el-upload
  56. class="avatar-uploader"
  57. style="height:122px"
  58. :action="baseURL + 'common/upload'"
  59. :headers="myHeaders"
  60. :show-file-list="false"
  61. :on-success="uploadSuccess"
  62. :before-upload="beforeUpload">
  63. <img v-if="addParentForm.imgUrl" :src="addParentForm.imgUrl" class="avatar">
  64. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  65. </el-upload>
  66. </el-form-item>
  67. <el-form-item label="税务编号" prop="taxNumber">
  68. <el-input placeholder="请输入税务编号" v-model="addParentForm.taxNumber" style="width: 250px;"></el-input>
  69. </el-form-item>
  70. <el-form-item label="税率" prop="taxPercent">
  71. <el-input placeholder="请输入税率" v-model="addParentForm.taxPercent" style="width: 250px;"></el-input>
  72. </el-form-item>
  73. <el-form-item label="状态" prop="status">
  74. <el-radio-group v-model="addParentForm.status">
  75. <el-radio :label="true">显示</el-radio>
  76. <el-radio :label="false">隐藏</el-radio>
  77. </el-radio-group>
  78. </el-form-item>
  79. <el-form-item label="排序" prop="sort">
  80. <el-input placeholder="请输入排序" v-model.number="addParentForm.sort" style="width: 250px;"></el-input>
  81. </el-form-item>
  82. </el-form>
  83. <div slot="footer" class="dialog-footer">
  84. <el-button @click="cancelAddParentForm">取 消</el-button>
  85. <el-button type="primary" @click="submitAddParentForm">确 定</el-button>
  86. </div>
  87. </el-dialog>
  88. <!-- 新增编辑 二级分类 -->
  89. <el-dialog :title="addChildFormType == 'add' ? '添加二级分类':'编辑二级分类'" :visible.sync="addChildFormVisible" :show-close="false" width="40%" :close-on-click-modal="false">
  90. <el-form ref="addChildForm" :model="addChildForm" :rules="addChildFormRules" label-position="left" label-width="80px">
  91. <el-form-item label="一级分类" prop="oneClassify">
  92. <el-select v-model="addChildForm.oneClassify" placeholder="请选择一级分类" disabled style="width: 250px;">
  93. <el-option :label="item.name" :value="item.categoryId" v-for="(item, index) in classifyList" :key="index"></el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-form-item label="二级分类" prop="twoClassify">
  97. <el-input type="text" placeholder="请输入二级分类名称" v-model="addChildForm.twoClassify" maxlength="10" show-word-limit style="width: 250px;"></el-input>
  98. </el-form-item>
  99. <el-form-item label="工单大类" prop="orderType">
  100. <el-select v-model="addChildForm.orderType" placeholder="请选择工单大类" style="width: 250px;" @change="changeOrderType()">
  101. <el-option :label="item.dictValue" :value="item.dictCode" v-for="(item, index) in orderMainType" :key="index">
  102. <span style="color: #8492a6">{{ item.dictCode }}</span>
  103. <span style="margin-left: 10px;">{{ item.dictValue }}</span>
  104. </el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item label="工单小类" prop="smallType">
  108. <el-select v-model="addChildForm.smallType" placeholder="请选择工单小类" style="width: 250px;" :disabled="!addChildForm.orderType">
  109. <el-option :label="item.dictValue" :value="item.dictCode" v-for="(item, index) in orderSmallType" :key="index">
  110. <span style="color: #8492a6">{{ item.dictCode }}</span>
  111. <span style="margin-left: 10px;">{{ item.dictValue }}</span>
  112. </el-option>
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item label="工单类型" prop="workOrderType">
  116. <el-radio-group v-model="addChildForm.workOrderType">
  117. <el-radio :label="'INSTALL'">安装</el-radio>
  118. <el-radio :label="'REPAIR'">维修</el-radio>
  119. </el-radio-group>
  120. </el-form-item>
  121. <el-form-item label="分类图片" prop="imgUrl">
  122. <el-upload
  123. class="avatar-uploader"
  124. style="height:122px"
  125. :action="baseURL + 'common/upload'"
  126. :headers="myHeaders"
  127. :show-file-list="false"
  128. :on-success="uploadSuccess"
  129. :before-upload="beforeUpload">
  130. <img v-if="addChildForm.imgUrl" :src="addChildForm.imgUrl" class="avatar">
  131. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  132. </el-upload>
  133. </el-form-item>
  134. <el-form-item label="税务编号" prop="taxNumber">
  135. <el-input placeholder="请输入税务编号" v-model="addChildForm.taxNumber" style="width: 250px;" disabled></el-input>
  136. </el-form-item>
  137. <el-form-item label="税率" prop="taxPercent">
  138. <el-input placeholder="请输入税率" v-model="addChildForm.taxPercent" style="width: 250px;" disabled></el-input>
  139. </el-form-item>
  140. <el-form-item label="状态" prop="status">
  141. <el-radio-group v-model="addChildForm.status">
  142. <el-radio :label="true">显示</el-radio>
  143. <el-radio :label="false">隐藏</el-radio>
  144. </el-radio-group>
  145. </el-form-item>
  146. <el-form-item label="排序" prop="sort">
  147. <el-input placeholder="请输入排序" v-model.number="addChildForm.sort" style="width: 250px;"></el-input>
  148. </el-form-item>
  149. </el-form>
  150. <div slot="footer" class="dialog-footer">
  151. <el-button @click="cancelAddChildForm">取 消</el-button>
  152. <el-button type="primary" @click="submitAddChildForm">确 定</el-button>
  153. </div>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script>
  158. import { getToken } from '@/utils/auth'
  159. import { getClassifyList, addClassify, editClassify, deleteClassify, getClassifyDetail } from '@/api/goods'
  160. import { getWorkerDictList } from '@/api/common'
  161. export default {
  162. data() {
  163. return {
  164. baseURL: process.env.VUE_APP_BASE_API,
  165. myHeaders: {'x-token': getToken()},
  166. dataList: [], // 列表数据
  167. listLoading: true, // 列表加载loading
  168. screenForm: { // 筛选表单数据
  169. keyword: '', // 关键词
  170. },
  171. editParentId: null,
  172. addParentFormType: 'add',
  173. addParentFormVisible: false,
  174. addParentForm: {
  175. oneClassify: '',
  176. twoClassify: '',
  177. imgUrl: '',
  178. taxNumber: '',
  179. taxPercent: '',
  180. status: true,
  181. sort: 0,
  182. },
  183. addParentFormRules: {
  184. oneClassify: [
  185. { required: true, message: '请填写一级分类名称', trigger: 'blur' },
  186. ],
  187. imgUrl: [
  188. { required: true, message: '请上传分类图片', trigger: 'change' }
  189. ]
  190. },
  191. editChildId: null,
  192. addChildFormType: 'add',
  193. addChildFormVisible: false,
  194. addChildForm: {
  195. oneClassify: '',
  196. twoClassify: '',
  197. orderType: '',
  198. smallType: '',
  199. workOrderType: 'REPAIR',
  200. imgUrl: '',
  201. taxNumber: '',
  202. taxPercent: '',
  203. status: true,
  204. sort: 0,
  205. },
  206. addChildFormRules: {
  207. oneClassify: [
  208. { required: true, message: '请选择一级分类', trigger: 'change' }
  209. ],
  210. twoClassify: [
  211. { required: true, message: '请填写二级分类', trigger: 'blur' }
  212. ],
  213. workOrderType: [
  214. { required: true, message: '请选择工单类型', trigger: 'change' }
  215. ],
  216. imgUrl: [
  217. { required: true, message: '请上传分类图片', trigger: 'change' }
  218. ],
  219. },
  220. classifyList: [],
  221. orderMainType: [],
  222. orderSmallType: [],
  223. }
  224. },
  225. created() {
  226. this.getList();
  227. },
  228. methods: {
  229. getList() {
  230. this.listLoading = true;
  231. let params = {
  232. name: this.screenForm.keyword,
  233. };
  234. getClassifyList(params).then(res => {
  235. this.dataList = res.data;
  236. })
  237. },
  238. // 筛选后重新获取列表
  239. getListByScreen() {
  240. this.currentPage = 1;
  241. this.getList();
  242. },
  243. // 打开 新增编辑 一级分类
  244. addOrEditParent(type, cid) {
  245. this.addParentFormType = type;
  246. this.addParentFormVisible = true;
  247. if(type == 'edit') {
  248. this.editParentId = cid;
  249. getClassifyDetail({categoryId: cid}).then(res => {
  250. this.addParentForm = {
  251. oneClassify: res.data.name,
  252. status: res.data.status,
  253. imgUrl: res.data.imgUrl,
  254. taxNumber: res.data.taxNumber,
  255. taxPercent: res.data.taxPercent,
  256. sort: res.data.sortNum
  257. }
  258. })
  259. }
  260. },
  261. // 取消 新增编辑 一级分类
  262. cancelAddParentForm(){
  263. this.addParentFormVisible = false;
  264. this.$refs.addParentForm.resetFields();
  265. },
  266. // 提交 一级分类
  267. submitAddParentForm() {
  268. this.$refs.addParentForm.validate((valid) => {
  269. if (valid) {
  270. let params = {
  271. name: this.addParentForm.oneClassify,
  272. imgUrl: this.addParentForm.imgUrl,
  273. taxNumber: this.addParentForm.taxNumber,
  274. taxPercent: this.addParentForm.taxPercent,
  275. status: this.addParentForm.status,
  276. sortNum: this.addParentForm.sort,
  277. }
  278. if(this.addParentFormType == 'edit') {
  279. params.categoryId = this.editParentId;
  280. editClassify(params).then(res => {
  281. this.cancelAddParentForm();
  282. this.getList();
  283. this.$successMsg('编辑成功');
  284. })
  285. }else {
  286. addClassify(params).then(res => {
  287. this.cancelAddParentForm();
  288. this.getList();
  289. this.$successMsg('添加成功');
  290. })
  291. }
  292. }
  293. })
  294. },
  295. // 改变大类
  296. changeOrderType() {
  297. this.addChildForm.smallType = '';
  298. this.getSmallType();
  299. },
  300. getMainType() {
  301. getWorkerDictList({
  302. dictType: 'MAIN_TYPE',
  303. }).then(res => {
  304. this.orderMainType = res.data;
  305. })
  306. },
  307. getSmallType() {
  308. getWorkerDictList({
  309. dictType: 'SMALL_TYPE',
  310. parentDictType: 'MAIN_TYPE',
  311. parentDictCode: this.addChildForm.orderType,
  312. }).then(res => {
  313. this.orderSmallType = res.data;
  314. })
  315. },
  316. // 打开 新增编辑 二级分类
  317. addOrEditChild(type, cid) {
  318. this.addChildFormType = type;
  319. this.addChildFormVisible = true;
  320. getClassifyList({name: ''}).then(res => {
  321. this.classifyList = res.data;
  322. })
  323. this.getMainType();
  324. if(type == 'add') {
  325. this.addChildForm.oneClassify = cid;
  326. let item = this.dataList.find(item => item.categoryId == cid);
  327. this.addChildForm.taxNumber = item.taxNumber;
  328. this.addChildForm.taxPercent = item.taxPercent;
  329. }
  330. if(type == 'edit') {
  331. this.editChildId = cid;
  332. getClassifyDetail({categoryId: cid}).then(res => {
  333. this.addChildForm = {
  334. oneClassify: res.data.parentId,
  335. twoClassify: res.data.name,
  336. orderType: res.data.mainNumber,
  337. smallType: res.data.smallNumber,
  338. workOrderType: res.data.workOrderType,
  339. imgUrl: res.data.imgUrl,
  340. taxNumber: res.data.taxNumber,
  341. taxPercent: res.data.taxPercent,
  342. status: res.data.status,
  343. sort: res.data.sortNum
  344. }
  345. this.getSmallType();
  346. })
  347. }
  348. },
  349. // 取消 新增编辑 二级分类
  350. cancelAddChildForm(){
  351. this.addChildFormVisible = false;
  352. this.$refs.addChildForm.resetFields();
  353. },
  354. // 提交 二级分类
  355. submitAddChildForm() {
  356. this.$refs.addChildForm.validate((valid) => {
  357. if (valid) {
  358. let params = {}
  359. if(this.addChildFormType == 'edit') {
  360. params = {
  361. categoryId: this.editChildId,
  362. name: this.addChildForm.twoClassify,
  363. mainNumber: this.addChildForm.orderType || '',
  364. mainName: this.addChildForm.orderType ? this.orderMainType.find(item => item.dictCode == this.addChildForm.orderType).dictValue : '',
  365. smallNumber: this.addChildForm.smallType || '',
  366. smallName: this.addChildForm.smallType ? this.orderSmallType.find(item => item.dictCode == this.addChildForm.smallType).dictValue : '',
  367. workOrderType: this.addChildForm.workOrderType,
  368. imgUrl: this.addChildForm.imgUrl,
  369. taxNumber: this.addChildForm.taxNumber,
  370. taxPercent: this.addChildForm.taxPercent,
  371. status: this.addChildForm.status,
  372. sortNum: this.addChildForm.sort
  373. }
  374. editClassify(params).then(res => {
  375. this.cancelAddChildForm();
  376. this.getList();
  377. this.$successMsg('编辑成功');
  378. })
  379. }else {
  380. params = {
  381. children: [{
  382. parentId: this.addChildForm.oneClassify,
  383. name: this.addChildForm.twoClassify,
  384. mainNumber: this.addChildForm.orderType || '',
  385. mainName: this.addChildForm.orderType ? this.orderMainType.find(item => item.dictCode == this.addChildForm.orderType).dictValue : '',
  386. imgUrl: this.addChildForm.imgUrl,
  387. taxNumber: this.addChildForm.taxNumber,
  388. taxPercent: this.addChildForm.taxPercent,
  389. status: this.addChildForm.status,
  390. sortNum: this.addChildForm.sort
  391. }]
  392. }
  393. addClassify(params).then(res => {
  394. this.cancelAddChildForm();
  395. this.getList();
  396. this.$successMsg('添加成功');
  397. })
  398. }
  399. }
  400. })
  401. },
  402. // 操作 - 删除
  403. handleDelete(id) {
  404. deleteClassify({categoryId: id}).then(res => {
  405. this.getList();
  406. this.$successMsg();
  407. })
  408. },
  409. uploadSuccess(res, file, index) {
  410. if (this.addParentFormVisible) {
  411. this.addParentForm.imgUrl = res.data.url
  412. } else {
  413. this.addChildForm.imgUrl = res.data.url
  414. }
  415. },
  416. beforeUpload(file) {
  417. const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1);
  418. const whiteList = ['jpg', 'jpeg', 'png'];
  419. if (whiteList.indexOf(fileSuffix) === -1) {
  420. this.$errorMsg('只支持上传jpg/png文件!');
  421. return false;
  422. }
  423. },
  424. }
  425. }
  426. </script>
  427. <style scoped lang="scss">
  428. </style>
  429. <style lang="scss">
  430. .el-image-viewer__wrapper .el-icon-circle-close {
  431. color: #ffffff !important;
  432. font-size: 60px;
  433. }
  434. .el-table__row.expanded {
  435. background: #f5f5f5;
  436. }
  437. th:first-child, th:last-child {
  438. text-align: center !important;
  439. }
  440. </style>