recommend.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="店铺ID" prop="storeId">
  5. <el-input
  6. v-model="queryParams.storeId"
  7. placeholder="请输入店铺ID"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="店铺名称" prop="storeId">
  14. <el-input
  15. v-model="queryParams.storeName"
  16. placeholder="请输入推荐店铺名称"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="状态" prop="status">
  23. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  24. <el-option
  25. v-for="dict in statusOptions"
  26. :key="dict.dictValue"
  27. :label="dict.dictLabel"
  28. :value="dict.dictValue"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['store:recommend:add']"
  46. >新增</el-button>
  47. </el-col>
  48. <el-col :span="1.5">
  49. <el-button
  50. type="success"
  51. plain
  52. icon="el-icon-edit"
  53. size="mini"
  54. :disabled="single"
  55. @click="handleUpdate"
  56. v-hasPermi="['store:recommend:edit']"
  57. >修改</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="danger"
  62. plain
  63. icon="el-icon-delete"
  64. size="mini"
  65. :disabled="multiple"
  66. @click="handleDelete"
  67. v-hasPermi="['store:recommend:delete']"
  68. >删除</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="warning"
  73. plain
  74. icon="el-icon-download"
  75. size="mini"
  76. :loading="exportLoading"
  77. @click="handleExport"
  78. v-hasPermi="['store:recommend:export']"
  79. >导出</el-button>
  80. </el-col>
  81. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  82. </el-row>
  83. <el-table v-loading="loading" border :data="recommendScrmList" @selection-change="handleSelectionChange">
  84. <el-table-column type="selection" width="55" align="center" />
  85. <el-table-column label="ID" align="center" prop="id" />
  86. <el-table-column label="店铺ID" align="center" prop="storeId" />
  87. <el-table-column label="推荐店铺ID" align="center" prop="storeId" />
  88. <el-table-column label="推荐店铺名称" align="center" prop="storeName" />
  89. <el-table-column label="排序" align="center" prop="sortOrder" />
  90. <!-- <el-table-column label="开始时间" align="center" prop="beginTime" width="180">
  91. <template slot-scope="scope">
  92. <span>{{ parseTime(scope.row.beginTime) }}</span>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="结束时间" align="center" prop="endTime" width="180">
  96. <template slot-scope="scope">
  97. <span>{{ parseTime(scope.row.endTime) }}</span>
  98. </template>
  99. </el-table-column>-->
  100. <el-table-column label="状态" align="center" prop="status">
  101. <template slot-scope="scope">
  102. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  106. <template slot-scope="scope">
  107. <span>{{ parseTime(scope.row.createTime) }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
  111. <template slot-scope="scope">
  112. <span>{{ parseTime(scope.row.updateTime) }}</span>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  116. <template slot-scope="scope">
  117. <el-button
  118. size="mini"
  119. type="text"
  120. icon="el-icon-edit"
  121. @click="handleUpdate(scope.row)"
  122. v-hasPermi="['store:recommend:edit']"
  123. >修改</el-button>
  124. <el-button
  125. size="mini"
  126. type="text"
  127. icon="el-icon-delete"
  128. @click="handleDelete(scope.row)"
  129. v-hasPermi="['store:recommend:remove']"
  130. >删除</el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <pagination
  135. v-show="total>0"
  136. :total="total"
  137. :page.sync="queryParams.pageNum"
  138. :limit.sync="queryParams.pageSize"
  139. @pagination="getList"
  140. />
  141. <!-- 添加或修改推荐店铺对话框 -->
  142. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  143. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  144. <el-form-item label="推荐店铺Id" prop="storeName">
  145. <el-select
  146. v-model="form.storeId"
  147. filterable
  148. remote
  149. :remote-method="searchStore"
  150. :loading="storeLoading"
  151. placeholder="请输入并搜索店铺名称"
  152. clearable
  153. @change="setStore"
  154. >
  155. <el-option
  156. v-for="item in storeOptions"
  157. :key="item.storeId"
  158. :label="item.storeId"
  159. :value="item.storeId"
  160. >
  161. <span style="float: left">{{ item.storeName }}</span>
  162. <span style="float: right; color: #8492a6; font-size: 13px">ID: {{ item.storeId }}</span>
  163. </el-option>
  164. </el-select>
  165. </el-form-item>
  166. <!-- 回显店铺名称,不可编辑 -->
  167. <el-form-item label="推荐店铺名称" prop="storeName" >
  168. <el-input v-model="form.storeName" placeholder="请输入推荐店铺名称" disabled/>
  169. </el-form-item>
  170. <el-form-item label="排序" prop="sortOrder">
  171. <el-input-number v-model="form.sortOrder" controls-position="right" :min="0" />
  172. </el-form-item>
  173. <el-form-item label="状态" prop="status">
  174. <el-radio-group v-model="form.status">
  175. <el-radio
  176. v-for="dict in statusOptions"
  177. :key="dict.dictValue"
  178. :label="parseInt(dict.dictValue)"
  179. >{{dict.dictLabel}}</el-radio>
  180. </el-radio-group>
  181. </el-form-item>
  182. </el-form>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button type="primary" @click="submitForm">确 定</el-button>
  185. <el-button @click="cancel">取 消</el-button>
  186. </div>
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import {
  192. listRecommendScrm,
  193. getRecommendScrm,
  194. delRecommendScrm,
  195. addRecommendScrm,
  196. updateRecommendScrm,
  197. exportRecommendScrm
  198. } from "@/api/hisStore/recommend";
  199. import { listStore } from '@/api/hisStore/store'
  200. export default {
  201. name: "RecommendScrm",
  202. data() {
  203. return {
  204. // 遮罩层
  205. loading: true,
  206. // 导出遮罩层
  207. exportLoading: false,
  208. // 选中数组
  209. ids: [],
  210. // 非单个禁用
  211. single: true,
  212. // 非多个禁用
  213. multiple: true,
  214. // 显示搜索条件
  215. showSearch: true,
  216. // 总条数
  217. total: 0,
  218. // 推荐店铺表格数据
  219. recommendScrmList: [],
  220. // 弹出层标题
  221. title: "",
  222. // 是否显示弹出层
  223. open: false,
  224. // 状态数据字典
  225. statusOptions: [],
  226. storeLoading: false, // 店铺搜索加载状态
  227. storeOptions: [],
  228. // 查询参数
  229. queryParams: {
  230. pageNum: 1,
  231. pageSize: 10,
  232. storeId: null,
  233. storeName: null,
  234. status: null
  235. },
  236. // 表单参数
  237. form: {},
  238. // 表单校验
  239. rules: {
  240. storeId: [
  241. { required: true, message: "店铺ID不能为空", trigger: "blur" }
  242. ],
  243. storeName: [
  244. { required: true, message: "推荐店铺名称不能为空", trigger: "blur" }
  245. ],
  246. sortOrder: [
  247. { required: true, message: "排序不能为空", trigger: "blur" }
  248. ],
  249. status: [
  250. { required: true, message: "状态不能为空", trigger: "change" }
  251. ]
  252. }
  253. };
  254. },
  255. created() {
  256. this.getList();
  257. this.getDicts("common_status").then(response => {
  258. this.statusOptions = response.data;
  259. });
  260. },
  261. methods: {
  262. /** 查询推荐店铺列表 */
  263. getList() {
  264. this.loading = true;
  265. listRecommendScrm(this.queryParams).then(response => {
  266. this.recommendScrmList = response.rows;
  267. this.total = response.total;
  268. this.loading = false;
  269. });
  270. },
  271. //
  272. setStore(){
  273. let storeId = this.form.storeId;
  274. this.form.storeName = this.storeOptions.filter(item => item.storeId === storeId)[0].storeName;
  275. },
  276. // 搜索店铺
  277. searchStore(query) {
  278. if (query !== '') {
  279. this.storeLoading = true;
  280. // 这里应该调用实际的API来搜索店铺
  281. // 示例代码,需要根据实际API调整
  282. listStore({ storeName: query }).then(response => {
  283. this.storeOptions = response.rows;
  284. this.storeLoading = false;
  285. }).catch(() => {
  286. this.storeLoading = false;
  287. });
  288. } else {
  289. this.storeOptions = [];
  290. }
  291. },
  292. // 取消按钮
  293. cancel() {
  294. this.open = false;
  295. this.reset();
  296. },
  297. // 表单重置
  298. reset() {
  299. this.form = {
  300. id: null,
  301. storeId: null,
  302. storeName: null,
  303. sortOrder: 0,
  304. status: 0
  305. };
  306. this.resetForm("form");
  307. },
  308. /** 搜索按钮操作 */
  309. handleQuery() {
  310. this.queryParams.pageNum = 1;
  311. this.getList();
  312. },
  313. /** 重置按钮操作 */
  314. resetQuery() {
  315. this.resetForm("queryForm");
  316. this.handleQuery();
  317. },
  318. // 多选框选中数据
  319. handleSelectionChange(selection) {
  320. this.ids = selection.map(item => item.id)
  321. this.single = selection.length!==1
  322. this.multiple = !selection.length
  323. },
  324. /** 新增按钮操作 */
  325. handleAdd() {
  326. this.reset();
  327. this.open = true;
  328. this.title = "添加推荐店铺";
  329. },
  330. /** 修改按钮操作 */
  331. handleUpdate(row) {
  332. this.reset();
  333. const id = row.id || this.ids
  334. getRecommendScrm(id).then(response => {
  335. this.form = response.data;
  336. this.open = true;
  337. this.title = "修改推荐店铺";
  338. });
  339. },
  340. /** 提交按钮 */
  341. submitForm() {
  342. this.$refs["form"].validate(valid => {
  343. if (valid) {
  344. if (this.form.id != null) {
  345. updateRecommendScrm(this.form).then(response => {
  346. this.msgSuccess("修改成功");
  347. this.open = false;
  348. this.getList();
  349. });
  350. } else {
  351. addRecommendScrm(this.form).then(response => {
  352. this.msgSuccess("新增成功");
  353. this.open = false;
  354. this.getList();
  355. });
  356. }
  357. }
  358. });
  359. },
  360. /** 删除按钮操作 */
  361. handleDelete(row) {
  362. const ids = row.id || this.ids;
  363. this.$confirm('是否确认删除推荐店铺编号为"' + ids + '"的数据项?', "警告", {
  364. confirmButtonText: "确定",
  365. cancelButtonText: "取消",
  366. type: "warning"
  367. }).then(function() {
  368. return delRecommendScrm(ids);
  369. }).then(() => {
  370. this.getList();
  371. this.msgSuccess("删除成功");
  372. }).catch(() => {});
  373. },
  374. /** 导出按钮操作 */
  375. handleExport() {
  376. const queryParams = this.queryParams;
  377. this.$confirm('是否确认导出所有推荐店铺数据项?', "警告", {
  378. confirmButtonText: "确定",
  379. cancelButtonText: "取消",
  380. type: "warning"
  381. }).then(() => {
  382. this.exportLoading = true;
  383. return exportRecommendScrm(queryParams);
  384. }).then(response => {
  385. this.download(response.msg);
  386. this.exportLoading = false;
  387. }).catch(() => {});
  388. }
  389. }
  390. };
  391. </script>