index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" size="small">
  4. <el-form-item label="租户" prop="tenantId">
  5. <el-select v-model="queryParams.tenantId" placeholder="选择租户" clearable filterable>
  6. <el-option v-for="c in companyList" :key="c.companyId" :label="c.companyName" :value="c.companyId" />
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="短信类型" prop="smsType">
  10. <el-select v-model="queryParams.smsType" placeholder="请选择" clearable>
  11. <el-option v-for="item in smsTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  16. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  17. </el-form-item>
  18. </el-form>
  19. <el-row :gutter="10" class="mb8">
  20. <el-col :span="1.5">
  21. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增绑定</el-button>
  22. </el-col>
  23. </el-row>
  24. <el-table v-loading="loading" :data="bindList" border size="small">
  25. <el-table-column label="ID" align="center" prop="id" width="60" />
  26. <el-table-column label="租户名称" align="center" prop="companyName" min-width="140" show-overflow-tooltip />
  27. <el-table-column label="接口名称" align="center" prop="apiName" min-width="140" show-overflow-tooltip />
  28. <el-table-column label="短信类型" align="center" prop="smsType" width="140">
  29. <template slot-scope="scope">
  30. <el-tag :type="scope.row.smsType === 1 ? 'success' : scope.row.smsType === 2 ? 'warning' : 'danger'" size="small">
  31. {{ smsTypeFormat(scope.row.smsType) }}
  32. </el-tag>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="服务商" align="center" prop="provider" width="80">
  36. <template slot-scope="scope">{{ providerFormat(scope.row.provider) }}</template>
  37. </el-table-column>
  38. <el-table-column label="优先级" align="center" prop="priority" width="70">
  39. <template slot-scope="scope">
  40. <el-tag type="warning" size="mini">{{ scope.row.priority || 1 }}</el-tag>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="成本价" align="center" prop="costPrice" width="100">
  44. <template slot-scope="scope">
  45. <span style="color:#909399">{{ scope.row.costPrice || '-' }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="租户售价(元/条)" align="center" prop="price" width="130">
  49. <template slot-scope="scope">
  50. <span style="color:#e6a23c;font-weight:bold">{{ scope.row.price }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="利润(元/条)" align="center" width="110">
  54. <template slot-scope="scope">
  55. <span style="color:#67c23a;font-weight:bold">{{ calcProfit(scope.row) }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="手动选择" align="center" prop="allowManual" width="80">
  59. <template slot-scope="scope">
  60. <el-tag :type="scope.row.allowManual === 1 ? 'success' : 'info'" size="mini">{{ scope.row.allowManual === 1 ? '允许' : '否' }}</el-tag>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="状态" align="center" prop="status" width="70">
  64. <template slot-scope="scope">
  65. <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'" size="small">{{ scope.row.status === 1 ? '启用' : '禁用' }}</el-tag>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作" align="center" width="160">
  69. <template slot-scope="scope">
  70. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">调价</el-button>
  71. <el-button size="mini" type="text" icon="el-icon-delete" style="color:#f56c6c" @click="handleDelete(scope.row)">解除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <!-- 新增绑定弹窗 -->
  76. <el-dialog title="新增短信接口-租户绑定" :visible.sync="addDialogVisible" width="500px" append-to-body>
  77. <el-form ref="addForm" :model="addForm" :rules="addRules" label-width="100px" size="small">
  78. <el-form-item label="选择接口" prop="apiId">
  79. <el-select v-model="addForm.apiId" placeholder="请选择短信接口" style="width:100%" @change="onApiChange">
  80. <el-option v-for="api in apiOptions" :key="api.apiId" :label="api.apiName + ' (' + smsTypeFormat(api.smsType) + ')'" :value="api.apiId" />
  81. </el-select>
  82. </el-form-item>
  83. <el-form-item label="选择租户" prop="tenantId">
  84. <el-select v-model="addForm.tenantId" placeholder="请选择租户" filterable style="width:100%">
  85. <el-option v-for="c in companyList" :key="c.tenantId" :label="c.companyName" :value="c.tenantId" />
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item label="租户售价" prop="price">
  89. <el-input-number v-model="addForm.price" :precision="4" :step="0.001" :min="0" style="width:100%" />
  90. <span style="color:#909399;font-size:12px;margin-left:8px">元/条</span>
  91. </el-form-item>
  92. <el-form-item label="优先级" prop="priority">
  93. <el-input-number v-model="addForm.priority" :min="1" :max="99" style="width:100%" />
  94. <span style="color:#909399;font-size:12px;margin-left:8px">1最高,同类型多接口时按优先级选择</span>
  95. </el-form-item>
  96. <el-form-item label="允许手动选择">
  97. <el-switch v-model="addForm.allowManual" :active-value="1" :inactive-value="0" active-text="允许" inactive-text="否" />
  98. <span style="color:#909399;font-size:12px;margin-left:8px">是否允许销售手动选择此接口发送</span>
  99. </el-form-item>
  100. <el-form-item v-if="selectedApiCost" label="">
  101. <span style="color:#909399;font-size:12px">该接口成本价: {{ selectedApiCost }} 元/条,建议售价 >= 成本价</span>
  102. </el-form-item>
  103. </el-form>
  104. <div slot="footer">
  105. <el-button type="primary" @click="submitAdd">确 定</el-button>
  106. <el-button @click="addDialogVisible = false">取 消</el-button>
  107. </div>
  108. </el-dialog>
  109. <!-- 调价弹窗 -->
  110. <el-dialog title="调整租户售价" :visible.sync="editDialogVisible" width="450px" append-to-body>
  111. <el-form ref="editForm" :model="editForm" label-width="100px" size="small">
  112. <el-form-item label="租户">
  113. <span>{{ editForm.companyName }}</span>
  114. </el-form-item>
  115. <el-form-item label="接口">
  116. <span>{{ editForm.apiName }}</span>
  117. </el-form-item>
  118. <el-form-item label="成本价">
  119. <span style="color:#909399">{{ editForm.costPrice }} 元/条</span>
  120. </el-form-item>
  121. <el-form-item label="租户售价" prop="price">
  122. <el-input-number v-model="editForm.price" :precision="4" :step="0.001" :min="0" style="width:100%" />
  123. <span style="color:#909399;font-size:12px;margin-left:8px">元/条</span>
  124. </el-form-item>
  125. <el-form-item label="优先级">
  126. <el-input-number v-model="editForm.priority" :min="1" :max="99" style="width:100%" />
  127. </el-form-item>
  128. <el-form-item label="允许手动选择">
  129. <el-switch v-model="editForm.allowManual" :active-value="1" :inactive-value="0" active-text="允许" inactive-text="否" />
  130. </el-form-item>
  131. <el-form-item label="状态">
  132. <el-switch v-model="editForm.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="禁用" />
  133. </el-form-item>
  134. </el-form>
  135. <div slot="footer">
  136. <el-button type="primary" @click="submitEdit">确 定</el-button>
  137. <el-button @click="editDialogVisible = false">取 消</el-button>
  138. </div>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import { listSmsApiTenant, addSmsApiTenant, updateSmsApiTenant, delSmsApiTenant, listSmsApi } from '@/api/system/smsApi'
  144. import { listAllCompanies } from '@/api/admin/sysCompany'
  145. export default {
  146. name: 'AdminSmsApiTenant',
  147. data() {
  148. return {
  149. loading: false,
  150. bindList: [],
  151. companyList: [],
  152. apiOptions: [],
  153. smsTypeOptions: [
  154. { value: 1, label: '行业验证码通知短信' },
  155. { value: 2, label: '营销短信' },
  156. { value: 3, label: '5G消息' }
  157. ],
  158. queryParams: { tenantId: undefined, smsType: undefined },
  159. addDialogVisible: false,
  160. editDialogVisible: false,
  161. addForm: { apiId: undefined, tenantId: undefined, price: 0, priority: 1, allowManual: 0 },
  162. editForm: { id: undefined, price: 0, priority: 1, allowManual: 0, status: 1, companyName: '', apiName: '', costPrice: 0 },
  163. addRules: {
  164. apiId: [{ required: true, message: '请选择接口', trigger: 'change' }],
  165. tenantId: [{ required: true, message: '请选择租户', trigger: 'change' }],
  166. price: [{ required: true, message: '请填写售价', trigger: 'blur' }]
  167. }
  168. }
  169. },
  170. computed: {
  171. selectedApiCost() {
  172. const api = this.apiOptions.find(a => a.apiId === this.addForm.apiId)
  173. return api && api.costPrice ? api.costPrice : ''
  174. }
  175. },
  176. created() {
  177. this.getList()
  178. this.loadCompanyList()
  179. this.loadApiOptions()
  180. },
  181. methods: {
  182. smsTypeFormat(type) {
  183. const map = { 1: '行业验证码通知', 2: '营销短信', 3: '5G消息' }
  184. return map[type] || '未知'
  185. },
  186. providerFormat(p) {
  187. const map = { my: '迈远', card: '手机卡' }
  188. return map[p] || p
  189. },
  190. calcProfit(row) {
  191. if (row.price != null && row.costPrice != null) {
  192. return (row.price - row.costPrice).toFixed(4)
  193. }
  194. return '-'
  195. },
  196. getList() {
  197. this.loading = true
  198. listSmsApiTenant(this.queryParams).then(res => {
  199. this.bindList = res.data || []
  200. }).finally(() => { this.loading = false })
  201. },
  202. loadCompanyList() {
  203. listAllCompanies({ pageNum: 1, pageSize: 1000 }).then(res => {
  204. this.companyList = res.rows || res.data || []
  205. })
  206. },
  207. loadApiOptions() {
  208. listSmsApi({ status: 1 }).then(res => {
  209. this.apiOptions = res.data || []
  210. })
  211. },
  212. onApiChange(apiId) {
  213. // 当选择接口时,自动填充默认售价
  214. const api = this.apiOptions.find(a => a.apiId === apiId)
  215. if (api && api.costPrice) {
  216. this.addForm.price = api.costPrice
  217. }
  218. },
  219. handleQuery() { this.getList() },
  220. resetQuery() {
  221. this.queryParams = { tenantId: undefined, smsType: undefined }
  222. this.handleQuery()
  223. },
  224. handleAdd() {
  225. this.addForm = { apiId: undefined, tenantId: undefined, price: 0, priority: 1, allowManual: 0 }
  226. this.addDialogVisible = true
  227. },
  228. submitAdd() {
  229. this.$refs.addForm.validate(valid => {
  230. if (!valid) return
  231. addSmsApiTenant({ ...this.addForm, status: 1 }).then(() => {
  232. this.$message.success('绑定成功')
  233. this.addDialogVisible = false
  234. this.getList()
  235. })
  236. })
  237. },
  238. handleUpdate(row) {
  239. this.editForm = {
  240. id: row.id,
  241. price: row.price,
  242. priority: row.priority || 1,
  243. allowManual: row.allowManual || 0,
  244. status: row.status,
  245. companyName: row.companyName,
  246. apiName: row.apiName,
  247. costPrice: row.costPrice
  248. }
  249. this.editDialogVisible = true
  250. },
  251. submitEdit() {
  252. updateSmsApiTenant({ id: this.editForm.id, price: this.editForm.price, priority: this.editForm.priority, allowManual: this.editForm.allowManual, status: this.editForm.status }).then(() => {
  253. this.$message.success('修改成功')
  254. this.editDialogVisible = false
  255. this.getList()
  256. })
  257. },
  258. handleDelete(row) {
  259. this.$confirm('确认解除租户"' + row.companyName + '"与接口"' + row.apiName + '"的绑定?', '提示', {
  260. confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
  261. }).then(() => {
  262. delSmsApiTenant(row.id).then(() => {
  263. this.$message.success('解除绑定成功')
  264. this.getList()
  265. })
  266. }).catch(() => {})
  267. }
  268. }
  269. }
  270. </script>
  271. <style scoped>
  272. </style>