index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <style>
  2. .el-table th>.cell {
  3. color: #333;
  4. font-weight: bold;
  5. font-size: 14px;
  6. }
  7. .table1 .el-table__footer-wrapper,
  8. .table1 .el-table__header-wrapper {
  9. border-bottom: 1.4px solid #D6D6D6;
  10. }
  11. .user_img{
  12. position: relative;
  13. margin-right: 8px;
  14. /* height: 50px;
  15. width: 50px; */
  16. }
  17. .default-avatar{
  18. width: 50px;
  19. height: 50px;
  20. border-radius: 50%;
  21. margin-right: 8px;
  22. }
  23. .uer-nickname {
  24. flex: 1;
  25. }
  26. </style>
  27. <div id="app">
  28. <div class="table-body" style="min-width: 1000px;">
  29. <div slot="header" class="clearfix" style="height: 20px;">
  30. <span>大区管理</span>
  31. <el-button style="float: right; padding: 3px 12px;margin-left: 20px;height: 32px;" type="primary" @click="onCreate">添加大区</el-button>
  32. </div>
  33. <div slot="header" class="clearfix" style="margin-top: 20px;">
  34. <div class="demo-input-suffix" style="margin-top: 20px;margin-bottom: 10px;">
  35. <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="请输入大区名称/ID" v-model="search.keyword" clearable></el-input>
  36. <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="输入管辖区域名称" v-model="search.address" clearable></el-input>
  37. <el-button type="primary" size="small" @click="toSearch">搜索</el-button>
  38. </div>
  39. </div>
  40. <template>
  41. <el-table :data="list" stripe style="width: 100%" v-loading="listLoading" class="table1">
  42. <el-table-column prop="id" label="ID" align="center" width="160"></el-table-column>
  43. <el-table-column label="大区名称" prop="regional_name" width="200"></el-table-column>
  44. <el-table-column label="管辖区域" prop="area" align="left">
  45. <template slot-scope="scope">
  46. {{scope.row.area}}
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="启用" align="center" width="80">
  50. <template slot-scope="scope">
  51. <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0"
  52. @change="onChangeStatus(scope.row)"></el-switch>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="添加时间" width="180" align="center">
  56. <template slot-scope="scope">
  57. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" width="120" align="center">
  61. <template slot-scope="scope">
  62. <el-button @click="onEditRow(scope.row, scope.$index)" type="text" size="mini">编辑</el-button>
  63. <el-popconfirm @confirm="onDelete(scope.row, scope.$index)" title="您真的要删除当前大区吗?">
  64. <el-button type="text" slot="reference" style="color: #F56C6C">删除</el-button>
  65. </el-popconfirm>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. <div flex="main:right cross:center" style="margin-top: 20px;">
  70. <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize"
  71. style="display: inline-block;float: right;" background @current-change="pageChange"
  72. layout="prev, pager, next" :total="pagination.totalCount">
  73. </el-pagination>
  74. </div>
  75. </template>
  76. <el-dialog :visible.sync="createDialogShow" width="600px" title="添加/修改大区" center>
  77. <div v-loading="loading">
  78. <el-form ref="form" :model="form" size="small" label-width="120px">
  79. <el-form-item label="大区名称" prop="regional_name" :rules="[{required: true, message: '大区名称不能为空'}]">
  80. <el-input v-model="form.regional_name" placeholder="请输入大区名称" clearable></el-input>
  81. </el-form-item>
  82. <el-form-item label="添加省份" prop="province_ids" :rules="[{required: true, message: '所辖省份不能为空'}]">
  83. <el-select v-model="selectDistrict" multiple placeholder="请选择大区所辖省份" filterable clearable style="width: 100%;" @change="handleChangeProvice">
  84. <el-option v-for="item in district" :key="item.id" :label="item.name" :value="item.id" :disabled="existProvinces.indexOf(item.id) != -1"></el-option>
  85. </el-select>
  86. </el-form-item>
  87. </el-form>
  88. </div>
  89. <span slot="footer" class="dialog-footer">
  90. <el-button @click="onCancel" type="default" size="small">取消</el-button>
  91. <el-button type="primary" :loading="btnLoading" style="margin-bottom: 10px;" size="small"
  92. @click="onSubmit">保存</el-button>
  93. </span>
  94. </el-dialog>
  95. </div>
  96. </div>
  97. <script>
  98. const app = new Vue({
  99. el: '#app',
  100. data() {
  101. return {
  102. btnLoading: false,
  103. createDialogShow: false,
  104. listLoading: false,
  105. list: [],
  106. pagination: {
  107. total: 0
  108. },
  109. loading: false,
  110. LoadDataType: -1, //默认显示全部数据
  111. dialogFormVisible: false, //默认不显示弹窗
  112. dialogLoading:false,
  113. level_map:null,
  114. selectDistrict: [],
  115. search: {
  116. page: 1,
  117. limit:10,
  118. keyword: '',
  119. address: '',
  120. },
  121. levelList:[
  122. ],
  123. show: false,
  124. level: {
  125. show: false,
  126. area: null,
  127. },
  128. current_area:null,
  129. form: {
  130. id: 0,
  131. regional_name: '',
  132. province_ids: '',
  133. area: ''
  134. },
  135. district: [],
  136. existProvinces: [],
  137. address: null,
  138. props: {
  139. value: 'id',
  140. label: 'name',
  141. children: 'list',
  142. },
  143. mapDialogShow: false
  144. }
  145. },
  146. methods: {
  147. //状态按钮的点击事件
  148. toSearch() {
  149. this.search.page = 1;
  150. this.loadData();
  151. },
  152. toSearchActivity() {
  153. this.loadData()
  154. },
  155. update(row) {
  156. this.$confirm('删除该区域代理, 是否继续?', '提示', {
  157. confirmButtonText: '确定',
  158. cancelButtonText: '取消',
  159. type: 'warning'
  160. }).then(() => {
  161. this.loading = true;
  162. request({
  163. params: {
  164. r: 'area/default/delete',
  165. },
  166. method: 'post',
  167. data: {
  168. id: row.id,
  169. }
  170. }).then(e => {
  171. let res = e.data;
  172. this.listLoading = false;
  173. if (res.code === 0) {
  174. this.$message.success(res.msg);
  175. this.loadData();
  176. } else {
  177. this.$message.error(res.msg);
  178. }
  179. }).catch(e => {});
  180. }).catch(() => {
  181. this.$message({
  182. type: 'info',
  183. message: '系统错误'
  184. });
  185. });
  186. },
  187. pageChange(page) {
  188. this.search.page = page;
  189. this.loadData();
  190. },
  191. loadData() {
  192. this.listLoading = true;
  193. let params = {
  194. r: 'area/regional/index'
  195. };
  196. params = Object.assign(params, this.search);
  197. request({
  198. params: params,
  199. method: 'get',
  200. }).then(e => {
  201. let res = e.data;
  202. this.listLoading = false;
  203. if (res.code === 0) {
  204. this.list = res.data.list;
  205. this.level_map = res.data.level_map;
  206. this.pagination = res.data.pagination; //拿到关于页码页容量的数据
  207. } else {
  208. this.$message.error(res.msg);
  209. }
  210. }).catch(e => {});
  211. },
  212. onCancel() {
  213. this.createDialogShow = false
  214. },
  215. onCreate() {
  216. this.form = {
  217. id: 0,
  218. regional_name: '',
  219. province_ids: '',
  220. area: ''
  221. }
  222. this.selectDistrict = []
  223. this.createDialogShow = true
  224. this.getExist();
  225. this.getDistrict();
  226. },
  227. addressChange(e) {
  228. },
  229. // 获取省市区列表
  230. getDistrict() {
  231. request({
  232. params: {
  233. r: 'area/default/district',
  234. level: 1
  235. },
  236. }).then(e => {
  237. if (e.data.code == 0) {
  238. this.district = e.data.data.district;
  239. }
  240. }).catch(e => { });
  241. },
  242. getExist() {
  243. request({
  244. params: {
  245. r: 'area/regional/exist'
  246. },
  247. }).then(e => {
  248. if (e.data.code == 0) {
  249. if (this.selectDistrict.length > 0) {
  250. this.existProvinces = e.data.data.filter(item => !this.selectDistrict.includes(item));
  251. }else {
  252. this.existProvinces = e.data.data;
  253. }
  254. }
  255. }).catch(e => { });
  256. },
  257. onSubmit() {
  258. this.$refs['form'].validate((valid) => {
  259. if (valid) {
  260. this.loading = true
  261. request({
  262. method: 'post',
  263. params: {
  264. r: 'area/regional/save',
  265. },
  266. data: this.form
  267. }).then(e => {
  268. this.loading = false;
  269. if (e.data.code === 0) {
  270. this.createDialogShow = false
  271. this.search.page = 1;
  272. this.loadData()
  273. this.$message.success(e.data.msg);
  274. } else {
  275. this.$message.error(e.data.msg);
  276. }
  277. }).catch(e => {
  278. this.loading = false;
  279. });
  280. } else {
  281. console.log(valid)
  282. }
  283. })
  284. },
  285. onDelete(item, index) {
  286. request({
  287. method: 'post',
  288. params: {
  289. r: 'area/regional/delete',
  290. },
  291. data: {id: item.id}
  292. }).then(e => {
  293. this.loading = false;
  294. if (e.data.code === 0) {
  295. this.$message.success(e.data.msg);
  296. this.list.splice(index, 1)
  297. } else {
  298. this.$message.error(e.data.msg);
  299. }
  300. }).catch(e => {
  301. });
  302. },
  303. onChangeStatus(item) {
  304. request({
  305. method: 'post',
  306. params: {
  307. r: 'area/regional/status',
  308. },
  309. data: {id: item.id, status: item.status}
  310. }).then(e => {
  311. this.loading = false;
  312. if (e.data.code === 0) {
  313. this.$message.success(e.data.msg);
  314. } else {
  315. this.$message.error(e.data.msg);
  316. }
  317. }).catch(e => {
  318. });
  319. },
  320. onEditRow(item, index) {
  321. this.onCreate()
  322. this.form = JSON.parse(JSON.stringify(item))
  323. this.selectDistrict = (item.province_ids + '').split(',').map(Number)
  324. console.log(this.selectDistrict)
  325. },
  326. handleChangeProvice(e) {
  327. let provinceSelected = [];
  328. let areaSelected = [];
  329. for(let i=0; i<e.length; i++){
  330. this.district.find(item => { //这里的options就是数据源
  331. if(item.id == e[i]){
  332. provinceSelected.push(item.id)
  333. areaSelected.push(item.name)
  334. }
  335. })
  336. }
  337. this.form.province_ids = provinceSelected.join(',')
  338. this.form.area = areaSelected.join(',');
  339. }
  340. },
  341. // 加载的时候获取到列表页
  342. mounted() {
  343. // 数据初始化
  344. this.LoadDataType = -1;
  345. this.loadData();
  346. }
  347. })
  348. </script>