area-level.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template id="area-level">
  2. <el-dialog :visible.sync="edit.visible" width="20%" title="修改区域代理等级" center>
  3. <div v-loading="edit.loading">
  4. <el-form @submit.native.prevent size="small" label-width="120px">
  5. <el-form-item label="等级">
  6. <el-select v-model="level" placeholder="请选择区域代理等级" @change="levelChange">
  7. <el-option
  8. v-for="(item, index) in level_list"
  9. v-if="index > 0"
  10. :key="index"
  11. :label="item"
  12. :value="parseInt(index)">
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. </el-form>
  17. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level == 6">
  18. <el-form-item label="大区">
  19. <el-select v-model="regional_id" placeholder="请选择大区">
  20. <el-option
  21. v-for="item in regional_list"
  22. :label="item.regional_name"
  23. :key="item.id"
  24. :value="item.id">
  25. </el-option>
  26. </el-select>
  27. </el-form-item>
  28. </el-form>
  29. <template v-else-if="level>0">
  30. <el-form @submit.native.prevent size="small" label-width="120px">
  31. <el-form-item label="省市区" prop="address">
  32. <el-cascader
  33. @change="addressChange"
  34. :options="district"
  35. :props="props"
  36. v-model="address">
  37. </el-cascader>
  38. </el-form-item>
  39. </el-form>
  40. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 3">
  41. <el-form-item label="镇">
  42. <el-select v-model="town_id" placeholder="请选择镇" @change="onChangeTown">
  43. <el-option
  44. v-for="item in town_list"
  45. :label="item.name"
  46. :key="item.id"
  47. :value="item.id">
  48. </el-option>
  49. </el-select>
  50. </el-form-item>
  51. </el-form>
  52. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 4">
  53. <el-form-item label="小区">
  54. <el-select v-model="community_id" placeholder="请选择小区">
  55. <el-option
  56. v-for="item in community_list"
  57. :label="item.community_name"
  58. :key="item.id"
  59. :value="item.id">
  60. </el-option>
  61. </el-select>
  62. </el-form-item>
  63. </el-form>
  64. </template>
  65. <el-form v-if="config.is_enable_only_dividend == 1" @submit.native.prevent size="small" label-width="120px">
  66. <el-form-item label="是否参与分红">
  67. <label slot="label">是否参与分红
  68. <el-tooltip class="item" effect="dark" placement="top-start">
  69. <div slot="content">
  70. 开关开启的情况下该用户即享受分红条件
  71. </div>
  72. <i class="el-icon-info"></i>
  73. </el-tooltip>
  74. </label>
  75. <div>
  76. <el-switch v-model="is_enable_dividend" :active-value="1"
  77. :inactive-value="0">
  78. </el-switch>
  79. </div>
  80. </el-form-item>
  81. <el-form-item label="商品设置" v-if="config.only_dividend_goods_type == 0 && is_enable_dividend == 1">
  82. <com-dialog-select :multiple="true" @selected="onSelectedGoods" title="商品选择">
  83. <el-button>选择商品</el-button>
  84. </com-dialog-select>
  85. </el-form-item>
  86. </el-form>
  87. <el-table size="mini" border :data="goods" v-if="config.only_dividend_goods_type == 0 && is_enable_dividend == 1">
  88. <el-table-column label="商品ID" width="100" prop="goods_id" align="center"></el-table-column>
  89. <el-table-column label="商品信息" align="left">
  90. <template slot-scope="scope">
  91. <div class="user_img" flex="cross:center">
  92. <el-image class="default-avatar" :src="scope.row.cover_pic">
  93. <div slot="error" class="image-slot">
  94. <com-image src="/resources/img/common/default-avatar.png"></com-image>
  95. </div>
  96. </el-image>
  97. <div class="uer-nickname over1" style="color:#000;">{{scope.row.goods_name}}</div>
  98. </div>
  99. </template>
  100. </el-table-column>
  101. <el-table-column label="操作" width="100" align="center">
  102. <template slot-scope="scope">
  103. <el-popconfirm @confirm="onRemoveGoods(scope.$index)" title="您确定要移除当前商品吗?">
  104. <el-button type="danger" size="mini" slot="reference">移除</el-button>
  105. </el-popconfirm>
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. </div>
  110. <span slot="footer" class="dialog-footer">
  111. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  112. <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
  113. @click="editSave">保存</el-button>
  114. </span>
  115. </el-dialog>
  116. </template>
  117. <script>
  118. Vue.component('area-level', {
  119. template: '#area-level',
  120. props: {
  121. value: {
  122. type: Boolean,
  123. default: false
  124. },
  125. area: Object,
  126. config: Object
  127. },
  128. data() {
  129. return {
  130. edit: {
  131. visible: false,
  132. level: '',
  133. btnLoading: false,
  134. list: [],
  135. loading: false,
  136. },
  137. district: [],
  138. address: [],
  139. regional_list: [],
  140. regional_id: null,
  141. town_list: [],
  142. community_list: [],
  143. province_id: 0,
  144. city_id: 0,
  145. district_id: 0,
  146. town_id: '',
  147. community_id: '',
  148. props: {
  149. value: 'id',
  150. label: 'name',
  151. children: 'list'
  152. },
  153. level_list: {
  154. 1: '省代',
  155. 2: '市代',
  156. 3: '区代',
  157. 4: '镇代',
  158. 5: '小区代',
  159. 6: '大区代',
  160. },
  161. level: null,
  162. is_enable_dividend: 0,
  163. goods: [],
  164. goods_ids: []
  165. };
  166. },
  167. watch: {
  168. value() {
  169. if (this.value) {
  170. // console.log('this.area='+JSON.stringify(this.area));
  171. this.edit.visible = true;
  172. this.level = this.area.level;
  173. if (this.level == 6) {
  174. this.getRegional();
  175. }else{
  176. this.getDistrict(this.area.level > 4 ? 4 : this.area.level);
  177. }
  178. switch(this.area.level) {
  179. case 1:
  180. this.address = [this.area.province_id];
  181. break;
  182. case 2:
  183. this.address = [this.area.province_id,this.area.city_id];
  184. break;
  185. case 3:
  186. this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
  187. break;
  188. case 4:
  189. this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
  190. this.getTownList(this.area.district_id);
  191. this.town_id = this.area.town_id;
  192. break;
  193. case 6:
  194. this.address = [];
  195. this.province_id = 0;
  196. this.city_id = 0;
  197. this.district_id = 0;
  198. this.town_id = '';
  199. this.community_id = '';
  200. this.regional_id = this.area.regional_id;
  201. break;
  202. default:
  203. this.address = [this.area.province_id,this.area.city_id,this.area.district_id];
  204. this.getTownList(this.area.district_id);
  205. this.town_id = this.area.town_id;
  206. this.getCommunity(this.area.town_id);
  207. this.community_id = this.area.community_id;
  208. }
  209. // 新增
  210. this.goods_ids = []
  211. this.goods = []
  212. this.is_enable_dividend = this.area.is_enable_dividend
  213. if (this.area.goods) {
  214. for (const goodsKey in this.area.goods) {
  215. this.goods_ids.push(this.area.goods[goodsKey].id)
  216. this.goods.push({
  217. goods_id: this.area.goods[goodsKey].goods_id,
  218. goods_name: this.area.goods[goodsKey].goods.goods_name,
  219. cover_pic: this.area.goods[goodsKey].goods.cover_pic,
  220. });
  221. }
  222. }
  223. } else {
  224. this.edit.id = '';
  225. this.edit.visible = false;
  226. }
  227. },
  228. 'edit.visible'() {
  229. if (!this.edit.visible) {
  230. this.editCancel();
  231. }
  232. }
  233. },
  234. created() {
  235. this.getLevelList()
  236. },
  237. methods: {
  238. addressChange(e) { //选择省市区
  239. this.town_list = []
  240. this.town_id = '';
  241. if (e.length == 3) {
  242. this.getTownList(e[2]);
  243. }
  244. },
  245. getTownList(district_id) {
  246. request({
  247. params: {
  248. r: 'area/default/get-town-list',
  249. district_id: district_id
  250. },
  251. }).then(e => {
  252. if (e.data.code == 0) {
  253. this.town_list = e.data.data.list;
  254. if (JSON.stringify(this.town_list) == '[]' && (this.level == 4 || this.level == 5)) {
  255. this.level = ''
  256. this.$message.error('该区域无法选择该等级代理, 请重新选择');
  257. }
  258. }
  259. }).catch(e => {
  260. });
  261. },
  262. getRegional() {
  263. request({
  264. params: {
  265. r: 'area/regional/index',
  266. is_select: 1
  267. },
  268. }).then(e => {
  269. if (e.data.code == 0) {
  270. this.regional_list = e.data.data;
  271. }
  272. }).catch(e => { console.log(e) });
  273. },
  274. levelChange(e) {
  275. this.address = [];
  276. this.town_id = '';
  277. if (e == 6) {
  278. this.getRegional();
  279. }else{
  280. if (e >= 4) e = 4 // 如果选择的是小区代,那么就需要处理了
  281. this.getDistrict(e);
  282. }
  283. },
  284. // 获取省市区列表
  285. getDistrict(level) {
  286. if (level) {
  287. level1 = level;
  288. } else{
  289. level1 = 1;
  290. }
  291. request({
  292. params: {
  293. r: 'area/default/district',
  294. level: level1
  295. },
  296. }).then(e => {
  297. if (e.data.code == 0) {
  298. this.district = e.data.data.district;
  299. }
  300. }).catch(e => {
  301. });
  302. },
  303. editCancel() {
  304. this.$emit('input', false);
  305. },
  306. onChangeTown(val) {
  307. if (this.level > 4) this.getCommunity(val)
  308. },
  309. getCommunity(town_id) {
  310. request({
  311. params: {
  312. r: 'area/community/list',
  313. town_id: town_id
  314. },
  315. }).then(e => {
  316. if (e.data.code == 0) {
  317. this.community_list = e.data.data;
  318. }
  319. }).catch(e => {
  320. });
  321. },
  322. editSave() {
  323. if ((!this.address || this.address.length == 0) && this.level != 6) {
  324. this.$message.error('请选择地区');
  325. return;
  326. }
  327. if (this.level == 4) {
  328. if (this.town_id == '' || this.town_id == undefined) {
  329. this.$message.error('请选择镇');
  330. return;
  331. }
  332. }
  333. if (this.level == 5) {
  334. if (this.community_id == '' || this.community_id == undefined) {
  335. this.$message.error('请选择小区');
  336. return;
  337. }
  338. }
  339. if (this.level == 6) {
  340. if (this.regional_id == '' || this.regional_id == undefined) {
  341. this.$message.error('请选择大区');
  342. return;
  343. }
  344. }
  345. this.address.push(parseInt(this.town_id));
  346. this.address.push(parseInt(this.community_id));
  347. if (this.level == 1) {
  348. this.province_id = this.address[0];
  349. this.city_id = 0;
  350. this.district_id = 0;
  351. this.town_id = 0;
  352. this.community_id = 0;
  353. this.regional_id = 0;
  354. }
  355. if (this.level == 2) {
  356. this.province_id = this.address[0];
  357. this.city_id = this.address[1];
  358. this.district_id = 0;
  359. this.town_id = 0;
  360. this.community_id = 0;
  361. this.regional_id = 0;
  362. }
  363. if (this.level == 3) {
  364. this.province_id = this.address[0];
  365. this.city_id = this.address[1];
  366. this.district_id = this.address[2];
  367. this.town_id = 0;
  368. this.community_id = 0;
  369. this.regional_id = 0;
  370. }
  371. if (this.level == 4) {
  372. this.province_id = this.address[0];
  373. this.city_id = this.address[1];
  374. this.district_id = this.address[2];
  375. this.town_id = this.address[3];
  376. this.community_id = 0;
  377. this.regional_id = 0;
  378. }
  379. if (this.level == 5) {
  380. this.province_id = this.address[0];
  381. this.city_id = this.address[1];
  382. this.district_id = this.address[2];
  383. this.town_id = this.address[3];
  384. this.community_id = this.address[4];
  385. this.regional_id = 0;
  386. }
  387. if (this.level == 6) {
  388. this.province_id = 0;
  389. this.city_id = 0;
  390. this.district_id = 0;
  391. this.town_id = 0;
  392. this.community_id = 0;
  393. }
  394. this.edit.btnLoading = true;
  395. request({
  396. params: {
  397. r: 'area/default/edit'
  398. },
  399. method: 'post',
  400. data: {
  401. province_id: this.province_id,
  402. city_id: this.city_id,
  403. district_id: this.district_id,
  404. town_id: this.town_id,
  405. community_id: this.community_id,
  406. regional_id: this.regional_id,
  407. level: this.level,
  408. id: this.area.id,
  409. user_id:this.area.user_id,
  410. is_enable_dividend: this.is_enable_dividend,
  411. goods: JSON.stringify(this.goods)
  412. }
  413. }).then(response => {
  414. this.edit.btnLoading = false;
  415. if (response.data.code == 0) {
  416. this.$message.success('修改成功');
  417. this.editCancel();
  418. this.$emit('success', true);
  419. this.goods = []
  420. } else {
  421. this.$message.error(response.data.msg);
  422. }
  423. }).catch(response => {
  424. this.edit.btnLoading = false;
  425. });
  426. },
  427. onSelectedGoods(list) {
  428. for (let listKey in list) {
  429. if (this.goods_ids.indexOf(list[listKey].id) > -1) continue;
  430. this.goods_ids.push(list[listKey].id)
  431. this.goods.push({
  432. goods_id: list[listKey].id,
  433. goods_name: list[listKey].goods_name,
  434. cover_pic: list[listKey].cover_pic,
  435. });
  436. }
  437. },
  438. onRemoveGoods(index) {
  439. this.goods.splice(index, 1)
  440. },
  441. getLevelList() {
  442. request({
  443. params: {
  444. r: 'area/default/level-list',
  445. },
  446. }).then(e => {
  447. if (e.data.code == 0) {
  448. this.level_list = e.data.data;
  449. }
  450. }).catch(e => {
  451. });
  452. },
  453. }
  454. });
  455. </script>