boss-weight-goods-select.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @link:http://www.goodmall.com/
  4. * @copyright: Copyright (c) 2020
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-04-24
  8. * Time: 19:33
  9. */
  10. ?>
  11. <style>
  12. .com-dialog-dialog {
  13. min-width: 700px;
  14. }
  15. </style>
  16. <template id="boss-weight-goods-select">
  17. <div class="com-dialog-select">
  18. <el-dialog append-to-body :title="title" :visible.sync="visible" :close-on-click-modal="false"
  19. custom-class="com-dialog-dialog" :before-close="close" @close="close" center>
  20. <div style="display: flex;justify-content: center;">
  21. <el-input placeholder="请输入商品名字" v-model="keyword" size="small"@keyup.enter.native="getDetail(1)">
  22. <el-button slot="append" @click="getDetail(1)">搜索</el-button>
  23. </el-input>
  24. </div>
  25. <el-table
  26. :data="list"
  27. v-loading="listLoading"
  28. border
  29. style="width: 100%;margin-top: 10px;">
  30. <el-table-column width="100px" label="ID" align="center">
  31. <template slot-scope="props">
  32. <el-checkbox-group v-model="selectId" @change="handleSelectionChange">
  33. <el-checkbox :label="props.row.id"></el-checkbox>
  34. </el-checkbox-group>
  35. </template>
  36. </el-table-column>
  37. <el-table-column
  38. prop="name"
  39. label="商品名称"
  40. >
  41. <template slot-scope="scope">
  42. <div style="display: flex;align-items: center;">
  43. <img :src="scope.row.cover_pic" style="width: 40px;height: 40px;display: block;margin-right: 5px;" />
  44. <div>{{scope.row.goods_name}}</div>
  45. </div>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <div style="text-align: right;margin: 20px 0;">
  50. <el-pagination
  51. background
  52. @current-change="getDetail"
  53. layout="prev, pager, next"
  54. :page-count="pageCount">
  55. </el-pagination>
  56. </div>
  57. <div style="display: flex;justify-content: center;">
  58. <el-button type="primary" @click="confirm">确定</el-button>
  59. </div>
  60. </el-dialog>
  61. <div @click="click" style="display: inline-block">
  62. <slot></slot>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. Vue.component('boss-weight-goods-select', {
  68. template: '#boss-weight-goods-select',
  69. props: {
  70. url: {
  71. type: String,
  72. default: 'mall/goods/search'
  73. },
  74. multiple: Boolean,
  75. title: {
  76. type: String,
  77. default: '商品选择'
  78. },
  79. listKey: {
  80. type: String,
  81. default: 'name'
  82. },
  83. params: Object,
  84. display: Boolean,
  85. extraSearch: Object,
  86. },
  87. data() {
  88. return {
  89. visible: false,
  90. listLoading: false,
  91. list: [],
  92. pagination: null,
  93. radioSelection: 0,
  94. search: {
  95. keyword: ''
  96. },
  97. multipleSelection: [],
  98. selectId:[],
  99. tableData:[],
  100. pageCount:0,
  101. keyword:''
  102. }
  103. },
  104. methods: {
  105. close(){
  106. this.visible=false;
  107. this.$emit('close');
  108. },
  109. click() {
  110. this.getDetail(1);
  111. this.visible = !this.visible;
  112. },
  113. getDetail(page) {
  114. this.list = [];
  115. this.listLoading = true;
  116. console.log('请求商品列表前的参数page='+page+'--url='+this.url+'--keyword='+this.keyword)
  117. request({
  118. params: {
  119. r: this.url,
  120. page: page,
  121. limit:10,
  122. keyword:this.keyword
  123. },
  124. method: 'get',
  125. }).then(e => {
  126. console.log('商品列表结果='+JSON.stringify(e))
  127. this.listLoading = false;
  128. if (e.data.code === 0) {
  129. this.list = e.data.data.list;
  130. this.pageCount = e.data.data.page_count;
  131. } else {
  132. this.$message.error(e.data.msg);
  133. }
  134. }).catch(e => {
  135. this.listLoading = false;
  136. });
  137. },
  138. handleSelectionChange(val) {
  139. },
  140. confirm() {
  141. let arr = [];
  142. if(this.selectId.length > 0){
  143. this.list.forEach((value,index) => {
  144. this.selectId.forEach((v,i) => {
  145. if(value.id == v){
  146. arr.push(value);
  147. }
  148. });
  149. });
  150. }
  151. this.multipleSelection = arr;
  152. console.log(this.multipleSelection);
  153. this.visible = false;
  154. this.$emit('selected', this.multipleSelection);
  155. this.$emit('input', this.multipleSelection);
  156. },
  157. currentChange(){
  158. }
  159. }
  160. });
  161. </script>