实现省市二级联动效果

快来打我* 2022-10-10 12:32 348阅读 0赞

实现效果:
在这里插入图片描述
代码:

  1. <template>
  2. <div class="main_tableau">
  3. <div class="page_title">百城精算编辑</div>
  4. <CFlex type="flex" justify="space-between">
  5. <div style="margin-top:15px;">
  6. <div class="top_box" style=" font-weight: bold;">
  7. 选择区域
  8. </div>
  9. <div class="top_box">
  10. <span>已选区域:</span>
  11. <span class="margin_citys" v-for="(item, index) in city" :key="index" >{
  12. { item }}
  13. <span class="margin_citys_delete" @click="citydelete(index)" >x</span ></span >
  14. <!-- <span class="margin_c_d" @click="clear">清空</span> -->
  15. </div>
  16. </div>
  17. </CFlex>
  18. <!-- 多选区域 -->
  19. <div class="deliverySetting" style="z-index:0px">
  20. <div class="content" :style="openShow ? 'max-height:1000px;' : ''" >
  21. <div class="content_between">
  22. <div style="margin-top:10px">
  23. <el-checkbox :indeterminate="indeterminate" v-model="ischeckAll" @change="handleCheckAllChange" ></el-checkbox>
  24. 全选
  25. </div>
  26. <div style="margin-top:10px">
  27. <div class="openShow" @click="openShow = !openShow">
  28. <span>
  29. <img :class="openShow ? 'openShow_transition' : ''" src="@/assets/svg/icon_展开.svg" />
  30. <span v-show="!openShow" style="cursor: pointer;">展开</span>
  31. <span v-show="openShow" style="cursor: pointer;">收起</span>
  32. </span>
  33. </div>
  34. </div>
  35. </div>
  36. <div>
  37. <CFlex class="project_info_content">
  38. <div class="project_info_content_dataa " >
  39. <CollapseTransition>
  40. <div v-show="openShow" class="project_info_content_dataa" style="width:100%;padding:10px;overflow:visible" >
  41. <div class="table-body" v-for="(partition, partitionIndex) in distributorsInfo" :key="partitionIndex" >
  42. <div class="selection" style="z-index:0px">
  43. <el-checkbox :indeterminate="partition.indeterminate" v-model="partition.selected" @change=" handleCheckedCountryAllChange( partitionIndex, partition, $event ) " :key="partitionIndex" ></el-checkbox>
  44. <span @click="isopenshow(partitionIndex)">
  45. {
  46. { partition.value }}
  47. </span>
  48. </div>
  49. <div class="width265" v-if="partition.actived" style="z-index:1000px" >
  50. <el-checkbox v-for="children in partition.children" :key="children.value" v-model="children.selected" @change=" handleCheckedCountryChange( partitionIndex, children, $event ) " :label="children" >{
  51. { children.value }}</el-checkbox >
  52. </div>
  53. </div>
  54. </div>
  55. </CollapseTransition>
  56. </div>
  57. </CFlex>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- Table 栏 -->
  62. <div style="margin-top:20px;">
  63. <div class="top_box" style=" font-weight: bold;">
  64. 选择药品
  65. </div>
  66. <div class="top_box" style=" font-weight: bold;">
  67. <div class="search">
  68. <div class="search_content">
  69. <Form :model="formItem" :label-width="85" inline>
  70. <FormItem label="疾病种类:" style="margin-bottom:0px;">
  71. <Input v-model.trim="searchData.virustype" />
  72. </FormItem>
  73. <FormItem label="药品名称:" style="margin-bottom:0px;">
  74. <Input v-model.trim="searchData.drugstype" />
  75. </FormItem>
  76. </Form>
  77. </div>
  78. <div class="search_btns">
  79. <CButton type="default" @click.native="reset">重置</CButton>
  80. <CButton type="primary" @click.native="searchUserData()" style="margin-left: 8px;width:0px;height:0px" >查找</CButton >
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <Table class="table" ref="selection" :columns="columns4" :data="data1" @on-selection-change="handleSelectAll" @on-select-cancel="cancel" @on-select="change" ></Table>
  86. <div class="page_bottom">
  87. <Page :total="count" @on-change="onchangePage" :page-size="pageSize" :current="page">
  88. </Page>
  89. </div>
  90. <div class="vw_bottom">
  91. <CButton @click.native="remove" style="padding-right:10px;">取消</CButton>
  92. <CButton type="primary" @click.native="Submit">保存</CButton>
  93. </div>
  94. </div>
  95. </template>
  96. <script> import Api from "../../api/isip/hundredcitiesactuarial"; import ChinaAddressV4Data from "@/datas/china_address_other"; import CollapseTransition from "@/components/transition/collapse-transition"; // import api from '../schedulePlan/actuarialModel/api'; export default { name: "edithundredcity", components: { CollapseTransition, }, data() { return { city: [], projectid: this.$route.query.projectId, versionId: "v01", //省 province: "", //市 citys: "", // actuaryCityInfos: [], // 多选 // sonIdlist: [], // sonId:'', openShow: true, distributorsInfo: "", ischeckAll: false, indeterminate: false, // 多选数据回收 overalldata: [], // 展开与隐藏 Provinces: ChinaAddressV4Data, // table 数据 searchData: { virustype: "", drugstype: "", }, page: 1, pageSize: 10, count: 0, //总条数 columns4: [ { type: "selection", width: 60, align: "center", }, { title: "商品名", key: "drugN", align: "center", }, { title: "通用名", key: "drugName", align: "center", }, { title: "厂商", key: "drugProductor", align: "center", }, { title: "疾病种类", key: "cancerType", align: "center", }, { title: "适应症限制", key: "indication", align: "center", }, { title: "选药优先级", key: "chooseDrugPri", align: "center", }, ], data1: [], ids: [], idss: [], }; }, mounted() { this.getCitys(); this.querylist(); this.getActuaryDrugSalesInfos(); }, methods: { querylist() { let data = { cancerType: this.searchData.virustype, drugName: this.searchData.drugstype, pageSize: this.pageSize, page: this.page, }; new Promise((resolve, reject) => { Api.getChoosedDrugInfos(data) .then((response) => { this.data1 = response.result.records.map((item) => { item._checked = (this.ids && this.ids.includes(item.id)) || false; return item; }); this.count = response.result.total; }) .catch((error) => { reject(error); }); }); }, citydelete(index) { this.city.splice(index, 1); }, // clear() { // console.log("清除"); // }, reset() { (this.searchData.virustype = ""), (this.searchData.drugstype = ""), this.querylist(); }, //查找 searchUserData() { let data = { cancerType: this.searchData.virustype, drugName: this.searchData.drugstype, pageSize: this.pageSize, page: this.page, }; console.log(this.ids); new Promise((resolve, reject) => { Api.getChoosedDrugInfos(data) .then((response) => { this.data1 = response.result.records.map((item) => { item._checked = (this.ids && this.ids.includes(item.id)) || false; return item; }); }) .catch((error) => { reject(error); }); }); }, // 全选反选 handleSelectAll(status) { status.forEach((item)=>{ this.ids.push(item.id) }) // this.ids = status }, //勾选 change(item) { item.forEach((data) => { this.idss.push(data.id); }); for (let i = 0; i < this.idss.length; i++) { if (this.ids.indexOf(this.idss[i]) == -1) { this.ids.push(this.idss[i]); } } }, //取消勾选 cancel(item, row) { let index = this.ids.indexOf(row.id); this.ids.splice(index, 1); }, onchangePage(page) { this.page = page; this.querylist(); }, remove() { this.$router.push({ path: "/hundredactuarial", }); }, Submit() { this.$Spin.show({ render: (h) => { return h("div", [ h("Icon", { class: "demo-spin-icon-load", props: { type: "ios-loading", size: 18, }, }), h("div", "系统努力运算中,请稍等…"), ]); }, }); setTimeout(() => { this.$Spin.hide(); }, 2000); let arr = []; this.distributorsInfo.map((item) => { item.children.map((cityitem) => { let isd = { }; if (cityitem.selected) { isd.province = item.value; isd.city = cityitem.value; arr.push(isd); } }); }); let data = { actuaryCityInfos: arr, ids: this.ids, }; // if(this.ids=[]){ // this.$Modal.info('药品没选') // } // if(this.actuaryCityInfos = []){ // this.$Modal.info('城市没有选择') // } // if(data = []){ // this.$Modal.info('请选择您的城市和药品') // } new Promise((reslove, resject) => { Api.saveActuaryWord(data) .then((rp) => { this.$router.go(-1); }) .catch((error) => { }); }); }, // 多选 handleCheckAllChange(e) { //一级change事件 this.ischeckAll = e; this.indeterminate = false; for (var i = 0, len = this.distributorsInfo.length; i < len; i++) { //二级全选反选 this.distributorsInfo[i].selected = e; this.distributorsInfo[i].indeterminate = false; //去掉二级不确定状态 for ( var j = 0, len1 = this.distributorsInfo[i].children.length; j < len1; j++ ) { //三级全选反选 this.distributorsInfo[i].children[j].selected = e; } } }, handleCheckedCountryAllChange(index, sonId, e) { console.log("父级", index, sonId, e); //二级change事件 this.distributorsInfo[index].selected = e; //二级勾选后,子级全部勾选或者取消 this.distributorsInfo[index].indeterminate = false; //去掉二级不确定状态 var childrenArray = this.distributorsInfo[index].children; if (childrenArray) for (var i = 0, len = childrenArray.length; i < len; i++) childrenArray[i].selected = e; this.getIsCheckAll(); //省 // if (sonId.selected == true) { // this.distributorsInfo.push(sonId); // } }, handleCheckedCountryChange(topIndex, sonId, e) { console.log("子级", topIndex, sonId, e); //三级change事件 var childrenArray = this.distributorsInfo[topIndex].children; var tickCount = 0, unTickCount = 0, len = childrenArray.length; for (var i = 0; i < len; i++) { if (sonId == childrenArray[i].value) childrenArray[i].selected = e; if (childrenArray[i].selected == true) tickCount++; if (childrenArray[i].selected == false) unTickCount++; } if (tickCount == len) { //三级级全勾选 this.distributorsInfo[topIndex].selected = true; this.distributorsInfo[topIndex].indeterminate = false; } else if (unTickCount == len) { //三级级全不勾选 this.distributorsInfo[topIndex].selected = false; this.distributorsInfo[topIndex].indeterminate = false; } else { this.distributorsInfo[topIndex].selected = false; this.distributorsInfo[topIndex].indeterminate = true; //添加二级不确定状态 } this.getIsCheckAll(); // if (sonId.selected == true){ // this.distributorsInfo.push(sonId); // } }, getIsCheckAll() { var tickCount = 0, unTickCount = 0, indeterminateCount = 0, ArrLength = this.distributorsInfo.length; for (var j = 0; j < ArrLength; j++) { //全选checkbox状态 if (this.distributorsInfo[j].selected == true) tickCount++; if (this.distributorsInfo[j].selected == false) unTickCount++; if (this.distributorsInfo[j].indeterminate == true) indeterminateCount++; } if (tickCount == ArrLength) { //二级全勾选 this.ischeckAll = true; this.indeterminate = false; } else if (unTickCount == ArrLength) { //二级全不勾选 this.ischeckAll = false; if (indeterminateCount > 0) { this.indeterminate = true; } else { this.indeterminate = false; } } else { this.ischeckAll = false; this.indeterminate = true; //添加一级不确定状态 } }, // 展示与隐藏 isopenshow(activedIndex) { this.distributorsInfo.filter(function(value, index, arr) { return activedIndex === index ? (value.actived = !value.actived) : (value.actived = false); }); }, //省市e getCitys() { new Promise((reslove, resject) => { Api.getCitys() .then((rp) => { let arr = []; rp.result.map((item) => { let a = { }; a.actived = false; a.selected = false; a.value = item.city; a.children = []; arr.push(a); item.children.map((item) => { let b = { }; b.selected = false; b.value = item.city; a.children.push(b); }); }); this.distributorsInfo = arr; this.getActuaryDrugSalesInfos(this.distributorsInfo); }) .catch((error) => { }); }); }, //回显数据 getActuaryDrugSalesInfos(arry) { console.log(arry); let data = { }; return new Promise((resolve, resject) => { Api.getActuaryDrugSalesInfos(data) .then((rp) => { console.log(rp); //回显的数据 // this.distributorsInfo = rp.result.actuaryCityInfos let data = rp.result.actuaryCityInfos; data.forEach((item) => { if (this.city.indexOf(item.province) == -1) { this.city.push(item.province); } arry.forEach((it) => { if (item.province == it.value) { it.selected = true; } it.children.forEach((im) => { if (item.city == im.value) { im.selected = true; } }); }); }); }) .catch((error) => { }); }); }, }, }; </script>
  97. <style lang="less" scoped> @import "hundrecity.less"; .page_title { font-size: 25px; color: #333333; font-weight: 500; } .main_tableau { position: relative; margin-top: 10px; padding: 10px; } /deep/ .cus_btn_primary { width: 150px; height: 50px; } .top_box { font-size: 18px; margin-top: 8px; .margin_citys { padding: 7px; font-size: 15px; font-weight: bold; background: #eeeeee; margin-right: 20px; .margin_citys_delete { background: #ccc; padding: 2px; cursor: pointer; border-radius: 15px; color: #ffffff; display: inline-block; height: 15px; line-height: 10px; } } .margin_c_d { cursor: pointer; color: white; padding: 10px 30px; font-size: 15px; font-weight: bold; background: #156cee; border-radius: 15px; margin-right: 20px; } } </style>
  98. <style lang="less" scoped> .content { margin-top: 20px; width: 100%; z-index: 0px !important; .content_between { border-top-left-radius: 8px; border-top-right-radius: 8px; padding: 5px 10px; box-shadow: 1px 1px 5px 0 #a0a0a0; border-bottom: 1px solid #ccc; display: flex; justify-content: space-between; } } .project_info_content { box-shadow: 1px 1px 5px 0 #a0a0a0; border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; border-top: none; background: #ffffff; position: relative; transition: max-height 1s; max-height: 500px; .project_info_content_data { display: flex; flex-wrap: wrap; // z-index: 0; // justify-content: space-between; > div { min-width: 150px; } } .project_info_content_dataa{ display: flex; flex-wrap: wrap; > div { min-width: 150px; } } .openShow { position: absolute; bottom: 20px; left: 20px; cursor: pointer; color: #156cee; user-select: none; img { transform: rotate(0deg); transition: transform 0.3s; } } } .openShow_transition { transform: rotate(180deg) !important; } .ivu-checkbox-wrapper { cursor: pointer; font-size: 14px; display: inline-block; padding-top: 10px; margin-right: 70px; } // table .search { display: flex; padding: 10px 0; .search_content { .item_class { width: 250px; padding: 5px; } } .search_item { width: 200px; margin-right: 20px; margin-bottom: 15px; } .search_btns { display: flex; } } /deep/ .cus_btn_primary { width: 60px; height: 35px; } .page_bottom { display: flex; justify-content: flex-end; padding-bottom: 10px; } .table { border-radius: 8px; box-shadow: 0px 5px 20px 0px rgba(0, 0, 0, 0.1); margin-bottom: 20px; } .vw_bottom { position: absolute; bottom: -30px; right: 10px; /* margin-bottom: 10px; */ padding-bottom: 5px; } .chec_box { padding: 10px 0; // padding-right: 50px; // position: relative; } .table-body { position: relative; .selection { padding: 5px 0; cursor: pointer; } .width265 { width: 250px; padding: 10px; border-radius: 10px; z-index: 10 !important; background: #ffffff; box-shadow: 0px 5px 20px 0px rgba(0, 0, 0, 0.1); position: absolute; } } </style>
  99. <style lang="less" scoped> .demo-spin-icon-load { animation: ani-demo-spin 1s linear infinite; } /deep/ .project_info_content_dataa{ visibility: visible !important; overflow: visible !important; } </style>

发表评论

表情:
评论列表 (有 0 条评论,348人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Java数组实现省市二级联动

    数组的强大之处毋庸置疑,今天我要写的是用一个一维数组和一个二维数组来实现一个省市二级联动的功能。 1.首先定义一个一维数组,用来存放34个省级行政区域;定义一个二维数组,用来