index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title + '-列表', essential: true }]">
  3. <template slot-scope="{activeKey, data}">
  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-width="100px">
  64. <el-row :gutter="20" justify="start">
  65. <el-col :span="6">
  66. <el-form-item label="上级" prop="parentId">
  67. <el-cascader style="width: 100%" :options="dataList2"
  68. :props="{ checkStrictly: true, value: 'websitId', label: 'name' }" v-model="mainForm.parentId" filterable
  69. clearable>
  70. </el-cascader>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="6">
  74. <el-form-item label="名称" prop="name">
  75. <el-input placeholder="请输入网点名称" v-model="mainForm.name"></el-input>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="6">
  79. <el-form-item label="联系人" prop="linkName">
  80. <el-input placeholder="请输入联系人名称" v-model="mainForm.linkName"></el-input>
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="6">
  84. <el-form-item label="联系人电话" prop="websitPhone">
  85. <el-input placeholder="请输入联系人电话" maxlength="11" type="number" v-model="mainForm.websitPhone"></el-input>
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="12">
  89. <el-form-item label="地址" prop="address">
  90. <div style="display:flex;">
  91. <el-input placeholder="请选择地址" style="margin-right: 20px;" v-model="mainForm.address"></el-input>
  92. <geographicalPosi :formData="mainForm" @selectPosi="selectAddress"></geographicalPosi>
  93. </div>
  94. </el-form-item>
  95. </el-col>
  96. <el-col :span="6">
  97. <el-form-item label="状态" prop="status">
  98. <el-radio-group v-model="mainForm.status">
  99. <el-radio :label="true">启用</el-radio>
  100. <el-radio :label="false">禁用</el-radio>
  101. </el-radio-group>
  102. </el-form-item>
  103. </el-col>
  104. <el-col :span="6">
  105. <el-form-item label="增值服务" prop="isIncre">
  106. <el-radio-group v-model="mainForm.isIncre">
  107. <el-radio :label="true">启用</el-radio>
  108. <el-radio :label="false">禁用</el-radio>
  109. </el-radio-group>
  110. </el-form-item>
  111. </el-col>
  112. </el-row>
  113. <!-- <el-form-item v-if="mainForm.type == 'B'" label="商品出入库" prop="joinCode">
  114. <el-radio-group v-model="mainForm.joinCode">
  115. <el-radio :label="true">关联条码</el-radio>
  116. <el-radio :label="false">不关联条码</el-radio>
  117. </el-radio-group>
  118. </el-form-item> -->
  119. </el-form>
  120. <div class="footer">
  121. <el-button @click="data.removeTab()">取 消</el-button>
  122. <el-button type="primary" @click="submitMainForm(data.removeTab)">确 定</el-button>
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. </zj-tab-page>
  128. </template>
  129. <script>
  130. import { getDepartmentList, addDepartment, editDepartment, getDepartmentDetail, deleteDepartment } from '@/api/setting'
  131. import geographicalPosi from '@/components/geographicalPosi/index.vue'
  132. export default {
  133. components: { geographicalPosi },
  134. data() {
  135. return {
  136. dataList: [], // 列表数据
  137. dataList2: [], // 列表数据
  138. listLoading: true, // 列表加载loading
  139. currentPage: 1, // 当前页码
  140. pageSize: 15, // 每页数量
  141. editId: null,
  142. mainFormType: 'add',
  143. mainFormVisible: false,
  144. addressVisible: false,
  145. input: '',
  146. value1: [],
  147. levels: [],
  148. types: [{ label: '平台', value: 'A' }, { label: '商户', value: 'B' }, { label: '网点', value: 'C' }],
  149. mainForm: {
  150. parentId: '',
  151. name: '',
  152. linkName: '',
  153. websitPhone: '',
  154. lat: '',
  155. lng: '',
  156. address: '',
  157. status: true,
  158. isIncre: true,
  159. joinCode: "",
  160. type: ""
  161. },
  162. mainFormRules: {
  163. name: [{ required: true, message: '请填写网点名称', trigger: 'blur' }],
  164. linkName: [{ required: true, message: '请填写联系人名称', trigger: 'blur' }],
  165. websitPhone: [{ required: true, message: '请填写联系人电话', trigger: 'blur' }],
  166. address: [{ required: true, message: '请选择GPS地址', trigger: 'blur' }],
  167. }
  168. }
  169. },
  170. created() {
  171. this.getList()
  172. },
  173. computed: {
  174. showList() {
  175. return [...this.dataList]
  176. .filter(item => {
  177. return (
  178. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  179. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  180. )
  181. })
  182. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  183. },
  184. listTotal() {
  185. return [...this.dataList].filter(item => {
  186. return (
  187. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  188. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  189. )
  190. }).length
  191. }
  192. },
  193. watch: {
  194. value1() {
  195. this.$nextTick(() => {
  196. this.currentPage = 1
  197. })
  198. },
  199. input() {
  200. this.$nextTick(() => {
  201. this.currentPage = 1
  202. })
  203. }
  204. },
  205. methods: {
  206. // 获取网点列表
  207. getList() {
  208. var list_ = []
  209. var levels = []
  210. function dg(list, level = 1, pname = []) {
  211. for (let { children, name, ...item } of list) {
  212. console.log(item)
  213. var n_ = ''
  214. for (var i = 1; i < level; i++) n_ += ` -> `
  215. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  216. if (!~levels.indexOf(level)) levels.push(level)
  217. if (children && children.length) dg(children, level + 1, [...pname, name])
  218. }
  219. }
  220. getDepartmentList().then(res => {
  221. this.dataList2 = res.data
  222. dg(res.data)
  223. this.dataList = list_
  224. this.levels = levels
  225. })
  226. },
  227. selectAddress(res) {
  228. this.mainForm.lng = res.center[0]
  229. this.mainForm.lat = res.center[1]
  230. this.mainForm.address = res.name
  231. },
  232. // 更改每页数量
  233. handleSizeChange(val) {
  234. this.pageSize = val
  235. this.currentPage = 1
  236. // this.getList()
  237. },
  238. // 更改当前页
  239. handleCurrentChange(val) {
  240. this.currentPage = val
  241. // this.getList()
  242. },
  243. // 操作 - 删除
  244. handleDelete(id) {
  245. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  246. confirmButtonText: '确定',
  247. cancelButtonText: '取消',
  248. showClose: false,
  249. type: 'warning'
  250. }).then(() => {
  251. deleteDepartment({ id: id }).then(res => {
  252. this.getList()
  253. this.$successMsg()
  254. })
  255. }).catch(() => {
  256. });
  257. },
  258. // 打开 新增编辑 网点表单
  259. openMainForm(type, id) {
  260. this.$refs.tabPage.addTab({
  261. // 对应显示的模块
  262. activeKey: type,
  263. // 唯一标识
  264. key: type,
  265. // 页签名称
  266. label: ({ edit: "编辑", add: "新增" })[type],
  267. // 打开时事件
  268. triggerEvent: () => {
  269. this.cancelMainForm()
  270. this.$nextTick(() => {
  271. this.mainFormType = type
  272. this.mainFormVisible = true
  273. if (type == 'add') {
  274. this.mainForm.parentId = id
  275. } else {
  276. this.editId = id
  277. getDepartmentDetail({ id }).then(res => {
  278. this.mainForm = {
  279. parentId: res.data.parentId,
  280. name: res.data.name,
  281. linkName: res.data.linkName,
  282. websitPhone: res.data.websitPhone,
  283. lat: res.data.lat,
  284. lng: res.data.lng,
  285. address: res.data.address,
  286. status: res.data.status,
  287. isIncre: res.data.isIncre,
  288. joinCode: res.data.joinCode,
  289. type: res.data.type,
  290. }
  291. })
  292. }
  293. })
  294. },
  295. // 关闭时事件
  296. closeEvent: () => {
  297. }
  298. })
  299. },
  300. // 取消 新增编辑 网点表单
  301. cancelMainForm() {
  302. this.mainFormVisible = false
  303. this.$refs?.mainForm?.resetFields()
  304. this.$data.mainForm = this.$options.data().mainForm
  305. },
  306. // 提交 网点表单
  307. submitMainForm(removeTab) {
  308. this.$refs.mainForm.validate(valid => {
  309. if (valid) {
  310. let parentId = null
  311. if (this.mainForm.parentId instanceof Array) {
  312. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  313. } else {
  314. parentId = this.mainForm.parentId
  315. }
  316. let params = {
  317. parentId,
  318. name: this.mainForm.name,
  319. linkName: this.mainForm.linkName,
  320. websitPhone: this.mainForm.websitPhone,
  321. lat: this.mainForm.lat,
  322. lng: this.mainForm.lng,
  323. address: this.mainForm.address,
  324. status: this.mainForm.status,
  325. isIncre: this.mainForm.isIncre,
  326. joinCode: this.mainForm.joinCode
  327. }
  328. if (this.mainFormType == 'edit') {
  329. params.websitId = this.editId
  330. editDepartment(params).then(res => {
  331. this.getList()
  332. this.$successMsg('编辑成功')
  333. removeTab('list')
  334. })
  335. } else {
  336. addDepartment(params).then(res => {
  337. this.getList()
  338. this.$successMsg('添加成功')
  339. removeTab('list')
  340. })
  341. }
  342. }
  343. })
  344. }
  345. }
  346. }
  347. </script>
  348. <style scoped lang="scss">
  349. .footer {
  350. position: fixed;
  351. bottom: 0;
  352. left: 0;
  353. z-index: 1;
  354. width: 100%;
  355. background: #fff;
  356. padding: 15px 40px;
  357. box-sizing: border-box;
  358. transition: all 0.28s;
  359. text-align: right;
  360. box-shadow: 0 2px 5px 0 rgb(0 0 0 / 50%), 0 2px 5px 0 rgb(0 0 0 / 10%);
  361. &.hideSidebar {
  362. margin-left: 54px;
  363. width: calc(100vw - 54px);
  364. }
  365. &.openSidebar {
  366. margin-left: 210px;
  367. width: calc(100vw - 210px);
  368. }
  369. .tips {
  370. font-size: 12px;
  371. color: red;
  372. margin-top: 10px;
  373. }
  374. }
  375. </style>