com-dialog-select-store.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.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="com-dialog-select-store">
  17. <div class="com-dialog-select-store">
  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">
  20. <div>
  21. <el-input v-model="keyword" placeholder="根据商品名称或商品ID搜索" @keyup.enter.native="getDetail(1)">
  22. <el-button slot="append" @click="getDetail(1)">搜索</el-button>
  23. </el-input>
  24. <slot name="inputslot"></slot>
  25. <el-table ref="multipleTable" border v-loading="listLoading" :data="list" style="margin-top: 24px;"
  26. @selection-change="handleSelectionChange">
  27. <el-table-column type="selection" width="60px" label="ID" props="id" v-if="multiple">
  28. </el-table-column>
  29. <el-table-column width="100px" label="ID" props="id" v-else>
  30. <template slot-scope="props">
  31. <el-radio-group v-model="radioSelection" @change="handleSelectionChange(props.row)">
  32. <el-radio :label="props.row.id"></el-radio>
  33. </el-radio-group>
  34. </template>
  35. </el-table-column>
  36. <el-table-column v-if="multiple" prop="id" label="ID" width="80" align="center"></el-table-column>
  37. <el-table-column label="名称">
  38. <template slot-scope="props">
  39. <div style="display: flex;">
  40. <el-image fit="cover" style="width: 40px;height: 40px;display: block;margin-right: 5px;" :src="props.row.cover_pic"></el-image>
  41. <div>
  42. <com-ellipsis :line="2">{{props.row[listKey]}}</com-ellipsis>
  43. <div style="font-size: 12px;color: red;">¥{{props.row.price}}</div>
  44. </div>
  45. </div>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="成本价" width="100" prop="cost_price"></el-table-column>
  49. <el-table-column label="库存" width="100" prop="stock"></el-table-column>
  50. <el-table-column v-if="is_show_store_name" label="所属门店" width="100" prop="store_name"></el-table-column>
  51. </el-table>
  52. </div>
  53. <div style="margin-top: 24px;">
  54. <el-row>
  55. <el-pagination
  56. v-if="pagination"
  57. style="display: inline-block;"
  58. background
  59. :page-size="pagination.pageSize"
  60. @current-change="getDetail"
  61. layout="prev, pager, next"
  62. :total="pagination.total_count">
  63. </el-pagination>
  64. <el-button type="primary" size="small" style="float: right" @click="confirm">选择</el-button>
  65. </el-row>
  66. </div>
  67. </el-dialog>
  68. <div @click="click" style="display: inline-block">
  69. <slot></slot>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. Vue.component('com-dialog-select-store', {
  75. template: '#com-dialog-select-store',
  76. props: {
  77. /* visible : {
  78. type: String,
  79. }, */
  80. url: {
  81. type: String,
  82. default: 'store/store-goods/search'
  83. },
  84. multiple: Boolean,//是否开启选
  85. title: {
  86. type: String,
  87. default: '商品选择'
  88. },
  89. listKey: { //键值
  90. type: String,
  91. default: 'goods_name'
  92. },
  93. params: Object,
  94. display: Boolean,
  95. extraSearch: Object,
  96. is_show_store_name: {
  97. type: Boolean,
  98. default: false,
  99. },//是否显示门店,
  100. },
  101. data() {
  102. return {
  103. visible: false,
  104. listLoading: false,
  105. list: [],
  106. total_count:1,
  107. pageSize:20,
  108. pagination: null,
  109. radioSelection: 0,
  110. keyword: null,
  111. multipleSelection: []
  112. }
  113. },
  114. methods: {
  115. close(){
  116. this.visible=false;
  117. this.$emit('close');
  118. },
  119. click() {
  120. this.getDetail(1);
  121. this.visible = !this.visible;
  122. },
  123. getDetail(page) {
  124. this.list = [];
  125. this.listLoading = true;
  126. let params = Object.assign({
  127. r: this.url,
  128. keyword: this.keyword,
  129. page: page
  130. }, this.params);
  131. request({
  132. params: params
  133. }).then(e => {
  134. this.listLoading = false;
  135. //console.log("商品的数据=="+JSON.stringify(e))
  136. if (e.data.code === 0) {
  137. this.list = e.data.data.list;
  138. this.pagination = e.data.data.pagination;
  139. this.pagination.pageSize = e.data.data.page_size;
  140. this.pagination.total_count = this.pagination.totalCount;
  141. } else {
  142. this.$message.error(e.data.msg);
  143. }
  144. }).catch(e => {
  145. this.listLoading = false;
  146. });
  147. },
  148. chooseAll(){
  149. this.list.forEach(row => {
  150. this.$refs.multipleTable.toggleRowSelection(row);
  151. });
  152. },
  153. clear(){
  154. this.$refs.multipleTable.clearSelection();
  155. },
  156. handleSelectionChange(val) {
  157. this.multipleSelection = val;
  158. },
  159. confirm() {
  160. this.visible = false;
  161. this.$emit('selected', this.multipleSelection);
  162. this.$emit('input', this.multipleSelection);
  163. }
  164. }
  165. });
  166. </script>