AddCondition.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. <template>
  2. <el-container>
  3. <el-header height="50px" class="header">
  4. <el-page-header
  5. @back="handleBack"
  6. :content="!id ? '添加页面' : '详情页面'"
  7. >
  8. </el-page-header>
  9. </el-header>
  10. <div class="line">
  11. <el-divider></el-divider>
  12. <h4>限定条件</h4>
  13. <el-divider></el-divider>
  14. </div>
  15. <el-main v-if="!id">
  16. <el-row>
  17. <el-row :gutter="50">
  18. <el-col
  19. :xs="24"
  20. :sm="24"
  21. :lg="24"
  22. class="mgb"
  23. v-for="(item, index) in conditionBox"
  24. :key="index"
  25. >
  26. <el-row>
  27. <el-row class="pdt">
  28. <el-button
  29. type="primary"
  30. size="small"
  31. @click="(VisibleModle = true), getMaterialLists(index)"
  32. >添加机型</el-button
  33. >
  34. <el-button
  35. type="primary"
  36. size="small"
  37. @click="handleDeleteRow(index)"
  38. >删除机型</el-button
  39. >
  40. </el-row>
  41. <el-row>
  42. <el-table
  43. style="width: 100%"
  44. :data="item"
  45. border
  46. @select="hanleSelectAll($event, index)"
  47. @select-all="hanleSelectAll($event, index)"
  48. >
  49. <el-table-column type="selection" width="55" align="center">
  50. </el-table-column>
  51. <el-table-column
  52. label="货品名称"
  53. width="300"
  54. align="center"
  55. prop="materialName"
  56. >
  57. </el-table-column>
  58. <el-table-column
  59. prop="specification"
  60. label="规格型号"
  61. align="center"
  62. >
  63. </el-table-column>
  64. </el-table>
  65. </el-row>
  66. </el-row>
  67. </el-col>
  68. </el-row>
  69. <el-row>
  70. <el-form label-width="120px" :inline="false" size="small">
  71. <el-row>
  72. <el-form-item label="配置比例设置"> </el-form-item>
  73. </el-row>
  74. <el-col :xs="24" :sm="8" :lg="8">
  75. <el-form-item label="限定机型">
  76. <el-input size="small" v-model="limit"></el-input>
  77. </el-form-item>
  78. </el-col>
  79. <el-col
  80. :xs="24"
  81. :sm="8"
  82. :lg="8"
  83. v-for="(len, index) in conditionBox.length - 1"
  84. >
  85. <el-form-item :label="'配提' + (index + 1) + '比例'">
  86. <el-input
  87. size="small"
  88. v-model="popArr['line_' + index]"
  89. ></el-input>
  90. </el-form-item>
  91. </el-col>
  92. </el-form>
  93. </el-row>
  94. <el-divider></el-divider>
  95. </el-row>
  96. </el-main>
  97. <el-main v-else>
  98. <el-row>
  99. <el-row :gutter="50">
  100. <el-col
  101. :xs="24"
  102. :sm="24"
  103. :lg="24"
  104. class="mgb"
  105. v-for="(item, index) in conditionBoxs"
  106. :key="index"
  107. >
  108. <el-row>
  109. <el-row>
  110. <el-table style="width: 100%" :data="item" border>
  111. <el-table-column
  112. type="selection"
  113. width="55"
  114. align="center"
  115. v-if="!id"
  116. >
  117. </el-table-column>
  118. <el-table-column
  119. type="index"
  120. label="序号"
  121. width="55"
  122. align="center"
  123. v-else
  124. >
  125. </el-table-column>
  126. <el-table-column
  127. label="货品名称"
  128. width="300"
  129. align="center"
  130. prop="materialName"
  131. >
  132. <template slot-scope="scope">{{
  133. scope.row.materialName
  134. }}</template>
  135. </el-table-column>
  136. <el-table-column
  137. prop="specification"
  138. label="规格型号"
  139. align="center"
  140. >
  141. </el-table-column>
  142. </el-table>
  143. </el-row>
  144. </el-row>
  145. </el-col>
  146. </el-row>
  147. <el-row v-if="conditionBoxs.length">
  148. <el-form label-width="120px" :inline="false" size="small">
  149. <el-row>
  150. <el-form-item label="配置比例设置"> </el-form-item>
  151. </el-row>
  152. <el-col :xs="24" :sm="8" :lg="8">
  153. <el-form-item label="限定机型">
  154. <el-input
  155. size="small"
  156. v-model="limit"
  157. :readonly="!id ? false : true"
  158. ></el-input>
  159. </el-form-item>
  160. </el-col>
  161. <el-col
  162. :xs="24"
  163. :sm="8"
  164. :lg="8"
  165. v-for="(len, index) in conditionBoxs.length - 1"
  166. >
  167. <el-form-item :label="'配提' + (index + 1) + '比例'">
  168. <el-input
  169. size="small"
  170. :readonly="!id ? false : true"
  171. v-model="popArr['line_' + index]"
  172. ></el-input>
  173. </el-form-item>
  174. </el-col>
  175. </el-form>
  176. <el-col class="text_rihgt" v-if="false">
  177. <el-button type="primary" size="small" @click=""
  178. >添加限定条件</el-button
  179. ></el-col
  180. >
  181. </el-row>
  182. <el-divider></el-divider>
  183. </el-row>
  184. </el-main>
  185. <el-footer height="100px" v-if="!id">
  186. <el-row :gutter="20">
  187. <el-col :xs="24" :sm="12" :lg="12" :offset="0">
  188. <el-button type="primary" size="small" @click="handleSubmit"
  189. >保存</el-button
  190. >
  191. </el-col>
  192. <el-col :xs="24" :sm="12" :lg="12" :offset="0" class="tr">
  193. <el-button type="primary" size="small" @click="hanleAddModel"
  194. >添加</el-button
  195. >
  196. <el-button type="primary" size="small" @click="handleresale"
  197. >重置</el-button
  198. >
  199. </el-col>
  200. </el-row>
  201. </el-footer>
  202. <el-dialog :visible.sync="VisibleModle" width="70%" center>
  203. <div>
  204. <el-container>
  205. <el-header height="">
  206. <el-form label-width="0" :inline="false" size="small">
  207. <el-col :xs="24" :sm="8" :lg="8" :offset="0">
  208. <el-form-item label="">
  209. <el-input
  210. v-model="saleTypeCode"
  211. placeholder="类型编号"
  212. ></el-input>
  213. </el-form-item>
  214. </el-col>
  215. </el-form>
  216. </el-header>
  217. <el-main height="">
  218. <el-row>
  219. <el-row :gutter="50">
  220. <el-col :xs="10" :ms="10" :lg="10">
  221. <el-row>
  222. <el-row> </el-row>
  223. <el-row>
  224. <el-row class="title"> 可选产品列表 </el-row>
  225. <el-table
  226. style="width: 100%"
  227. :data="conditList"
  228. border
  229. height="400"
  230. @select-all="handleSelectionAllChange"
  231. @selection-change="handleSelectionChange"
  232. >
  233. <el-table-column
  234. type="selection"
  235. width="55"
  236. align="center"
  237. >
  238. </el-table-column>
  239. <el-table-column
  240. label="产品编码"
  241. prop="materialNumber"
  242. width="120"
  243. align="center"
  244. >
  245. </el-table-column>
  246. <el-table-column
  247. prop="materialName"
  248. label="产品名称"
  249. align="center"
  250. >
  251. </el-table-column>
  252. <el-table-column
  253. prop="specification"
  254. label="产品型号"
  255. align="center"
  256. >
  257. </el-table-column>
  258. <el-table-column
  259. prop="price"
  260. label="产品价格"
  261. align="center"
  262. >
  263. </el-table-column>
  264. </el-table>
  265. <el-row class="mg">
  266. <div>
  267. <el-pagination
  268. @size-change="handleSizeChange"
  269. @current-change="handleCurrentChange"
  270. :current-page="currentPage"
  271. :page-sizes="[10, 20, 30, 50]"
  272. :page-size="10"
  273. layout="total, sizes, prev, pager, next, jumper"
  274. :total="listTotal"
  275. >
  276. </el-pagination>
  277. </div>
  278. </el-row>
  279. </el-row>
  280. </el-row>
  281. </el-col>
  282. <el-col :xs="4" :ms="4" :lg="4" class="middle">
  283. <el-row :gutter="20" justify="center" align="middle">
  284. <el-row class="btn">
  285. <el-button
  286. type="primary"
  287. size="small "
  288. @click="handleAllAdd"
  289. :disabled="type == 2"
  290. >全部添加</el-button
  291. >
  292. </el-row>
  293. <el-row class="btn">
  294. <el-button
  295. type="primary"
  296. size="small "
  297. @click="handleAdd"
  298. :disabled="type == 2"
  299. >增加</el-button
  300. >
  301. </el-row>
  302. <el-row class="btn">
  303. <el-button
  304. type="primary"
  305. size="small "
  306. @click="handleDelete"
  307. :disabled="type == 1"
  308. >删除</el-button
  309. ></el-row
  310. >
  311. <el-row class="btn"
  312. ><el-button
  313. :disabled="type == 1"
  314. type="primary"
  315. size="small "
  316. @click="handleAllDelete"
  317. >全部删除</el-button
  318. ></el-row
  319. >
  320. </el-row>
  321. </el-col>
  322. <el-col :xs="10" :ms="10" :lg="10">
  323. <el-row>
  324. <el-row> </el-row>
  325. <el-row>
  326. <el-row class="title"> 已选产品列表 </el-row>
  327. <el-table
  328. style="width: 100%"
  329. :data="conditList2"
  330. @select-all="handleSelectionAllChange2"
  331. @selection-change="handleSelectionChange2"
  332. border
  333. height="400"
  334. >
  335. <el-table-column
  336. type="selection"
  337. width="55"
  338. align="center"
  339. >
  340. </el-table-column>
  341. <el-table-column
  342. label="产品编码"
  343. prop="materialNumber"
  344. width="120"
  345. align="center"
  346. >
  347. </el-table-column>
  348. <el-table-column
  349. prop="materialName"
  350. label="产品名称"
  351. align="center"
  352. >
  353. </el-table-column>
  354. <el-table-column
  355. prop="specification"
  356. label="产品型号"
  357. align="center"
  358. >
  359. </el-table-column>
  360. <el-table-column
  361. prop="price"
  362. label="产品价格"
  363. align="center"
  364. >
  365. </el-table-column>
  366. </el-table>
  367. <el-row class="mg">
  368. <!-- <Pagination /> -->
  369. </el-row>
  370. </el-row>
  371. </el-row>
  372. </el-col>
  373. </el-row>
  374. </el-row>
  375. </el-main>
  376. </el-container>
  377. </div>
  378. <span slot="footer" class="dialog-footer">
  379. <el-button @click="VisibleModle = false">取 消</el-button>
  380. <el-button type="primary" @click="handleDiaSubmit">确 定</el-button>
  381. </span>
  382. </el-dialog>
  383. </el-container>
  384. </template>
  385. <script>
  386. import {
  387. getId,
  388. addPoliyCondition,
  389. getConditionMaterialList,
  390. getMaterialList,
  391. getConditionMaterialDetail,
  392. } from "@/api/policy_list";
  393. import TabelTransfer from "./TabelTransfer.vue";
  394. import { mapState } from "vuex";
  395. import AddModel from "./AddModel";
  396. import Minxin from "@/mixin";
  397. export default {
  398. mixins: [Minxin],
  399. props: {
  400. id: {
  401. type: String,
  402. default: "",
  403. },
  404. policyId: {
  405. type: String,
  406. default: "",
  407. },
  408. },
  409. data() {
  410. return {
  411. base: {
  412. id: null,
  413. policyConditionMaterials: [
  414. {
  415. id: null,
  416. materialId: "",
  417. materialName: "",
  418. materialNumber: "",
  419. policyConditionId: "",
  420. policyId: "",
  421. policyMaterialId: "",
  422. popType: 0,
  423. specification: "",
  424. walletType: "",
  425. },
  426. ],
  427. policyId: "",
  428. policyName: "",
  429. pop: "",
  430. },
  431. limit: "",
  432. VisibleModle: false,
  433. conditionBox: [[], []],
  434. conditionBoxs: [],
  435. multipleSelection: [],
  436. searchForm: {
  437. code: "",
  438. },
  439. pop: "",
  440. conditList: [],
  441. leftData: [],
  442. rightData: [],
  443. conditList2: [],
  444. type: "",
  445. saleTypeCode: "",
  446. arrIndex: 0,
  447. popArr: {},
  448. };
  449. },
  450. created() {
  451. this.getCommonApi();
  452. },
  453. computed: mapState({
  454. comCode: (state) => state.sales.code,
  455. }),
  456. updated() {},
  457. methods: {
  458. getList() {},
  459. handleBack() {
  460. if (this.$parent.isShow == 10) {
  461. this.$parent.isShow = 8;
  462. } else {
  463. this.$parent.isCondition = 0;
  464. }
  465. },
  466. getCommonApi() {
  467. if (this.id) {
  468. getConditionMaterialDetail({ id: this.policyId }).then((res) => {
  469. this.pop = res.data.pop;
  470. let pop = res.data.pop.split(":");
  471. for (let i = 0; i < pop.length; i++) {
  472. if (i == 0) {
  473. this.limit = pop[i];
  474. continue;
  475. }
  476. this.$set(this.popArr, `line_${i - 1}`, pop[i]);
  477. }
  478. console.log(this.popArr);
  479. for (let k = 0; k < pop.length; k++) {
  480. getConditionMaterialList({
  481. pageNum: 1,
  482. pageSize: -1,
  483. policyConditionId: res.data.id,
  484. popType: k + 1,
  485. }).then((res) => {
  486. this.conditionBoxs.push(res.data.records);
  487. });
  488. }
  489. console.log(this.conditionBoxs);
  490. });
  491. }
  492. },
  493. toggleSelection(rows) {
  494. if (rows) {
  495. rows.forEach((row) => {
  496. this.$refs.multipleTable.toggleRowSelection(row);
  497. });
  498. } else {
  499. this.$refs.multipleTable.clearSelection();
  500. }
  501. },
  502. hanleAddModel() {
  503. this.conditionBox.push([{}]);
  504. },
  505. handleSubmit() {
  506. var tableData = [];
  507. for (let i = 0; i < this.conditionBox.length; i++) {
  508. for (let j = 0; j < this.conditionBox[i].length; j++) {
  509. this.conditionBox[i][j].popType = i + 1;
  510. this.conditionBox[i][j].policyId = this.comCode;
  511. this.conditionBox[i][j].id = "";
  512. // this.conditionBox[i][j].policyMaterialId =this.conditionBox[i][j].materialId
  513. }
  514. tableData = [...tableData, ...this.conditionBox[i]];
  515. }
  516. if (!tableData.length) {
  517. this.$errorMsg("请选择机型");
  518. return;
  519. }
  520. var pop = [this.limit];
  521. for (const key in this.popArr) {
  522. pop.push(this.popArr[key]);
  523. }
  524. console.log(pop.join(":"));
  525. const params = {
  526. id: "",
  527. policyConditionMaterials: tableData,
  528. policyId: this.comCode,
  529. policyName: "",
  530. pop: pop.join(":"),
  531. };
  532. addPoliyCondition(params).then((res) => {
  533. this.$successMsg("添加成功");
  534. this.$parent.isCondition = 0;
  535. this.$parent.isFlag = 1;
  536. this.$emit("handleSubmitCon", this.comCode);
  537. });
  538. },
  539. handleSelectionChange(val) {
  540. this.multipleSelection = val;
  541. },
  542. // 筛选全部数据
  543. hanleSelectAll(selection, index) {
  544. this.arrIndex = index;
  545. this.ids = selection.map((k) => {
  546. return k.id;
  547. });
  548. console.log(this.ids);
  549. },
  550. handleDeleteRow(index) {
  551. if (this.arrIndex == index && this.ids.length) {
  552. for (let i = 0; i < this.conditionBox[index].length; i++) {
  553. for (let j = 0; j < this.ids.length; j++) {
  554. if (this.conditionBox[index][i].id == this.ids[j]) {
  555. this.conditionBox[index].splice(i, 1);
  556. }
  557. }
  558. }
  559. }
  560. console.log(index, this.arrIndex);
  561. },
  562. getMaterialLists(index) {
  563. this.arrIndex = index;
  564. getMaterialList({
  565. pageNum: this.currentPage,
  566. pageSize: this.pageSize,
  567. saleTypeCode: this.saleTypeCode,
  568. policyId: this.comCode,
  569. }).then((res) => {
  570. this.conditList = res.data.records;
  571. console.log(4545, this.conditList);
  572. this.listTotal = res.data.total;
  573. });
  574. },
  575. handleSelectionAllChange(e) {
  576. this.leftData = e;
  577. this.type = 1;
  578. },
  579. handleSelectionChange(e) {
  580. this.leftData = e;
  581. this.type = 1;
  582. },
  583. handleSelectionAllChange2(e) {
  584. this.rightData = e;
  585. this.type = 2;
  586. },
  587. handleSelectionChange2(e) {
  588. this.rightData = e;
  589. this.type = 2;
  590. },
  591. handleAllAdd() {
  592. this.conditList2 = this.leftData;
  593. this.leftData = [];
  594. },
  595. handleAllDelete() {
  596. this.conditList2 = [];
  597. },
  598. handleAdd() {
  599. this.conditList2 = this.leftData;
  600. },
  601. handleDelete() {
  602. if (this.type == 2) {
  603. for (let k = 0; k < this.conditList2.length; k++) {
  604. for (let i = 0; i < this.rightData.length; i++) {
  605. if (this.rightData[i].id == this.rightData[k].id) {
  606. this.conditList2.splice(i, 1);
  607. }
  608. }
  609. }
  610. }
  611. },
  612. handleDiaSubmit() {
  613. if (this.conditList2.length) {
  614. for (let i = 0; i < this.conditionBox.length; i++) {
  615. console.log(this.conditionBox[i]);
  616. if (i == this.arrIndex) {
  617. this.$set(this.conditionBox, i, [
  618. ...this.conditList2,
  619. ...this.conditionBox[i],
  620. ]);
  621. console.log(this.conditionBox);
  622. }
  623. }
  624. this.VisibleModle = false;
  625. this.conditList2 = [];
  626. } else {
  627. this.$errorMsg("请选择内容");
  628. }
  629. },
  630. handleresale() {
  631. Object.assign(this.$data, this.$options.data());
  632. },
  633. },
  634. components: {
  635. AddModel,
  636. TabelTransfer,
  637. },
  638. };
  639. </script>
  640. <style lang="scss" scoped>
  641. .line {
  642. margin: 0 20px;
  643. }
  644. .mgb {
  645. margin-bottom: 20px;
  646. }
  647. .pdt {
  648. padding-bottom: 20px;
  649. }
  650. .text_rihgt {
  651. text-align: right;
  652. }
  653. .header {
  654. margin-bottom: 40px;
  655. }
  656. .el-main {
  657. overflow: hidden;
  658. }
  659. .btn {
  660. margin: 20px 0;
  661. text-align: center;
  662. }
  663. .query_btn {
  664. margin-left: 0;
  665. }
  666. .mg {
  667. margin: 20px;
  668. }
  669. .pdt {
  670. margin: 20px 0;
  671. }
  672. .el-main {
  673. overflow: hidden;
  674. }
  675. .middle {
  676. height: 430px;
  677. display: flex;
  678. align-content: center;
  679. justify-content: center;
  680. align-items: center;
  681. }
  682. .title {
  683. padding: 10px 0;
  684. text-align: center;
  685. border-left: 1px solid #ebeef5;
  686. border-right: 1px solid #ebeef5;
  687. border-top: 1px solid #ebeef5;
  688. }
  689. </style>