com-dialog-select.php 11 KB

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