index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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="120px">
  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.name }}</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.orgId }}</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.mchNo }}</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.appid }}</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. payWorkerCodeId: [{ required: true, message: '请选择电子支付商户', trigger: 'blur' }]
  329. },
  330. indexs: [0]
  331. }
  332. },
  333. created() {
  334. this.getList()
  335. },
  336. computed: {
  337. showList() {
  338. return [...this.dataList]
  339. .filter(item => {
  340. return (
  341. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  342. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  343. )
  344. })
  345. .splice((this.currentPage - 1) * this.pageSize, this.pageSize)
  346. },
  347. listTotal() {
  348. return [...this.dataList].filter(item => {
  349. return (
  350. (this.value1.length ? !!~this.value1.indexOf(item.type) : true) &&
  351. (this.input ? !!~item.name.indexOf(this.input) || !!~item.pname.indexOf(this.input) : true)
  352. )
  353. }).length
  354. }
  355. },
  356. watch: {
  357. value1() {
  358. this.$nextTick(() => {
  359. this.currentPage = 1
  360. })
  361. },
  362. input() {
  363. this.$nextTick(() => {
  364. this.currentPage = 1
  365. })
  366. }
  367. },
  368. methods: {
  369. // 获取网点列表
  370. getList() {
  371. var list_ = []
  372. var levels = []
  373. function dg(list, level = 1, pname = []) {
  374. for (let { children, name, ...item } of list) {
  375. console.log(item)
  376. var n_ = ''
  377. for (var i = 1; i < level; i++) n_ += ` -> `
  378. list_.push({ ...item, name: n_ + name, level, pname: [...pname] })
  379. if (!~levels.indexOf(level)) levels.push(level)
  380. if (children && children.length) dg(children, level + 1, [...pname, name])
  381. }
  382. }
  383. getDepartmentList().then(res => {
  384. this.dataList2 = res.data
  385. dg(res.data)
  386. this.dataList = list_
  387. this.levels = levels
  388. })
  389. },
  390. selectAddress(res) {
  391. this.mainForm.lng = res.center[0]
  392. this.mainForm.lat = res.center[1]
  393. this.mainForm.address = res.name
  394. },
  395. // 更改每页数量
  396. handleSizeChange(val) {
  397. this.pageSize = val
  398. this.currentPage = 1
  399. // this.getList()
  400. },
  401. // 更改当前页
  402. handleCurrentChange(val) {
  403. this.currentPage = val
  404. // this.getList()
  405. },
  406. // 操作 - 删除
  407. handleDelete(id) {
  408. this.$confirm('此操作将永久删除, 是否继续?', '提示', {
  409. confirmButtonText: '确定',
  410. cancelButtonText: '取消',
  411. showClose: false,
  412. type: 'warning'
  413. })
  414. .then(() => {
  415. deleteDepartment({ id: id }).then(res => {
  416. this.getList()
  417. this.$successMsg()
  418. })
  419. })
  420. .catch(() => {})
  421. },
  422. // 打开 新增编辑 网点表单
  423. openMainForm(type, id) {
  424. this.$refs.tabPage.addTab({
  425. // 对应显示的模块
  426. activeKey: type,
  427. // 唯一标识
  428. key: type,
  429. // 页签名称
  430. label: { edit: '编辑', add: '新增' }[type],
  431. // 打开时事件
  432. triggerEvent: () => {
  433. adminCompanyPayConfigList({ pageNum: 1, pageSize: -1, params: [] }).then(res => {
  434. this.PayConfigList = res.data.records.map(item => ({
  435. label: item.payMerchantName,
  436. value: item.id
  437. }))
  438. })
  439. this.cancelMainForm()
  440. this.$nextTick(() => {
  441. this.mainFormType = type
  442. this.mainFormVisible = true
  443. if (type == 'add') {
  444. this.editId = null
  445. this.mainForm.parentId = id
  446. } else {
  447. this.editId = id
  448. getDepartmentDetail({ id }).then(res => {
  449. this.mainForm = {
  450. parentId: res.data.parentId,
  451. name: res.data.name,
  452. linkName: res.data.linkName,
  453. websitPhone: res.data.websitPhone,
  454. lat: res.data.lat,
  455. lng: res.data.lng,
  456. address: res.data.address,
  457. status: res.data.status,
  458. isUseAllinpay: res.data.isUseAllinpay,
  459. payWorkerCodeId: res.data.payWorkerCodeId,
  460. payConfigList: res.data.payConfigList || [],
  461. isIncre: res.data.isIncre,
  462. joinCode: res.data.joinCode,
  463. type: res.data.type
  464. }
  465. })
  466. }
  467. })
  468. },
  469. // 关闭时事件
  470. closeEvent: () => {}
  471. })
  472. },
  473. // 取消 新增编辑 网点表单
  474. cancelMainForm() {
  475. this.mainFormVisible = false
  476. this.$refs?.mainForm?.resetFields()
  477. this.$data.mainForm = this.$options.data().mainForm
  478. },
  479. // 提交 网点表单
  480. submitMainForm(removeTab) {
  481. this.$refs.mainForm.validate(valid => {
  482. if (valid) {
  483. let parentId = null
  484. if (this.mainForm.parentId instanceof Array) {
  485. parentId = this.mainForm.parentId[this.mainForm.parentId.length - 1]
  486. } else {
  487. parentId = this.mainForm.parentId
  488. }
  489. let params = {
  490. parentId,
  491. name: this.mainForm.name,
  492. linkName: this.mainForm.linkName,
  493. websitPhone: this.mainForm.websitPhone,
  494. lat: this.mainForm.lat,
  495. lng: this.mainForm.lng,
  496. address: this.mainForm.address,
  497. status: this.mainForm.status,
  498. isIncre: this.mainForm.isIncre,
  499. isUseAllinpay: this.mainForm.isUseAllinpay,
  500. payWorkerCodeId: this.mainForm.payWorkerCodeId,
  501. payConfigList: this.mainForm.payConfigList,
  502. joinCode: this.mainForm.joinCode
  503. }
  504. if (this.mainFormType == 'edit') {
  505. params.websitId = this.editId
  506. editDepartment(params).then(res => {
  507. this.getList()
  508. this.$successMsg('编辑成功')
  509. removeTab('list')
  510. })
  511. } else {
  512. addDepartment(params).then(res => {
  513. this.getList()
  514. this.$successMsg('添加成功')
  515. removeTab('list')
  516. })
  517. }
  518. }
  519. })
  520. },
  521. caozuoanniuSave(data) {
  522. adminWebsitSavePayConfig({
  523. ...{
  524. companyWechatName: JSON.parse(localStorage.getItem('greemall_user'))?.companyName || '',
  525. companyWechatId: JSON.parse(localStorage.getItem('greemall_user'))?.companyWechatId || '',
  526. websitId: this.editId
  527. },
  528. ...data.row
  529. }).then(res => {
  530. getDepartmentDetail({ id: this.editId }).then(res => {
  531. this.mainForm = {
  532. parentId: res.data.parentId,
  533. name: res.data.name,
  534. linkName: res.data.linkName,
  535. websitPhone: res.data.websitPhone,
  536. lat: res.data.lat,
  537. lng: res.data.lng,
  538. address: res.data.address,
  539. status: res.data.status,
  540. isUseAllinpay: res.data.isUseAllinpay,
  541. payWorkerCodeId: res.data.payWorkerCodeId,
  542. payConfigList: res.data.payConfigList || [],
  543. isIncre: res.data.isIncre,
  544. joinCode: res.data.joinCode,
  545. type: res.data.type
  546. }
  547. this.$successMsg('保存成功')
  548. if (data.$index > 0) {
  549. if (~indexs.indexOf(data.$index)) {
  550. this.indexs.splice(indexs.indexOf(data.$index), 1)
  551. }
  552. }
  553. })
  554. })
  555. },
  556. caozuoanniuDel(data) {
  557. adminWebsitDeletePayConfig({
  558. id: data.row.id
  559. }).then(res => {
  560. getDepartmentDetail({ id: this.editId }).then(res => {
  561. this.mainForm = {
  562. parentId: res.data.parentId,
  563. name: res.data.name,
  564. linkName: res.data.linkName,
  565. websitPhone: res.data.websitPhone,
  566. lat: res.data.lat,
  567. lng: res.data.lng,
  568. address: res.data.address,
  569. status: res.data.status,
  570. isUseAllinpay: res.data.isUseAllinpay,
  571. payWorkerCodeId: res.data.payWorkerCodeId,
  572. payConfigList: res.data.payConfigList || [],
  573. isIncre: res.data.isIncre,
  574. joinCode: res.data.joinCode,
  575. type: res.data.type
  576. }
  577. this.$successMsg('删除成功')
  578. if (data.$index > 0) {
  579. if (~indexs.indexOf(data.$index)) {
  580. this.indexs.splice(indexs.indexOf(data.$index), 1)
  581. }
  582. }
  583. })
  584. })
  585. },
  586. caozuoanniuEid(data) {
  587. if (!~this.indexs.indexOf(data.$index)) {
  588. this.indexs.push(data.$index)
  589. }
  590. }
  591. }
  592. }
  593. </script>
  594. <style scoped lang="scss">
  595. .footer {
  596. position: fixed;
  597. bottom: 0;
  598. left: 0;
  599. z-index: 1;
  600. width: 100%;
  601. background: #fff;
  602. padding: 15px 40px;
  603. box-sizing: border-box;
  604. transition: all 0.28s;
  605. text-align: right;
  606. box-shadow: 0 2px 5px 0 rgb(0 0 0 / 50%), 0 2px 5px 0 rgb(0 0 0 / 10%);
  607. &.hideSidebar {
  608. margin-left: 54px;
  609. width: calc(100vw - 54px);
  610. }
  611. &.openSidebar {
  612. margin-left: 210px;
  613. width: calc(100vw - 210px);
  614. }
  615. .tips {
  616. font-size: 12px;
  617. color: red;
  618. margin-top: 10px;
  619. }
  620. }
  621. </style>