index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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="onRefresh" @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="0">正常</el-radio>
  13. <el-radio class="fl" style="margin-top: 8px;" v-model="radio" :label="1">禁用</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 = 0
  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: 0,
  103. label: '正常'
  104. }, {
  105. value: 1,
  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: 0,
  123. label: '销售属性'
  124. }, {
  125. value: 1,
  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. align: 'left',
  146. checkbox: true,
  147. height: 600
  148. },
  149. columns: [{
  150. width: 500,
  151. title: '名称',
  152. field: 'name',
  153. isDetail: true,
  154. }, {
  155. title: '属性值',
  156. field: 'attributeValue',
  157. component: AttributeValue,
  158. },
  159. {
  160. width: 100,
  161. title: '属性类型',
  162. field: 'attributeType',
  163. component: AssemblyNature,
  164. }, {
  165. width: 80,
  166. title: '状态',
  167. field: 'status',
  168. component: Assembly,
  169. }, {
  170. width: 120,
  171. title: '操作',
  172. action: true,
  173. plugins: [{
  174. icon: 'el-icon-edit',
  175. name: '编辑',
  176. audit: '',
  177. event: {
  178. click: (item : any) => {
  179. (this as any).openEdit(item)
  180. }
  181. }
  182. }, {
  183. name: '删除',
  184. event: {
  185. click: (item : any) => (this as any).doDelete2(item)
  186. }
  187. }]
  188. }]
  189. },
  190. }
  191. addConfig = {
  192. attr: {
  193. size: 'small',
  194. rules: {
  195. name: [{
  196. required: true, message: '请输入名称', trigger: 'blur'
  197. }],
  198. attributeType: [{
  199. required: true, message: '请输入销售属性', trigger: 'blur'
  200. }],
  201. }
  202. },
  203. columns: [
  204. [
  205. {
  206. span: 23,
  207. labelWidth: '80px',
  208. label: '名称',
  209. prop: 'name',
  210. component: 'by-input',
  211. },
  212. {
  213. span: 23,
  214. labelWidth: '80px',
  215. label: '显示状态',
  216. slot: true,
  217. prop: 'status',
  218. },
  219. {
  220. span: 23,
  221. labelWidth: '80px',
  222. label: '属性类型',
  223. slot: true,
  224. prop: 'attributeType',
  225. component: 'by-select',
  226. compConfig: {
  227. attr: {
  228. placeholder: '请选择数据',
  229. clearable: true,
  230. data: [{
  231. value: 0,
  232. label: '销售属性'
  233. }, {
  234. value: 1,
  235. label: '基本属性'
  236. }]
  237. }
  238. }
  239. },
  240. {
  241. span: 23,
  242. labelWidth: '80px',
  243. label: '属性值',
  244. slot: true,
  245. prop: 'attributeValue',
  246. },
  247. ],
  248. ]
  249. }
  250. mounted() {
  251. this.timer = setInterval(() => {
  252. this.getDataList()
  253. }, 300)
  254. }
  255. // 添加
  256. showInput(index : any) {
  257. let inputValue = (this as any).$refs['getValue_' + index][0].getValue();
  258. // console.log(this.tableConfig[index]);
  259. if (this.tableConfig[index].list.indexOf(inputValue) !== -1) return (this as any).$refs['getValue_' + index][0].clearValue();
  260. if (inputValue) {
  261. this.tableConfig[index].list.push(inputValue);
  262. }
  263. (this as any).$refs['getValue_' + index][0].clearValue();
  264. }
  265. // 删除标签
  266. handleClose(tag : any, index : any) {
  267. // console.log(tag);
  268. this.tableConfig[index].list.splice(this.tableConfig[index].list.indexOf(tag), 1);
  269. }
  270. // 删除数组
  271. closeGroup(index : any) {
  272. this.tableConfig.splice(index, 1)
  273. }
  274. // 添加新规格
  275. doComfirm() {
  276. this.normsValue = this.normsValue.trim();
  277. this.norms = this.norms.trim();
  278. if (!this.normsValue || !this.norms) return (this as any).$message.warning('请添加完整的规格');
  279. let obj : any = {
  280. title: this.norms,
  281. field: this.norms + '_field_name',
  282. list: [this.normsValue]
  283. }
  284. this.tableConfig.push(obj);
  285. this.norms = '';
  286. this.normsValue = '';
  287. }
  288. // 确认新增/编辑
  289. confirm() {
  290. (this as any).$refs.addFormId.validate().then(() => {
  291. if (this.tableConfig.length <= 0) return this.$message.warning('验证未通过,请添加完整的规格');
  292. let query = (this as any).$refs.addFormId.getValue();
  293. query.status = this.radio;
  294. query.attributeValue = JSON.stringify(this.tableConfig)
  295. this.dialogFormVisible = false;
  296. console.log(query);
  297. let loading = this.$loading({ target: '.main-container' });
  298. if (this.popTitle === '新增') {
  299. api.saveList(query, 'maindataMaterialAttribute').then((res : any) => {
  300. if (res.code === 200) {
  301. this.$message.success('新增成功');
  302. this.getDataList();
  303. loading.close();
  304. } else this.$message.error(res.msg);
  305. })
  306. } else if (this.popTitle === '编辑') {
  307. api.updateList(query, 'maindataMaterialAttribute').then((res : any) => {
  308. if (res.code === 200) {
  309. this.$message.success('编辑成功');
  310. this.getDataList();
  311. loading.close();
  312. } else this.$message.error(res.msg);
  313. })
  314. }
  315. })
  316. }
  317. // 获取列表数据
  318. getDataList() {
  319. if (!this.$refs.moduleView) {
  320. if (this.timeNum > 5) {
  321. clearInterval(this.timer)
  322. }
  323. this.timeNum++;
  324. return
  325. }
  326. clearInterval(this.timer)
  327. let query = (this.$refs.moduleView as any).getQuery();
  328. // console.log('表单字段 ==> ', query);
  329. this.getPageList(query)
  330. }
  331. getPageList(query : any) {
  332. let loading = this.$loading({ target: '.main-container' });
  333. api.pageList(query, 'maindataMaterialAttribute').then((res : any) => {
  334. if (res.code === 200) {
  335. (this.$refs.moduleView as any).setTableValue(res.data.records);
  336. let page = {
  337. pageNo: res.data.current, //当前页
  338. pageSize: res.data.size, //每页条数
  339. total: res.data.total //总条数
  340. };
  341. (this.$refs.moduleView as any).setPage(page);
  342. loading.close();
  343. } else this.$message.error(res.msg);
  344. })
  345. }
  346. // 工具栏方法
  347. clickHandle(e : any) {
  348. if (e === 'onAdd') this.onAdd();
  349. if (e === 'onDelete') this.onDelete();
  350. }
  351. // 打开新增
  352. onAdd() {
  353. this.popTitle = '新增'
  354. this.dialogFormVisible = true;
  355. this.radio = 0
  356. this.tableConfig = [];
  357. this.$nextTick(() => {
  358. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue();
  359. });
  360. }
  361. // 打开编辑
  362. openEdit(e : any) {
  363. this.popTitle = '编辑';
  364. let loading = this.$loading({ target: '.main-container' });
  365. api.single({ id: e.id }, 'maindataMaterialAttribute').then((res : any) => {
  366. if (res.code === 200) {
  367. let data = res.data;
  368. this.dialogFormVisible = true;
  369. this.radio = data.status;
  370. loading.close();
  371. this.$nextTick(() => {
  372. if ((this as any).$refs.addFormId) (this as any).$refs.addFormId.setValue(data);
  373. })
  374. }
  375. })
  376. }
  377. // 工具栏删除
  378. onDelete() {
  379. let selectData = (this.$refs.moduleView as any).getSelectData()
  380. let ids = '';
  381. if (selectData.length > 0) {
  382. selectData.map((v : any) => {
  383. ids += v.id + ','
  384. })
  385. } else return this.$message({ type: 'warning', message: '请选择删除数据' })
  386. ids = ids.slice(0, ids.length - 1);
  387. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  388. confirmButtonText: '确定',
  389. cancelButtonText: '取消',
  390. type: 'warning',
  391. center: true
  392. }).then(() => {
  393. api.deleteList({ ids: ids }, 'maindataMaterialAttribute').then((res : any) => {
  394. if (res.code === 200) {
  395. this.getDataList();
  396. this.$message.success('删除成功');
  397. } else this.$message.error(res.msg);
  398. })
  399. }).catch(() => this.$message.info('已取消删除'));
  400. }
  401. // 操作删除
  402. doDelete2(item : any) {
  403. this.$confirm('确定删除吗,此操作不能撤销!', '注意', {
  404. confirmButtonText: '确定',
  405. cancelButtonText: '取消',
  406. type: 'warning',
  407. center: true
  408. }).then(() => {
  409. api.deleteList({ ids: item.id }, 'maindataMaterialAttribute').then((res : any) => {
  410. if (res.code === 200) {
  411. this.getDataList();
  412. this.$message.success('删除成功');
  413. } else this.$message.error(res.msg);
  414. })
  415. }).catch(() => this.$message.info('已取消删除'));
  416. }
  417. // 刷新/重置
  418. onRefresh() {
  419. (this as any).$refs.moduleView.clearSearch();
  420. this.getDataList();
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped>
  425. .my-container {
  426. width: 100%;
  427. box-sizing: border-box;
  428. display: flex;
  429. padding: 16px;
  430. .tab-title {
  431. // padding: 10px 0 0;
  432. }
  433. .item-tab {
  434. margin-right: 16px;
  435. }
  436. .input-new-tag {
  437. width: 130px;
  438. }
  439. .flex-item {
  440. margin-right: 20px;
  441. }
  442. .search-btn {
  443. width: 100%;
  444. display: flex;
  445. justify-content: flex-end;
  446. margin-bottom: 20px;
  447. }
  448. .bill-left {
  449. position: relative;
  450. border-right: solid #EEE 1px;
  451. padding-right: 16px;
  452. flex-shrink: 0;
  453. // box-sizing: border-box;
  454. .bill-tab {
  455. width: 150px;
  456. height: 100%;
  457. transition: all .5s;
  458. overflow: hidden;
  459. }
  460. .title {
  461. font-size: 16px;
  462. padding-bottom: 16px;
  463. width: 200px;
  464. }
  465. .bill-nav {
  466. font-size: 14px;
  467. height: 30px;
  468. line-height: 30px;
  469. width: 200px;
  470. box-sizing: border-box;
  471. padding: 0 8px;
  472. cursor: pointer;
  473. margin-bottom: 2px;
  474. border-radius: 5px;
  475. }
  476. .onBill {
  477. background-color: #bde3f7;
  478. }
  479. .bill-nav:hover {
  480. background-color: #bde3f7;
  481. }
  482. .close {
  483. height: 22px;
  484. width: 22px;
  485. border-radius: 50%;
  486. border: solid #EEE 1px;
  487. position: absolute;
  488. top: 30px;
  489. right: -11px;
  490. background-color: #FFF;
  491. display: flex;
  492. justify-content: center;
  493. align-items: center;
  494. cursor: pointer;
  495. }
  496. }
  497. .bill-main {
  498. width: calc(100% - 16px);
  499. box-sizing: border-box;
  500. margin-left: 16px;
  501. position: relative;
  502. .bill-box {
  503. width: 100%;
  504. position: absolute;
  505. left: 0;
  506. top: 0;
  507. opacity: 0;
  508. z-index: -1;
  509. transition: all .5s;
  510. .bill-tool,
  511. .table-tool {
  512. width: 100%;
  513. padding-bottom: 16px;
  514. }
  515. .form {
  516. margin-bottom: 8px;
  517. }
  518. }
  519. .on-show {
  520. opacity: 1;
  521. z-index: 1;
  522. }
  523. }
  524. }
  525. </style>