com-dialog-select.php 9.6 KB

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