index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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 v-if="$restrict('add')" 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 && $restrict('add')" @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 && $restrict('edit')" @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 && $restrict('edit')" @click="addOrEditChild('edit', scope.row.categoryId)"></el-button>
  40. <el-popconfirm v-if="$restrict('del')" style="margin-left: 10px;" title="确定删除吗?" @confirm="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="main">
  100. <el-select v-model="addChildForm.main" value-key="categoryId" placeholder="请选择工单大类" style="width: 250px;" @change="changeOrderType">
  101. <el-option :label="item.name" :value="item" v-for="(item, index) in orderMainType" :key="index">
  102. <!-- <span style="color: #8492a6">{{ item.number }}</span>
  103. <span style="margin-left: 10px;">{{ item.name }}</span> -->
  104. </el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item label="工单小类" prop="smallType">
  108. <el-select v-model="addChildForm.small" value-key="categoryId" placeholder="请选择工单小类" style="width: 250px;" :disabled="!addChildForm.main.name">
  109. <el-option :label="item.name" :value="item" v-for="(item, index) in orderSmallType" :key="index">
  110. <!-- <span style="color: #8492a6">{{ item.id }}</span>
  111. <span style="margin-left: 10px;">{{ item.name }}</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, getSmallType } from '@/api/goods'
  160. import { ORDER_MAIN_TYPE } from "@/utils/select_data";
  161. import { getMainList } from "@/api/workOrder/settlementStandardInstall";
  162. export default {
  163. data() {
  164. return {
  165. baseURL: process.env.VUE_APP_BASE_API,
  166. myHeaders: {'x-token': getToken()},
  167. dataList: [], // 列表数据
  168. listLoading: true, // 列表加载loading
  169. screenForm: { // 筛选表单数据
  170. keyword: '', // 关键词
  171. },
  172. editParentId: null,
  173. addParentFormType: 'add',
  174. addParentFormVisible: false,
  175. addParentForm: {
  176. oneClassify: '',
  177. twoClassify: '',
  178. imgUrl: '',
  179. taxNumber: '',
  180. taxPercent: '',
  181. status: true,
  182. sort: 0,
  183. },
  184. addParentFormRules: {
  185. oneClassify: [
  186. { required: true, message: '请填写一级分类名称', trigger: 'blur' },
  187. ],
  188. imgUrl: [
  189. { required: true, message: '请上传分类图片', trigger: 'change' }
  190. ]
  191. },
  192. editChildId: null,
  193. addChildFormType: 'add',
  194. addChildFormVisible: false,
  195. addChildForm: {
  196. oneClassify: '',
  197. twoClassify: '',
  198. main: {},
  199. small: {},
  200. workOrderType: 'REPAIR',
  201. imgUrl: '',
  202. taxNumber: '',
  203. taxPercent: '',
  204. status: true,
  205. sort: 0,
  206. },
  207. addChildFormRules: {
  208. oneClassify: [
  209. { required: true, message: '请选择一级分类', trigger: 'change' }
  210. ],
  211. twoClassify: [
  212. { required: true, message: '请填写二级分类', trigger: 'blur' }
  213. ],
  214. workOrderType: [
  215. { required: true, message: '请选择工单类型', trigger: 'change' }
  216. ],
  217. imgUrl: [
  218. { required: true, message: '请上传分类图片', trigger: 'change' }
  219. ],
  220. },
  221. classifyList: [],
  222. // orderMainType: ORDER_MAIN_TYPE,
  223. orderMainType: [],
  224. orderSmallType: [],
  225. }
  226. },
  227. created() {
  228. this.getList();
  229. this.getMainList()
  230. },
  231. methods: {
  232. getList() {
  233. this.listLoading = true;
  234. let params = {
  235. name: this.screenForm.keyword,
  236. };
  237. getClassifyList(params).then(res => {
  238. this.dataList = res.data;
  239. })
  240. },
  241. getMainList(){
  242. getMainList({type: 2}).then(res => {
  243. this.orderMainType = res.data
  244. })
  245. },
  246. // 筛选后重新获取列表
  247. getListByScreen() {
  248. this.currentPage = 1;
  249. this.getList();
  250. },
  251. // 打开 新增编辑 一级分类
  252. addOrEditParent(type, cid) {
  253. this.addParentFormType = type;
  254. this.addParentFormVisible = true;
  255. if(type == 'edit') {
  256. this.editParentId = cid;
  257. getClassifyDetail({categoryId: cid}).then(res => {
  258. this.addParentForm = {
  259. oneClassify: res.data.name,
  260. status: res.data.status,
  261. imgUrl: res.data.imgUrl,
  262. taxNumber: res.data.taxNumber,
  263. taxPercent: res.data.taxPercent,
  264. sort: res.data.sortNum
  265. }
  266. })
  267. }
  268. },
  269. // 取消 新增编辑 一级分类
  270. cancelAddParentForm(){
  271. this.addParentFormVisible = false;
  272. this.$refs.addParentForm.resetFields();
  273. },
  274. // 提交 一级分类
  275. submitAddParentForm() {
  276. this.$refs.addParentForm.validate((valid) => {
  277. if (valid) {
  278. let params = {
  279. name: this.addParentForm.oneClassify,
  280. imgUrl: this.addParentForm.imgUrl,
  281. taxNumber: this.addParentForm.taxNumber,
  282. taxPercent: this.addParentForm.taxPercent,
  283. status: this.addParentForm.status,
  284. sortNum: this.addParentForm.sort,
  285. }
  286. if(this.addParentFormType == 'edit') {
  287. params.categoryId = this.editParentId;
  288. editClassify(params).then(res => {
  289. this.cancelAddParentForm();
  290. this.getList();
  291. this.$successMsg('编辑成功');
  292. })
  293. }else {
  294. addClassify(params).then(res => {
  295. this.cancelAddParentForm();
  296. this.getList();
  297. this.$successMsg('添加成功');
  298. })
  299. }
  300. }
  301. })
  302. },
  303. // 改变大类
  304. changeOrderType(e) {
  305. this.orderSmallType = e.children
  306. this.addChildForm.small = {};
  307. // this.getSmallType();
  308. },
  309. getSmallType() {
  310. getSmallType({
  311. mainNumber: this.addChildForm.orderType,
  312. categoryId: this.addChildForm.oneClassify
  313. }).then(res => {
  314. this.orderSmallType = res.data;
  315. })
  316. },
  317. // 打开 新增编辑 二级分类
  318. addOrEditChild(type, cid) {
  319. this.getMainList()
  320. this.addChildFormType = type;
  321. this.addChildFormVisible = true;
  322. getClassifyList({name: ''}).then(res => {
  323. this.classifyList = res.data;
  324. })
  325. if(type == 'add') {
  326. this.addChildForm.oneClassify = cid;
  327. let item = this.dataList[this.$findElem(this.dataList, 'categoryId', cid)];
  328. this.addChildForm.taxNumber = item.taxNumber;
  329. this.addChildForm.taxPercent = item.taxPercent;
  330. }
  331. if(type == 'edit') {
  332. this.editChildId = cid;
  333. getClassifyDetail({categoryId: cid}).then(res => {
  334. console.log(this.orderMainType,'获取大类')
  335. this.orderMainType.forEach(item =>{
  336. if(item.categoryId == res.data.mainNumber){
  337. this.orderSmallType = item.children
  338. }
  339. })
  340. this.addChildForm = {
  341. oneClassify: res.data.parentId,
  342. twoClassify: res.data.name,
  343. main: {name: res.data.mainName,categoryId: res.data.mainNumber},
  344. small: {name: res.data.smallName,categoryId: res.data.smallNumber},
  345. workOrderType: res.data.workOrderType,
  346. imgUrl: res.data.imgUrl,
  347. taxNumber: res.data.taxNumber,
  348. taxPercent: res.data.taxPercent,
  349. status: res.data.status,
  350. sort: res.data.sortNum
  351. }
  352. // this.getSmallType();
  353. })
  354. }
  355. },
  356. // 取消 新增编辑 二级分类
  357. cancelAddChildForm(){
  358. this.addChildFormVisible = false;
  359. this.$refs.addChildForm.resetFields();
  360. },
  361. // 提交 二级分类
  362. submitAddChildForm() {
  363. this.$refs.addChildForm.validate((valid) => {
  364. if (valid) {
  365. // let index = this.$findElem(ORDER_MAIN_TYPE, 'number', this.addChildForm.orderType);
  366. // let mainName = index >= 0 ? ORDER_MAIN_TYPE[index].name : '';
  367. // let index2 = this.$findElem(this.orderSmallType, 'id', this.addChildForm.smallType);
  368. // let smallName = index2 >= 0 ? this.orderSmallType[index2].name : '';
  369. let params = {}
  370. if(this.addChildFormType == 'edit') {
  371. params = {
  372. categoryId: this.editChildId,
  373. name: this.addChildForm.twoClassify,
  374. mainNumber: this.addChildForm.main.categoryId || '',
  375. mainName: this.addChildForm.main.name || '',
  376. smallNumber: this.addChildForm.small.categoryId || '',
  377. smallName: this.addChildForm.small.name,
  378. workOrderType: this.addChildForm.workOrderType,
  379. imgUrl: this.addChildForm.imgUrl,
  380. taxNumber: this.addChildForm.taxNumber,
  381. taxPercent: this.addChildForm.taxPercent,
  382. status: this.addChildForm.status,
  383. sortNum: this.addChildForm.sort
  384. }
  385. editClassify(params).then(res => {
  386. this.cancelAddChildForm();
  387. this.getList();
  388. this.$successMsg('编辑成功');
  389. })
  390. }else {
  391. params = {
  392. children: [{
  393. parentId: this.addChildForm.oneClassify,
  394. name: this.addChildForm.twoClassify,
  395. mainNumber: this.addChildForm.main.categoryId || '',
  396. mainName: this.addChildForm.main.name || '',
  397. smallNumber: this.addChildForm.small.categoryId || '',
  398. smallName: this.addChildForm.small.name,
  399. imgUrl: this.addChildForm.imgUrl,
  400. taxNumber: this.addChildForm.taxNumber,
  401. taxPercent: this.addChildForm.taxPercent,
  402. status: this.addChildForm.status,
  403. sortNum: this.addChildForm.sort
  404. }]
  405. }
  406. addClassify(params).then(res => {
  407. this.cancelAddChildForm();
  408. this.getList();
  409. this.$successMsg('添加成功');
  410. })
  411. }
  412. }
  413. })
  414. },
  415. // 操作 - 删除
  416. handleDelete(id) {
  417. deleteClassify({categoryId: id}).then(res => {
  418. this.getList();
  419. this.$successMsg();
  420. })
  421. },
  422. uploadSuccess(res, file, index) {
  423. if (this.addParentFormVisible) {
  424. this.addParentForm.imgUrl = res.data.url
  425. } else {
  426. this.addChildForm.imgUrl = res.data.url
  427. }
  428. },
  429. beforeUpload(file) {
  430. const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1);
  431. const whiteList = ['jpg', 'jpeg', 'png', 'gif'];
  432. if (whiteList.indexOf(fileSuffix) === -1) {
  433. this.$errorMsg('只支持上传jpg/jpeg/png/gif文件!');
  434. return false;
  435. }
  436. },
  437. }
  438. }
  439. </script>
  440. <style scoped lang="scss">
  441. </style>
  442. <style lang="scss">
  443. .el-image-viewer__wrapper .el-icon-circle-close {
  444. color: #ffffff !important;
  445. font-size: 60px;
  446. }
  447. .el-table__row.expanded {
  448. background: #f5f5f5;
  449. }
  450. th:first-child, th:last-child {
  451. text-align: center !important;
  452. }
  453. </style>