index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class='app-container'>
  3. <!-- 搜索 -->
  4. <el-form inline size="mini">
  5. <el-form-item label="门店名称:">
  6. <el-input v-model="form.name" placeholder="请输入门店名称" clearable />
  7. </el-form-item>
  8. <el-form-item label="城市筛选:">
  9. <el-cascader v-model="form.list" :options="options" placeholder="请选择省市区" clearable
  10. :props="{ value: 'id', label: 'name', children: 'childList', checkStrictly: true }" />
  11. </el-form-item>
  12. <el-form-item label="当前状态:">
  13. <el-select v-model="form.status" placeholder="请选择当前状态" clearable>
  14. <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  19. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  20. <el-button type="primary" icon="el-icon-plus" plain @click="getDetail()"
  21. v-hasPermi="['operation:map:add']">新增</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <!-- 列表 -->
  25. <el-table :data="tableData" v-loading="loading">
  26. <el-table-column label="序号" type="index" align="center" />
  27. <el-table-column label="门店名称" prop="name" align="center" show-overflow-tooltip />
  28. <el-table-column label="联系电话" prop="linkPhone" align="center">
  29. <template slot-scope="scope">
  30. {{ scope.row.linkPhone ? scope.row.linkPhone : '暂无联系电话' }}
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="门店图片" align="center" width="100px">
  34. <template slot-scope="scope">
  35. <el-image :src="scope.row.icon" />
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="地区" align="center" :formatter="areaFormatter" />
  39. <el-table-column label="详细地址" prop="address" align="center" show-overflow-tooltip />
  40. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  41. <el-table-column label="创建时间" prop="createTime" align="center" />
  42. <el-table-column label="操作" align="center">
  43. <template slot-scope="scope">
  44. <el-button type="text" @click="getDetail(scope.row.id, true)">查看</el-button>
  45. <el-button v-if="scope.row.status === 0" type="text" @click="getChange(scope.row.id, 1, '禁用')"
  46. v-hasPermi="['operation:map:down']">禁用</el-button>
  47. <span v-else style="margin-left: 10px;">
  48. <el-button type="text" @click="getDetail(scope.row.id)" v-hasPermi="['operation:map:edit']">编辑</el-button>
  49. <el-button type="text" @click="getChange(scope.row.id, 0, '启用')"
  50. v-hasPermi="['operation:map:up']">启用</el-button>
  51. <el-button type="delete" @click="getDelete(scope.row)" v-hasPermi="['operation:map:delete']">删除</el-button>
  52. </span>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  57. @pagination="getList" />
  58. </div>
  59. </template>
  60. <script>
  61. import { list, options, change, remove } from '@/api/operation/map'
  62. export default {
  63. data() {
  64. return {
  65. // 遮罩层
  66. loading: false,
  67. // 表单
  68. form: {
  69. pageNum: 1,
  70. pageSize: 10,
  71. list: []
  72. },
  73. // 总数据
  74. total: 0,
  75. // 省市区
  76. options: [],
  77. // 列表
  78. tableData: [],
  79. // 当前状态
  80. statusOptions: [{
  81. value: 0,
  82. label: '启用'
  83. }, {
  84. value: 1,
  85. label: '禁用'
  86. }]
  87. }
  88. },
  89. watch: {
  90. 'form.list'(val) {
  91. this.form.province = val[0]
  92. this.form.city = val[1]
  93. this.form.area = val[2]
  94. }
  95. },
  96. async mounted() {
  97. await this.getOptions()
  98. this.getList()
  99. },
  100. methods: {
  101. // 列表
  102. getList() {
  103. this.loading = true
  104. list(this.form).then(res => {
  105. if (res.code === 0) {
  106. this.tableData = res.data.records
  107. this.total = res.data.total
  108. this.loading = false
  109. }
  110. })
  111. },
  112. // 搜索
  113. getSearch() {
  114. this.form.pageNum = 1
  115. this.getList()
  116. },
  117. // 重置
  118. getRefresh() {
  119. this.form = {
  120. pageNum: 1,
  121. pageSize: 10
  122. }
  123. this.getList()
  124. },
  125. // 省市区
  126. getOptions() {
  127. return new Promise((reslove, reject) => {
  128. options().then(res => {
  129. if (res.code === 0) {
  130. reslove(this.options = res.data)
  131. }
  132. })
  133. })
  134. },
  135. // 新增、 编辑、 查看
  136. getDetail(id, boolean) {
  137. this.$router.push({
  138. path: `/operation/map/detail`,
  139. query: {
  140. id: id,
  141. boolean: boolean
  142. }
  143. })
  144. },
  145. // 启用 禁用
  146. getChange(id, status, title) {
  147. change(id, status).then(res => {
  148. if (res.code === 0) {
  149. this.$message.success(`${title}成功!`)
  150. this.getList()
  151. }
  152. })
  153. },
  154. // 删除
  155. getDelete(row) {
  156. this.$confirm(`是否删除${row.name}?`, '提示', {
  157. type: 'warning'
  158. }).then(() => {
  159. remove(row.id).then(res => {
  160. if (res.code === 0) {
  161. this.$message.success('删除成功!')
  162. this.getList()
  163. }
  164. })
  165. })
  166. },
  167. // 字典翻译
  168. areaFormatter(row) {
  169. let province = this.options.find(i => i.id == row.province)
  170. let city = province.childList.find(i => i.id == row.city)
  171. let area = city.childList.find(i => i.id == row.area)
  172. return `${province.name}-${city.name}-${area.name}`
  173. },
  174. statusFormatter(row) {
  175. return this.selectDictLabel(this.statusOptions, row.status)
  176. }
  177. }
  178. }
  179. </script>