index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24" >
  6. <div class="head-container">
  7. <!-- <el-input
  8. v-model="channelName"
  9. placeholder="请输入渠道名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. /> -->
  15. </div>
  16. <div class="head-container" style="overflow-x:scroll">
  17. <el-tree
  18. :props="defaultProps"
  19. ref="tree"
  20. :load="loadNode"
  21. :data="channelOptions"
  22. lazy
  23. @node-click="handleNodeClick"
  24. />
  25. </div>
  26. </el-col>
  27. <!--用户数据-->
  28. <el-col :span="20" :xs="24">
  29. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  30. <el-form-item label="渠道名称" prop="name">
  31. <el-input
  32. v-model="queryParams.name"
  33. placeholder="请输入渠道名称"
  34. clearable
  35. size="small"
  36. style="width: 240px"
  37. @keyup.enter.native="handleQuery"
  38. />
  39. </el-form-item>
  40. <el-form-item label="手机号码" prop="mobile">
  41. <el-input
  42. v-model="queryParams.mobile"
  43. placeholder="请输入手机号码"
  44. clearable
  45. size="small"
  46. style="width: 240px"
  47. @keyup.enter.native="handleQuery"
  48. />
  49. </el-form-item>
  50. <el-form-item label="地区">
  51. <el-select
  52. v-model="queryParams.provinceId"
  53. placeholder="选择省份"
  54. clearable
  55. size="small"
  56. @change="getCityList()"
  57. style="width: 120px;margin-right: 1px;">
  58. <el-option
  59. v-for="item in provinceList"
  60. :key="item.areaId"
  61. :label="item.areaName"
  62. :value="item.areaId"
  63. />
  64. </el-select>
  65. <el-select
  66. v-model="queryParams.cityId"
  67. placeholder="选择市"
  68. clearable
  69. size="small"
  70. @change="getAreaList()"
  71. style="width: 120px;margin-right: 1px;">
  72. <el-option
  73. v-for="item in cityList"
  74. :key="item.areaId"
  75. :label="item.areaName"
  76. :value="item.areaId"
  77. />
  78. </el-select>
  79. <el-select v-model="queryParams.areaId" placeholder="选择区" clearable size="small" style="width: 120px;margin-right: 1px;">
  80. <el-option
  81. v-for="item in areaList"
  82. :key="item.areaId"
  83. :label="item.areaName"
  84. :value="item.areaId"
  85. />
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item>
  89. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  90. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  91. </el-form-item>
  92. </el-form>
  93. <el-row :gutter="10" class="mb8">
  94. <el-col :span="1.5">
  95. <el-button
  96. type="primary"
  97. icon="el-icon-plus"
  98. size="mini"
  99. @click="handleAdd"
  100. v-hasPermi="['business:channel:add']"
  101. >添加一级渠道</el-button>
  102. </el-col>
  103. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  104. </el-row>
  105. <el-table v-loading="loading" :data="channelList">
  106. <el-table-column label="渠道编号" prop="channelId" width="100px" />
  107. <el-table-column label="渠道名称" prop="name" show-overflow-tooltip width="180px"/>
  108. <el-table-column label="手机号码" prop="mobile" show-overflow-tooltip width="120px"/>
  109. <el-table-column label="佣金比例" prop="commRate">
  110. <template slot-scope="scope">
  111. {{scope.row.commRate}}%
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="渠道级别" prop="level">
  115. <template slot-scope="scope">
  116. {{scope.row.level}}级渠道
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="经销商数" prop="siteCnt" />
  120. <el-table-column label="用户数" prop="userCnt" />
  121. <el-table-column label="状态" key="statusV">
  122. <template slot-scope="scope">
  123. <el-switch
  124. v-model="scope.row.statusV"
  125. active-value="1"
  126. inactive-value="2"
  127. @change="handleStatusChange(scope.row)"
  128. ></el-switch>
  129. </template>
  130. <!-- <template slot-scope="{ row, column }">
  131. <span v-if="getValue(row.status) == 1" style="color: blue;"> {{getDesc(row.status)}}</span>
  132. <span v-if="getValue(row.status) == 2" style="color: red;"> {{getDesc(row.status)}}</span>
  133. </template> -->
  134. </el-table-column>
  135. <el-table-column
  136. label="操作"
  137. align="center"
  138. width="200"
  139. class-name="small-padding fixed-width"
  140. >
  141. <template slot-scope="scope" v-if="scope.row.userId !== 1">
  142. <el-button
  143. size="mini"
  144. type="text"
  145. @click="handleDetail(scope.row)"
  146. v-hasPermi="['admin:channel:read']"
  147. >查看</el-button>
  148. <el-button
  149. size="mini"
  150. type="text"
  151. @click="handleUpdate(scope.row)"
  152. v-hasPermi="['admin:channel:edit']"
  153. >编辑</el-button>
  154. <!-- <el-button
  155. size="mini"
  156. type="text"
  157. disabled
  158. icon="el-icon-plus"
  159. @click="handleAdd(scope.row)"
  160. v-hasPermi="['admin:channel:add']"
  161. >添加子渠道</el-button> -->
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <pagination
  166. v-show="total>0"
  167. :total="total"
  168. :page.sync="pageParams.pageNum"
  169. :limit.sync="pageParams.pageSize"
  170. @pagination="getList"
  171. />
  172. </el-col>
  173. </el-row>
  174. <!-- 新建 -->
  175. <channel-create
  176. v-if="createShow"
  177. :dialog-visible="createShow"
  178. :edit-id="editId"
  179. @saveSuccess="submitSuccess"
  180. @close="hideDialog"
  181. />
  182. <!-- 详情 -->
  183. <channel-detail
  184. v-if="detailShow"
  185. :dialog-visible="detailShow"
  186. :edit-id="editId"
  187. @close="hideDialog"
  188. />
  189. </div>
  190. </template>
  191. <script>
  192. import { getToken } from "@/utils/auth";
  193. import { treeChannel, listChannel, updateChannelStatus} from "@/api/admin/channel";
  194. import { listAreaByPid} from "@/api/admin/area";
  195. import Treeselect from "@riophae/vue-treeselect";
  196. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  197. import ChannelCreate from './components/Create'
  198. import ChannelDetail from './components/Detail'
  199. export default {
  200. name: "ChannelIndex",
  201. components: {
  202. Treeselect,
  203. ChannelCreate,
  204. ChannelDetail
  205. },
  206. data() {
  207. return {
  208. // 遮罩层
  209. loading: true,
  210. // 导出遮罩层
  211. exportLoading: false,
  212. // 选中数组
  213. ids: [],
  214. // 创建编辑
  215. createShow: false,
  216. // 详情
  217. detailShow: false,
  218. provinceList:[],
  219. cityList:[],
  220. areaList:[],
  221. // 编辑项ID
  222. editId: null,
  223. // 显示搜索条件
  224. showSearch: true,
  225. // 总条数
  226. total: 0,
  227. // 用户表格数据
  228. channelList: [],
  229. channelOptions: [],
  230. channelName:"",
  231. // 状态数据字典
  232. statusOptions: [],
  233. // 表单参数
  234. form: {},
  235. defaultProps: {
  236. children: "children",
  237. label: "name"
  238. },
  239. // 查询参数
  240. queryParams: {
  241. name: "",
  242. mobile: "",
  243. provinceId:"",
  244. cityId:"",
  245. areaId:""
  246. },
  247. pageParams: {
  248. pageNum: 1,
  249. pageSize: 10
  250. }
  251. };
  252. },
  253. watch: {
  254. // 根据渠道名称筛选渠道树
  255. channelName(val) {
  256. this.$refs.tree.filter(val);
  257. }
  258. },
  259. mounted() {
  260. this.getProvinceList()
  261. },
  262. created() {
  263. this.getList();
  264. },
  265. methods: {
  266. /** 查询用户列表 */
  267. getList() {
  268. this.loading = true;
  269. listChannel('pageNum='+this.pageParams.pageNum + '&pageSize='+this.pageParams.pageSize+'&', this.queryParams).then(response => {
  270. this.channelList = response.rows;
  271. this.channelList.forEach(item => {
  272. item.statusV = JSON.parse(item.status).value+""
  273. })
  274. this.total = response.total;
  275. this.loading = false;
  276. }
  277. );
  278. },
  279. // 节点单击事件
  280. handleNodeClick(data) {
  281. this.queryParams.parentId = data.channelId;
  282. this.getList();
  283. },
  284. // 懒加载节点
  285. loadNode(node, resolve) {
  286. if(node.level === 0){
  287. treeChannel({}).then(response => {
  288. return resolve(response.data);
  289. });
  290. }else{
  291. var params = {
  292. parentId:node.data.channelId
  293. }
  294. treeChannel(params).then(response => {
  295. return resolve(response.data);
  296. });
  297. }
  298. },
  299. refreshChannelTree(){
  300. treeChannel({}).then(response => {
  301. this.channelOptions = response.data
  302. });
  303. },
  304. // 省
  305. getProvinceList(){
  306. this.cityList = []
  307. this.areaList = []
  308. this.queryParams.cityId = ""
  309. this.queryParams.areaId = ""
  310. listAreaByPid(0).then(response => {
  311. // console.log("getProvinceList"+JSON.stringify(response))
  312. this.provinceList = response || [];
  313. });
  314. },
  315. getCityList(){
  316. this.cityList = []
  317. this.areaList = []
  318. this.queryParams.cityId = ""
  319. this.queryParams.areaId = ""
  320. var provinceId = this.queryParams.provinceId
  321. listAreaByPid(provinceId).then(response => {
  322. // console.log("getCityList"+JSON.stringify(response))
  323. this.cityList = response || [];
  324. });
  325. },
  326. getAreaList(){
  327. var cityId = this.queryParams.cityId
  328. listAreaByPid(cityId).then(response => {
  329. // console.log("getAreaList"+JSON.stringify(response))
  330. this.areaList = response || [];
  331. });
  332. },
  333. // 状态修改
  334. handleStatusChange(row) {
  335. var newStatus = this.getValue(row.status) == 2?1:2
  336. let text = this.getValue(row.status) == 2 ? "启用" : "停用";
  337. this.$confirm('确认要"' + text + '""' + row.name + '"渠道吗?', "警告", {
  338. confirmButtonText: "确定",
  339. cancelButtonText: "取消",
  340. type: "warning"
  341. }).then(function() {
  342. var params={
  343. channelId:row.channelId,
  344. status: newStatus
  345. }
  346. return updateChannelStatus(params);
  347. }).then(() => {
  348. this.msgSuccess(text + "成功");
  349. this.getList();
  350. }).catch(function() {
  351. // row.status = row.status === "0" ? "1" : "0";
  352. });
  353. },
  354. /** 搜索按钮操作 */
  355. handleQuery() {
  356. this.queryParams.pageNum = 1;
  357. this.getList();
  358. },
  359. /** 重置按钮操作 */
  360. resetQuery() {
  361. this.queryParams= {
  362. pageNum: 1,
  363. pageSize: 10,
  364. name: "",
  365. mobile: "",
  366. provinceId:"",
  367. cityId:"",
  368. areaId:""
  369. },
  370. this.resetForm("queryForm");
  371. this.handleQuery();
  372. },
  373. handleDetail(row){
  374. this.detailShow = true
  375. this.editId = row.channelId
  376. },
  377. /** 新增按钮操作 */
  378. handleAdd() {
  379. this.createShow = true
  380. this.editId = null
  381. },
  382. /** 修改按钮操作 */
  383. handleUpdate(row) {
  384. this.createShow = true
  385. this.editId = row.channelId
  386. },
  387. // 保存后的操作
  388. submitSuccess(){
  389. this.getList();
  390. this.refreshChannelTree();
  391. },
  392. /**关闭弹窗*/
  393. hideDialog(){
  394. this.createShow = false
  395. this.detailShow = false
  396. },
  397. getDesc(val) {
  398. // console.log("val == "+val);
  399. const dataObj = JSON.parse(val);
  400. return (dataObj && dataObj.desc) || "";
  401. },
  402. getValue(val) {
  403. // console.log("val == "+val);
  404. const dataObj = JSON.parse(val);
  405. return (dataObj && dataObj.value) || "";
  406. },
  407. }
  408. };
  409. </script>
  410. <style lang="sass" scoped>
  411. </style>