index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div class="page-container list-container">
  3. <!-- 功能按钮区 -->
  4. <div class="list-btns-container">
  5. <el-button
  6. type="primary"
  7. size="small"
  8. icon="Plus"
  9. @click="handleAdd"
  10. v-hasPermi="['business:channel:add']"
  11. >新增</el-button
  12. >
  13. <el-button
  14. type="danger"
  15. size="small"
  16. icon="Delete"
  17. :disabled="multiple"
  18. @click="handleDelete"
  19. v-hasPermi="['business:channel:remove']"
  20. >删除</el-button
  21. >
  22. <!--<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
  23. </div>
  24. <!-- 搜索区 -->
  25. <el-form
  26. class="list-search-container"
  27. size="small"
  28. :model="queryParams"
  29. ref="queryRef"
  30. :inline="true"
  31. label-width="68px"
  32. >
  33. <el-form-item label="渠道名称:" prop="name">
  34. <el-input
  35. v-model="queryParams.name"
  36. placeholder="请输入渠道名称"
  37. style="width: 150px"
  38. size="small"
  39. clearable
  40. @keyup.enter="handleQuery"
  41. />
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="Search" @click="handleQuery"
  45. >搜索</el-button
  46. >
  47. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  48. </el-form-item>
  49. </el-form>
  50. <!-- 列表区 -->
  51. <el-table
  52. v-loading="loading"
  53. :data="channelList"
  54. size="small"
  55. border
  56. height="100%"
  57. @selection-change="handleSelectionChange"
  58. >
  59. <el-table-column type="selection" width="55" align="center" />
  60. <!-- <el-table-column label="序号" align="center" type="index" /> -->
  61. <el-table-column label="渠道名称" align="center" prop="name">
  62. <template #default="scope">
  63. <el-input
  64. v-if="scope.row.isAdd"
  65. v-model="scope.row.name"
  66. size="small"
  67. placeholder="请输入渠道"
  68. ></el-input>
  69. <el-input
  70. v-else-if="scope.row.isEdit"
  71. size="small"
  72. v-model="scope.row.name"
  73. ></el-input>
  74. <span v-else>{{ scope.row.name }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column
  78. v-if="categoryShow"
  79. label="渠道类别"
  80. align="center"
  81. prop="channelCategoryName"
  82. />
  83. <el-table-column label="负责人" align="center" prop="creatorName">
  84. <template #default="scope">
  85. <el-autocomplete
  86. size="small"
  87. v-if="scope.row.isEdit || scope.row.isAdd"
  88. v-model="scope.row.creatorName"
  89. :fetch-suggestions="querySearchAsync"
  90. style="width: 100%"
  91. :trigger-on-focus="true"
  92. placeholder="请输入负责人"
  93. @select="handleSelect"
  94. />
  95. <span v-else>{{ scope.row.creatorName }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. label="添加时间"
  100. align="center"
  101. prop="createTime"
  102. width="180"
  103. >
  104. <template #default="scope">
  105. <span>{{ parseTime(scope.row.createTime) }}</span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column
  109. label="操作"
  110. align="center"
  111. class-name="small-padding fixed-width"
  112. width="120"
  113. >
  114. <template #default="scope">
  115. <template v-if="!scope.row.isEdit && !scope.row.isAdd">
  116. <el-button
  117. v-show="!scope.row.isEdit && !scope.row.isAdd"
  118. link
  119. type="warning"
  120. size="small"
  121. @click="handleUpdate(scope.row)"
  122. v-hasPermi="['business:channel:edit']"
  123. >修改</el-button
  124. >
  125. <el-button
  126. v-show="!scope.row.isEdit && !scope.row.isAdd"
  127. link
  128. type="danger"
  129. size="small"
  130. @click="handleDelete(scope.row)"
  131. v-hasPermi="['business:channel:remove']"
  132. >删除</el-button
  133. >
  134. </template>
  135. <template v-if="scope.row.isEdit || scope.row.isAdd">
  136. <el-button
  137. v-show="scope.row.isEdit || scope.row.isAdd"
  138. link
  139. type="primary"
  140. size="small"
  141. @click="handleSave(scope.row)"
  142. >保存</el-button
  143. >
  144. <el-button
  145. v-show="scope.row.isEdit || scope.row.isAdd"
  146. link
  147. size="small"
  148. @click="handCancel(scope.row)"
  149. >取消</el-button
  150. >
  151. </template>
  152. </template>
  153. </el-table-column>
  154. </el-table>
  155. <!-- 分页 -->
  156. <pagination
  157. v-show="total > 0"
  158. :total="total"
  159. v-model:page="queryParams.pageNum"
  160. v-model:limit="queryParams.pageSize"
  161. @pagination="getList"
  162. />
  163. </div>
  164. </template>
  165. <script setup name="Channel">
  166. import { listUser } from "@/api/system/user";
  167. import {
  168. listChannel,
  169. delChannel,
  170. listCategory,
  171. updateChannel,
  172. addChannel,
  173. } from "@/api/business/channel";
  174. import { ref } from "vue";
  175. // import channelForm from "./form"
  176. const { proxy } = getCurrentInstance();
  177. /** 字典数组区 */
  178. /** 查询 对象 */
  179. const channelList = ref([]);
  180. const categoryList = ref([]);
  181. const loading = ref(true);
  182. const ids = ref([]);
  183. const single = ref(true);
  184. const multiple = ref(true);
  185. const total = ref(0);
  186. const dateRange = ref([]);
  187. const userList = ref([]);
  188. const nickNameLits = ref([]);
  189. const categoryShow = ref(false);
  190. /** 查询对象 */
  191. const queryParams = ref({
  192. pageNum: 1,
  193. pageSize: 10,
  194. code: null,
  195. name: null,
  196. contact: null,
  197. phone: null,
  198. orderByColumn: "create_time",
  199. email: null,
  200. owner: null,
  201. status: null,
  202. createTime: null,
  203. employeeId: null,
  204. creatorName: "",
  205. channelCategoryId: null,
  206. channelCategoryName: null,
  207. isEdit: false,
  208. isAdd: false,
  209. });
  210. const queryNickName = ref({
  211. nickName: null,
  212. });
  213. /** 渠道类型对象 */
  214. const queryCategory = {
  215. pageNum: 1,
  216. pageSize: 10,
  217. orderByColumn: "create_time",
  218. id: null,
  219. name: null,
  220. };
  221. /** 用户对象 */
  222. const queryUser = {
  223. pageNum: 1,
  224. pageSize: 10,
  225. userName: null,
  226. phonenumber: null,
  227. status: null,
  228. deptId: null,
  229. userId: null,
  230. nickName: null,
  231. };
  232. const LinkItem = {
  233. value: "",
  234. };
  235. const links = ref([]);
  236. /*********************** 方法区 ****************************/
  237. /** 查询渠道列表 */
  238. function getList() {
  239. Promise.all([
  240. listChannel(queryParams.value),
  241. listUser(proxy.addDateRange(queryUser, dateRange.value)),
  242. listCategory(queryCategory.value),
  243. ]).then((result) => {
  244. channelList.value = result[0].rows;
  245. userList.value = result[1].rows;
  246. categoryList.value = result[2].rows;
  247. total.value = result[0].total;
  248. loading.value = false;
  249. userNameList();
  250. }).catch;
  251. }
  252. /** 输入框输出建议 */
  253. const querySearchAsync = (queryString, cb) => {
  254. console.log(links);
  255. const results = queryString
  256. ? links.value.filter(createFilter(queryString))
  257. : links.value;
  258. cb(results);
  259. };
  260. function createFilter(queryString) {
  261. return (restaurant) => {
  262. return (
  263. restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
  264. );
  265. };
  266. }
  267. function userNameList() {
  268. /** 比较user表和渠道表的员工ID */
  269. links.value.length = 0;
  270. for (let i = 0; i < userList.value.length; i++) {
  271. links.value.push({ value: userList.value[i].nickName });
  272. for (let j = 0; j < channelList.value.length; j++) {
  273. if (userList.value[i].userId == channelList.value[j].employeeId) {
  274. channelList.value[j].creatorName = userList.value[i].nickName;
  275. }
  276. }
  277. }
  278. /** 比较渠道类别表和渠道表的类别ID */
  279. for (let i = 0; i < categoryList.value.length; i++) {
  280. for (let j = 0; j < channelList.value.length; j++) {
  281. if (categoryList.value[i].id == channelList.value[j].channelCategoryId) {
  282. channelList.value[j].channelCategoryName = categoryList.value[i].name;
  283. }
  284. }
  285. }
  286. }
  287. /** 取消按钮操作 */
  288. function handCancel(row) {
  289. if (row.isEdit) row.isEdit = false;
  290. else channelList.value.length = channelList.value.length - 1;
  291. }
  292. /** 搜索按钮操作 */
  293. function handleQuery() {
  294. queryParams.value.pageNum = 1;
  295. getList();
  296. }
  297. /** 重置按钮操作 */
  298. function resetQuery() {
  299. proxy.resetForm("queryRef");
  300. handleQuery();
  301. }
  302. // 多选框选中数据
  303. function handleSelectionChange(selection) {
  304. ids.value = selection.map((item) => item.id);
  305. single.value = selection.length != 1;
  306. multiple.value = !selection.length;
  307. }
  308. /** 新增按钮操作 */
  309. function handleAdd() {
  310. // 此处必须进行深拷贝,否则添加的明细,将都指向了一个对象
  311. const _newSource = JSON.parse(JSON.stringify(queryParams.value));
  312. channelList.value.push(_newSource);
  313. handleSourceCurrentChange(_newSource);
  314. }
  315. /** 修改新增属性判断 */
  316. function handleSourceCurrentChange(row) {
  317. row.isAdd = true;
  318. }
  319. /** 保存按钮操作 */
  320. function handleSave(row) {
  321. if (
  322. row.name.length > 0 &&
  323. row.creatorName.length > 0 &&
  324. row.name !== null &&
  325. row.creatorName !== null
  326. ) {
  327. const index = userList.value.findIndex(
  328. (item) => item.nickName == row.creatorName
  329. );
  330. if (index != -1) {
  331. row.employeeId = userList.value[index].userId;
  332. }
  333. console.log(row);
  334. if (row.isAdd) {
  335. addChannel(row).then((response) => {
  336. proxy.$modal.msgSuccess("添加成功");
  337. // visible.value = false;
  338. getList.value();
  339. });
  340. row.isAdd = false;
  341. getList();
  342. }
  343. if (row.isEdit) {
  344. updateChannel(row).then((response) => {
  345. proxy.$modal.msgSuccess("修改成功");
  346. // visible.value = false;
  347. getList.value();
  348. });
  349. queryParams.isEdit = false;
  350. getList();
  351. }
  352. getList();
  353. } else {
  354. proxy.$modal.msgError("渠道名称和负责人不能为空!");
  355. }
  356. }
  357. /** 修改按钮操作 */
  358. function handleUpdate(row) {
  359. row.isEdit = true;
  360. }
  361. /** 删除按钮操作 */
  362. function handleDelete(row) {
  363. const _ids = row.id || ids.value;
  364. proxy.$modal
  365. .confirm("是否确认删除选中的数据项?")
  366. .then(function () {
  367. return delChannel(_ids);
  368. })
  369. .then(() => {
  370. getList();
  371. proxy.$modal.msgSuccess("删除成功!");
  372. })
  373. .catch(() => {});
  374. }
  375. /** 导出按钮操作 */
  376. function handleExport() {
  377. proxy.download(
  378. "business/channel/export",
  379. {
  380. ...queryParams.value,
  381. },
  382. `channel_${new Date().getTime()}.xlsx`
  383. );
  384. }
  385. getList();
  386. </script>