clientList.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div class="full-container-p24">
  3. <div style="display: flex; justify-content: space-between">
  4. <div style="display: flex">
  5. <el-input
  6. placeholder="请输入姓名/手机号"
  7. prefix-icon="el-icon-search"
  8. v-model="term"
  9. clearable
  10. style="height: 32px; width: 330px; line-height: 32px"
  11. @keyup.enter.native="getClientList"
  12. ></el-input>
  13. <div class="seach-btn" @click="getClientList">查询</div>
  14. </div>
  15. <el-button v-auth="'CLIENTACCOUNT'" type="primary" @click="showAddModal"
  16. >添加客户</el-button
  17. >
  18. </div>
  19. <el-dialog
  20. v-model="visable"
  21. :title="accountId ? '修改客户' : '添加客户'"
  22. width="550px"
  23. @close="resetForm()"
  24. >
  25. <template v-slot:default>
  26. <div class="df jcc">
  27. <el-form
  28. :model="ruleForm"
  29. :rules="rules"
  30. ref="form"
  31. label-width="110px"
  32. label-position="left"
  33. >
  34. <el-form-item prop="name" label="姓名">
  35. <el-input style="width: 280px" v-model="ruleForm.name"></el-input>
  36. </el-form-item>
  37. <el-form-item prop="phone" label="手机号">
  38. <el-input
  39. style="width: 280px"
  40. v-model="ruleForm.phone"
  41. ></el-input>
  42. </el-form-item>
  43. <el-form-item prop="sharePermission" label="查看分享">
  44. <el-radio
  45. v-model="ruleForm.sharePermission"
  46. :label="1"
  47. size="large"
  48. >有权限</el-radio
  49. >
  50. <el-radio
  51. v-model="ruleForm.sharePermission"
  52. :label="0"
  53. size="large"
  54. >无权限</el-radio
  55. >
  56. </el-form-item>
  57. </el-form>
  58. </div>
  59. </template>
  60. <template v-slot:footer>
  61. <div class="dialog-footer">
  62. <el-button @click="resetForm">取 消</el-button>
  63. <el-button type="primary" @click="addClient(ruleForm)">
  64. 确 定
  65. </el-button>
  66. </div>
  67. </template>
  68. </el-dialog>
  69. <div style="margin-top: 24px">
  70. <el-table :data="tableData" stripe style="width: 100%">
  71. <el-table-column
  72. type="index"
  73. label="序号"
  74. min-width="40"
  75. align="center"
  76. ></el-table-column>
  77. <el-table-column
  78. prop="userName"
  79. label="姓名"
  80. min-width="80"
  81. align="center"
  82. ></el-table-column>
  83. <el-table-column
  84. prop="phone"
  85. label="手机号"
  86. min-width="100"
  87. align="center"
  88. ></el-table-column>
  89. <!-- <el-table-column
  90. prop="accountStatus"
  91. label="状态"
  92. min-width="80"
  93. align="center"
  94. >
  95. <template v-slot="scope">
  96. <el-switch
  97. v-model="scope.row.accountStatus"
  98. active-color="#13ce66"
  99. inactive-color="#ff4949"
  100. active-text="启用"
  101. inactive-text="禁用"
  102. :active-value="1"
  103. :inactive-value="0"
  104. /> </template
  105. ></el-table-column> -->
  106. <el-table-column
  107. prop="sharePermission"
  108. label="分享权限"
  109. min-width="80"
  110. align="center"
  111. >
  112. <template v-slot="scope">
  113. <el-switch
  114. v-model="scope.row.sharePermission"
  115. active-color="#13ce66"
  116. inactive-color="#ff4949"
  117. active-text="启用"
  118. inactive-text="禁用"
  119. :active-value="1"
  120. :inactive-value="0"
  121. @change="changeSharePermission($event, scope.row)"
  122. /> </template
  123. ></el-table-column>
  124. <el-table-column
  125. v-auth="'ADDACCOUNT'"
  126. label="操作"
  127. min-width="120"
  128. align="center"
  129. >
  130. <template v-slot="scope">
  131. <div class="df aic jcsa">
  132. <!-- <el-switch
  133. v-model="scope.row.accountStatus"
  134. active-color="#13ce66"
  135. inactive-color="#ff4949"
  136. active-text="启用"
  137. inactive-text="禁用"
  138. :active-value="1"
  139. :inactive-value="0"
  140. />
  141. <div
  142. style="
  143. color: red;
  144. margin-left: 10px;
  145. font-size: 14px;
  146. text-decoration: underline;
  147. cursor: pointer;
  148. "
  149. >
  150. 删除
  151. </div> -->
  152. <el-button
  153. @click="showUpdateModal(scope.row, 1)"
  154. size="small"
  155. type="primary"
  156. >修改客户权限</el-button
  157. >
  158. </div>
  159. </template>
  160. </el-table-column>
  161. </el-table>
  162. <div style="width: 100%; text-align: right; margin-top: 43px">
  163. <el-pagination
  164. background
  165. layout="prev, pager, next"
  166. :total="total"
  167. @current-change="pageChange"
  168. ></el-pagination>
  169. </div>
  170. </div>
  171. </div>
  172. </template>
  173. <script setup>
  174. import api from "../../apis/fetch";
  175. import { ref, onMounted, reactive } from "vue";
  176. import { ElNotification, ElMessageBox } from "element-plus";
  177. import store from "../../store/index";
  178. let tableData = ref([]);
  179. let currentPage = ref(1);
  180. let total = ref(0);
  181. let term = ref("");
  182. let loginAccountId = ref(0);
  183. let accountId = ref("");
  184. let ruleForm = ref({
  185. name: "",
  186. phone: "",
  187. roleId: "",
  188. deptId: "",
  189. });
  190. const rules = reactive({
  191. name: [
  192. {
  193. required: true,
  194. message: "请填写姓名",
  195. trigger: "blur",
  196. },
  197. ],
  198. phone: [
  199. {
  200. required: true,
  201. message: "请填写手机号",
  202. trigger: "blur",
  203. },
  204. ],
  205. sharePermission: [
  206. {
  207. required: true,
  208. message: "请选择权限",
  209. trigger: "blur",
  210. },
  211. ],
  212. });
  213. function showAddModal() {
  214. visable.value = true;
  215. ruleForm.value = {
  216. name: "",
  217. phone: "",
  218. sharePermission: "",
  219. };
  220. }
  221. async function getClientList() {
  222. let res = await api.getClientList({
  223. term: term.value,
  224. currentPage: currentPage.value,
  225. size: 10,
  226. loginAccountId: loginAccountId.value,
  227. });
  228. if (res.data.status == 0) {
  229. tableData.value = res.data.result;
  230. total.value = res.data.total;
  231. } else {
  232. tableData.value = [];
  233. total.value = 0;
  234. }
  235. }
  236. function pageChange(e) {
  237. currentPage.value = e;
  238. getClientList();
  239. }
  240. let visable = ref(false);
  241. let form = ref(null);
  242. async function addClient() {
  243. form.value.validate(async (valid) => {
  244. if (valid) {
  245. let postData = {
  246. ...ruleForm.value,
  247. loginAccountId: loginAccountId.value,
  248. };
  249. if (accountId.value) {
  250. postData.accountId = accountId.value;
  251. }
  252. let res = await api[accountId.value ? "updateClient" : "addClient"](
  253. postData
  254. );
  255. if (res.data.status == 0) {
  256. ElNotification({
  257. title: "成功",
  258. duration: 1500,
  259. message: res.data.msg,
  260. type: "success",
  261. });
  262. resetForm();
  263. getClientList();
  264. } else {
  265. ElNotification({
  266. title: "失败",
  267. duration: 1500,
  268. message: res.data.msg,
  269. type: "error",
  270. });
  271. }
  272. }
  273. });
  274. }
  275. function resetForm() {
  276. visable.value = false;
  277. accountId.value = "";
  278. form.value.resetFields();
  279. }
  280. function showUpdateModal(item, type) {
  281. visable.value = true;
  282. accountId.value = item.id;
  283. console.log(item);
  284. ruleForm.value = {
  285. name: item.userName,
  286. phone: item.phone,
  287. sharePermission: item.sharePermission,
  288. };
  289. }
  290. async function changeSharePermission(sharePermission, item) {
  291. let postData = {
  292. accountId: item.id,
  293. name: item.userName,
  294. phone: item.phone,
  295. sharePermission,
  296. loginAccountId: loginAccountId.value,
  297. };
  298. let res = await api["updateClient"](postData);
  299. if (res.data.status == 0) {
  300. ElNotification({
  301. title: "成功",
  302. duration: 1500,
  303. message: res.data.msg,
  304. type: "success",
  305. });
  306. resetForm();
  307. getClientList();
  308. } else {
  309. ElNotification({
  310. title: "失败",
  311. duration: 1500,
  312. message: res.data.msg,
  313. type: "error",
  314. });
  315. }
  316. }
  317. onMounted(() => {
  318. loginAccountId.value = localStorage.loginAccountId;
  319. getClientList();
  320. });
  321. </script>
  322. <style scoped>
  323. .seach-btn {
  324. display: inline-block;
  325. width: 60px;
  326. height: 38px;
  327. background: #0094fe;
  328. border-radius: 2px;
  329. font-size: 14px;
  330. font-family: PingFangSC-Regular, PingFang SC;
  331. font-weight: 400;
  332. color: #ffffff;
  333. text-align: center;
  334. line-height: 38px;
  335. margin-left: 10px;
  336. cursor: pointer;
  337. }
  338. </style>