index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <tabPage ref="tabPage" :defaultActives="[{ key: 'list', label: '列表页面', essential: true }]">
  3. <template slot-scope="{activeKey}">
  4. <div class="app-container">
  5. <div v-if="activeKey == 'list'" class="mymain-container">
  6. <div>
  7. <el-select v-model="value1" multiple placeholder="显示层级">
  8. <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value">
  9. </el-option>
  10. </el-select>
  11. <span style="display: inline-block; width: 220px; margin-left: 10px"><el-input v-model="input"
  12. placeholder="模糊搜索"></el-input></span>
  13. </div>
  14. <div class="table">
  15. <el-table :data="showList" border>
  16. <el-table-column prop="type" label="级别" width="70">
  17. <template slot-scope="scope">
  18. <el-tag v-if="scope.row.type == 'A'" type="success">平台</el-tag>
  19. <el-tag v-if="scope.row.type == 'B'">商户</el-tag>
  20. <el-tag v-if="scope.row.type == 'C'" type="warning">网点</el-tag>
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="name" label="网点名称"> </el-table-column>
  24. <el-table-column prop="" label="结构">
  25. <template slot-scope="scope">
  26. {{ scope.row.pname.join(' -> ') }}
  27. </template>
  28. </el-table-column>
  29. <el-table-column align="center" label="状态" class-name="status-col" width="80">
  30. <template slot-scope="scope">
  31. <el-tag :type="scope.row.status ? 'success' : 'danger'">{{
  32. scope.row.status ? '启用' : '禁用'
  33. }}</el-tag>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="操作" width="268" fixed="right">
  37. <template slot-scope="scope">
  38. <el-button type="primary" size="mini" icon="el-icon-edit"
  39. @click="openMainForm('edit', scope.row.websitId)">编辑</el-button>
  40. <el-button type="primary" size="mini" icon="el-icon-edit"
  41. @click="handleDelete(scope.row.websitId)">删除</el-button>
  42. <el-button v-if="!!~['A', 'B'].indexOf(scope.row.type)"
  43. :type="({ A: 'primary', B: 'warning' })[scope.row.type]" plain size="mini" icon="el-icon-plus"
  44. @click="openMainForm('add', scope.row.websitId)">
  45. 添加{{ scope.row.type
  46. == 'A' ? '商户' :
  47. scope.row.type == 'B' ? '网点' : '网点' }}
  48. </el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. </div>
  53. <div class="pagination clearfix">
  54. <div class="fr">
  55. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
  56. :current-page="currentPage" :page-sizes="[15, 20, 30, 50]" :page-size="pageSize"
  57. layout="total, sizes, prev, pager, next, jumper" :total="listTotal">
  58. </el-pagination>
  59. </div>
  60. </div>
  61. </div>
  62. <div v-if="~['add', 'edit'].indexOf(activeKey)">
  63. <el-form ref="mainForm" :model="mainForm" :rules="mainFormRules" label-position="top" label-width="80px">
  64. <el-form-item label="上级" prop="parentId">
  65. <el-cascader style="width: 100%" :options="dataList2"
  66. :props="{ checkStrictly: true, value: 'websitId', label: 'name' }" v-model="mainForm.parentId" filterable
  67. clearable>
  68. </el-cascader>
  69. </el-form-item>
  70. <el-form-item label="名称" prop="name">
  71. <el-input placeholder="请输入网点名称" v-model="mainForm.name"></el-input>
  72. </el-form-item>
  73. <el-form-item label="联系人" prop="linkName">
  74. <el-input placeholder="请输入联系人名称" v-model="mainForm.linkName"></el-input>
  75. </el-form-item>
  76. <el-form-item label="联系人电话" prop="websitPhone">
  77. <el-input placeholder="请输入联系人电话" maxlength="11" type="number" v-model="mainForm.websitPhone"></el-input>
  78. </el-form-item>
  79. <el-form-item label="地址" prop="address">
  80. <div style="display:flex;">
  81. <el-input placeholder="请选择地址" readonly style="margin-right: 20px;" v-model="mainForm.address"></el-input>
  82. <geographicalPosi :formData="mainForm" @selectPosi="selectAddress"></geographicalPosi>
  83. </div>
  84. </el-form-item>
  85. <el-form-item label="状态" prop="status">
  86. <el-radio-group v-model="mainForm.status">
  87. <el-radio :label="true">启用</el-radio>
  88. <el-radio :label="false">禁用</el-radio>
  89. </el-radio-group>
  90. </el-form-item>
  91. <el-form-item label="增值服务" prop="isIncre">
  92. <el-radio-group v-model="mainForm.isIncre">
  93. <el-radio :label="true">启用</el-radio>
  94. <el-radio :label="false">禁用</el-radio>
  95. </el-radio-group>
  96. </el-form-item>
  97. </el-form>
  98. <div slot="footer" class="dialog-footer">
  99. <el-button @click="cancelMainForm">取 消</el-button>
  100. <el-button type="primary" @click="submitMainForm">确 定</el-button>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. </tabPage>
  106. </template>
  107. <script>
  108. import { getDepartmentList, addDepartment, editDepartment, getDepartmentDetail, deleteDepartment } from '@/api/setting'
  109. import geographicalPosi from '@/components/geographicalPosi/index.vue'
  110. export default {
  111. components: { geographicalPosi },
  112. data() {
  113. return {
  114. dataList: [], // 列表数据
  115. dataList2: [], // 列表数据
  116. listLoading: true, // 列表加载loading
  117. currentPage: 1, // 当前页码
  118. pageSize: 15, // 每页数量
  119. editId: null,
  120. mainFormType: 'add',
  121. mainFormVisible: false,
  122. addressVisible: false,
  123. input: '',
  124. value1: [],
  125. levels: [],
  126. types: [{ label: '平台', value: 'A' }, { label: '商户', value: 'B' }, { label: '网点', value: 'C' }],
  127. mainForm: {
  128. parentId: '',
  129. name: '',
  130. linkName: '',
  131. websitPhone: '',
  132. lat: '',
  133. lng: '',
  134. address: '',
  135. status: true,
  136. isIncre: true,
  137. },
  138. mainFormRules: {
  139. name: [{ required: true, message: '请填写网点名称', trigger: 'blur' }],
  140. linkName: [{ required: true, message: '请填写联系人名称', trigger: 'blur' }],
  141. websitPhone: [{ required: true, message: '请填写联系人电话', trigger: 'blur' }],
  142. address: [{ required: true, message: '请选择GPS地址', trigger: 'blur' }],
  143. }
  144. }
  145. },
  146. created() {
  147. this.getList()
  148. },
  149. computed: {
  150. showList() {
  151. return [...this.dataList]
  152. .filter(item => {
  153. return (
  154. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  155. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  156. )
  157. })
  158. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  159. },
  160. listTotal() {
  161. return [...this.dataList].filter(item => {
  162. return (
  163. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  164. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  165. )
  166. }).length
  167. }
  168. },
  169. watch: {
  170. value1() {
  171. this.$nextTick(() => {
  172. this.currentPage = 1
  173. })
  174. },
  175. input() {
  176. this.$nextTick(() => {
  177. this.currentPage = 1
  178. })
  179. }
  180. },
  181. methods: {
  182. // 获取网点列表
  183. getList() {
  184. var list_ = []
  185. var levels = []
  186. function dg(list, level = 1, pname = []) {
  187. for (let { children, name, ...item } of list) {
  188. console.log(item)
  189. var n_ = ''
  190. for (var i = 1; i < level; i++) n_ += ` -> `
  191. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  192. if (!~levels.indexOf(level)) levels.push(level)
  193. if (children && children.length) dg(children, level + 1, [...pname, name])
  194. }
  195. }
  196. getDepartmentList().then(res => {
  197. this.dataList2 = res.data
  198. dg(res.data)
  199. this.dataList = list_
  200. this.levels = levels
  201. })
  202. },
  203. selectAddress(res) {
  204. this.mainForm.lng = res.center[0]
  205. this.mainForm.lat = res.center[1]
  206. this.mainForm.address = res.name
  207. },
  208. // 更改每页数量
  209. handleSizeChange(val) {
  210. this.pageSize = val
  211. this.currentPage = 1
  212. // this.getList()
  213. },
  214. // 更改当前页
  215. handleCurrentChange(val) {
  216. this.currentPage = val
  217. // this.getList()
  218. },
  219. // 操作 - 删除
  220. handleDelete(id) {
  221. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  222. confirmButtonText: '确定',
  223. cancelButtonText: '取消',
  224. showClose: false,
  225. type: 'warning'
  226. }).then(() => {
  227. deleteDepartment({ id: id }).then(res => {
  228. this.getList()
  229. this.$successMsg()
  230. })
  231. }).catch(() => {
  232. });
  233. },
  234. // 打开 新增编辑 网点表单
  235. openMainForm(type, id) {
  236. this.$refs.tabPage.addTab({
  237. // 对应显示的模块
  238. activeKey: type,
  239. // 唯一标识
  240. key: type,
  241. // 页签名称
  242. label: ({ edit: "编辑", add: "新增" })[type],
  243. // 打开时事件
  244. triggerEvent: () => {
  245. this.cancelMainForm()
  246. this.$nextTick(()=>{
  247. this.mainFormType = type
  248. this.mainFormVisible = true
  249. if (type == 'add') {
  250. this.mainForm.parentId = id
  251. } else {
  252. this.editId = id
  253. getDepartmentDetail({ id }).then(res => {
  254. this.mainForm = {
  255. parentId: res.data.parentId,
  256. name: res.data.name,
  257. linkName: res.data.linkName,
  258. websitPhone: res.data.websitPhone,
  259. lat: res.data.lat,
  260. lng: res.data.lng,
  261. address: res.data.address,
  262. status: res.data.status,
  263. isIncre: res.data.isIncre
  264. }
  265. })
  266. }
  267. })
  268. },
  269. // 关闭时事件
  270. closeEvent: () => {
  271. }
  272. })
  273. },
  274. // 取消 新增编辑 网点表单
  275. cancelMainForm() {
  276. this.mainFormVisible = false
  277. this.$refs?.mainForm?.resetFields()
  278. this.$data.mainForm = this.$options.data().mainForm
  279. },
  280. // 提交 网点表单
  281. submitMainForm() {
  282. this.$refs.mainForm.validate(valid => {
  283. if (valid) {
  284. let parentId = null
  285. if (this.mainForm.parentId instanceof Array) {
  286. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  287. } else {
  288. parentId = this.mainForm.parentId
  289. }
  290. let params = {
  291. parentId,
  292. name: this.mainForm.name,
  293. linkName: this.mainForm.linkName,
  294. websitPhone: this.mainForm.websitPhone,
  295. lat: this.mainForm.lat,
  296. lng: this.mainForm.lng,
  297. address: this.mainForm.address,
  298. status: this.mainForm.status,
  299. isIncre: this.mainForm.isIncre
  300. }
  301. if (this.mainFormType == 'edit') {
  302. params.websitId = this.editId
  303. editDepartment(params).then(res => {
  304. this.cancelMainForm()
  305. this.getList()
  306. this.$successMsg('编辑成功')
  307. })
  308. } else {
  309. addDepartment(params).then(res => {
  310. this.cancelMainForm()
  311. this.getList()
  312. this.$successMsg('添加成功')
  313. })
  314. }
  315. }
  316. })
  317. }
  318. }
  319. }
  320. </script>
  321. <style scoped lang="scss"></style>