com-dialog-screen-select.php 7.9 KB

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