index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-qq-map');
  4. ?>
  5. <style>
  6. .el-table th>.cell {
  7. color: #333;
  8. font-weight: bold;
  9. font-size: 14px;
  10. }
  11. .table1 .el-table__footer-wrapper,
  12. .table1 .el-table__header-wrapper {
  13. border-bottom: 1.4px solid #D6D6D6;
  14. }
  15. .user_img{
  16. position: relative;
  17. margin-right: 8px;
  18. /* height: 50px;
  19. width: 50px; */
  20. }
  21. .default-avatar{
  22. width: 50px;
  23. height: 50px;
  24. border-radius: 50%;
  25. margin-right: 8px;
  26. }
  27. .uer-nickname {
  28. flex: 1;
  29. }
  30. </style>
  31. <div id="app">
  32. <div class="table-body" style="min-width: 1000px;">
  33. <div slot="header" class="clearfix" style="height: 20px;">
  34. <span>小区管理</span>
  35. <el-button style="float: right; padding: 3px 12px;margin-left: 20px;height: 32px;" type="primary" @click="onCreate">添加小区</el-button>
  36. </div>
  37. <div slot="header" class="clearfix" style="margin-top: 20px;">
  38. <div class="demo-input-suffix" style="margin-top: 20px;margin-bottom: 10px;">
  39. <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="请输入小区名称/ID" v-model="search.keyword" clearable></el-input>
  40. <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="输入地址" v-model="search.address" clearable></el-input>
  41. <el-button type="primary" size="small" @click="toSearch">搜索</el-button>
  42. </div>
  43. </div>
  44. <template>
  45. <el-table :data="list" stripe style="width: 100%" v-loading="listLoading" class="table1">
  46. <el-table-column prop="id" label="ID" align="center" width="160"></el-table-column>
  47. <el-table-column label="小区名称" prop="community_name"></el-table-column>
  48. <el-table-column label="地址" prop="fully_address" align="left">
  49. <template slot-scope="scope">
  50. {{scope.row.area}}{{scope.row.street}}
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="启用" align="center" width="80">
  54. <template slot-scope="scope">
  55. <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0"
  56. @change="onChangeStatus(scope.row)"></el-switch>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="添加时间" width="180" align="center">
  60. <template slot-scope="scope">
  61. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="操作" width="120" align="center">
  65. <template slot-scope="scope">
  66. <el-button @click="onEditRow(scope.row, scope.$index)" type="text" size="mini">编辑</el-button>
  67. <el-popconfirm @confirm="onDelete(scope.row, scope.$index)" title="您真的要删除当前小区吗?">
  68. <el-button type="text" slot="reference" style="color: #F56C6C">删除</el-button>
  69. </el-popconfirm>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <div flex="main:right cross:center" style="margin-top: 20px;">
  74. <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize"
  75. style="display: inline-block;float: right;" background @current-change="pageChange"
  76. layout="prev, pager, next" :total="pagination.totalCount">
  77. </el-pagination>
  78. </div>
  79. </template>
  80. <el-dialog :visible.sync="createDialogShow" width="600px" title="添加/修改小区" center>
  81. <div v-loading="loading">
  82. <el-form ref="form" :model="form" size="small" label-width="120px">
  83. <el-form-item label="省市区" prop="address">
  84. <el-cascader
  85. @change="addressChange"
  86. :options="district"
  87. :props="props"
  88. v-model="address">
  89. </el-cascader>
  90. </el-form-item>
  91. <el-form-item label="镇">
  92. <el-select v-model="form.town_id" placeholder="请选择镇">
  93. <el-option
  94. v-for="item in town_list"
  95. :key="item.id"
  96. :label="item.name"
  97. :value="item.id">
  98. </el-option>
  99. </el-select>
  100. </el-form-item>
  101. <el-form-item label="小区名称" prop="community_name" :rules="[
  102. {required: true, message: '小区名称不能为空'}
  103. ]">
  104. <el-input v-model="form.community_name"></el-input>
  105. </el-form-item>
  106. <el-form-item label="经纬度" prop="lat_lng" :rules="[
  107. {required: true, message: '小区名称不能为空'}
  108. ]">
  109. <el-input :disabled="true" v-model="form.lat_lng">
  110. <template #append>
  111. <com-qq-map
  112. @on-hide="onHideMapDialog"
  113. @map-submit="mapEvent"
  114. :address="form.fully_address"
  115. :lat="form.lat"
  116. :long="form.lng"
  117. :show="mapDialogShow"
  118. :append-to-body="true"
  119. >
  120. 展开地图
  121. </com-qq-map>
  122. </template>
  123. </el-input>
  124. </el-form-item>
  125. <el-form-item label="详细地址" prop="fully_address" :rules="[
  126. {required: true, message: '详细地址不能为空'}
  127. ]">
  128. <el-input :disabled="true" v-model="form.fully_address"></el-input>
  129. </el-form-item>
  130. </el-form>
  131. </div>
  132. <span slot="footer" class="dialog-footer">
  133. <el-button @click="onCancel" type="default" size="small">取消</el-button>
  134. <el-button type="primary" :loading="btnLoading" style="margin-bottom: 10px;" size="small"
  135. @click="onSubmit">保存</el-button>
  136. </span>
  137. </el-dialog>
  138. </div>
  139. </div>
  140. <script>
  141. const app = new Vue({
  142. el: '#app',
  143. data() {
  144. return {
  145. btnLoading: false,
  146. createDialogShow: false,
  147. listLoading: false,
  148. list: [],
  149. pagination: {
  150. total: 0
  151. },
  152. loading: false,
  153. LoadDataType: -1, //默认显示全部数据
  154. dialogFormVisible: false, //默认不显示弹窗
  155. group_buy_attr_list: [],
  156. goodsDetail: {},
  157. dialogLoading:false,
  158. commander_level_limit_text:'',
  159. user_level_limit_text:'',
  160. level_map:null,
  161. selectDate:'',
  162. search: {
  163. page: 1,
  164. limit:10,
  165. keyword: '',
  166. address: '',
  167. },
  168. levelList:[
  169. ],
  170. show: false,
  171. level: {
  172. show: false,
  173. area: null,
  174. },
  175. current_area:null,
  176. form: {
  177. id: 0,
  178. community_name: '',
  179. province_id: 0,
  180. city_id: 0,
  181. district_id: 0,
  182. town_id: '',
  183. province: '',
  184. city: '',
  185. district: '',
  186. town: '',
  187. street: '',
  188. lng: '',
  189. lat: '',
  190. fully_address: '',
  191. lat_lng: '',
  192. addressComponents: null
  193. },
  194. district: [],
  195. town_id: '',
  196. town_list: [],
  197. address: null,
  198. props: {
  199. value: 'id',
  200. label: 'name',
  201. children: 'list',
  202. },
  203. mapDialogShow: false
  204. }
  205. },
  206. methods: {
  207. //状态按钮的点击事件
  208. toSearch() {
  209. this.search.page = 1;
  210. this.loadData();
  211. },
  212. toSearchActivity() {
  213. this.loadData()
  214. },
  215. update(row) {
  216. this.$confirm('删除该区域代理, 是否继续?', '提示', {
  217. confirmButtonText: '确定',
  218. cancelButtonText: '取消',
  219. type: 'warning'
  220. }).then(() => {
  221. this.loading = true;
  222. request({
  223. params: {
  224. r: 'area/default/delete',
  225. },
  226. method: 'post',
  227. data: {
  228. id: row.id,
  229. }
  230. }).then(e => {
  231. let res = e.data;
  232. this.listLoading = false;
  233. if (res.code === 0) {
  234. this.$message.success(res.msg);
  235. this.loadData();
  236. } else {
  237. this.$message.error(res.msg);
  238. }
  239. }).catch(e => {});
  240. }).catch(() => {
  241. this.$message({
  242. type: 'info',
  243. message: '系统错误'
  244. });
  245. });
  246. },
  247. pageChange(page) {
  248. this.search.page = page;
  249. this.loadData();
  250. },
  251. // 请求获取数据--获取拼团商品列表
  252. loadData() {
  253. this.listLoading = true;
  254. let params = {
  255. r: 'area/community/index'
  256. };
  257. params = Object.assign(params, this.search);
  258. request({
  259. params: params,
  260. method: 'get',
  261. }).then(e => {
  262. let res = e.data;
  263. this.listLoading = false;
  264. if (res.code === 0) {
  265. this.list = res.data.list;
  266. this.level_map = res.data.level_map;
  267. this.pagination = res.data.pagination; //拿到关于页码页容量的数据
  268. } else {
  269. this.$message.error(res.msg);
  270. }
  271. }).catch(e => {});
  272. },
  273. editClick() {
  274. this.show = true;
  275. },
  276. levelSuccess() {
  277. this.loadData();
  278. },
  279. editLevel(row) {
  280. this.level.show = true;
  281. this.current_area = row;
  282. },
  283. onCancel() {
  284. this.createDialogShow = false
  285. },
  286. onCreate() {
  287. this.form = {
  288. id: 0,
  289. community_name: '',
  290. province_id: 0,
  291. city_id: 0,
  292. district_id: 0,
  293. town_id: '',
  294. province: '',
  295. city: '',
  296. district: '',
  297. town: '',
  298. street: '',
  299. lng: '',
  300. lat: '',
  301. fully_address: '',
  302. lat_lng: '',
  303. addressComponents: null
  304. }
  305. this.address = null
  306. this.createDialogShow = true
  307. this.getDistrict(3);
  308. },
  309. addressChange(e) {
  310. this.town_list = []
  311. this.town_id = '';
  312. if (e.length === 3) {
  313. this.form.province_id = e[0]
  314. this.form.city_id = e[1]
  315. this.form.district_id = e[2]
  316. this.getTownList(e[2]);
  317. }
  318. },
  319. setFullyAddress() {
  320. let address = '';
  321. for (let districtKey in this.district) {
  322. if (this.district[districtKey].id === this.form.province_id) {
  323. address += this.district[districtKey].name
  324. for (let districtElementKey in this.district[districtKey].list) {
  325. if (this.district[districtKey].list[districtElementKey].id === this.form.city_id) {
  326. address += this.district[districtKey].list[districtElementKey].name
  327. for (let districtElementChildKey in this.district[districtKey].list[districtElementKey].list) {
  328. if (this.district[districtKey].list[districtElementKey].list[districtElementChildKey].id === this.form.district_id) {
  329. address += this.district[districtKey].list[districtElementKey].list[districtElementChildKey].name
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }
  336. for (let townListKey in this.town_list) {
  337. if (this.form.town_id === this.town_list[townListKey].id) {
  338. address += this.town_list[townListKey].name
  339. }
  340. }
  341. address += this.form.community_name
  342. this.form.fully_address = address
  343. },
  344. getTownList(district_id) {
  345. request({
  346. params: {
  347. r: 'area/default/get-town-list',
  348. district_id: district_id
  349. },
  350. }).then(e => {
  351. if (e.data.code === 0) {
  352. this.town_list = e.data.data.list;
  353. }
  354. }).catch(e => {
  355. });
  356. },
  357. // 获取省市区列表
  358. getDistrict(level) {
  359. if (level) {
  360. level1 = level;
  361. } else{
  362. level1 = 1;
  363. }
  364. request({
  365. params: {
  366. r: 'area/default/district',
  367. level: level1
  368. },
  369. }).then(e => {
  370. if (e.data.code == 0) {
  371. this.district = e.data.data.district;
  372. }
  373. }).catch(e => {
  374. });
  375. },
  376. areaClick(row) {
  377. //console.log('选择了用户row='+JSON.stringify(row))
  378. this.edit.id = row.id
  379. },
  380. onSubmit() {
  381. this.$refs['form'].validate((valid) => {
  382. if (valid) {
  383. this.loading = true
  384. request({
  385. method: 'post',
  386. params: {
  387. r: 'area/community/create',
  388. },
  389. data: this.form
  390. }).then(e => {
  391. this.loading = false;
  392. if (e.data.code === 0) {
  393. this.createDialogShow = false
  394. this.search.page = 1;
  395. this.loadData()
  396. this.$message.success(e.data.msg);
  397. } else {
  398. this.$message.error(e.data.msg);
  399. }
  400. }).catch(e => {
  401. this.loading = false;
  402. });
  403. } else {
  404. console.log(valid)
  405. }
  406. })
  407. },
  408. mapEvent(e) {
  409. this.form.lat_lng = e.lat + ',' + e.long;
  410. this.form.lng = e.long;
  411. this.form.lat = e.lat;
  412. this.form.fully_address = e.address;
  413. this.form.addressComponents = e.address_component
  414. this.form.street = e.address_component.street_number
  415. this.mapDialogShow = false
  416. },
  417. onShowMap(e) {
  418. if (this.form.id === 0) this.setFullyAddress()
  419. this.mapDialogShow = true
  420. },
  421. onHideMapDialog(e) {
  422. this.mapDialogShow = false
  423. },
  424. onDelete(item, index) {
  425. request({
  426. method: 'post',
  427. params: {
  428. r: 'area/community/delete',
  429. },
  430. data: {id: item.id}
  431. }).then(e => {
  432. this.loading = false;
  433. if (e.data.code === 0) {
  434. this.$message.success(e.data.msg);
  435. this.list.splice(index, 1)
  436. } else {
  437. this.$message.error(e.data.msg);
  438. }
  439. }).catch(e => {
  440. });
  441. },
  442. onChangeStatus(item) {
  443. request({
  444. method: 'post',
  445. params: {
  446. r: 'area/community/status',
  447. },
  448. data: {id: item.id, status: item.status}
  449. }).then(e => {
  450. this.loading = false;
  451. if (e.data.code === 0) {
  452. this.$message.success(e.data.msg);
  453. } else {
  454. this.$message.error(e.data.msg);
  455. }
  456. }).catch(e => {
  457. });
  458. },
  459. onEditRow(item, index) {
  460. this.onCreate()
  461. this.address = [
  462. item.province_id,
  463. item.city_id,
  464. item.district_id,
  465. ];
  466. console.log(item.id)
  467. this.getTownList(item.district_id);
  468. this.form = item
  469. this.form.lat_lng = item.lat + ',' + item.lng;
  470. }
  471. },
  472. // 加载的时候获取到列表页
  473. mounted() {
  474. // 数据初始化
  475. this.LoadDataType = -1;
  476. this.loadData();
  477. }
  478. })
  479. </script>