index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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-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="请选择地址" 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-item v-if="mainForm.type == 'B'" label="商品出入库" prop="joinCode">
  98. <el-radio-group v-model="mainForm.joinCode">
  99. <el-radio :label="true">关联条码</el-radio>
  100. <el-radio :label="false">不关联条码</el-radio>
  101. </el-radio-group>
  102. </el-form-item>
  103. </el-form>
  104. <div slot="footer" class="dialog-footer">
  105. <el-button @click="data.removeTab()">取 消</el-button>
  106. <el-button type="primary" @click="submitMainForm(data.removeTab)">确 定</el-button>
  107. </div>
  108. </div>
  109. </div>
  110. </template>
  111. </zj-tab-page>
  112. </template>
  113. <script>
  114. import { getDepartmentList, addDepartment, editDepartment, getDepartmentDetail, deleteDepartment } from '@/api/setting'
  115. import geographicalPosi from '@/components/geographicalPosi/index.vue'
  116. export default {
  117. components: { geographicalPosi },
  118. data() {
  119. return {
  120. dataList: [], // 列表数据
  121. dataList2: [], // 列表数据
  122. listLoading: true, // 列表加载loading
  123. currentPage: 1, // 当前页码
  124. pageSize: 15, // 每页数量
  125. editId: null,
  126. mainFormType: 'add',
  127. mainFormVisible: false,
  128. addressVisible: false,
  129. input: '',
  130. value1: [],
  131. levels: [],
  132. types: [{ label: '平台', value: 'A' }, { label: '商户', value: 'B' }, { label: '网点', value: 'C' }],
  133. mainForm: {
  134. parentId: '',
  135. name: '',
  136. linkName: '',
  137. websitPhone: '',
  138. lat: '',
  139. lng: '',
  140. address: '',
  141. status: true,
  142. isIncre: true,
  143. joinCode: true,
  144. type: ""
  145. },
  146. mainFormRules: {
  147. name: [{ required: true, message: '请填写网点名称', trigger: 'blur' }],
  148. linkName: [{ required: true, message: '请填写联系人名称', trigger: 'blur' }],
  149. websitPhone: [{ required: true, message: '请填写联系人电话', trigger: 'blur' }],
  150. address: [{ required: true, message: '请选择GPS地址', trigger: 'blur' }],
  151. }
  152. }
  153. },
  154. created() {
  155. this.getList()
  156. },
  157. computed: {
  158. showList() {
  159. return [...this.dataList]
  160. .filter(item => {
  161. return (
  162. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  163. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  164. )
  165. })
  166. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  167. },
  168. listTotal() {
  169. return [...this.dataList].filter(item => {
  170. return (
  171. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  172. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  173. )
  174. }).length
  175. }
  176. },
  177. watch: {
  178. value1() {
  179. this.$nextTick(() => {
  180. this.currentPage = 1
  181. })
  182. },
  183. input() {
  184. this.$nextTick(() => {
  185. this.currentPage = 1
  186. })
  187. }
  188. },
  189. methods: {
  190. // 获取网点列表
  191. getList() {
  192. var list_ = []
  193. var levels = []
  194. function dg(list, level = 1, pname = []) {
  195. for (let { children, name, ...item } of list) {
  196. console.log(item)
  197. var n_ = ''
  198. for (var i = 1; i < level; i++) n_ += ` -> `
  199. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  200. if (!~levels.indexOf(level)) levels.push(level)
  201. if (children && children.length) dg(children, level + 1, [...pname, name])
  202. }
  203. }
  204. getDepartmentList().then(res => {
  205. this.dataList2 = res.data
  206. dg(res.data)
  207. this.dataList = list_
  208. this.levels = levels
  209. })
  210. },
  211. selectAddress(res) {
  212. this.mainForm.lng = res.center[0]
  213. this.mainForm.lat = res.center[1]
  214. this.mainForm.address = res.name
  215. },
  216. // 更改每页数量
  217. handleSizeChange(val) {
  218. this.pageSize = val
  219. this.currentPage = 1
  220. // this.getList()
  221. },
  222. // 更改当前页
  223. handleCurrentChange(val) {
  224. this.currentPage = val
  225. // this.getList()
  226. },
  227. // 操作 - 删除
  228. handleDelete(id) {
  229. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  230. confirmButtonText: '确定',
  231. cancelButtonText: '取消',
  232. showClose: false,
  233. type: 'warning'
  234. }).then(() => {
  235. deleteDepartment({ id: id }).then(res => {
  236. this.getList()
  237. this.$successMsg()
  238. })
  239. }).catch(() => {
  240. });
  241. },
  242. // 打开 新增编辑 网点表单
  243. openMainForm(type, id) {
  244. this.$refs.tabPage.addTab({
  245. // 对应显示的模块
  246. activeKey: type,
  247. // 唯一标识
  248. key: type,
  249. // 页签名称
  250. label: ({ edit: "编辑", add: "新增" })[type],
  251. // 打开时事件
  252. triggerEvent: () => {
  253. this.cancelMainForm()
  254. this.$nextTick(() => {
  255. this.mainFormType = type
  256. this.mainFormVisible = true
  257. if (type == 'add') {
  258. this.mainForm.parentId = id
  259. } else {
  260. this.editId = id
  261. getDepartmentDetail({ id }).then(res => {
  262. this.mainForm = {
  263. parentId: res.data.parentId,
  264. name: res.data.name,
  265. linkName: res.data.linkName,
  266. websitPhone: res.data.websitPhone,
  267. lat: res.data.lat,
  268. lng: res.data.lng,
  269. address: res.data.address,
  270. status: res.data.status,
  271. isIncre: res.data.isIncre,
  272. joinCode: res.data.joinCode,
  273. type: res.data.type,
  274. }
  275. })
  276. }
  277. })
  278. },
  279. // 关闭时事件
  280. closeEvent: () => {
  281. }
  282. })
  283. },
  284. // 取消 新增编辑 网点表单
  285. cancelMainForm() {
  286. this.mainFormVisible = false
  287. this.$refs?.mainForm?.resetFields()
  288. this.$data.mainForm = this.$options.data().mainForm
  289. },
  290. // 提交 网点表单
  291. submitMainForm(removeTab) {
  292. this.$refs.mainForm.validate(valid => {
  293. if (valid) {
  294. let parentId = null
  295. if (this.mainForm.parentId instanceof Array) {
  296. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  297. } else {
  298. parentId = this.mainForm.parentId
  299. }
  300. let params = {
  301. parentId,
  302. name: this.mainForm.name,
  303. linkName: this.mainForm.linkName,
  304. websitPhone: this.mainForm.websitPhone,
  305. lat: this.mainForm.lat,
  306. lng: this.mainForm.lng,
  307. address: this.mainForm.address,
  308. status: this.mainForm.status,
  309. isIncre: this.mainForm.isIncre,
  310. joinCode: this.mainForm.joinCode
  311. }
  312. if (this.mainFormType == 'edit') {
  313. params.websitId = this.editId
  314. editDepartment(params).then(res => {
  315. this.getList()
  316. this.$successMsg('编辑成功')
  317. removeTab('list')
  318. })
  319. } else {
  320. addDepartment(params).then(res => {
  321. this.getList()
  322. this.$successMsg('添加成功')
  323. removeTab('list')
  324. })
  325. }
  326. }
  327. })
  328. }
  329. }
  330. }
  331. </script>
  332. <style scoped lang="scss"></style>