index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 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. },
  145. mainFormRules: {
  146. name: [{ required: true, message: '请填写网点名称', trigger: 'blur' }],
  147. linkName: [{ required: true, message: '请填写联系人名称', trigger: 'blur' }],
  148. websitPhone: [{ required: true, message: '请填写联系人电话', trigger: 'blur' }],
  149. address: [{ required: true, message: '请选择GPS地址', trigger: 'blur' }],
  150. }
  151. }
  152. },
  153. created() {
  154. this.getList()
  155. },
  156. computed: {
  157. showList() {
  158. return [...this.dataList]
  159. .filter(item => {
  160. return (
  161. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  162. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  163. )
  164. })
  165. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  166. },
  167. listTotal() {
  168. return [...this.dataList].filter(item => {
  169. return (
  170. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  171. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  172. )
  173. }).length
  174. }
  175. },
  176. watch: {
  177. value1() {
  178. this.$nextTick(() => {
  179. this.currentPage = 1
  180. })
  181. },
  182. input() {
  183. this.$nextTick(() => {
  184. this.currentPage = 1
  185. })
  186. }
  187. },
  188. methods: {
  189. // 获取网点列表
  190. getList() {
  191. var list_ = []
  192. var levels = []
  193. function dg(list, level = 1, pname = []) {
  194. for (let { children, name, ...item } of list) {
  195. console.log(item)
  196. var n_ = ''
  197. for (var i = 1; i < level; i++) n_ += ` -> `
  198. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  199. if (!~levels.indexOf(level)) levels.push(level)
  200. if (children && children.length) dg(children, level + 1, [...pname, name])
  201. }
  202. }
  203. getDepartmentList().then(res => {
  204. this.dataList2 = res.data
  205. dg(res.data)
  206. this.dataList = list_
  207. this.levels = levels
  208. })
  209. },
  210. selectAddress(res) {
  211. this.mainForm.lng = res.center[0]
  212. this.mainForm.lat = res.center[1]
  213. this.mainForm.address = res.name
  214. },
  215. // 更改每页数量
  216. handleSizeChange(val) {
  217. this.pageSize = val
  218. this.currentPage = 1
  219. // this.getList()
  220. },
  221. // 更改当前页
  222. handleCurrentChange(val) {
  223. this.currentPage = val
  224. // this.getList()
  225. },
  226. // 操作 - 删除
  227. handleDelete(id) {
  228. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  229. confirmButtonText: '确定',
  230. cancelButtonText: '取消',
  231. showClose: false,
  232. type: 'warning'
  233. }).then(() => {
  234. deleteDepartment({ id: id }).then(res => {
  235. this.getList()
  236. this.$successMsg()
  237. })
  238. }).catch(() => {
  239. });
  240. },
  241. // 打开 新增编辑 网点表单
  242. openMainForm(type, id) {
  243. this.$refs.tabPage.addTab({
  244. // 对应显示的模块
  245. activeKey: type,
  246. // 唯一标识
  247. key: type,
  248. // 页签名称
  249. label: ({ edit: "编辑", add: "新增" })[type],
  250. // 打开时事件
  251. triggerEvent: () => {
  252. this.cancelMainForm()
  253. this.$nextTick(() => {
  254. this.mainFormType = type
  255. this.mainFormVisible = true
  256. if (type == 'add') {
  257. this.mainForm.parentId = id
  258. } else {
  259. this.editId = id
  260. getDepartmentDetail({ id }).then(res => {
  261. this.mainForm = {
  262. parentId: res.data.parentId,
  263. name: res.data.name,
  264. linkName: res.data.linkName,
  265. websitPhone: res.data.websitPhone,
  266. lat: res.data.lat,
  267. lng: res.data.lng,
  268. address: res.data.address,
  269. status: res.data.status,
  270. isIncre: res.data.isIncre,
  271. joinCode: res.data.joinCode
  272. }
  273. })
  274. }
  275. })
  276. },
  277. // 关闭时事件
  278. closeEvent: () => {
  279. }
  280. })
  281. },
  282. // 取消 新增编辑 网点表单
  283. cancelMainForm() {
  284. this.mainFormVisible = false
  285. this.$refs?.mainForm?.resetFields()
  286. this.$data.mainForm = this.$options.data().mainForm
  287. },
  288. // 提交 网点表单
  289. submitMainForm(removeTab) {
  290. this.$refs.mainForm.validate(valid => {
  291. if (valid) {
  292. let parentId = null
  293. if (this.mainForm.parentId instanceof Array) {
  294. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  295. } else {
  296. parentId = this.mainForm.parentId
  297. }
  298. let params = {
  299. parentId,
  300. name: this.mainForm.name,
  301. linkName: this.mainForm.linkName,
  302. websitPhone: this.mainForm.websitPhone,
  303. lat: this.mainForm.lat,
  304. lng: this.mainForm.lng,
  305. address: this.mainForm.address,
  306. status: this.mainForm.status,
  307. isIncre: this.mainForm.isIncre,
  308. joinCode: this.mainForm.joinCode
  309. }
  310. if (this.mainFormType == 'edit') {
  311. params.websitId = this.editId
  312. editDepartment(params).then(res => {
  313. this.getList()
  314. this.$successMsg('编辑成功')
  315. removeTab('list')
  316. })
  317. } else {
  318. addDepartment(params).then(res => {
  319. this.getList()
  320. this.$successMsg('添加成功')
  321. removeTab('list')
  322. })
  323. }
  324. }
  325. })
  326. }
  327. }
  328. }
  329. </script>
  330. <style scoped lang="scss"></style>