EditCondition.vue 20 KB

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