| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <template id="area-level">
- <el-dialog :visible.sync="edit.visible" width="20%" title="修改区域代理等级" center>
- <div v-loading="edit.loading">
- <el-form @submit.native.prevent size="small" label-width="120px">
- <el-form-item label="等级">
- <el-select v-model="level" placeholder="请选择区域代理等级" @change="levelChange">
- <el-option
- v-for="(item, index) in level_list"
- v-if="index > 0"
- :key="index"
- :label="item"
- :value="parseInt(index)">
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <el-form @submit.native.prevent size="small" label-width="120px" v-if="level == 6">
- <el-form-item label="大区">
- <el-select v-model="regional_id" placeholder="请选择大区">
- <el-option
- v-for="item in regional_list"
- :label="item.regional_name"
- :key="item.id"
- :value="item.id">
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <template v-else-if="level>0">
- <el-form @submit.native.prevent size="small" label-width="120px">
- <el-form-item label="省市区" prop="address">
- <el-cascader
- @change="addressChange"
- :options="district"
- :props="props"
- v-model="address">
- </el-cascader>
- </el-form-item>
- </el-form>
- <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 3">
- <el-form-item label="镇">
- <el-select v-model="town_id" placeholder="请选择镇" @change="onChangeTown">
- <el-option
- v-for="item in town_list"
- :label="item.name"
- :key="item.id"
- :value="item.id">
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 4">
- <el-form-item label="小区">
- <el-select v-model="community_id" placeholder="请选择小区">
- <el-option
- v-for="item in community_list"
- :label="item.community_name"
- :key="item.id"
- :value="item.id">
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- </template>
- <el-form v-if="config.is_enable_only_dividend == 1" @submit.native.prevent size="small" label-width="120px">
- <el-form-item label="是否参与分红">
- <label slot="label">是否参与分红
- <el-tooltip class="item" effect="dark" placement="top-start">
- <div slot="content">
- 开关开启的情况下该用户即享受分红条件
- </div>
- <i class="el-icon-info"></i>
- </el-tooltip>
- </label>
- <div>
- <el-switch v-model="is_enable_dividend" :active-value="1"
- :inactive-value="0">
- </el-switch>
- </div>
- </el-form-item>
- <el-form-item label="商品设置" v-if="config.only_dividend_goods_type == 0 && is_enable_dividend == 1">
- <com-dialog-select :multiple="true" @selected="onSelectedGoods" title="商品选择">
- <el-button>选择商品</el-button>
- </com-dialog-select>
- </el-form-item>
- </el-form>
- <el-table size="mini" border :data="goods" v-if="config.only_dividend_goods_type == 0 && is_enable_dividend == 1">
- <el-table-column label="商品ID" width="100" prop="goods_id" align="center"></el-table-column>
- <el-table-column label="商品信息" align="left">
- <template slot-scope="scope">
- <div class="user_img" flex="cross:center">
- <el-image class="default-avatar" :src="scope.row.cover_pic">
- <div slot="error" class="image-slot">
- <com-image src="/resources/img/common/default-avatar.png"></com-image>
- </div>
- </el-image>
- <div class="uer-nickname over1" style="color:#000;">{{scope.row.goods_name}}</div>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="100" align="center">
- <template slot-scope="scope">
- <el-popconfirm @confirm="onRemoveGoods(scope.$index)" title="您确定要移除当前商品吗?">
- <el-button type="danger" size="mini" slot="reference">移除</el-button>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="editCancel" type="default" size="small">取消</el-button>
- <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
- @click="editSave">保存</el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- Vue.component('area-level', {
- template: '#area-level',
- props: {
- value: {
- type: Boolean,
- default: false
- },
- area: Object,
- config: Object
- },
- data() {
- return {
- edit: {
- visible: false,
- level: '',
- btnLoading: false,
- list: [],
- loading: false,
- },
- district: [],
- address: [],
- regional_list: [],
- regional_id: null,
- town_list: [],
- community_list: [],
- province_id: 0,
- city_id: 0,
- district_id: 0,
- town_id: '',
- community_id: '',
- props: {
- value: 'id',
- label: 'name',
- children: 'list'
- },
- level_list: {
- 1: '省代',
- 2: '市代',
- 3: '区代',
- 4: '镇代',
- 5: '小区代',
- 6: '大区代',
- },
- level: null,
- is_enable_dividend: 0,
- goods: [],
- goods_ids: []
- };
- },
- watch: {
- value() {
- if (this.value) {
- // console.log('this.area='+JSON.stringify(this.area));
- this.edit.visible = true;
- this.level = this.area.level;
- if (this.level == 6) {
- this.getRegional();
- }else{
- this.getDistrict(this.area.level > 4 ? 4 : this.area.level);
- }
- switch(this.area.level) {
- case 1:
- this.address = [this.area.province_id];
- break;
- case 2:
- this.address = [this.area.province_id,this.area.city_id];
- break;
- case 3:
- this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
- break;
- case 4:
- this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
- this.getTownList(this.area.district_id);
- this.town_id = this.area.town_id;
- break;
- case 6:
- this.address = [];
- this.province_id = 0;
- this.city_id = 0;
- this.district_id = 0;
- this.town_id = '';
- this.community_id = '';
- this.regional_id = this.area.regional_id;
- break;
- default:
- this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
- this.getTownList(this.area.district_id);
- this.town_id = this.area.town_id;
- this.getCommunity(this.area.town_id);
- this.community_id = this.area.community_id;
- }
- // 新增
- this.goods_ids = []
- this.goods = []
- this.is_enable_dividend = this.area.is_enable_dividend
- if (this.area.goods) {
- for (const goodsKey in this.area.goods) {
- this.goods_ids.push(this.area.goods[goodsKey].id)
- this.goods.push({
- goods_id: this.area.goods[goodsKey].goods_id,
- goods_name: this.area.goods[goodsKey].goods.goods_name,
- cover_pic: this.area.goods[goodsKey].goods.cover_pic,
- });
- }
- }
- } else {
- this.edit.id = '';
- this.edit.visible = false;
- }
- },
- 'edit.visible'() {
- if (!this.edit.visible) {
- this.editCancel();
- }
- }
- },
- created() {
- this.getLevelList()
- },
- methods: {
- addressChange(e) { //选择省市区
- this.town_list = []
- this.town_id = '';
- if (e.length == 3) {
- this.getTownList(e[2]);
- }
- },
- getTownList(district_id) {
- request({
- params: {
- r: 'area/default/get-town-list',
- district_id: district_id
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.town_list = e.data.data.list;
- if (JSON.stringify(this.town_list) == '[]' && (this.level == 4 || this.level == 5)) {
- this.level = ''
- this.$message.error('该区域无法选择该等级代理, 请重新选择');
- }
- }
- }).catch(e => {
- });
- },
- getRegional() {
- request({
- params: {
- r: 'area/regional/index',
- is_select: 1
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.regional_list = e.data.data;
- }
- }).catch(e => { console.log(e) });
- },
- levelChange(e) {
- this.address = [];
- this.town_id = '';
- if (e == 6) {
- this.getRegional();
- }else{
- if (e >= 4) e = 4 // 如果选择的是小区代,那么就需要处理了
- this.getDistrict(e);
- }
- },
- // 获取省市区列表
- getDistrict(level) {
- if (level) {
- level1 = level;
- } else{
- level1 = 1;
- }
- request({
- params: {
- r: 'area/default/district',
- level: level1
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.district = e.data.data.district;
- }
- }).catch(e => {
- });
- },
- editCancel() {
- this.$emit('input', false);
- },
- onChangeTown(val) {
- if (this.level > 4) this.getCommunity(val)
- },
- getCommunity(town_id) {
- request({
- params: {
- r: 'area/community/list',
- town_id: town_id
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.community_list = e.data.data;
- }
- }).catch(e => {
- });
- },
- editSave() {
- if ((!this.address || this.address.length == 0) && this.level != 6) {
- this.$message.error('请选择地区');
- return;
- }
- if (this.level == 4) {
- if (this.town_id == '' || this.town_id == undefined) {
- this.$message.error('请选择镇');
- return;
- }
- }
- if (this.level == 5) {
- if (this.community_id == '' || this.community_id == undefined) {
- this.$message.error('请选择小区');
- return;
- }
- }
- if (this.level == 6) {
- if (this.regional_id == '' || this.regional_id == undefined) {
- this.$message.error('请选择大区');
- return;
- }
- }
- this.address.push(parseInt(this.town_id));
- this.address.push(parseInt(this.community_id));
- if (this.level == 1) {
- this.province_id = this.address[0];
- this.city_id = 0;
- this.district_id = 0;
- this.town_id = 0;
- this.community_id = 0;
- this.regional_id = 0;
- }
- if (this.level == 2) {
- this.province_id = this.address[0];
- this.city_id = this.address[1];
- this.district_id = 0;
- this.town_id = 0;
- this.community_id = 0;
- this.regional_id = 0;
- }
- if (this.level == 3) {
- this.province_id = this.address[0];
- this.city_id = this.address[1];
- this.district_id = this.address[2];
- this.town_id = 0;
- this.community_id = 0;
- this.regional_id = 0;
- }
- if (this.level == 4) {
- this.province_id = this.address[0];
- this.city_id = this.address[1];
- this.district_id = this.address[2];
- this.town_id = this.address[3];
- this.community_id = 0;
- this.regional_id = 0;
- }
- if (this.level == 5) {
- this.province_id = this.address[0];
- this.city_id = this.address[1];
- this.district_id = this.address[2];
- this.town_id = this.address[3];
- this.community_id = this.address[4];
- this.regional_id = 0;
- }
- if (this.level == 6) {
- this.province_id = 0;
- this.city_id = 0;
- this.district_id = 0;
- this.town_id = 0;
- this.community_id = 0;
- }
- this.edit.btnLoading = true;
- request({
- params: {
- r: 'area/default/edit'
- },
- method: 'post',
- data: {
- province_id: this.province_id,
- city_id: this.city_id,
- district_id: this.district_id,
- town_id: this.town_id,
- community_id: this.community_id,
- regional_id: this.regional_id,
- level: this.level,
- id: this.area.id,
- user_id:this.area.user_id,
- is_enable_dividend: this.is_enable_dividend,
- goods: JSON.stringify(this.goods)
- }
- }).then(response => {
- this.edit.btnLoading = false;
- if (response.data.code == 0) {
- this.$message.success('修改成功');
- this.editCancel();
- this.$emit('success', true);
- this.goods = []
- } else {
- this.$message.error(response.data.msg);
- }
- }).catch(response => {
- this.edit.btnLoading = false;
- });
- },
- onSelectedGoods(list) {
- for (let listKey in list) {
- if (this.goods_ids.indexOf(list[listKey].id) > -1) continue;
- this.goods_ids.push(list[listKey].id)
- this.goods.push({
- goods_id: list[listKey].id,
- goods_name: list[listKey].goods_name,
- cover_pic: list[listKey].cover_pic,
- });
- }
- },
- onRemoveGoods(index) {
- this.goods.splice(index, 1)
- },
- getLevelList() {
- request({
- params: {
- r: 'area/default/level-list',
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.level_list = e.data.data;
- }
- }).catch(e => {
- });
- },
- }
- });
- </script>
|