index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <style>
  2. .table-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. }
  6. .input-item {
  7. width: 250px;
  8. margin: 0 0 20px;
  9. }
  10. .input-item .el-input__inner {
  11. border-right: 0;
  12. }
  13. .input-item .el-input__inner:hover{
  14. border: 1px solid #dcdfe6;
  15. border-right: 0;
  16. outline: 0;
  17. }
  18. .input-item .el-input__inner:focus{
  19. border: 1px solid #dcdfe6;
  20. border-right: 0;
  21. outline: 0;
  22. }
  23. .input-item .el-input-group__append {
  24. background-color: #fff;
  25. border-left: 0;
  26. width: 10%;
  27. padding: 0;
  28. }
  29. .input-item .el-input-group__append .el-button {
  30. padding: 0;
  31. }
  32. .input-item .el-input-group__append .el-button {
  33. margin: 0;
  34. }
  35. .table-body .el-button {
  36. padding: 0!important;
  37. border: 0;
  38. margin: 0 5px;
  39. }
  40. .sort-input {
  41. width: 100%;
  42. background-color: #F3F5F6;
  43. height: 32px;
  44. }
  45. .sort-input span {
  46. height: 32px;
  47. width: 100%;
  48. line-height: 32px;
  49. display: inline-block;
  50. padding: 0 10px;
  51. font-size: 13px;
  52. }
  53. .sort-input .el-input__inner {
  54. height: 32px;
  55. line-height: 32px;
  56. background-color: #F3F5F6;
  57. float: left;
  58. padding: 0 10px;
  59. border: 0;
  60. }
  61. </style>
  62. <div id="app" v-cloak>
  63. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  64. <div slot="header">
  65. <span>奖品列表</span>
  66. <el-button style="float: right; margin: -5px 0" type="primary" size="small" @click="$navigate({r:'scratch/scratch/edit'})">添加奖品
  67. </el-button>
  68. </div>
  69. <div class="table-body">
  70. <el-form size="small" :inline="true" :model="search">
  71. <!-- 搜索框 -->
  72. <el-form-item>
  73. <el-select style="width: 120px" @change="scratchSearch" v-model="search.type">
  74. <el-option label="全部" value="0"></el-option>
  75. <el-option :key="index" :label="item" :value="index"
  76. v-for="(item, index) in types"></el-option>
  77. </el-select>
  78. </el-form-item>
  79. <el-form-item>
  80. <div class="input-item">
  81. <el-input @keyup.enter.native="scratchSearch" size="small" placeholder="请输入搜索内容" v-model="search.keyword" clearable @clear='scratchSearch'>
  82. <el-button slot="append" icon="el-icon-search" @click="scratchSearch"></el-button>
  83. </el-input>
  84. </div>
  85. </el-form-item>
  86. </el-form>
  87. <el-table :data="list" stripe v-loading="loading" size="small" style="margin-bottom: 15px;">
  88. <el-table-column prop="id" label="ID" width="100"></el-table-column>
  89. <el-table-column prop="name" label="奖品名称" width="100"></el-table-column>
  90. <el-table-column prop="pic" label="奖品图标" width="100">
  91. <template slot-scope="scope">
  92. <com-image style="float: left;margin-right: 5px;" mode="aspectFill" :src="scope.row.pic"></com-image>
  93. </template>
  94. </el-table-column>
  95. <el-table-column prop="type" label="奖品类型" width="220">
  96. <template slot-scope="scope">
  97. <span v-if="scope.row.type == 1">红包</span>
  98. <span v-if="scope.row.type == 2">余额</span>
  99. <span v-if="scope.row.type == 3">优惠券</span>
  100. <span v-if="scope.row.type == 4">积分</span>
  101. <span v-if="scope.row.type == 5">商品</span>
  102. </template>
  103. </el-table-column>
  104. <el-table-column prop="name" label="奖品明细">
  105. <template slot-scope="scope">
  106. <span v-if="scope.row.type == 1">{{ scope.row.price }}元</span>
  107. <span v-if="scope.row.type == 2">{{ scope.row.balance }}元</span>
  108. <span v-if="scope.row.type == 3">{{ scope.row.coupon_data.name}}</span>
  109. <span v-if="scope.row.type == 4">{{ scope.row.num}}积分</span>
  110. <span v-if="scope.row.type == 5">{{ scope.row.goods.goods_name }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column prop="stock" label="库存" width="150">
  114. <template slot-scope="scope">
  115. <div v-if="editForm.id != scope.row.id">
  116. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  117. <span>{{scope.row.stock}}</span>
  118. </el-tooltip>
  119. <el-button class="edit-sort" type="text" @click="editSort(scope.row)">
  120. <img src="resources/img/common/order/edit.png" alt="">
  121. </el-button>
  122. </div>
  123. <div style="display: flex;align-items: center" v-else>
  124. <el-input style="min-width: 70px" type="number" size="mini" class="change" v-model="editForm.stock"
  125. autocomplete="off"></el-input>
  126. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error"
  127. circle @click="quit()"></el-button>
  128. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px"
  129. icon="el-icon-success" circle @click="editSubmit(scope.row)">
  130. </el-button>
  131. </div>
  132. </template>
  133. </el-table-column>
  134. <el-table-column prop="status" label="状态" width="100">
  135. <template slot-scope="scope">
  136. <el-switch
  137. v-model="scope.row.status"
  138. :active-value="1"
  139. :inactive-value="0"
  140. @change="toChosen(scope.row)"
  141. >
  142. </el-switch>
  143. </template>
  144. </el-table-column>
  145. <el-table-column prop="updated_at" label="操作时间" width="200">
  146. <template slot-scope="scope">
  147. {{scope.row.updated_at|dateTimeFormat('Y-m-d H:i:s')}}
  148. </template>
  149. </el-table-column>
  150. <el-table-column label="操作" width="220">
  151. <template slot-scope="scope">
  152. <el-button type="text" size="mini" v-if="false" circle @click="handleEdit(scope.$index, scope.row)">
  153. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  154. <img src="resources/img/common/edit.png" alt="">
  155. </el-tooltip>
  156. </el-button>
  157. <el-button type="text" size="mini" circle @click="handleDel(scope.$index, scope.row,list.id)">
  158. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  159. <img src="resources/img/common/del.png" alt="">
  160. </el-tooltip>
  161. </el-button>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <div flex="box:last cross:center">
  166. <div style="visibility: hidden">
  167. <el-button plain type="primary" size="small">批量操作1</el-button>
  168. <el-button plain type="primary" size="small">批量操作2</el-button>
  169. </div>
  170. <div>
  171. <el-pagination
  172. v-if="pagination"
  173. style="display: inline-block;float: right;"
  174. background
  175. :page-size="page_size"
  176. @current-change="pageChange"
  177. layout="prev, pager, next"
  178. :total="pagination.totalCount">
  179. </el-pagination>
  180. </div>
  181. </div>
  182. </div>
  183. </el-card>
  184. </div>
  185. <script>
  186. const app = new Vue({
  187. el: '#app',
  188. data() {
  189. return {
  190. search: {
  191. keyword: '',
  192. type: '0',
  193. },
  194. list: [],
  195. coupon: [],
  196. types: [],
  197. loading: false,
  198. pagination: "",
  199. page_size: 1,
  200. page:1,
  201. //修改门店
  202. dialogEdit: false,
  203. editForm: {
  204. id: 0,
  205. stock: 0,
  206. },
  207. editFormRules: {
  208. stock: [
  209. { required: true, message: '库存不能为空', trigger: 'blur' },
  210. ],
  211. },
  212. btnLoading: false,
  213. };
  214. },
  215. directives: {
  216. // 注册一个局部的自定义指令 v-focus
  217. focus: {
  218. // 指令的定义
  219. inserted: function (el) {
  220. // 聚焦元素
  221. el.querySelector('input').focus()
  222. }
  223. }
  224. },
  225. methods: {
  226. scratchSearch(){
  227. this.page = 1;
  228. this.getList();
  229. },
  230. //分页
  231. pageChange(page) {
  232. this.list= [];
  233. this.page = page;
  234. this.getList();
  235. },
  236. editSubmit(row) {
  237. row.stock = this.editForm.stock;
  238. let para = Object.assign({}, this.editForm);
  239. this.btnLoading = true;
  240. request({
  241. params: {
  242. r: 'scratch/scratch/edit-stock'
  243. },
  244. data: para,
  245. method: 'post'
  246. }).then(e => {
  247. if (e.data.code == 0) {
  248. this.$message.success(e.data.msg);
  249. this.editForm.id = null;
  250. } else {
  251. this.$alert(e.data.msg, '提示', {
  252. confirmButtonText: '确定'
  253. })
  254. }
  255. this.btnLoading = false;
  256. }).catch(e => {});
  257. },
  258. editSort(row) {
  259. this.editForm.id = row.id;
  260. this.editForm.stock = row.stock;
  261. },
  262. quit() {
  263. this.editForm.id = null;
  264. },
  265. // 切换状态
  266. toChosen(val) {
  267. console.log(val)
  268. request({
  269. params: {
  270. r: 'scratch/scratch/edit-status'
  271. },
  272. data: {
  273. id: val.id,
  274. status: val.status,
  275. },
  276. method: 'post'
  277. }).then(e => {
  278. if (e.data.code == 0) {
  279. this.$message({
  280. message: '切换成功',
  281. type: 'success'
  282. });
  283. } else {
  284. this.$alert(e.data.msg, '提示', {
  285. confirmButtonText: '确定'
  286. })
  287. }
  288. }).catch(e => {
  289. this.$alert(e.data.msg, '提示', {
  290. confirmButtonText: '确定'
  291. })
  292. });
  293. },
  294. //带着ID前往编辑页面
  295. handleEdit: function(row, column) {
  296. navigateTo({ r: 'scratch/edit', id: column.id });
  297. },
  298. //删除
  299. handleDel: function(row, column) {
  300. this.$confirm('确认删除该记录吗?', '提示', {
  301. type: 'warning'
  302. }).then(() => {
  303. let para = { id: column.id };
  304. request({
  305. params: {
  306. r: 'scratch/scratch/delete'
  307. },
  308. data: para,
  309. method: 'post'
  310. }).then(e => {
  311. if (e.data.code === 0) {
  312. const h = this.$createElement;
  313. this.$message({
  314. message: '删除成功',
  315. type: 'success'
  316. });
  317. setTimeout(function() {
  318. location.reload();
  319. }, 300);
  320. } else {
  321. this.$alert(e.data.msg, '提示', {
  322. confirmButtonText: '确定'
  323. })
  324. }
  325. }).catch(e => {
  326. this.$alert(e.data.msg, '提示', {
  327. confirmButtonText: '确定'
  328. })
  329. });
  330. })
  331. },
  332. getList() {
  333. this.loading = true;
  334. request({
  335. params: {
  336. r: 'scratch/scratch/get-list',
  337. page: this.page,
  338. type: this.search.type,
  339. keyword: this.search.keyword,
  340. },
  341. }).then(e => {
  342. if (e.data.code == 0) {
  343. this.loading = false;
  344. this.list = e.data.data.list;
  345. this.types = e.data.data.types;
  346. this.page_size = e.data.data.page_size;
  347. this.pagination = e.data.data.pagination;
  348. }
  349. }).catch(e => {
  350. });
  351. },
  352. },
  353. mounted() {
  354. this.getList();
  355. }
  356. })
  357. </script>