index.vue 20 KB

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