index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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"> </el-option>
  9. </el-select>
  10. <span style="display: inline-block; width: 220px; margin-left: 10px"
  11. ><el-input v-model="input" placeholder="模糊搜索"></el-input
  12. ></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
  39. type="primary"
  40. size="mini"
  41. icon="el-icon-edit"
  42. @click="openMainForm('edit', scope.row.websitId)"
  43. >编辑</el-button
  44. >
  45. <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleDelete(scope.row.websitId)"
  46. >删除</el-button
  47. >
  48. <el-button
  49. v-if="!!~['A', 'B'].indexOf(scope.row.type)"
  50. :type="{ A: 'primary', B: 'warning' }[scope.row.type]"
  51. plain
  52. size="mini"
  53. icon="el-icon-plus"
  54. @click="openMainForm('add', scope.row.websitId)"
  55. >
  56. 添加{{ scope.row.type == 'A' ? '商户' : scope.row.type == 'B' ? '网点' : '网点' }}
  57. </el-button>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. </div>
  62. <div class="pagination clearfix">
  63. <div class="fr">
  64. <el-pagination
  65. @size-change="handleSizeChange"
  66. @current-change="handleCurrentChange"
  67. :current-page="currentPage"
  68. :page-sizes="[15, 20, 30, 50]"
  69. :page-size="pageSize"
  70. layout="total, sizes, prev, pager, next, jumper"
  71. :total="listTotal"
  72. >
  73. </el-pagination>
  74. </div>
  75. </div>
  76. </div>
  77. <div v-if="~['add', 'edit'].indexOf(activeKey)">
  78. <el-form ref="mainForm" :model="mainForm" :rules="mainFormRules" label-width="100px">
  79. <el-row :gutter="20" justify="start">
  80. <el-col :span="6">
  81. <el-form-item label="上级" prop="parentId">
  82. <el-cascader
  83. style="width: 100%"
  84. :options="dataList2"
  85. :props="{ checkStrictly: true, value: 'websitId', label: 'name' }"
  86. v-model="mainForm.parentId"
  87. filterable
  88. clearable
  89. >
  90. </el-cascader>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="6">
  94. <el-form-item label="名称" prop="name">
  95. <el-input placeholder="请输入网点名称" v-model="mainForm.name"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="6">
  99. <el-form-item label="联系人" prop="linkName">
  100. <el-input placeholder="请输入联系人名称" v-model="mainForm.linkName"></el-input>
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="6">
  104. <el-form-item label="联系人电话" prop="websitPhone">
  105. <el-input
  106. placeholder="请输入联系人电话"
  107. maxlength="11"
  108. type="number"
  109. v-model="mainForm.websitPhone"
  110. ></el-input>
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="12">
  114. <el-form-item label="地址" prop="address">
  115. <div style="display: flex">
  116. <el-input placeholder="请选择地址" style="margin-right: 20px" v-model="mainForm.address"></el-input>
  117. <geographicalPosi :formData="mainForm" @selectPosi="selectAddress"></geographicalPosi>
  118. </div>
  119. </el-form-item>
  120. </el-col>
  121. <el-col :span="6">
  122. <el-form-item label="电子支付商户" prop="payWorkerCodeId">
  123. <el-select v-model="mainForm.payWorkerCodeId" placeholder="请选择">
  124. <el-option v-for="item in PayConfigList" :key="item.value" :label="item.label" :value="item.value">
  125. </el-option>
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :span="6">
  130. <el-form-item label="状态" prop="status">
  131. <el-radio-group v-model="mainForm.status">
  132. <el-radio :label="true">启用</el-radio>
  133. <el-radio :label="false">禁用</el-radio>
  134. </el-radio-group>
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="24">
  138. <el-form-item label="通联支付" prop="isUseAllinpay">
  139. <el-switch v-model="mainForm.isUseAllinpay" active-color="#13ce66" inactive-color="#ff4949">
  140. </el-switch>
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="24" v-if="mainForm.isUseAllinpay">
  144. <el-button
  145. v-if="!editId"
  146. type="text"
  147. @click="
  148. () => {
  149. mainForm.payConfigList.push({})
  150. }
  151. "
  152. >添加</el-button
  153. >
  154. <el-table
  155. :data="editId ? [{}, ...(mainForm.payConfigList || [])] : mainForm.payConfigList || []"
  156. style="width: 100%"
  157. >
  158. <el-table-column prop="name" label="商户名称">
  159. <template slot-scope="scope">
  160. <el-input
  161. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  162. v-model="scope.row.name"
  163. placeholder="请输入内容"
  164. ></el-input>
  165. <span v-else>{{ scope.row.type }}</span>
  166. </template>
  167. </el-table-column>
  168. <el-table-column prop="orgId" label="通联集团号">
  169. <template slot-scope="scope">
  170. <el-input
  171. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  172. v-model="scope.row.orgId"
  173. placeholder="请输入内容"
  174. ></el-input>
  175. <span v-else>{{ scope.row.type }}</span>
  176. </template>
  177. </el-table-column>
  178. <el-table-column prop="type" label="类别">
  179. <template slot-scope="scope">
  180. <el-select
  181. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  182. v-model="scope.row.type"
  183. placeholder="请选择"
  184. >
  185. <el-option label="辅材" value="M" />
  186. <el-option label="配件" value="P" />
  187. </el-select>
  188. <span v-else>{{ { M: '辅材', P: '配件' }[scope.row.type] }}</span>
  189. </template>
  190. </el-table-column>
  191. <el-table-column prop="mchNo" label="通联商户号">
  192. <template slot-scope="scope">
  193. <el-input
  194. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  195. v-model="scope.row.mchNo"
  196. placeholder="请输入内容"
  197. ></el-input>
  198. <span v-else>{{ scope.row.type }}</span>
  199. </template>
  200. </el-table-column>
  201. <el-table-column prop="appid" label="通联商户appid">
  202. <template slot-scope="scope">
  203. <el-input
  204. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  205. v-model="scope.row.appid"
  206. placeholder="请输入内容"
  207. ></el-input>
  208. <span v-else>{{ scope.row.type }}</span>
  209. </template>
  210. </el-table-column>
  211. <el-table-column prop="status" label="状态">
  212. <template slot-scope="scope">
  213. <el-select
  214. v-if="!!~indexs.indexOf(scope.$index) || !editId"
  215. v-model="scope.row.status"
  216. placeholder="请选择"
  217. >
  218. <el-option label="开启" :value="true" />
  219. <el-option label="关闭" :value="false" />
  220. </el-select>
  221. <span v-else>{{ scope.row.type ? '开启' : '关闭' }}</span>
  222. </template>
  223. </el-table-column>
  224. <el-table-column v-if="editId" prop="createBy" label="创建人"> </el-table-column>
  225. <el-table-column v-if="editId" prop="createTime" label="创建时间"> </el-table-column>
  226. <el-table-column v-if="editId" prop="updateBy" label="修改人"> </el-table-column>
  227. <el-table-column v-if="editId" prop="" label="操作">
  228. <template slot-scope="scope">
  229. <el-button v-if="!!~indexs.indexOf(scope.$index)" type="text" @click="caozuoanniuSave(scope)"
  230. >保存</el-button
  231. >
  232. <el-button
  233. v-if="!~indexs.indexOf(scope.$index) && scope.$index > 0"
  234. type="text"
  235. @click="caozuoanniuEid(scope)"
  236. >编辑</el-button
  237. >
  238. <el-button
  239. v-if="!~indexs.indexOf(scope.$index) && scope.$index > 0"
  240. type="text"
  241. @click="caozuoanniuDel(scope)"
  242. >删除</el-button
  243. >
  244. </template>
  245. </el-table-column>
  246. </el-table>
  247. </el-col>
  248. <!-- <el-col :span="6">
  249. <el-form-item label="增值服务" prop="isIncre">
  250. <el-radio-group v-model="mainForm.isIncre">
  251. <el-radio :label="true">启用</el-radio>
  252. <el-radio :label="false">禁用</el-radio>
  253. </el-radio-group>
  254. </el-form-item>
  255. </el-col> -->
  256. </el-row>
  257. <!-- <el-form-item v-if="mainForm.type == 'B'" label="商品出入库" prop="joinCode">
  258. <el-radio-group v-model="mainForm.joinCode">
  259. <el-radio :label="true">关联条码</el-radio>
  260. <el-radio :label="false">不关联条码</el-radio>
  261. </el-radio-group>
  262. </el-form-item> -->
  263. </el-form>
  264. <div class="footer">
  265. <el-button @click="data.removeTab()">取 消</el-button>
  266. <el-button type="primary" @click="submitMainForm(data.removeTab)">确 定</el-button>
  267. </div>
  268. </div>
  269. </div>
  270. </template>
  271. </zj-tab-page>
  272. </template>
  273. <script>
  274. import {
  275. getDepartmentList,
  276. addDepartment,
  277. editDepartment,
  278. getDepartmentDetail,
  279. deleteDepartment,
  280. adminWebsitSavePayConfig,
  281. adminWebsitDeletePayConfig
  282. } from '@/api/setting'
  283. import geographicalPosi from '@/components/geographicalPosi/index.vue'
  284. import { adminCompanyPayConfigList } from '@/api/paymentMerchantManagement'
  285. export default {
  286. components: { geographicalPosi },
  287. data() {
  288. return {
  289. PayConfigList: [],
  290. dataList: [], // 列表数据
  291. dataList2: [], // 列表数据
  292. listLoading: true, // 列表加载loading
  293. currentPage: 1, // 当前页码
  294. pageSize: 15, // 每页数量
  295. editId: null,
  296. mainFormType: 'add',
  297. mainFormVisible: false,
  298. addressVisible: false,
  299. input: '',
  300. value1: [],
  301. levels: [],
  302. types: [
  303. { label: '平台', value: 'A' },
  304. { label: '商户', value: 'B' },
  305. { label: '网点', value: 'C' }
  306. ],
  307. mainForm: {
  308. parentId: '',
  309. name: '',
  310. linkName: '',
  311. websitPhone: '',
  312. lat: '',
  313. lng: '',
  314. address: '',
  315. status: true,
  316. isUseAllinpay: true,
  317. payWorkerCodeId: '',
  318. payConfigList: [],
  319. isIncre: true,
  320. joinCode: '',
  321. type: ''
  322. },
  323. mainFormRules: {
  324. name: [{ required: true, message: '请填写网点名称', trigger: 'blur' }],
  325. linkName: [{ required: true, message: '请填写联系人名称', trigger: 'blur' }],
  326. websitPhone: [{ required: true, message: '请填写联系人电话', trigger: 'blur' }],
  327. address: [{ required: true, message: '请选择GPS地址', trigger: 'blur' }]
  328. },
  329. indexs: [0]
  330. }
  331. },
  332. created() {
  333. this.getList()
  334. },
  335. computed: {
  336. showList() {
  337. return [...this.dataList]
  338. .filter(item => {
  339. return (
  340. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  341. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  342. )
  343. })
  344. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  345. },
  346. listTotal() {
  347. return [...this.dataList].filter(item => {
  348. return (
  349. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  350. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  351. )
  352. }).length
  353. }
  354. },
  355. watch: {
  356. value1() {
  357. this.$nextTick(() => {
  358. this.currentPage = 1
  359. })
  360. },
  361. input() {
  362. this.$nextTick(() => {
  363. this.currentPage = 1
  364. })
  365. }
  366. },
  367. methods: {
  368. // 获取网点列表
  369. getList() {
  370. var list_ = []
  371. var levels = []
  372. function dg(list, level = 1, pname = []) {
  373. for (let { children, name, ...item } of list) {
  374. console.log(item)
  375. var n_ = ''
  376. for (var i = 1; i < level; i++) n_ += ` -> `
  377. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  378. if (!~levels.indexOf(level)) levels.push(level)
  379. if (children && children.length) dg(children, level + 1, [...pname, name])
  380. }
  381. }
  382. getDepartmentList().then(res => {
  383. this.dataList2 = res.data
  384. dg(res.data)
  385. this.dataList = list_
  386. this.levels = levels
  387. })
  388. },
  389. selectAddress(res) {
  390. this.mainForm.lng = res.center[0]
  391. this.mainForm.lat = res.center[1]
  392. this.mainForm.address = res.name
  393. },
  394. // 更改每页数量
  395. handleSizeChange(val) {
  396. this.pageSize = val
  397. this.currentPage = 1
  398. // this.getList()
  399. },
  400. // 更改当前页
  401. handleCurrentChange(val) {
  402. this.currentPage = val
  403. // this.getList()
  404. },
  405. // 操作 - 删除
  406. handleDelete(id) {
  407. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  408. confirmButtonText: '确定',
  409. cancelButtonText: '取消',
  410. showClose: false,
  411. type: 'warning'
  412. })
  413. .then(() => {
  414. deleteDepartment({ id: id }).then(res => {
  415. this.getList()
  416. this.$successMsg()
  417. })
  418. })
  419. .catch(() => {})
  420. },
  421. // 打开 新增编辑 网点表单
  422. openMainForm(type, id) {
  423. this.$refs.tabPage.addTab({
  424. // 对应显示的模块
  425. activeKey: type,
  426. // 唯一标识
  427. key: type,
  428. // 页签名称
  429. label: { edit: '编辑', add: '新增' }[type],
  430. // 打开时事件
  431. triggerEvent: () => {
  432. adminCompanyPayConfigList({ pageNum: 1, pageSize: -1, params: [] }).then(res => {
  433. this.PayConfigList = res.data.records.map(item => ({
  434. label: item.payMerchantName,
  435. value: item.id
  436. }))
  437. })
  438. this.cancelMainForm()
  439. this.$nextTick(() => {
  440. this.mainFormType = type
  441. this.mainFormVisible = true
  442. if (type == 'add') {
  443. this.editId = null
  444. this.mainForm.parentId = id
  445. } else {
  446. this.editId = id
  447. getDepartmentDetail({ id }).then(res => {
  448. this.mainForm = {
  449. parentId: res.data.parentId,
  450. name: res.data.name,
  451. linkName: res.data.linkName,
  452. websitPhone: res.data.websitPhone,
  453. lat: res.data.lat,
  454. lng: res.data.lng,
  455. address: res.data.address,
  456. status: res.data.status,
  457. isUseAllinpay: res.data.isUseAllinpay,
  458. payWorkerCodeId: res.data.payWorkerCodeId,
  459. payConfigList: res.data.payConfigList || [],
  460. isIncre: res.data.isIncre,
  461. joinCode: res.data.joinCode,
  462. type: res.data.type
  463. }
  464. })
  465. }
  466. })
  467. },
  468. // 关闭时事件
  469. closeEvent: () => {}
  470. })
  471. },
  472. // 取消 新增编辑 网点表单
  473. cancelMainForm() {
  474. this.mainFormVisible = false
  475. this.$refs?.mainForm?.resetFields()
  476. this.$data.mainForm = this.$options.data().mainForm
  477. },
  478. // 提交 网点表单
  479. submitMainForm(removeTab) {
  480. this.$refs.mainForm.validate(valid => {
  481. if (valid) {
  482. let parentId = null
  483. if (this.mainForm.parentId instanceof Array) {
  484. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  485. } else {
  486. parentId = this.mainForm.parentId
  487. }
  488. let params = {
  489. parentId,
  490. name: this.mainForm.name,
  491. linkName: this.mainForm.linkName,
  492. websitPhone: this.mainForm.websitPhone,
  493. lat: this.mainForm.lat,
  494. lng: this.mainForm.lng,
  495. address: this.mainForm.address,
  496. status: this.mainForm.status,
  497. isIncre: this.mainForm.isIncre,
  498. isUseAllinpay: this.mainForm.isUseAllinpay,
  499. payWorkerCodeId: this.mainForm.payWorkerCodeId,
  500. payConfigList: this.mainForm.payConfigList.filter(item => item.websitId),
  501. joinCode: this.mainForm.joinCode
  502. }
  503. if (this.mainFormType == 'edit') {
  504. params.websitId = this.editId
  505. editDepartment(params).then(res => {
  506. this.getList()
  507. this.$successMsg('编辑成功')
  508. removeTab('list')
  509. })
  510. } else {
  511. addDepartment(params).then(res => {
  512. this.getList()
  513. this.$successMsg('添加成功')
  514. removeTab('list')
  515. })
  516. }
  517. }
  518. })
  519. },
  520. caozuoanniuSave(data) {
  521. adminWebsitSavePayConfig({
  522. ...{
  523. companyWechatName: JSON.parse(localStorage.getItem('greemall_user'))?.companyName || '',
  524. companyWechatId: JSON.parse(localStorage.getItem('greemall_user'))?.companyWechatId || ''
  525. },
  526. ...data.row
  527. }).then(res => {
  528. getDepartmentDetail({ id: data.row.websitId }).then(res => {
  529. this.mainForm = {
  530. parentId: res.data.parentId,
  531. name: res.data.name,
  532. linkName: res.data.linkName,
  533. websitPhone: res.data.websitPhone,
  534. lat: res.data.lat,
  535. lng: res.data.lng,
  536. address: res.data.address,
  537. status: res.data.status,
  538. isUseAllinpay: res.data.isUseAllinpay,
  539. payWorkerCodeId: res.data.payWorkerCodeId,
  540. payConfigList: res.data.payConfigList || [],
  541. isIncre: res.data.isIncre,
  542. joinCode: res.data.joinCode,
  543. type: res.data.type
  544. }
  545. this.$successMsg('保存成功')
  546. if (data.$index > 0) {
  547. if (~indexs.indexOf(data.$index)) {
  548. this.indexs.splice(indexs.indexOf(data.$index), 1)
  549. }
  550. }
  551. })
  552. })
  553. },
  554. caozuoanniuDel(data) {
  555. adminWebsitDeletePayConfig({
  556. id: data.row.id
  557. }).then(res => {
  558. getDepartmentDetail({ id: data.row.websitId }).then(res => {
  559. this.mainForm = {
  560. parentId: res.data.parentId,
  561. name: res.data.name,
  562. linkName: res.data.linkName,
  563. websitPhone: res.data.websitPhone,
  564. lat: res.data.lat,
  565. lng: res.data.lng,
  566. address: res.data.address,
  567. status: res.data.status,
  568. isUseAllinpay: res.data.isUseAllinpay,
  569. payWorkerCodeId: res.data.payWorkerCodeId,
  570. payConfigList: res.data.payConfigList || [],
  571. isIncre: res.data.isIncre,
  572. joinCode: res.data.joinCode,
  573. type: res.data.type
  574. }
  575. this.$successMsg('删除成功')
  576. if (data.$index > 0) {
  577. if (~indexs.indexOf(data.$index)) {
  578. this.indexs.splice(indexs.indexOf(data.$index), 1)
  579. }
  580. }
  581. })
  582. })
  583. },
  584. caozuoanniuEid(data) {
  585. if (!~this.indexs.indexOf(data.$index)) {
  586. this.indexs.push(data.$index)
  587. }
  588. }
  589. }
  590. }
  591. </script>
  592. <style scoped lang="scss">
  593. .footer {
  594. position: fixed;
  595. bottom: 0;
  596. left: 0;
  597. z-index: 1;
  598. width: 100%;
  599. background: #fff;
  600. padding: 15px 40px;
  601. box-sizing: border-box;
  602. transition: all 0.28s;
  603. text-align: right;
  604. box-shadow: 0 2px 5px 0 rgb(0 0 0 / 50%), 0 2px 5px 0 rgb(0 0 0 / 10%);
  605. &.hideSidebar {
  606. margin-left: 54px;
  607. width: calc(100vw - 54px);
  608. }
  609. &.openSidebar {
  610. margin-left: 210px;
  611. width: calc(100vw - 210px);
  612. }
  613. .tips {
  614. font-size: 12px;
  615. color: red;
  616. margin-top: 10px;
  617. }
  618. }
  619. </style>