business-type.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div class="page-box" v-loading="loading > 0">
  3. <Header :title="title"></Header>
  4. <div class="container">
  5. <div class="content">
  6. <!-- 表格 -->
  7. <div class="btn" @click="handleModal('add')">+添加商家类型</div>
  8. <el-table
  9. :data="list"
  10. class="table no-border-table"
  11. ref="table"
  12. :header-cell-style="{
  13. border: 'none',
  14. color: '#333',
  15. background: '#f6f6f6',
  16. borderBottom: '1px solid #E8E8E8',
  17. height: '54px',
  18. }"
  19. :row-style="{
  20. height: '54px',
  21. }"
  22. >
  23. <el-table-column
  24. type="index"
  25. :index="tableIndex"
  26. align="center"
  27. label="编号"
  28. width="120"
  29. ></el-table-column>
  30. <el-table-column prop="pic" align="center" label="商家类型图标">
  31. <div slot-scope="scope">
  32. <img class="table-img" :src="scope.row.pic" alt="" />
  33. </div>
  34. </el-table-column>
  35. <el-table-column prop="name" align="center" label="类型名称">
  36. </el-table-column>
  37. <el-table-column prop="orderBy" align="center" label="排序">
  38. <div slot-scope="scope" @click="changeSortModal(scope.row.id)">
  39. {{ scope.row.orderBy }}
  40. </div>
  41. </el-table-column>
  42. <el-table-column label="操作" align="center">
  43. <div
  44. slot-scope="scope"
  45. style="display: flex; justify-content: center"
  46. >
  47. <div>
  48. <button
  49. size="mini"
  50. class="table-btn"
  51. @click="handleModal('edit', scope.row)"
  52. >
  53. 编辑
  54. </button>
  55. </div>
  56. <div>
  57. <button
  58. size="mini"
  59. class="table-btn"
  60. @click="handleDelete(scope.row.id)"
  61. >
  62. 删除
  63. </button>
  64. </div>
  65. </div>
  66. </el-table-column>
  67. </el-table>
  68. </div>
  69. <!-- 分页按钮 -->
  70. <div class="footer">
  71. <el-pagination
  72. @current-change="handleCurrentChange"
  73. :current-page.sync="currentPage"
  74. background
  75. layout="total, prev, pager, next, jumper"
  76. :page-size="size"
  77. :total="total"
  78. ></el-pagination>
  79. </div>
  80. </div>
  81. <el-dialog :visible.sync="addShow" class="dialog" width="560px" top="25vh">
  82. <div slot="title" class="dialog-title">
  83. {{ (type === "add" ? "新增" : "编辑") + "商家类型" }}
  84. </div>
  85. <el-form
  86. ref="form"
  87. :rules="rules"
  88. :model="addForm"
  89. class="form"
  90. label-width="auto"
  91. >
  92. <el-form-item label="商家类型名称:" prop="name" class="form-item">
  93. <el-input
  94. placeholder="请输入分类名称"
  95. class="add-renovation-input"
  96. style="width: 160px"
  97. v-model="addForm.name"
  98. ></el-input>
  99. </el-form-item>
  100. <el-form-item label="排序:" prop="sort" class="form-item">
  101. <el-input
  102. placeholder="请输入序号"
  103. class="add-renovation-input"
  104. style="width: 160px"
  105. v-model.number="addForm.orderBy"
  106. type="number"
  107. onkeypress="return( /[\d]/.test(String.fromCharCode(event.keyCode)))"
  108. ></el-input>
  109. <div class="sort-tip">数值越大,排序越靠前</div>
  110. </el-form-item>
  111. <el-form-item class="img_item" prop="pic" label="图片:">
  112. <div class="addImg">
  113. <div class="img-box">
  114. <img ref="img" :src="addForm.pic" v-if="addForm.pic" />
  115. <div class="icon" v-else>
  116. <p><i class="el-icon-plus" style="font-size: 32px"></i></p>
  117. <!-- <p>图片</p>
  118. <p class="tip">支持扩展名:.jpg .png</p> -->
  119. </div>
  120. <input
  121. type="file"
  122. class="file"
  123. ref="inputImg"
  124. @change="addChangeImg"
  125. />
  126. </div>
  127. <p class="tips">支持jpg、png格式</p>
  128. </div>
  129. </el-form-item>
  130. <el-form-item label="打赏上限比例:" prop="ratio" class="form-item">
  131. <el-input
  132. placeholder="请输入打赏上限比例"
  133. class="add-renovation-input"
  134. style="width: 160px"
  135. v-model.number="addForm.ratio"
  136. type="number"
  137. ></el-input>
  138. </el-form-item>
  139. </el-form>
  140. <div slot="footer" class="dialog-footer">
  141. <el-button class="cancel-btn btn" @click="addShow = false"
  142. >取 消</el-button
  143. >
  144. <el-button class="confirm-btn btn" @click="handleConfirm"
  145. >确 定</el-button
  146. >
  147. </div>
  148. </el-dialog>
  149. </div>
  150. </template>
  151. <script type="text/ecmascript-6">
  152. import Header from '../../components/common/header';
  153. export default {
  154. components: {
  155. Header
  156. },
  157. name: 'banner',
  158. data() {
  159. return {
  160. loading: 0, // 加载中
  161. currentPage: 1, // 当前页码
  162. size: 20, // 每页条数
  163. total: 0, // 总页数
  164. title: {
  165. // 页面标题
  166. firstTitile: '商家管理',
  167. secondTitle: '商家类型'
  168. },
  169. list: [], // 轮播列表
  170. rules: {},
  171. addForm: {
  172. pic: '',
  173. name: '',
  174. orderBy: null,
  175. ratio: null
  176. },
  177. addShow: false,
  178. id: null,
  179. type: ''
  180. };
  181. },
  182. mounted() {
  183. // 获取列表
  184. this.getList();
  185. },
  186. computed: {},
  187. methods: {
  188. // 表格序号
  189. tableIndex(index) {
  190. return ++index;
  191. },
  192. // 切换页码
  193. handleCurrentChange(page) {
  194. this.currentPage = page;
  195. this.getList();
  196. },
  197. // 获取轮播列表
  198. getList() {
  199. this.loading++;
  200. this.httpGet(this.$root.getBusinessTypeList, {}).then(
  201. (res) => {
  202. this.loading--;
  203. this.list = res.list;
  204. this.total = res.total;
  205. },
  206. (res) => {
  207. this.loading--;
  208. this.$message.error(res);
  209. }
  210. );
  211. },
  212. // 编辑轮播弹窗
  213. handleModal(type, rowData) {
  214. this.type = type;
  215. if (type === 'edit') {
  216. this.id = rowData.id;
  217. this.addForm = {
  218. pic: rowData.pic,
  219. name: rowData.name,
  220. orderBy: rowData.orderBy,
  221. ratio: rowData.ratio
  222. };
  223. } else {
  224. this.addForm = {
  225. pic: '',
  226. name: '',
  227. orderBy: null,
  228. ratio: null
  229. };
  230. this.$refs.form && this.$refs.form.clearValidate();
  231. }
  232. this.addShow = true;
  233. },
  234. // 删除
  235. handleDelete(id) {
  236. this.$confirm(
  237. `<p class='title'><i class='icon el-icon-question'></i>提醒</p><p class='text'>确定要删除该类型吗?</p>`,
  238. {
  239. confirmButtonText: '确定',
  240. cancelButtonText: '取消',
  241. cancelButtonClass: 'cancel-btn',
  242. confirmButtonClass: 'confirm-btn',
  243. customClass: 'confirm-box',
  244. dangerouslyUseHTMLString: true,
  245. showClose: false,
  246. type: 'none'
  247. }
  248. ).then(() => {
  249. this.loading++;
  250. this.httpDelete(this.$root.deleteBusinessType, {
  251. id
  252. }).then(
  253. (res) => {
  254. this.$message({
  255. message: '操作成功',
  256. type: 'success'
  257. });
  258. this.loading--;
  259. this.getList();
  260. },
  261. (res) => {
  262. this.loading--;
  263. this.$message.error(res);
  264. }
  265. );
  266. });
  267. },
  268. //
  269. handleConfirm() {
  270. this.$refs.form.validate((valid) => {
  271. if (valid) {
  272. let url =
  273. this.type === 'add'
  274. ? this.$root.addBusinessType
  275. : this.$root.updateBusinessType;
  276. let method = this.type === 'add' ? 'httpPost' : 'httpPut';
  277. let inputData =
  278. this.type === 'add'
  279. ? {
  280. ...this.addForm
  281. }
  282. : {
  283. ...this.addForm,
  284. id: this.id
  285. };
  286. inputData.ratio = +inputData.ratio;
  287. this.loading++;
  288. this[method](url, inputData).then(
  289. (res) => {
  290. this.$message({
  291. message: '操作成功',
  292. type: 'success'
  293. });
  294. this.loading--;
  295. this.addShow = false;
  296. this.getList();
  297. },
  298. (res) => {
  299. this.loading--;
  300. this.$message.error(res);
  301. }
  302. );
  303. }
  304. });
  305. },
  306. // 图片改变
  307. addChangeImg(e) {
  308. this.upPic(e, (res) => {
  309. this.$set(this.addForm, 'pic', res);
  310. // 清空input value,解决重复图片不触发change
  311. this.$refs.inputImg.value = '';
  312. this.$refs.form.clearValidate(['pic']);
  313. });
  314. },
  315. // 上传图片
  316. upPic(e, fun) {
  317. // 上传图片
  318. let file = e.target.files[0];
  319. if (!file) {
  320. return;
  321. }
  322. this.request.upPic({ prefix: 'other', file: file }).then(
  323. (res) => {
  324. fun(res);
  325. },
  326. (res) => {}
  327. );
  328. }
  329. }
  330. };
  331. </script>
  332. <style lang="stylus" rel="stylesheet/stylus">
  333. @import '~assets/public.styl';
  334. </style>
  335. <style lang="stylus" rel="stylesheet/stylus" scoped>
  336. @import '~assets/main.styl';
  337. .page-box {
  338. height: 100%;
  339. width: 100%;
  340. flex-y(flex-start, flex-start);
  341. overflow-y: hidden;
  342. background: bg-color;
  343. .container {
  344. box-sizing: border-box;
  345. height: 100%;
  346. width: 100%;
  347. overflow-y: auto;
  348. flex-y(flex-start, flex-start);
  349. padding: 24px;
  350. // content 表格
  351. .content {
  352. flex: 1;
  353. width: 100%;
  354. font-size: 14px;
  355. background: white;
  356. box-sizing: border-box;
  357. padding: 24px 32px;
  358. border-radius: 2px;
  359. // 按钮
  360. .btn {
  361. // width: 100px;
  362. display: inline-block;
  363. padding: 0 16px;
  364. height: 32px;
  365. line-height: 32px;
  366. confirm-btn();
  367. font-size: 14px;
  368. margin-bottom: 16px;
  369. // margin: 16px 0;
  370. }
  371. .tip {
  372. margin-left: 32px;
  373. color: #999;
  374. }
  375. // 表格按钮
  376. .table-btn {
  377. width: 65px;
  378. height: 24px;
  379. line-height: 24px;
  380. color: gray3;
  381. font-size: 12px;
  382. margin-right: 8px;
  383. cancel-btn();
  384. }
  385. .table-img {
  386. height: 36px;
  387. width: auto;
  388. }
  389. }
  390. }
  391. .dialog-content {
  392. flex-y();
  393. }
  394. .addImg {
  395. .icon {
  396. width: 80px;
  397. height: 80px;
  398. background: #E8E8E8;
  399. border-width: 0;
  400. i {
  401. color: #979797;
  402. }
  403. }
  404. }
  405. .form {
  406. margin-top: 16px;
  407. margin-bottom: 30px;
  408. padding-left: 80px;
  409. .form-item {
  410. margin-top: 24px;
  411. }
  412. .sort-tip {
  413. word(14px, #c8c8c8);
  414. line-height: 20px;
  415. }
  416. }
  417. }
  418. </style>