product.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <div class="app-container">
  3. <el-card class="fiche">
  4. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList">收起</right-toolbar>
  5. <span style="margin-bottom: 10px;color:#333333;font:14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial,sans-serif">所选条件:</span>
  6. <div style="float: right;margin-right:1%">
  7. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  8. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" style="float: ;">重置</el-button>
  9. </div>
  10. <hr style="margin-top: 16px;">
  11. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  12. <el-form-item label="菜单名称" prop="spiProducName">
  13. <el-input
  14. v-model="queryParams.spiProducName"
  15. placeholder="请输入菜单名称"
  16. clearable
  17. size="small"
  18. @keyup.enter.native="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item label="菜单描述" prop="spiProducDescribe">
  22. <el-input
  23. v-model="queryParams.spiProducDescribe"
  24. placeholder="请输入菜单描述"
  25. clearable
  26. size="small"
  27. @keyup.enter.native="handleQuery"
  28. />
  29. </el-form-item>
  30. <!-- <el-form-item label="状态" prop="spiState">
  31. <el-select
  32. v-model="queryParams.spiState"
  33. placeholder="菜单状态"
  34. clearable
  35. size="small"
  36. style="width: 240px"
  37. >
  38. <el-option
  39. v-for="dict in spiStateOptions"
  40. :key="dict.dictValue"
  41. :label="dict.dictLabel"
  42. :value="dict.dictValue"
  43. />
  44. </el-select>
  45. </el-form-item> -->
  46. <!-- <el-form-item>
  47. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  48. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  49. </el-form-item> -->
  50. </el-form>
  51. </el-card>
  52. <el-row :gutter="10" class="mb8">
  53. <el-col :span="1.5">
  54. <el-button
  55. type="primary"
  56. icon="el-icon-plus"
  57. size="mini"
  58. @click="handleAdd"
  59. v-hasPermi="['system:product:add']"
  60. >新增</el-button>
  61. </el-col>
  62. <!-- <el-col :span="1.5">
  63. <el-button
  64. type="success"
  65. icon="el-icon-edit"
  66. size="mini"
  67. :disabled="single"
  68. @click="handleUpdate"
  69. v-hasPermi="['system:product:edit']"
  70. >修改</el-button>
  71. </el-col> -->
  72. <!-- <el-col :span="1.5">
  73. <el-button
  74. type="danger"
  75. icon="el-icon-delete"
  76. size="mini"
  77. :disabled="multiple"
  78. @click="handleDelete"
  79. v-hasPermi="['system:product:remove']"
  80. >删除</el-button>
  81. </el-col> -->
  82. <!-- <el-col :span="1.5">
  83. <el-button
  84. type="warning"
  85. icon="el-icon-download"
  86. size="mini"
  87. @click="handleExport"
  88. v-hasPermi="['system:product:export']"
  89. >导出</el-button>
  90. </el-col> -->
  91. <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
  92. </el-row>
  93. <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange" stripe border>
  94. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  95. <el-table-column label="序号" type="index" width="55" align="center" />
  96. <el-table-column label="菜单名称" align="center" prop="spiProducName" />
  97. <el-table-column label="菜单描述" align="center" prop="spiProducDescribe" :show-overflow-tooltip="true"/>
  98. <!-- <el-table-column label="状态" align="center" width="100">
  99. <template slot-scope="scope">
  100. <el-switch
  101. v-model="scope.row.spiState"
  102. active-value="00"
  103. inactive-value="01"
  104. @change="handleStatusChange(scope.row)"
  105. ></el-switch>
  106. </template>
  107. </el-table-column> -->
  108. <el-table-column label="备注" align="center" prop="spiRemark" :show-overflow-tooltip="true"/>
  109. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  110. <template slot-scope="scope">
  111. <el-button
  112. size="mini"
  113. type="text"
  114. icon="el-icon-edit"
  115. @click="handleUpdate(scope.row)"
  116. v-hasPermi="['system:product:edit']"
  117. >修改</el-button>
  118. <!-- <el-button
  119. size="mini"
  120. type="text"
  121. icon="el-icon-edit"
  122. @click="handleAttr(scope.row)"
  123. v-hasPermi="['system:attr:add']"
  124. >附加信息</el-button> -->
  125. <el-button
  126. size="mini"
  127. type="text"
  128. icon="el-icon-delete"
  129. @click="handleDelete(scope.row)"
  130. v-hasPermi="['system:product:remove']"
  131. >删除</el-button>
  132. </template>
  133. </el-table-column>
  134. </el-table>
  135. <pagination
  136. v-show="total>0"
  137. :total="total"
  138. :page.sync="queryParams.pageNum"
  139. :limit.sync="queryParams.pageSize"
  140. @pagination="getList"
  141. />
  142. <!-- 添加或修改菜单信息对话框 -->
  143. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  144. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  145. <el-form-item label="菜单名称" prop="spiProducName">
  146. <el-input v-model="form.spiProducName" placeholder="请输入菜单名称" maxlength="10" show-word-limit />
  147. </el-form-item>
  148. <el-form-item label="菜单描述" prop="spiProducDescribe">
  149. <el-input v-model="form.spiProducDescribe" type="textarea" placeholder="请输入菜单描述" maxlength="30" show-word-limit/>
  150. </el-form-item>
  151. <!-- <el-form-item label="状态" prop="spiState">
  152. <el-radio-group v-model="form.spiState">
  153. <el-radio
  154. v-for="dict in spiStateOptions"
  155. :key="dict.dictValue"
  156. :label="dict.dictValue"
  157. >{{dict.dictLabel}}</el-radio>
  158. </el-radio-group>
  159. </el-form-item> -->
  160. <el-form-item label="菜单权限">
  161. <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
  162. <el-checkbox v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
  163. <el-checkbox v-model="form.spiMenuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
  164. <el-tree
  165. class="tree-border"
  166. :data="menuOptions"
  167. show-checkbox
  168. ref="menu"
  169. node-key="id"
  170. :check-strictly="!form.spiMenuCheckStrictly"
  171. empty-text="加载中,请稍后"
  172. :props="defaultProps"
  173. ></el-tree>
  174. </el-form-item>
  175. <el-form-item label="备注" prop="spiRemark">
  176. <el-input v-model="form.spiRemark" type="textarea" placeholder="请输入内容" maxlength="100" show-word-limit />
  177. </el-form-item>
  178. </el-form>
  179. <div slot="footer" class="dialog-footer">
  180. <el-button type="primary" @click="submitForm">确 定</el-button>
  181. <el-button @click="cancel">取 消</el-button>
  182. </div>
  183. </el-dialog>
  184. <!-- 菜单附加信息配置对话框 -->
  185. <el-dialog :title="title" :visible.sync="openAttr" width="500px" append-to-body>
  186. <el-form ref="attrForm" :model="attrForm" label-width="80px">
  187. <el-table v-loading="loading" :data="productAttrList">
  188. <el-table-column label="序号" type="index" width="55" align="center" />
  189. <el-table-column label="附加字段" align="center" prop="spaCode">
  190. <template slot-scope="scope">
  191. <el-select v-model="scope.row.spaCode" placeholder="请选择">
  192. <el-option
  193. v-for="(item, index) in attrCodeOptions"
  194. :key="index"
  195. :label="item.dictLabel"
  196. :value="item.dictValue">
  197. </el-option>
  198. </el-select>
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  202. <template slot-scope="scope">
  203. <el-button
  204. size="mini"
  205. type="text"
  206. @click="deleteRow(scope.row)"
  207. >移除</el-button>
  208. </template>
  209. </el-table-column>
  210. </el-table>
  211. <el-button
  212. size="mini"
  213. type="text"
  214. @click="addRow()"
  215. >添加</el-button>
  216. </el-form>
  217. <div slot="footer" class="dialog-footer">
  218. <el-button type="primary" @click="submitAttrForm">确 定</el-button>
  219. <el-button @click="cancel">取 消</el-button>
  220. </div>
  221. </el-dialog>
  222. </div>
  223. </template>
  224. <script>
  225. import { listProduct, getProduct, delProduct, addProduct, updateProduct,changeProductStatus,listProductAttr,addProductAttr,updateProductAttr,delProductAttr } from "@/api/system/product";
  226. import { treeselect as menuTreeselect, productMenuTreeselect } from "@/api/system/menu";
  227. export default {
  228. name: "Product",
  229. components: {
  230. },
  231. data() {
  232. return {
  233. // 遮罩层
  234. loading: true,
  235. // 选中数组
  236. ids: [],
  237. // 非单个禁用
  238. single: true,
  239. // 非多个禁用
  240. multiple: true,
  241. // 显示搜索条件
  242. showSearch: true,
  243. // 总条数
  244. total: 0,
  245. // 菜单信息表格数据
  246. productList: [],
  247. productAttrList: [],
  248. // 状态字典
  249. spiStateOptions: [],
  250. attrCodeOptions:[],
  251. // 弹出层标题
  252. title: "",
  253. // 是否显示弹出层
  254. open: false,
  255. openAttr: false,
  256. menuExpand: false,
  257. menuNodeAll: false,
  258. // 查询参数
  259. queryParams: {
  260. pageNum: 1,
  261. pageSize: 10,
  262. spiProducName: null,
  263. spiProducDescribe: null,
  264. spiMenuCheckStrictly: null,
  265. spiState: null,
  266. spiIsDel: null,
  267. spiRemark: null
  268. },
  269. // 菜单列表
  270. menuOptions: [],
  271. // 表单参数
  272. form: {},
  273. attrForm: {},
  274. defaultProps: {
  275. children: "children",
  276. label: "label"
  277. },
  278. // 表单校验
  279. rules: {
  280. spiProducName: [
  281. { required: true, message: "菜单名称不能为空", trigger: "blur" }
  282. ],
  283. spiState: [
  284. { required: true, message: "菜单状态不能为空", trigger: "blur" }
  285. ],
  286. }
  287. };
  288. },
  289. created() {
  290. this.getList();
  291. this.getDicts("spi_state").then(response => {
  292. this.spiStateOptions = response.data;
  293. });
  294. this.getDicts("product_attr_code").then(response => {
  295. this.attrCodeOptions = response.data;
  296. });
  297. },
  298. methods: {
  299. /** 查询菜单信息列表 */
  300. getList() {
  301. this.loading = true;
  302. listProduct(this.queryParams).then(response => {
  303. this.productList = response.rows;
  304. this.total = response.total;
  305. this.loading = false;
  306. });
  307. },
  308. /** 查询菜单树结构 */
  309. getMenuTreeselect() {
  310. menuTreeselect().then(response => {
  311. this.menuOptions = response.data;
  312. });
  313. },
  314. /** 根据菜单ID查询菜单树结构 */
  315. getProductMenuTreeselect(spiProducId) {
  316. return productMenuTreeselect(spiProducId).then(response => {
  317. this.menuOptions = response.menus;
  318. return response;
  319. });
  320. },
  321. // 树权限(展开/折叠)
  322. handleCheckedTreeExpand(value, type) {
  323. if (type == 'menu') {
  324. let treeList = this.menuOptions;
  325. for (let i = 0; i < treeList.length; i++) {
  326. this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
  327. }
  328. } else if (type == 'dept') {
  329. let treeList = this.deptOptions;
  330. for (let i = 0; i < treeList.length; i++) {
  331. this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
  332. }
  333. }
  334. },
  335. // 树权限(全选/全不选)
  336. handleCheckedTreeNodeAll(value, type) {
  337. if (type == 'menu') {
  338. this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
  339. } else if (type == 'dept') {
  340. this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
  341. }
  342. },
  343. // 树权限(父子联动)
  344. handleCheckedTreeConnect(value, type) {
  345. if (type == 'menu') {
  346. this.form.spiMenuCheckStrictly = value ? true: false;
  347. } else if (type == 'dept') {
  348. this.form.deptCheckStrictly = value ? true: false;
  349. }
  350. },
  351. // 所有菜单节点数据
  352. getMenuAllCheckedKeys() {
  353. // 目前被选中的菜单节点
  354. let checkedKeys = this.$refs.menu.getCheckedKeys();
  355. // 半选中的菜单节点
  356. let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
  357. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  358. return checkedKeys;
  359. },
  360. // 取消按钮
  361. cancel() {
  362. this.open = false;
  363. this.openAttr = false;
  364. this.reset();
  365. },
  366. // 表单重置
  367. reset() {
  368. if (this.$refs.menu != undefined) {
  369. this.$refs.menu.setCheckedKeys([]);
  370. }
  371. this.form = {
  372. menuCheckStrictly: true,
  373. menuIds: [],
  374. spiProducId: null,
  375. spiProducName: null,
  376. spiProducDescribe: null,
  377. spiMenuCheckStrictly: true,
  378. spiState: '00',
  379. spiIsDel: null,
  380. createBy: null,
  381. createTime: null,
  382. updateBy: null,
  383. updateTime: null,
  384. spiRemark: null
  385. };
  386. this.attrForm = {},
  387. this.menuExpand = false,
  388. this.menuNodeAll = false,
  389. this.resetForm("form");
  390. },
  391. /** 搜索按钮操作 */
  392. handleQuery() {
  393. this.queryParams.pageNum = 1;
  394. this.getList();
  395. },
  396. /** 重置按钮操作 */
  397. resetQuery() {
  398. this.resetForm("queryForm");
  399. this.handleQuery();
  400. },
  401. // 多选框选中数据
  402. handleSelectionChange(selection) {
  403. this.ids = selection.map(item => item.spiProducId)
  404. this.single = selection.length!==1
  405. this.multiple = !selection.length
  406. },
  407. /** 新增按钮操作 */
  408. handleAdd() {
  409. this.reset();
  410. this.getMenuTreeselect();
  411. this.open = true;
  412. this.title = "添加菜单信息";
  413. },
  414. /** 修改按钮操作 */
  415. handleUpdate(row) {
  416. this.reset();
  417. const spiProducId = row.spiProducId || this.ids
  418. const productMenu = this.getProductMenuTreeselect(spiProducId);
  419. getProduct(spiProducId).then(response => {
  420. this.form = response.data;
  421. this.open = true;
  422. this.$nextTick(() => {
  423. productMenu.then(res => {
  424. this.$refs.menu.setCheckedKeys(res.checkedKeys);
  425. });
  426. });
  427. this.title = "修改菜单信息";
  428. });
  429. },
  430. /** 附加信息按钮操作 */
  431. handleAttr(row) {
  432. this.reset();
  433. const spiProducId = row.spiProducId || this.ids
  434. this.queryParams.scpProducId = spiProducId
  435. listProductAttr(this.queryParams).then(response => {
  436. console.log(response)
  437. this.productAttrList = response.rows;
  438. this.openAttr = true;
  439. this.title = "菜单附加信息配置";
  440. });
  441. },
  442. /** 增加节点 */
  443. addRow(){
  444. addProductAttr(this.queryParams).then(response => {
  445. this.msgSuccess("新增成功");
  446. listProductAttr(this.queryParams).then(response => {
  447. this.productAttrList = response.rows;
  448. });
  449. });
  450. },
  451. /** 移除节点 */
  452. deleteRow(rows) {
  453. delProductAttr(rows.spaId).then(response => {
  454. this.msgSuccess("移除成功");
  455. listProductAttr(this.queryParams).then(response => {
  456. this.productAttrList = response.rows;
  457. });
  458. });
  459. },
  460. // 菜单状态修改
  461. handleStatusChange(row) {
  462. let text = row.spiState === "00" ? "启用" : "停用";
  463. this.$confirm('确认要' + text + '"' + row.spiProducName + '"菜单吗?', "警告", {
  464. confirmButtonText: "确定",
  465. cancelButtonText: "取消",
  466. type: "warning"
  467. }).then(function() {
  468. return changeProductStatus(row.spiProducId, row.spiState);
  469. }).then(() => {
  470. this.msgSuccess(text + "成功");
  471. }).catch(function() {
  472. row.spiState = row.spiState === "00" ? "01" : "00";
  473. });
  474. },
  475. /** 提交按钮 */
  476. submitForm() {
  477. this.$refs["form"].validate(valid => {
  478. this.form.menuIds = this.getMenuAllCheckedKeys();
  479. if (valid) {
  480. if(this.form.menuIds.length != '0'){
  481. if (this.form.spiProducId != null) {
  482. const loading = this.$loading({
  483. lock: true,
  484. text: "Loading",
  485. spinner: "el-icon-loading",
  486. background: "rgba(0, 0, 0, 0.7)",
  487. })
  488. updateProduct(this.form).then(response => {
  489. loading.close();
  490. this.msgSuccess("修改成功");
  491. this.open = false;
  492. this.getList();
  493. }).catch((response)=>{
  494. loading.close();
  495. });
  496. } else {
  497. const loading = this.$loading({
  498. lock: true,
  499. text: "Loading",
  500. spinner: "el-icon-loading",
  501. background: "rgba(0, 0, 0, 0.7)",
  502. })
  503. this.form.menuIds = this.getMenuAllCheckedKeys();
  504. addProduct(this.form).then(response => {
  505. loading.close();
  506. this.msgSuccess("新增成功");
  507. this.open = false;
  508. this.getList();
  509. }).catch((response)=>{
  510. loading.close();
  511. });
  512. }
  513. }else{
  514. this.$message({
  515. message: '请选择菜单菜单',
  516. type: 'warning'
  517. });
  518. return;
  519. }
  520. }
  521. });
  522. },
  523. /** 附加信息提交按钮 */
  524. submitAttrForm() {
  525. const loading = this.$loading({
  526. lock: true,
  527. text: "Loading",
  528. spinner: "el-icon-loading",
  529. background: "rgba(0, 0, 0, 0.7)",
  530. })
  531. updateProductAttr(this.productAttrList).then(response => {
  532. loading.close();
  533. this.msgSuccess("修改成功");
  534. this.openAttr = false;
  535. this.getList();
  536. }).catch((response)=>{
  537. loading.close();
  538. });
  539. },
  540. /** 删除按钮操作 */
  541. handleDelete(row) {
  542. const spiProducIds = row.spiProducId || this.ids
  543. const spiProducName = row.spiProducName;
  544. this.$confirm('是否确认删除菜单名称为"' + spiProducName + '"的数据项?', "警告", {
  545. confirmButtonText: "确定",
  546. cancelButtonText: "取消",
  547. type: "warning"
  548. }).then(function() {
  549. return delProduct(spiProducIds);
  550. }).then(() => {
  551. this.getList();
  552. this.msgSuccess("删除成功");
  553. })
  554. .catch(() => {
  555. this.$message({
  556. type: "warning",
  557. message: "已取消删除",
  558. });
  559. });
  560. },
  561. /** 导出按钮操作 */
  562. handleExport() {
  563. this.download('system/product/export', {
  564. ...this.queryParams
  565. }, `system_product.xlsx`)
  566. }
  567. }
  568. };
  569. </script>