index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-main">
  4. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  5. @resert="getDataList" @clickHandle="clickHandle" @detail="openEdit" @onRefresh="onRefresh">
  6. </module-view>
  7. </div>
  8. <!-- 新增/编辑弹窗 -->
  9. <el-dialog :title="popTitle+'属性'" :visible.sync="dialogFormVisible" width="50%">
  10. <by-form :propConfig="addConfig" ref="addFormId">
  11. <template v-slot:status class="clearfix">
  12. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="1">正常</el-radio>
  13. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="2">禁用</el-radio>
  14. </template>
  15. <template v-slot:attributeValue="{value}">
  16. <div style="margin-bottom: 20px;" v-if="tableConfig.length>0">
  17. <div v-for="(item,index) of tableConfig" :key="index">
  18. <div class="tab-title">{{item.title}} <i class="el-icon-circle-close" @click="closeGroup(index)"></i>
  19. </div>
  20. <el-tag class="item-tab" :disable-transitions="true" :key="i" v-for="(tag,i) of item.list" closable
  21. @close="handleClose(tag,index)">
  22. {{tag}}
  23. </el-tag>
  24. <by-input class="input-new-tag" :ref="'getValue_'+index"></by-input>
  25. <el-button class="button-new-tag" @click="showInput(index)">添加</el-button>
  26. </div>
  27. </div>
  28. <div style="display: flex;">
  29. <div style="margin-right: 20px;">
  30. <label>规格:</label>
  31. <div class="el-input el-input--small" style="width: 250px;">
  32. <input type="text" v-model="norms" placeholder="请输入规格" class="el-input__inner">
  33. </div>
  34. </div>
  35. <div style="margin-right: 20px;">
  36. <label>规格值:</label>
  37. <div class="el-input el-input--small" style="width: 250px;">
  38. <input type="text" v-model="normsValue" placeholder="请输入规格值" class="el-input__inner">
  39. </div>
  40. </div>
  41. <div @click="doComfirm" class="el-button el-button--primary el-button--small">确定</div>
  42. </div>
  43. </template>
  44. </by-form>
  45. <div slot="footer" class="dialog-footer">
  46. <el-button @click="dialogFormVisible = false">取 消</el-button>
  47. <el-button type="primary" @click="confirm">确 定</el-button>
  48. </div>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script lang="ts">
  53. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  54. import api from "@/api/currency";
  55. import Assembly from "@/components/Assembly/material.vue";
  56. import AssemblyNature from "@/components/Assembly/nature.vue";
  57. import AttributeValue from "@/components/Assembly/attributeValue.vue";
  58. import ForTab from "@/components/ForTab/index.vue";
  59. @Component({ components: { ForTab } })
  60. export default class Attribute extends Vue {
  61. // 右边
  62. baseURL : any = process.env.VUE_APP_BASE_API
  63. loading : any = null
  64. norms : any = ''
  65. normsValue : any = ''
  66. timeNum = 0;
  67. timer : any = null
  68. popTitle : any = ''
  69. radio : any = 1
  70. dialogFormVisible : boolean = false
  71. tableConfig : any = []
  72. config : any = {
  73. search: {
  74. attr: {
  75. size: 'mini'
  76. },
  77. columns: [
  78. [{
  79. span: 6,
  80. label: '名称',
  81. prop: 'name',
  82. component: 'by-input',
  83. labelWidth: '80px',
  84. compConfig: {
  85. attr: {
  86. placeholder: '请输入名称',
  87. clearable: true
  88. },
  89. },
  90. },
  91. {
  92. span: 6,
  93. label: '状态',
  94. prop: 'status',
  95. component: 'by-select',
  96. labelWidth: '80px',
  97. compConfig: {
  98. attr: {
  99. placeholder: '请选择数据',
  100. clearable: true,
  101. data: [{
  102. value: 1,
  103. label: '正常'
  104. }, {
  105. value: 2,
  106. label: '禁用'
  107. }]
  108. }
  109. }
  110. },
  111. {
  112. span: 6,
  113. label: '属性类型',
  114. prop: 'attributeType',
  115. component: 'by-select',
  116. labelWidth: '90px',
  117. compConfig: {
  118. attr: {
  119. placeholder: '请选择数据',
  120. clearable: true,
  121. data: [{
  122. value: 1,
  123. label: '销售属性'
  124. }, {
  125. value: 2,
  126. label: '基本属性'
  127. }]
  128. }
  129. }
  130. },
  131. ]
  132. ]
  133. },
  134. tool: {
  135. tools: {
  136. add: true,
  137. delete: true,
  138. search: true,
  139. refresh: true
  140. }
  141. },
  142. table: {
  143. attr: {
  144. size: 'mini',
  145. seq: true,
  146. align: 'center',
  147. checkbox: true,
  148. height: 600
  149. },
  150. columns: [{
  151. width: 500,
  152. title: '名称',
  153. field: 'name',
  154. isDetail: true,
  155. }, {
  156. title: '属性值',
  157. field: 'attributeValue',
  158. component: AttributeValue,
  159. },
  160. {
  161. width: 100,
  162. title: '属性类型',
  163. field: 'attributeType',
  164. component: AssemblyNature,
  165. }, {
  166. width: 80,
  167. title: '状态',
  168. field: 'status',
  169. component: Assembly,
  170. }, {
  171. width: 120,
  172. title: '操作',
  173. action: true,
  174. plugins: [{
  175. icon: 'el-icon-edit',
  176. name: '编辑',
  177. audit: '',
  178. event: {
  179. click: (item : any) => {
  180. (this as any).openEdit(item)
  181. }
  182. }
  183. }, {
  184. name: '删除',
  185. event: {
  186. click: (item : any) => (this as any).doDelete2(item)
  187. }
  188. }]
  189. }]
  190. },
  191. }
  192. addConfig = {
  193. attr: {
  194. size: 'small',
  195. rules: {
  196. name: [{
  197. required: true, message: '请输入名称', trigger: 'blur'
  198. }],
  199. attributeType: [{
  200. required: true, message: '请输入销售属性', trigger: 'blur'
  201. }],
  202. }
  203. },
  204. columns: [
  205. [
  206. {
  207. span: 23,
  208. labelWidth: '80px',
  209. label: '名称',
  210. prop: 'name',
  211. component: 'by-input',
  212. },
  213. {
  214. span: 23,
  215. labelWidth: '80px',
  216. label: '显示状态',
  217. slot: true,
  218. prop: 'status',
  219. },
  220. {
  221. span: 23,
  222. labelWidth: '80px',
  223. label: '属性类型',
  224. slot: true,
  225. prop: 'attributeTypeName',
  226. component: 'by-select',
  227. compConfig: {
  228. attr: {
  229. placeholder: '请选择数据',
  230. clearable: true,
  231. data: [{
  232. value: 1,
  233. label: '销售属性'
  234. }, {
  235. value: 2,
  236. label: '基本属性'
  237. }]
  238. }
  239. }
  240. },
  241. {
  242. span: 23,
  243. labelWidth: '80px',
  244. label: '属性值',
  245. slot: true,
  246. prop: 'attributeValue',
  247. },
  248. ],
  249. ]
  250. }
  251. mounted() {
  252. this.timer = setInterval(() => {
  253. this.getDataList()
  254. }, 300)
  255. }
  256. // 添加
  257. showInput(index : any) {
  258. let inputValue = (this as any).$refs['getValue_' + index][0].getValue();
  259. // console.log(this.tableConfig[index]);
  260. if (this.tableConfig[index].list.indexOf(inputValue) !== -1) return (this as any).$refs['getValue_' + index][0].clearValue();
  261. if (inputValue) {
  262. this.tableConfig[index].list.push(inputValue);
  263. }
  264. (this as any).$refs['getValue_' + index][0].clearValue();
  265. }
  266. // 删除标签
  267. handleClose(tag : any, index : any) {
  268. // console.log(tag);
  269. this.tableConfig[index].list.splice(this.tableConfig[index].list.indexOf(tag), 1);
  270. }
  271. // 删除数组
  272. closeGroup(index : any) {
  273. this.tableConfig.splice(index, 1)
  274. }
  275. // 添加新规格
  276. doComfirm() {
  277. if (!this.normsValue || !this.norms) return (this as any).$message({ type: "warning", message: '请添加完整的规格!' })
  278. let obj : any = {
  279. title: this.norms,
  280. field: this.norms + '_field_name',
  281. list: [this.normsValue]
  282. }
  283. this.tableConfig.push(obj);
  284. this.norms = '';
  285. this.normsValue = '';
  286. }
  287. // 确认新增/编辑
  288. confirm() {
  289. (this as any).$refs.addFormId.validate().then(() => {
  290. if (this.tableConfig.length <= 0) return this.$message({ type: 'warning', message: '验证未通过,请添加完整的规格!' })
  291. let query = (this as any).$refs.addFormId.getValue();
  292. query.status = this.radio;
  293. query.attributeValue = JSON.stringify(this.tableConfig)
  294. this.dialogFormVisible = false;
  295. console.log(query);
  296. if (this.popTitle === '新增') {
  297. api.saveList(query, 'maindataMaterialAttribute').then((res : any) => {
  298. if (res.code === 200) {
  299. this.$message({
  300. type: 'success',
  301. message: this.popTitle + '成功!'
  302. });
  303. this.getDataList();
  304. } else this.failHandle(res)
  305. })
  306. } else if (this.popTitle === '编辑') {
  307. api.updateList(query, 'maindataMaterialAttribute').then((res : any) => {
  308. if (res.code === 200) {
  309. this.$message({
  310. type: 'success',
  311. message: this.popTitle + '成功!'
  312. });
  313. this.getDataList();
  314. } else this.failHandle(res)
  315. })
  316. }
  317. })
  318. }
  319. // 获取列表数据
  320. getDataList() {
  321. if (!this.$refs.moduleView) {
  322. if (this.timeNum > 5) {
  323. clearInterval(this.timer)
  324. }
  325. this.timeNum++;
  326. return
  327. }
  328. clearInterval(this.timer)
  329. let query = (this.$refs.moduleView as any).getQuery();
  330. // console.log('表单字段 ==> ', query);
  331. api.pageList(query, 'maindataMaterialAttribute').then((res : any) => {
  332. if (res.code === 200) {
  333. (this.$refs.moduleView as any).setTableValue(res.data.records);
  334. let page = {
  335. pageNo: res.data.current, //当前页
  336. pageSize: res.data.size, //每页条数
  337. total: res.data.total //总条数
  338. };
  339. (this.$refs.moduleView as any).setPage(page)
  340. } else this.failHandle(res)
  341. })
  342. }
  343. // 工具栏方法
  344. clickHandle(e : any) {
  345. if (e === 'onAdd') this.onAdd();
  346. if (e === 'onDelete') this.onDelete();
  347. if (e === 'onExport') this.onExport();
  348. }
  349. // 打开新增
  350. onAdd() {
  351. this.popTitle = '新增'
  352. this.dialogFormVisible = true;
  353. this.radio = 0
  354. this.tableConfig = []
  355. setTimeout(() => {
  356. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue({});
  357. }, 0)
  358. }
  359. // 打开编辑
  360. openEdit(e : any) {
  361. this.popTitle = '编辑'
  362. this.dialogFormVisible = true;
  363. this.radio = e.status
  364. this.tableConfig = JSON.parse(e.attributeValue);
  365. e.attributeTypeName = e.attributeType === 1 ? '销售属性' : '基本属性';
  366. setTimeout(() => {
  367. console.log('编辑 ==> ', e);
  368. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue(e);
  369. }, 0)
  370. }
  371. // 工具栏删除
  372. onDelete() {
  373. let selectData = (this.$refs.moduleView as any).getSelectData()
  374. let ids = '';
  375. if (selectData.length > 0) {
  376. selectData.map((v : any) => {
  377. ids += v.id + ','
  378. })
  379. } else return this.$message({ type: 'warning', message: '请选择删除数据' })
  380. ids = ids.slice(0, ids.length - 1);
  381. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  382. confirmButtonText: '确定',
  383. cancelButtonText: '取消',
  384. type: 'warning',
  385. center: true
  386. }).then(() => {
  387. api.deleteList({ ids: ids }, 'maindataMaterialAttribute').then((res : any) => {
  388. if (res.code === 200) {
  389. this.getDataList();
  390. this.$message({
  391. type: 'success',
  392. message: '删除成功!'
  393. });
  394. } else this.failHandle(res)
  395. })
  396. }).catch(() => {
  397. this.$message({
  398. type: 'info',
  399. message: '已取消删除'
  400. });
  401. });
  402. }
  403. // 操作删除
  404. doDelete2(item : any) {
  405. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  406. confirmButtonText: '确定',
  407. cancelButtonText: '取消',
  408. type: 'warning',
  409. center: true
  410. }).then(() => {
  411. api.deleteList({ ids: item.id }, 'maindataMaterialAttribute').then((res : any) => {
  412. if (res.code === 200) {
  413. this.getDataList();
  414. this.$message({
  415. type: 'success',
  416. message: '删除成功!'
  417. });
  418. } else this.failHandle(res)
  419. })
  420. }).catch(() => {
  421. this.$message({
  422. type: 'info',
  423. message: '已取消删除'
  424. });
  425. });
  426. }
  427. // 刷新
  428. onRefresh(){
  429. this.loading = this.$loading({ target: '.main-container' });
  430. (this as any).$refs.moduleView.clearSearch();
  431. api.pageList({}, 'maindataMaterialAttribute').then((res : any) => {
  432. if (res.code === 200) {
  433. (this.$refs.moduleView as any).setTableValue(res.data.records);
  434. let page = {
  435. pageNo: res.data.current, //当前页
  436. pageSize: res.data.size, //每页条数
  437. total: res.data.total //总条数
  438. };
  439. (this.$refs.moduleView as any).setPage(page);
  440. this.loading.close();
  441. } else this.$message.error(res.msg);
  442. })
  443. }
  444. //导出
  445. onExport() {
  446. let urlArr = '/maindata/maindataMaterial';
  447. let query = (this.$refs.moduleView as any).getQuery();
  448. (this as any).$download(urlArr + '/export', {
  449. ...query
  450. }, urlArr[urlArr.length - 1] + `_${new Date().getTime()}.xlsx`)
  451. }
  452. // 运行错误
  453. failHandle(err : any) {
  454. let msg = err.msg ? err.msg : '运行错误!';
  455. this.$message.error(msg)
  456. }
  457. }
  458. </script>
  459. <style lang="scss" scoped>
  460. .my-container {
  461. width: 100%;
  462. box-sizing: border-box;
  463. display: flex;
  464. padding: 16px;
  465. .tab-title {
  466. // padding: 10px 0 0;
  467. }
  468. .item-tab {
  469. margin-right: 16px;
  470. }
  471. .input-new-tag {
  472. width: 130px;
  473. }
  474. .flex-item {
  475. margin-right: 20px;
  476. }
  477. .search-btn {
  478. width: 100%;
  479. display: flex;
  480. justify-content: flex-end;
  481. margin-bottom: 20px;
  482. }
  483. .bill-left {
  484. position: relative;
  485. border-right: solid #EEE 1px;
  486. padding-right: 16px;
  487. flex-shrink: 0;
  488. // box-sizing: border-box;
  489. .bill-tab {
  490. width: 150px;
  491. height: 100%;
  492. transition: all .5s;
  493. overflow: hidden;
  494. }
  495. .title {
  496. font-size: 16px;
  497. padding-bottom: 16px;
  498. width: 200px;
  499. }
  500. .bill-nav {
  501. font-size: 14px;
  502. height: 30px;
  503. line-height: 30px;
  504. width: 200px;
  505. box-sizing: border-box;
  506. padding: 0 8px;
  507. cursor: pointer;
  508. margin-bottom: 2px;
  509. border-radius: 5px;
  510. }
  511. .onBill {
  512. background-color: #bde3f7;
  513. }
  514. .bill-nav:hover {
  515. background-color: #bde3f7;
  516. }
  517. .close {
  518. height: 22px;
  519. width: 22px;
  520. border-radius: 50%;
  521. border: solid #EEE 1px;
  522. position: absolute;
  523. top: 30px;
  524. right: -11px;
  525. background-color: #FFF;
  526. display: flex;
  527. justify-content: center;
  528. align-items: center;
  529. cursor: pointer;
  530. }
  531. }
  532. .bill-main {
  533. width: calc(100% - 16px);
  534. box-sizing: border-box;
  535. margin-left: 16px;
  536. position: relative;
  537. .bill-box {
  538. width: 100%;
  539. position: absolute;
  540. left: 0;
  541. top: 0;
  542. opacity: 0;
  543. z-index: -1;
  544. transition: all .5s;
  545. .bill-tool,
  546. .table-tool {
  547. width: 100%;
  548. padding-bottom: 16px;
  549. }
  550. .form {
  551. margin-bottom: 8px;
  552. }
  553. }
  554. .on-show {
  555. opacity: 1;
  556. z-index: 1;
  557. }
  558. }
  559. }
  560. </style>