GoodsAdd.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="添加实物商品"
  5. width="1000px"
  6. :visible.sync="dialogVisible"
  7. :before-close="close"
  8. >
  9. <div class="dialog-search">
  10. <div>商品名称:</div>
  11. <el-input
  12. v-model="goodsTitle"
  13. placeholder="请输入商品名称"
  14. clearable
  15. size="small"
  16. style="width: 220px" @clear="pageParams.pageNum = 1;getGoodsList()"
  17. @keyup.enter.native="pageParams.pageNum = 1;getGoodsList()"
  18. />
  19. <div style="margin-left: 20px">商品价格:</div>
  20. <el-input style="width: 220px" v-model="queryParams.minValue" @clear="pageParams.pageNum = 1;getGoodsList()" placeholder="最低价格" clearable @keyup.enter.native="pageParams.pageNum = 1;getGoodsList()"/>
  21. <div style="width: 20px;text-align: center">-</div>
  22. <el-input style="width: 220px" v-model="queryParams.maxValue" @clear="pageParams.pageNum = 1;getGoodsList()" placeholder="最高价格" clearable @keyup.enter.native="pageParams.pageNum = 1;getGoodsList()"/>
  23. </div>
  24. <div class="dialog-search">
  25. <div>商品类型:</div>
  26. <el-select v-model="queryParams.type" placeholder="请选择商品类型" clearable @change="pageParams.pageNum = 1;getGoodsList()">
  27. <el-option label="全部" value=""/>
  28. <el-option label="实物商品" value="1"/>
  29. <el-option label="卡密商品" value="2"/>
  30. </el-select>
  31. <div class="ge"></div>
  32. <el-button
  33. type="primary"
  34. icon="el-icon-search"
  35. size="mini"
  36. @click="getGoodsList()"
  37. >查询</el-button
  38. >
  39. </div>
  40. <el-table
  41. v-loading="loading"
  42. :data="goodsList"
  43. row-key="goodsId"
  44. @selection-change="handleSelectionGoods"
  45. class="el-table"
  46. >
  47. <el-table-column
  48. type="selection"
  49. width="55"
  50. align="center"
  51. fixed="left"
  52. :reserve-selection="true"
  53. />
  54. <el-table-column label="商品ID" prop="goodsId" />
  55. <el-table-column label="商品图片">
  56. <template slot-scope="{ row }">
  57. <div v-if="row.picUrl">
  58. <el-image
  59. style="width: 100px; height: 100px"
  60. :src="row.picUrl.split(',')[0]"
  61. :preview-src-list="row.picUrl.split(',')"
  62. >
  63. </el-image>
  64. </div>
  65. <p v-else>-</p>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="商品名称" prop="title" min-width="85" />
  69. <el-table-column label="商品类型" min-width="85">
  70. <template slot-scope="scope">
  71. <div>{{ scope.row.type == 1 ? '实物商品':'卡密商品' }}</div>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="商品价格" min-width="85">
  75. <template slot-scope="scope">
  76. <div>¥{{ $numberFormat(scope.row.value) }}</div>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="商品库存" prop="quantity" width="80" />
  80. </el-table>
  81. <pagination
  82. v-show="goodsTotal > 0"
  83. :total="goodsTotal"
  84. :page.sync="pageParams.pageNum"
  85. :limit.sync="pageParams.pageSize"
  86. @pagination="getGoodsList"
  87. />
  88. <div class="dialog-btn">
  89. <el-button size="small" @click="close"> 取 消 </el-button>
  90. <div class="ge"></div>
  91. <el-button type="primary" size="small" @click="confirmGoods">
  92. 确 认
  93. </el-button>
  94. </div>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import { publicFileGetUrl } from "@/api/common";
  100. import { getGoodsList } from "@/api/business/goods";
  101. import { accMul } from '@/utils/util'
  102. export default {
  103. name: "GoodsAdd",
  104. props: {
  105. dialogVisible: {
  106. type: Boolean,
  107. default: false,
  108. },
  109. },
  110. data() {
  111. return {
  112. loading: false,
  113. goodsTitle: "", // 商品名称
  114. queryParams:{},
  115. goodsList: [], // 商品列表
  116. goodsTotal: 0, // 商品总数
  117. selectGoodsList: [], // 选中商品
  118. pageParams: {
  119. pageNum: 1,
  120. pageSize: 10,
  121. },
  122. };
  123. },
  124. created() {
  125. this.getGoodsList();
  126. },
  127. methods: {
  128. // 商品列表
  129. getGoodsList() {
  130. this.loading = true;
  131. getGoodsList(
  132. "pageNum=" +
  133. this.pageParams.pageNum +
  134. "&pageSize=" +
  135. this.pageParams.pageSize +
  136. "&",
  137. { title: this.goodsTitle, type: this.queryParams.type, status: "on", minValue: this.queryParams.minValue?accMul(this.queryParams.minValue, 100):this.queryParams.minValue, maxValue: this.queryParams.maxValue?accMul(this.queryParams.maxValue, 100):this.queryParams.maxValue,}
  138. ).then((res) => {
  139. this.goodsList = res.rows.map((item) => {
  140. return {
  141. ...item,
  142. picUrl: publicFileGetUrl + item.picUrl.split(",")[0],
  143. };
  144. });
  145. this.goodsTotal = res.total;
  146. this.loading = false;
  147. });
  148. },
  149. // 选中商品
  150. handleSelectionGoods(e) {
  151. this.selectGoodsList = e.map((item) => {
  152. return {
  153. type: "goods",
  154. // quantity: 1,
  155. goodsId: item.goodsId,
  156. picUrl: item.picUrl,
  157. title: item.title,
  158. sortWeight: 100
  159. };
  160. });
  161. },
  162. // 确认选中商品
  163. confirmGoods() {
  164. if(!this.selectGoodsList.length) {
  165. this.msgInfo('请选择商品')
  166. return
  167. }
  168. this.$emit("confirmGoods", this.selectGoodsList);
  169. },
  170. close() {
  171. this.$emit("close");
  172. },
  173. },
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. .dialog-search {
  178. display: flex;
  179. line-height: 32px;
  180. margin-bottom: 20px;
  181. .ge {
  182. width: 20px;
  183. }
  184. }
  185. .dialog-btn {
  186. display: flex;
  187. align-content: center;
  188. justify-content: flex-end;
  189. padding: 40px 0 0;
  190. .ge {
  191. width: 20px;
  192. }
  193. }
  194. </style>