com-dialog-store-goods.php 6.1 KB

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