index.vue 14 KB

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