index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container" style="margin: 10px 0 10px 0">
  4. <!-- 搜索字段 -->
  5. <div class="flex">
  6. <div class="w_input">
  7. <span class="textSpan"> 运营商:</span>
  8. <el-select size="small" v-model="body.Isp" clearable placeholder="请选择运营商" style="width: 65%" >
  9. <el-option
  10. v-for="item in status"
  11. :key="item.id"
  12. :label="item.name"
  13. :value="item.id"
  14. />
  15. </el-select>
  16. </div>
  17. <div class="w_input">
  18. <span class="textSpan"> 面额:</span>
  19. <el-input
  20. v-model="body.productPrice"
  21. style="width: 65%;"
  22. placeholder="请输入面额"
  23. size="small"
  24. clearable
  25. />
  26. </div>
  27. <div class="w_input">
  28. <span class="textSpan">产品名称:</span>
  29. <el-input
  30. v-model="body.productName"
  31. style="width:65%;"
  32. placeholder="请输入名称"
  33. size="small"
  34. clearable
  35. />
  36. </div>
  37. </div>
  38. <!-- 新增与搜索 -->
  39. <div class="flexend">
  40. <el-button class="filter-item" icon="el-icon-search" type="primary" plain @click="handleSearch">搜索</el-button>
  41. <el-button class="classitem" style="marginRight:50px" type="primary" plain icon="el-icon-plus" @click="handleAdd">新增
  42. </el-button>
  43. </div>
  44. <!-- 表格 -->
  45. <el-table v-loading="loading" :data="tableData" border style="width: 100%">
  46. <!-- <el-table-column type="selection" /> -->
  47. <el-table-column label="产品ID" width="100" align="center" show-overflow-tooltip>
  48. <template slot-scope="scope">
  49. <span>{{ scope.row.productId }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="产品名称" align="center" show-overflow-tooltip>
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.productName }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="产品编码" align="center" show-overflow-tooltip>
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.productCode }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="面额" width="100" align="center" show-overflow-tooltip>
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.productPrice }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="运营商" width="100" align="center" show-overflow-tooltip>
  68. <template slot-scope="scope">
  69. <!-- 运营商 1 : 移动 2 : 电信 3 : 联通 -->
  70. <span v-if="scope.row.operator==1">移动</span>
  71. <span v-if="scope.row.operator==2">电信</span>
  72. <span v-if="scope.row.operator==3">联通</span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="产品所属地区" width="120" align="center" show-overflow-tooltip>
  76. <template slot-scope="scope">
  77. <span>{{ scope.row.areaName }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" fixed="right" min-width="100" align="center">
  81. <template slot-scope="scope">
  82. <!--<el-button @click="handRest(scope.row)" type="warning" size="small">重置密码</el-button>-->
  83. <el-button size="small" icon="el-icon-edit" type="warning" plain @click="handleEdit(scope.row)">编辑</el-button>
  84. <el-button size="small" icon="el-icon-delete" type="danger" plain @click="handleDelete(scope.row)">删除
  85. </el-button>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. <!-- 分页 -->
  90. <div class="pagination">
  91. <el-pagination
  92. current-page.sync="page"
  93. @size-change="handleSizeChange"
  94. :current-page="page"
  95. @current-change="handleCurrentChange"
  96. :page-sizes="[10, 20, 30, 50]"
  97. :page-size="size"
  98. layout="total, sizes, prev, pager, next, jumper"
  99. background
  100. :total="total">
  101. </el-pagination>
  102. </div>
  103. <!-- 添加或修改对话框 -->
  104. <el-dialog :title="operation?'新增产品':'编辑产品'" :visible.sync="dialogFormVisible" center>
  105. <el-form ref="dataForm" :model="dataForm" :rules="rules2" label-width="80px" size="small" label-position="right">
  106. <el-form-item label="产品名称" :label-width="formLabelWidth" prop="productName" >
  107. <el-input v-model.trim="dataForm.productName" style="width: 90%;" placeholder="请输入产品名称" />
  108. </el-form-item>
  109. <el-form-item label="面额" :label-width="formLabelWidth" >
  110. <el-input v-model.trim="dataForm.productPrice" style="width: 90%;" placeholder="请输入面额" />
  111. </el-form-item>
  112. <el-form-item label="流量包ID" :label-width="formLabelWidth" >
  113. <el-input v-model.trim="dataForm.packageId" style="width: 90%;" placeholder="请输入流量包ID" />
  114. </el-form-item>
  115. <el-form-item label="产品所属地区" :label-width="formLabelWidth" >
  116. <!-- <el-input v-model="dataForm.ZONE" style="width: 90%;" placeholder="请选择产品地区" /> -->
  117. <el-select size="small" v-model="dataForm.areaName" clearable placeholder="请选择产品地区" style="width: 90%" >
  118. <el-option
  119. v-for="item in provinceList"
  120. :key="item.name"
  121. :label="item.name"
  122. :value="item.name"
  123. />
  124. </el-select>
  125. </el-form-item>
  126. <el-form-item label="运营商" :label-width="formLabelWidth" >
  127. <el-select size="small" v-model="dataForm.operator" placeholder="请选择运营商" style="width: 90%" >
  128. <el-option
  129. v-for="item in status"
  130. :key="item.id"
  131. :label="item.name"
  132. :value="item.id"
  133. />
  134. </el-select>
  135. </el-form-item>
  136. <el-form-item label="产品类型" :label-width="formLabelWidth" >
  137. <el-select size="small" v-model="dataForm.productType" placeholder="请选择产品类型" style="width: 90%" >
  138. <el-option
  139. v-for="item in type"
  140. :key="item.id"
  141. :label="item.name"
  142. :value="item.id"
  143. />
  144. </el-select>
  145. </el-form-item>
  146. <el-form-item label="产品编码" :label-width="formLabelWidth" >
  147. <el-input v-model.trim="dataForm.productCode" style="width: 90%;" placeholder="请输入产品编码" />
  148. </el-form-item>
  149. <el-form-item label="产品描述" :label-width="formLabelWidth" >
  150. <el-input v-model.trim="dataForm.productDesc" style="width: 90%;" placeholder="请输入产品描述" />
  151. </el-form-item>
  152. </el-form>
  153. <div slot="footer" class="dialog-footer">
  154. <el-button @click="dialogFormVisible = false">取 消</el-button>
  155. <el-button type="primary" @click="submitForm">确 定</el-button>
  156. </div>
  157. </el-dialog>
  158. </div>
  159. </div>
  160. </template>
  161. <script>
  162. import { Search,province,ProductAdd,ProductEdit } from '@/api/product'
  163. export default {
  164. data() {
  165. return {
  166. body:{
  167. productName:"",
  168. productPrice:"",
  169. Isp:""
  170. },
  171. provinceList:[], //省份
  172. type:[{
  173. id:1,
  174. name:"话费"
  175. },{
  176. id:2,
  177. name:"流量"
  178. }],
  179. status:[{
  180. id:1,
  181. name:"移动"
  182. },{
  183. id:2,
  184. name:"电信"
  185. },{
  186. id:3,
  187. name:"联通"
  188. },
  189. ],
  190. tableData: [],
  191. operation: false, // true:新增, false:编辑
  192. dialogFormVisible: false, // 控制弹出框
  193. formLabelWidth: '120px', //新增宽度
  194. rules2: {
  195. productName: [{ required: true, message: '请输入产品名称', trigger: 'blur' }
  196. ],
  197. },
  198. dataForm:{
  199. productName:"",
  200. productPrice:"",
  201. areaName:"",
  202. operator:"",
  203. productCode:"",
  204. productType:"",
  205. productDesc:""
  206. },
  207. page:1,
  208. size:10,
  209. total:0,
  210. loading:false
  211. }
  212. },
  213. created(){
  214. this.getTenantList()
  215. this.onprovince() //省份
  216. },
  217. methods: {
  218. //表格数据
  219. getTenantList() {
  220. this.loading = true
  221. const params = new URLSearchParams()
  222. params.append('productName', this.body.productName)
  223. params.append('productPrice', this.body.productPrice)
  224. params.append('operator', this.body.Isp)
  225. params.append('current', this.page)
  226. params.append('size', this.size)
  227. Search(params).then((res) => {
  228. this.loading = false
  229. this.tableData=res.data.data.records
  230. this.total=res.data.data.total
  231. })
  232. },
  233. //省份数据
  234. onprovince(){
  235. province().then((res)=>{
  236. // console.log(res)
  237. let province = res.data.data
  238. let arry=province.map((res)=>{
  239. return {name:res}
  240. })
  241. this.provinceList = arry
  242. })
  243. },
  244. //搜索
  245. handleSearch(){
  246. this.page = 1
  247. this.getTenantList()
  248. },
  249. //新增
  250. handleAdd(){
  251. this.dialogFormVisible = true
  252. this.operation = true
  253. this.dataForm={
  254. productName:"",
  255. productPrice:"",
  256. areaName:"",
  257. operator:"",
  258. productCode:""
  259. }
  260. },
  261. //编辑
  262. handleEdit: function(row) {
  263. this.dataForm={}
  264. this.dialogFormVisible = true
  265. this.operation = false
  266. let newObj=JSON.parse(JSON.stringify(row))
  267. this.dataForm = newObj
  268. // this.dataForm = Object.assign({}, row)
  269. // this.dataForm.jobId = row.jobId
  270. },
  271. //新增或修改API
  272. submitForm(){
  273. this.$refs['dataForm'].validate((valid) => {
  274. if (valid) {
  275. if (!this.operation) {
  276. // 编辑
  277. ProductEdit(this.dataForm).then(response => {
  278. if (response.status === 200) {
  279. this.$message({
  280. type: 'success',
  281. message: '操作成功'
  282. })
  283. this.dialogFormVisible = false
  284. this.getTenantList()
  285. } else {
  286. this.$message({
  287. type: 'error',
  288. message: response.data.msg
  289. })
  290. }
  291. })
  292. } else {
  293. console.log(this.dataForm)
  294. // // 添加
  295. ProductAdd(this.dataForm).then(response => {
  296. if (response.status === 200) {
  297. this.$message({
  298. type: 'success',
  299. message: '操作成功'
  300. })
  301. this.dialogFormVisible = false
  302. this.getTenantList()
  303. } else {
  304. this.$message({
  305. type: 'error',
  306. message: response.data.msg
  307. })
  308. }
  309. })
  310. }
  311. }
  312. })
  313. },
  314. // 删除
  315. handleDelete: function(row) {
  316. const that = this
  317. this.$confirm('此操作将删除该产品, 是否继续?', '提示', {
  318. confirmButtonText: '确定',
  319. cancelButtonText: '取消',
  320. type: 'warning'
  321. })
  322. .then(() => {
  323. row.isDelete = 1
  324. ProductEdit(row).then(response => {
  325. if (response.status === 200) {
  326. this.$message({
  327. type: 'success',
  328. message: '操作成功'
  329. })
  330. that.getTenantList()
  331. } else {
  332. this.$message({
  333. type: 'error',
  334. message: response.data.msg
  335. })
  336. }
  337. })
  338. })
  339. .catch(() => {
  340. this.$message({
  341. type: 'info',
  342. message: '已取消删除'
  343. })
  344. })
  345. },
  346. //分页
  347. handleSizeChange:function(val){
  348. this.size=val
  349. this.getTenantList()
  350. },
  351. // 换页
  352. handleCurrentChange: function(val) {
  353. this.page = val
  354. this.getTenantList()
  355. },
  356. }
  357. }
  358. </script>
  359. <style scoped>
  360. .flex{
  361. width: 90%;
  362. display: flex;
  363. flex-direction: row;
  364. margin-bottom: 10px;
  365. /* flex-wrap: wrap; */
  366. justify-content: flex-start;
  367. }
  368. .w_input{
  369. width:35.333%;
  370. }
  371. .textSpan{
  372. position: relative;
  373. top: 0;
  374. font-size: 14px;
  375. font-weight: 600;
  376. color:rgb(87, 86, 86)
  377. }
  378. .flexend{
  379. display: flex;
  380. justify-content: flex-end;
  381. /* padding-right: 2rem; */
  382. width: 100%;
  383. /* margin: 0 auto; */
  384. padding-bottom: 20px;
  385. }
  386. </style>