area-edit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template id="area-edit">
  2. <el-dialog :visible.sync="edit.visible" width="20%" title="添加区域代理" center>
  3. <div>
  4. <el-form @submit.native.prevent size="small" label-width="120px">
  5. <el-form-item label="用户昵称">
  6. <el-autocomplete size="small" v-model="edit.nickname" value-key="nickname"
  7. @keyup.enter.native="keyUp"
  8. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  9. @select="areaClick"></el-autocomplete>
  10. </el-form-item>
  11. <el-form-item label="用户真实姓名">
  12. <el-input style="width: 200px;" v-model.trim="realname" placeholder="请输入用户真实姓名"></el-input>
  13. </el-form-item>
  14. <el-form-item label="用户手机号码">
  15. <el-input style="width: 200px;" v-model.trim="mobile" type="text" placeholder="请输入用户手机号码"></el-input>
  16. </el-form-item>
  17. </el-form>
  18. <el-form @submit.native.prevent size="small" label-width="120px">
  19. <el-form-item label="等级">
  20. <el-select v-model="level" placeholder="请选择区域代理等级" @change="levelChange">
  21. <el-option
  22. v-for="(item, index) in level_list"
  23. v-if="index > 0"
  24. :label="item"
  25. :key="index"
  26. :value="index">
  27. </el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-form>
  31. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level == 6">
  32. <el-form-item label="大区">
  33. <el-select v-model="regional_id" placeholder="请选择大区">
  34. <el-option
  35. v-for="item in regional_list"
  36. :label="item.regional_name"
  37. :key="item.id"
  38. :value="item.id">
  39. </el-option>
  40. </el-select>
  41. </el-form-item>
  42. </el-form>
  43. <template v-else-if="level>0">
  44. <el-form @submit.native.prevent size="small" label-width="120px">
  45. <el-form-item label="省市区" prop="address">
  46. <el-cascader
  47. @change="addressChange"
  48. :options="district"
  49. :props="props"
  50. v-model="address">
  51. </el-cascader>
  52. </el-form-item>
  53. </el-form>
  54. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 3">
  55. <el-form-item label="镇">
  56. <el-select v-model="town_id" placeholder="请选择镇" @change="onChangeTown">
  57. <el-option
  58. v-for="item in town_list"
  59. :key="item.id"
  60. :label="item.name"
  61. :value="item.id">
  62. </el-option>
  63. </el-select>
  64. </el-form-item>
  65. </el-form>
  66. <el-form @submit.native.prevent size="small" label-width="120px" v-if="level > 4">
  67. <el-form-item label="小区">
  68. <el-select v-model="community_id" placeholder="请选择小区">
  69. <el-option
  70. v-for="item in community_list"
  71. :label="item.community_name"
  72. :key="item.id"
  73. :value="item.id">
  74. </el-option>
  75. </el-select>
  76. </el-form-item>
  77. </el-form>
  78. </template>
  79. </div>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  82. <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
  83. @click="editSave">保存</el-button>
  84. </span>
  85. </el-dialog>
  86. </template>
  87. <script>
  88. Vue.component('area-edit', {
  89. template: '#area-edit',
  90. props: {
  91. value: {
  92. type: Boolean,
  93. default: false
  94. }
  95. },
  96. data() {
  97. return {
  98. edit: {
  99. visible: false,
  100. keyword: '',
  101. nickname: '',
  102. id: '',
  103. btnLoading: false,
  104. },
  105. district: [],
  106. address: [],
  107. regional_list: [],
  108. town_list: [],
  109. community_list: [],
  110. regional_id: null,
  111. province_id: 0,
  112. city_id: 0,
  113. district_id: 0,
  114. town_id: '',
  115. community_id: '',
  116. props: {
  117. value: 'id',
  118. label: 'name',
  119. children: 'list',
  120. },
  121. level_list: {
  122. 1: '省代',
  123. 2: '市代',
  124. 3: '区代',
  125. 4: '镇代',
  126. 5: '小区代',
  127. 6: '大区代',
  128. },
  129. level: null,
  130. mobile:'',
  131. realname:'',
  132. }
  133. },
  134. watch: {
  135. value() {
  136. if (this.value) {
  137. this.edit.visible = true;
  138. } else {
  139. this.edit.id = '';
  140. this.edit.nickname = '';
  141. this.edit.keyword = '';
  142. this.edit.visible = false;
  143. }
  144. },
  145. 'edit.visible'() {
  146. if (!this.edit.visible) {
  147. this.editCancel();
  148. }
  149. }
  150. },
  151. created() {
  152. this.getDistrict(1);
  153. this.getLevelList()
  154. },
  155. methods: {
  156. addressChange(e) {
  157. this.town_list = []
  158. this.town_id = '';
  159. if (e.length == 3) {
  160. this.getTownList(e[2]);
  161. }
  162. },
  163. getTownList(district_id) {
  164. request({
  165. params: {
  166. r: 'area/default/get-town-list',
  167. district_id: district_id
  168. },
  169. }).then(e => {
  170. if (e.data.code == 0) {
  171. this.town_list = e.data.data.list;
  172. if (JSON.stringify(this.town_list) == '[]' && (this.level == 4 || this.level == 5)) {
  173. this.level = ''
  174. this.$message.error('该区域无法选择该等级代理, 请重新选择');
  175. }
  176. }
  177. }).catch(e => {
  178. });
  179. },
  180. onChangeTown(val) {
  181. this.getCommunity(val)
  182. },
  183. getCommunity(town_id) {
  184. request({
  185. params: {
  186. r: 'area/community/list',
  187. town_id: town_id
  188. },
  189. }).then(e => {
  190. if (e.data.code == 0) {
  191. this.community_list = e.data.data;
  192. }
  193. }).catch(e => {
  194. });
  195. },
  196. getRegional() {
  197. request({
  198. params: {
  199. r: 'area/regional/index',
  200. is_select: 1
  201. },
  202. }).then(e => {
  203. if (e.data.code == 0) {
  204. this.regional_list = e.data.data;
  205. }
  206. }).catch(e => { console.log(e) });
  207. },
  208. levelChange(e) {
  209. // console.log('e=='+e)
  210. if (e == 6) {
  211. this.getRegional();
  212. }else{
  213. if (e >= 4) e = 4 // 如果选择的是小区代,那么就需要处理了
  214. this.getDistrict(e);
  215. }
  216. },
  217. // 获取省市区列表
  218. getDistrict(level) {
  219. if (level) {
  220. level1 = level;
  221. } else{
  222. level1 = 1;
  223. }
  224. request({
  225. params: {
  226. r: 'area/default/district',
  227. level: level1
  228. },
  229. }).then(e => {
  230. if (e.data.code == 0) {
  231. this.district = e.data.data.district;
  232. }
  233. }).catch(e => {
  234. });
  235. },
  236. querySearchAsync(queryString, cb) {
  237. this.edit.keyword = queryString;
  238. this.get_user(cb);
  239. },
  240. get_user(cb) {
  241. request({
  242. params: {
  243. r: 'area/default/search-user',
  244. keyword: this.edit.keyword
  245. }
  246. }).then(res => {
  247. if (res.data.code == 0) {
  248. cb(res.data.data.list)
  249. } else {
  250. this.$message.error(res.data.msg);
  251. }
  252. });
  253. },
  254. areaClick(row) {
  255. //console.log('选择了用户row='+JSON.stringify(row))
  256. this.edit.id = row.id
  257. if (row.mobile != '') this.mobile = row.mobile
  258. },
  259. editCancel() {
  260. this.$emit('input', false);
  261. navigateTo({
  262. r: 'area/default/index',
  263. })
  264. },
  265. editSave() {
  266. if(!this.edit.id){
  267. return this.$message.error("请选择用户");
  268. }
  269. if(!this.realname){
  270. return this.$message.error("请输入用户真实姓名");
  271. }
  272. if(!this.mobile || (this.mobile + '').length != 11){
  273. return this.$message.error("请输入正确手机号码");
  274. }
  275. if(!this.level){
  276. return this.$message.error("请选择等级");
  277. }
  278. if (this.level == 6 && (this.regional_id == null || this.regional_id == '')) {
  279. return this.$message.error("请选择大区");
  280. }
  281. if(!this.address && this.level != 6){
  282. return this.$message.error("请选择省市区");
  283. }
  284. if (this.level > 3 && this.level != 6) {
  285. if (this.town_id == '' || this.town_id == undefined) {
  286. this.$message.error('请选择镇');
  287. return;
  288. }
  289. }
  290. if (this.level > 4 && this.level != 6) {
  291. if (this.community_id == '' || this.community_id == undefined) {
  292. this.$message.error('请选择小区');
  293. return;
  294. }
  295. }
  296. this.address.push(parseInt(this.town_id));
  297. this.address.push(parseInt(this.community_id));
  298. if (this.level == 1) {
  299. this.province_id = this.address[0];
  300. this.city_id = 0;
  301. this.district_id = 0;
  302. this.town_id = 0;
  303. this.community_id = 0;
  304. this.regional_id = 0;
  305. }
  306. if (this.level == 2) {
  307. this.province_id = this.address[0];
  308. this.city_id = this.address[1];
  309. this.district_id = 0;
  310. this.town_id = 0;
  311. this.community_id = 0;
  312. this.regional_id = 0;
  313. }
  314. if (this.level == 3) {
  315. this.province_id = this.address[0];
  316. this.city_id = this.address[1];
  317. this.district_id = this.address[2];
  318. this.town_id = 0;
  319. this.community_id = 0;
  320. this.regional_id = 0;
  321. }
  322. if (this.level == 4) {
  323. this.province_id = this.address[0];
  324. this.city_id = this.address[1];
  325. this.district_id = this.address[2];
  326. this.town_id = this.address[3];
  327. this.community_id = 0;
  328. this.regional_id = 0;
  329. }
  330. if (this.level == 5) {
  331. this.province_id = this.address[0];
  332. this.city_id = this.address[1];
  333. this.district_id = this.address[2];
  334. this.town_id = this.address[3];
  335. this.community_id = this.address[4];
  336. this.regional_id = 0;
  337. }
  338. if (this.level == 6) {
  339. this.province_id = 0;
  340. this.city_id = 0;
  341. this.district_id = 0;
  342. this.town_id = 0;
  343. this.community_id = 0;
  344. }
  345. // console.log('提交前的参数user_id='+this.edit.id)
  346. // console.log('提交前的参数province_id='+this.province_id)
  347. // console.log('提交前的参数city_id='+this.city_id)
  348. // console.log('提交前的参数district_id='+this.district_id)
  349. // console.log('提交前的参数town_id='+this.town_id)
  350. // console.log('提交前的参数level='+this.level)
  351. this.edit.btnLoading = true;
  352. let _data = {
  353. /* id: this.edit.id, */
  354. user_id: this.edit.id,
  355. level: this.level,
  356. province_id: this.province_id,
  357. city_id: this.city_id,
  358. district_id: this.district_id,
  359. town_id: this.town_id,
  360. community_id: this.community_id,
  361. regional_id: this.regional_id,
  362. mobile:this.mobile,
  363. realname:this.realname
  364. }
  365. request({
  366. params: {
  367. r: 'area/default/edit',
  368. },
  369. method: 'post',
  370. data: _data
  371. }).then(response => {
  372. this.edit.btnLoading = false;
  373. if (response.data.code == 0) {
  374. this.$message.success('添加成功');
  375. this.editCancel();
  376. } else {
  377. this.$message.error(response.data.msg);
  378. }
  379. }).catch(response => {
  380. this.edit.btnLoading = false;
  381. });
  382. },
  383. keyUp() {
  384. console.log('key up')
  385. },
  386. getLevelList() {
  387. request({
  388. params: {
  389. r: 'area/default/level-list',
  390. },
  391. }).then(e => {
  392. if (e.data.code == 0) {
  393. this.level_list = e.data.data;
  394. }
  395. }).catch(e => {
  396. });
  397. }
  398. }
  399. });
  400. </script>