index.vue 13 KB

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