瀏覽代碼

城市部分修改

lrf402788946 5 年之前
父節點
當前提交
8ce0a6398c
共有 3 個文件被更改,包括 187 次插入155 次删除
  1. 123 96
      src/components/tag-all-select.vue
  2. 57 57
      src/pages/student/views/resume/purpose.vue
  3. 7 2
      src/store/dictionary.js

+ 123 - 96
src/components/tag-all-select.vue

@@ -8,38 +8,37 @@
         </span>
         <span v-else>
           <span v-for="(item, index) in selected" :key="index" style="margin-right:0.1rem;font-size:0.75rem">
-            {{ item.label }}
+            {{ item.name }}
           </span>
         </span>
       </el-col>
     </el-row>
-    <el-dialog title="选择城市" :visible.sync="dialog" :fullscreen="true" :show-close="false">
+    <el-dialog :visible.sync="dialog" :fullscreen="true" :show-close="false">
+      <template #title>
+        <el-row type="flex" align="middle">
+          <el-col :span="6" class="el-icon-back" style="zoom:1.5" @click.native="dialog = false"></el-col>
+          <el-col :span="12" style="text-align:center;">选择城市</el-col>
+        </el-row>
+      </template>
       <el-row style="background:#ffffff;">
         <el-col :span="24" v-if="selectList.length > 0">
           <el-tag v-for="(item, index) in selected" :key="index" @click="tagClose(item)" style="margin-right:0.8rem;" :disable-transitions="true">
-            {{ item.label }}
+            {{ item.name }}
           </el-tag>
         </el-col>
         <el-col :span="24" style="width:100%;text-align:center;" v-else>请选择城市</el-col>
       </el-row>
       <el-row>
         <el-col :span="8">
-          <el-menu
-            background-color="#eee"
-            @select="
-              item => {
-                selectChange(item, 'first');
-              }
-            "
-          >
-            <el-menu-item v-for="(item, index) in firstList" :key="index" :index="item.label">
-              {{ item.label }}
-            </el-menu-item>
-          </el-menu>
+          <el-row class="firstMenu">
+            <el-col :span="24" v-for="(item, index) in firstList" :key="index" @click.native="selectChange(item.name, 'first')">
+              {{ item.name }}
+            </el-col>
+          </el-row>
         </el-col>
         <el-col :span="15">
           <span v-for="(item, index) in secondList" :key="index">
-            <el-button class="word" type="primary" size="mini" @click="selectChange(item.label, 'second')">{{ item.label }}</el-button>
+            <el-button class="word" type="primary" size="mini" @click="selectChange(item.name, 'second')">{{ item.name }}</el-button>
           </span>
         </el-col>
       </el-row>
@@ -58,31 +57,30 @@ export default {
   name: 'tag-all-select',
   props: {
     title: { type: String },
-    selected: { type: Array, default: () => [] }, //已选项
+    selected: null, //已选项
     placeholder: { type: String, default: '请选择' }, //提示
     firstList: { type: Array, default: () => [] }, //一级选项列表
     secondList: { type: Array, default: () => [] }, //二级选项列表
-    type: { type: String, default: '' },
+    type: { type: String },
   },
   components: {},
   data: () => ({
     dialog: false,
+    activeNames: '',
     selectList: [],
+    displayList: [],
   }),
   created() {
-    if (this.selected.length > 0) {
+    if (this.selected && this.selected.length > 0) {
       this.defaultProcess();
     }
   },
   watch: {
     selected: {
       handler(val, oval) {
-        if (val.length > 0) {
-          let dif = _.difference(val, oval);
-          let key = Object.keys(val[0]);
-          if (dif.length > 0) {
-            this.defaultProcess();
-          }
+        let dif = _.difference(val, oval);
+        if (dif.length > 0) {
+          this.defaultProcess();
         }
       },
     },
@@ -90,94 +88,94 @@ export default {
   computed: {},
   methods: {
     //一/二级选择方法
-    selectChange(value, type) {
-      //先查下之前有没有,有的话就过滤出去
+    selectChange(val, type) {
+      this.checkSelect(val, type);
+      let list = _.get(this, `${type}List`);
+      let select = list.filter(fil => fil.name === val);
+      if (select.length > 0) {
+        val = select[0].code;
+      }
       if (type === 'first') {
-        this.processProvince(value, type);
+        this.processProvince(val);
       } else {
-        let result = this.checkHas(value);
-        if (!result) {
-          return false;
-        }
-        this.processCity(value, type);
+        this.processCity();
       }
     },
     //处理直辖/省份
-    processProvince(value, type) {
-      //换成dialog后,是自己添加自己删除,不能用之前的数据了
-      //1,到这,说明这个数据没有被点过,应该看看此数据是被添加或者查找子列表
-      let hasCity = this.haveCity(value);
-      if (hasCity) {
-        //这不是直辖市/城市,查城市列表,不能将此选项当做可选项添加
-        let data = this.firstList.filter(item => item.label === value);
-        this.$emit('listChange', { value: data.length > 0 ? data[0] : undefined, type: this.type });
-        return;
-      }
-      //2直辖市查重
-      let result = this.checkHas(value);
-      if (!result) {
-        return false;
+    processProvince(val) {
+      //查下这个值是不是省份,是省份就干掉,不是省份再看是不是直辖市
+      let res = this.haveCity(val);
+      if (res) {
+        //不是直辖市,干掉,查询
+        let newArr = _.difference(this.selectList, [val]);
+        this.$set(this, `selectList`, newArr);
+        this.$emit(`listChange`, { type: this.type, val: val });
+      } else {
+        this.processCity();
       }
-      //3说明这个选项是可以添加的选项,添加
-      this.processCity(value, type);
     },
-    //看着名很咋地,其实就是同步数据
-    processCity(value, type) {
-      let filList = _.get(this, `${type}List`);
-      let object = filList.filter(item => item.label === value)[0];
-      this.selectList.push(object);
-      this.disFilter();
-    },
-    //查重,取消选择
-    checkHas(value) {
-      let dataList = this.selected.filter(item => item.label !== value);
-      //判断筛选后的数据和原数据是否一致,一致说明不是删除,需要继续处理;不一致说明这个选项之前选过了.干掉它,直接结束
-      if (dataList.length !== this.selected.length) {
-        //删除掉这个
-        this.$set(this, `selectList`, dataList);
-        this.$emit('selectChange', { value: dataList, type: this.type });
-        return false; //删除,不用继续进行了
+    checkSelect(val, type) {
+      let arr = [];
+      let list = _.get(this, `${type}List`);
+      let select = list.filter(fil => fil.name === val);
+      if (!select.length > 0) {
+        return;
       }
-      return true;
-    },
-    //初始化处理
-    defaultProcess() {
-      //处理复选框
-      let select = this.selected.filter(item => item.value !== undefined);
-      if (select.length > 0) {
-        // let result = this.selected.map(item => item.value);
-        this.$set(this, `selectList`, select);
+      let result = this.selectList.filter(fil => fil === select[0].code);
+      if (result.length > 0) {
+        arr = this.selectList.filter(item => item !== result[0]);
+        this.$set(this, `selectList`, arr);
+        return false;
       } else {
-        let result = this.selected.map(item => {
-          return this.defalutSearch(item);
-        });
-        this.disFilter(result);
+        this.selectList.push(select[0].code);
       }
     },
-    //显示处理;选择值
-    disFilter() {
-      this.$emit('selectChange', { value: this.selectList, type: this.type });
+    //看着名很咋地,其实就是同步数据
+    processCity() {
+      let newArr = [];
+      this.selectList.map(item => {
+        let result = this.firstList.filter(fil => fil.code === item);
+        if (result.length > 0) {
+          result.forEach(res => {
+            newArr.push(res);
+          });
+        } else {
+          result = this.secondList.filter(fil => fil.code === item);
+          if (result.length > 0) {
+            result.forEach(res => {
+              newArr.push(res);
+            });
+          } else {
+            result = this.displayList.filter(fil => fil.code === item);
+            if (result.length > 0) {
+              result.forEach(res => {
+                newArr.push(res);
+              });
+            }
+          }
+        }
+      });
+      this.disFilter(newArr);
     },
     //关闭标签方法
-    tagClose(value) {
-      console.log(value);
+    tagClose(val) {
       //取消选择
-      let leastList = this.selectList.filter(item => item.label !== value.label);
-      console.log(leastList);
+      let leastList = this.selectList.filter(item => item !== val.code);
+      let leastDisplayList = this.displayList.filter(item => item.code !== val.code);
       this.$set(this, `selectList`, leastList);
-      this.disFilter();
+      this.disFilter(leastDisplayList);
     },
     //是不是直辖市
     haveCity(item) {
-      let value;
+      let code;
       if (typeof item === 'object') {
-        value = item.value;
+        code = item.code;
       } else {
-        value = item;
+        code = item;
       }
-      if (value === '北京市') {
+      if (code === '110000' || code === '120000' || code === '310000' || code === '500000' || code === '710000' || code === '810000' || code === '820000') {
         return false;
-      } else if (value === '吉林省' || value === '沈阳省') {
+      } else if (code.indexOf('0000') > 0) {
         return true;
       } else {
         return false;
@@ -187,13 +185,34 @@ export default {
     changeDisplay() {
       this.$set(this, `dialog`, !this.dialog);
     },
-    defalutSearch(label) {
-      console.log(label);
-      let result = this.firstList.filter(fil => fil.label === label);
+    //初始化处理
+    defaultProcess() {
+      //处理复选框
+      if (!_.isObject(this.selected)) return;
+      let select = this.selected.filter(item => item.code !== undefined);
+      if (select.length > 0) {
+        let result = this.selected.map(item => item.code);
+        this.$set(this, `selectList`, result);
+        //处理显示
+        this.$set(this, `displayList`, this.selected);
+      } else {
+        let result = this.selected.map(item => {
+          return this.defalutSearch(item);
+        });
+        this.disFilter(result);
+      }
+    },
+    //显示处理;选择值
+    disFilter(val) {
+      this.$emit('selectChange', { val: val, type: this.type });
+      this.$set(this, `displayList`, val);
+    },
+    defalutSearch(name) {
+      let result = this.firstList.filter(fil => fil.name === name);
       if (result.length > 0) {
         return result[0];
       } else {
-        result = this.secondList.filter(fil => fil.label === label);
+        result = this.secondList.filter(fil => fil.name === name);
         if (result.length > 0) {
           return result[0];
         }
@@ -209,7 +228,15 @@ export default {
 }
 .firstMenu {
   background: #c9cacf;
-  border: 0.0625rem solid #e7e8ec;
+  border: 1px solid #e7e8ec;
+  height: 50vh;
+  overflow-y: scroll;
+  .el-col {
+    text-align: center;
+    padding: 0.5rem 0;
+    height: 2rem;
+    border-bottom: 1px solid #aaa;
+  }
 }
 /deep/.el-collapse-item__header {
   height: 0;

+ 57 - 57
src/pages/student/views/resume/purpose.vue

@@ -17,7 +17,7 @@
           <el-col :span="6">&nbsp;</el-col>
         </el-row>
       </template>
-      <el-row v-for="(item, index) in hyList" :key="index" @click.native="choose(item.name, 'isVisible', 'industry')" class="select__options">
+      <el-row v-for="(item, index) in hylbList" :key="index" @click.native="choose(item.name, 'isVisible', 'industry')" class="select__options">
         <el-col :span="20" style="text-indent: 1.25rem;">{{ item.name }}</el-col>
         <el-col :span="4" style="text-align: center;">
           <nut-icon v-if="isChoose(item.name, 'industry')" type="tick"> </nut-icon>
@@ -33,7 +33,7 @@
           <el-col :span="6">&nbsp;</el-col>
         </el-row>
       </template>
-      <el-row v-for="(item, index) in classList" :key="index" @click.native="choose(item.name, 'isVisible', 'category')" class="select__options">
+      <el-row v-for="(item, index) in zwlbList" :key="index" @click.native="choose(item.name, 'isVisible', 'category')" class="select__options">
         <el-col :span="20" style="text-indent: 1.25rem;">{{ item.name }}</el-col>
         <el-col :span="4" style="text-align: center;">
           <nut-icon v-if="isChoose(item.name, 'category')" type="tick"> </nut-icon>
@@ -49,7 +49,7 @@
           <el-col :span="6">&nbsp;</el-col>
         </el-row>
       </template>
-      <el-row v-for="(item, index) in salaList" :key="index" @click.native="salaChoose(item.name, 'salary')" class="select__options">
+      <el-row v-for="(item, index) in xzdyList" :key="index" @click.native="salaChoose(item.name, 'salary')" class="select__options">
         <el-col :span="20" style="text-indent: 1.25rem;">{{ item.name }}</el-col>
         <el-col :span="4" style="text-align: center;">
           <nut-icon v-if="isChoose(item.name, 'salary')" type="tick"> </nut-icon>
@@ -177,10 +177,6 @@ export default {
     tagAllSelect,
   },
   data: () => ({
-    val: '',
-    val1: '',
-    val2: '',
-
     dHy: false,
     dType: false,
     dSala: false,
@@ -188,17 +184,18 @@ export default {
     info: {},
     loading: false,
     expect: {},
+    hylbList: [],
+    zwlbList: [],
+    xzdyList: [],
     hyList: [],
     classList: [],
-    salaList: [{ name: '4K' }, { name: '5K' }, { name: '6K' }, { name: '7K' }, { name: '8K' }, { name: '10K' }],
+    salaList: [],
     cityList: [],
     charList: [{ name: '和平型' }, { name: '稳定型' }, { name: '上进型' }, { name: '思考型' }],
-    provinceList: [{ label: '北京市', value: '110000' }, { label: '吉林省', value: '220000' }, { label: '沈阳省', value: '210000' }],
-    secondList: [{ label: '长春市', value: '220100' }, { label: '吉林市', value: '220200' }],
-    secondList1: [{ label: '沈阳市', value: '210100' }, { label: '大连市', value: '210200' }],
+    provinceList: [],
   }),
   created() {
-    this.otherList();
+    this.getOtherList();
     this.search();
   },
   computed: {
@@ -271,24 +268,14 @@ export default {
 
       return data;
     },
-    returnData(data) {
+    async returnData(data) {
       if (data.expect.city) {
         let ind = data.expect.city.split(',');
         let selected = [];
         for (const select of ind) {
-          let res = this.provinceList.filter(item => item.label === select);
-          if (res.length > 0) {
-            selected = [...selected, ...res];
-          } else {
-            let res = this.secondList.filter(item => item.label === select);
-            if (res.length > 0) {
-              selected = [...selected, ...res];
-            } else {
-              let res = this.secondList1.filter(item => item.label === select);
-              if (res.length > 0) {
-                selected = [...selected, ...res];
-              }
-            }
+          let result = await this.dicOperation({ name: select });
+          if (`${result.errcode}` === '0') {
+            selected.push(result.data);
           }
         }
         this.$set(this.expect, `city`, selected);
@@ -300,11 +287,6 @@ export default {
 
       this.switchActionSheet(sheet);
     },
-    cityChoose(item, sheet) {
-      this.$set(this.info, `city`, item);
-
-      this.switchActionSheet(sheet);
-    },
     choose(item, sheet, type) {
       let prop = _.get(this.expect, `${type}`);
       // console.log(prop);
@@ -343,47 +325,65 @@ export default {
       let prop = _.get(this.expect, `${type}`);
       return prop && prop.indexOf(item) >= 0;
     },
-    listChange({ value, type }) {
+    listChange({ val, type }) {
       //此方法是更换子列表的
-      if (value.value === '220000') {
-        this.$set(this, `cityList`, this.secondList);
-      } else if (value.value === '210000') {
-        this.$set(this, `cityList`, this.secondList1);
+      if (type === 'city') {
+        let res = this.provinceList.filter(fil => fil.code === val);
+        this.getCityList(res[0].name);
       } else if (type === 'zy_req') {
         //专业查询模拟
-        this.$set(this, `subjectSubList`, value === '1' ? this.subjectSub : this.subjectSub2);
+        this.$set(this, `subjectSubList`, val === '1' ? this.subjectSub : this.subjectSub2);
       }
     },
-    selectChange({ value, type }) {
+    selectChange({ val, type }) {
       //此方法是同步选择
-      if (type === 'category' || type === 'city' || type === 'salary') {
-        this.$set(this.expect, type, value);
-      } else {
-        this.$set(this.info, type, value);
-      }
+      this.$set(this.expect, type, val);
     },
     switchActionSheet(param) {
       this[`${param}`] = !this[`${param}`];
     },
-    async otherList() {
-      let result = await this.dicOperation('hylb');
+    getOtherList() {
+      this.otherList('hylb');
+      this.otherList('zwlb');
+      this.otherList('xzdy');
+      this.otherList({ level: 1 });
+    },
+    async otherList(type) {
+      let result = await this.dicOperation(type);
       if (`${result.errcode}` === '0') {
-        //给this=>vue的实例下在中的list属性,赋予result。data的值
-        this.$set(this, `hyList`, result.data);
-      } else {
-        this.$message.error(result.errmsg ? result.errmsg : 'error');
+        let list = result.data;
+        if (_.isObject(type)) {
+          this.$set(this, `provinceList`, list);
+          return;
+        }
+        this.$set(this, `${type}List`, list);
       }
-      result = await this.dicOperation('zwlb');
-      if (`${result.errcode}` === '0') {
-        this.$set(this, `classList`, result.data);
+    },
+    async getCityList(name) {
+      let arr = await this.provinceList.filter(item => item.name === name && this.filterCity(name));
+      if (arr.length > 0) {
+        let pro = arr[0];
+        let result = await this.dicOperation({ level: 2, parent: pro.code });
+        if (`${result.errcode}` === '0') {
+          this.$set(this, `cityList`, result.data);
+        }
       } else {
-        this.$message.error(result.errmsg ? result.errmsg : 'error');
+        this.$set(this.info, `city`, '');
+        this.$set(this, `cityList`, [{ name: '无选项', code: 0, disabled: true }]);
       }
-      result = await this.dicOperation('xzdy');
-      if (`${result.errcode}` === '0') {
-        this.$set(this, `salaList`, result.data);
+    },
+    filterCity(name) {
+      if (
+        name.includes('特别行政区') ||
+        name.includes('北京市') ||
+        name.includes('天津市') ||
+        name.includes('上海市') ||
+        name.includes('重庆市') ||
+        name.includes('台湾省')
+      ) {
+        return false;
       } else {
-        this.$message.error(result.errmsg ? result.errmsg : 'error');
+        return true;
       }
     },
   },

+ 7 - 2
src/store/dictionary.js

@@ -5,6 +5,7 @@ import _ from 'lodash';
 Vue.use(Vuex);
 const api = {
   dictionary: '/code/{type}/items', //type === xzqh:query:level(1/2);parent(无/code)
+  findOne: '/code/xzqh/findOne', //query:name
 };
 
 export const state = () => ({});
@@ -16,8 +17,12 @@ export const actions = {
     if (!_.isObject(type)) {
       result = await this.$axios.$get(api.dictionary, { type: type });
     } else {
-      let { level, parent } = type;
-      result = await this.$axios.$get(api.dictionary, { type: 'xzqh' }, { level: level, parent: parent });
+      let { level, parent, name } = type;
+      if (name) {
+        result = await this.$axios.$get(api.findOne, {}, { name: name });
+      } else {
+        result = await this.$axios.$get(api.dictionary, { type: 'xzqh' }, { level: level, parent: parent });
+      }
     }
 
     return result;