selectGoods.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <el-dialog
  3. width="980px"
  4. title="商品列表"
  5. :visible.sync="innerVisible"
  6. append-to-body
  7. :close-on-click-modal="false"
  8. @close="$emit('close')"
  9. >
  10. <div class="screen-container">
  11. <el-form ref="tableScreenForm" :model="tableScreenForm" label-width="70px" size="small" label-position="left">
  12. <el-row :gutter="20">
  13. <el-col :xs="24" :sm="8" :lg="8">
  14. <el-form-item label="商品编号" prop="goodsId">
  15. <el-input v-model="tableScreenForm.goodsId" placeholder="商品编号" size="small" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :xs="24" :sm="8" :lg="8">
  19. <el-form-item label="辅材名称" prop="goodsName">
  20. <el-input v-model="tableScreenForm.goodsName" placeholder="辅材名称" size="small" />
  21. </el-form-item>
  22. </el-col>
  23. <el-col :xs="24" :sm="8" :lg="8">
  24. <el-form-item label="辅材小类" prop="categoryId">
  25. <el-cascader
  26. v-model="tableScreenForm.categoryId"
  27. placeholder="辅材小类"
  28. size="small"
  29. :show-all-levels="false"
  30. clearable
  31. :options="materialCategoryTree"
  32. :props="{
  33. options: materialCategoryTree,
  34. value: 'categoryId',
  35. label: 'categoryName',
  36. children: 'child',
  37. emitPath: false
  38. }"
  39. >
  40. </el-cascader>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :xs="24" :sm="8" :lg="8">
  44. <el-form-item label="商品代码" prop="goodsCode">
  45. <el-input v-model="tableScreenForm.goodsCode" placeholder="商品代码" size="small" />
  46. </el-form-item>
  47. </el-col>
  48. <el-col :xs="24" :sm="8" :lg="8">
  49. <el-form-item label="规格型号" prop="goodsSpecification">
  50. <el-input v-model="tableScreenForm.goodsSpecification" placeholder="规格型号" size="small" />
  51. </el-form-item>
  52. </el-col>
  53. <el-col :xs="24" :sm="8" :lg="8" class="tr">
  54. <el-form-item label="">
  55. <el-button size="small" @click="chongzhi">重置</el-button>
  56. <el-button size="small" type="primary" @click="getGoodsListByScreen">搜索</el-button>
  57. </el-form-item>
  58. </el-col>
  59. </el-row>
  60. </el-form>
  61. </div>
  62. <el-table
  63. ref="goodsTable"
  64. :data="goodsList"
  65. :row-key="getRowKeys"
  66. height="350"
  67. size="mini"
  68. border
  69. header-cell-class-name="headerRowColor"
  70. style="width: 100%"
  71. @selection-change="handleChooseGoods"
  72. >
  73. <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="selectable" />
  74. <el-table-column prop="parentCategoryName" label="大类类名称" />
  75. <el-table-column prop="categoryName" label="小类名称" />
  76. <el-table-column prop="goodsName" label="辅材名称" />
  77. <el-table-column prop="goodsId" label="商品编码" />
  78. <el-table-column prop="goodsCode" label="商品代码" />
  79. <el-table-column prop="goodsStockUnit" label="单位" />
  80. <el-table-column prop="goodsSpecification" label="规格型号" />
  81. <el-table-column prop="remark" label="备注" />
  82. </el-table>
  83. <div class="pagination clearfix" style="margin-top: 20px">
  84. <div class="fr">
  85. <el-pagination
  86. :current-page="table_currentPage"
  87. :page-size="table_pageSize"
  88. background
  89. layout="prev, pager, next"
  90. :total="table_listTotal"
  91. @current-change="handleTableCurrentChange"
  92. />
  93. </div>
  94. </div>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="selGoods">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. </template>
  100. <script>
  101. import { materialCategoryTree } from '@/api/auxiliaryMaterialClass'
  102. import { newGetList } from '@/api/masterAuxiliaryMaterials'
  103. export default {
  104. props: {
  105. guolvList: {
  106. type: Array,
  107. default: () => []
  108. }
  109. },
  110. data() {
  111. return {
  112. innerVisible: true,
  113. tableScreenForm: {
  114. goodsId: '',
  115. goodsName: '',
  116. goodsCode: '',
  117. categoryId: '',
  118. goodsSpecification: ''
  119. },
  120. goodsList: [],
  121. table_currentPage: 1,
  122. table_pageSize: 10,
  123. table_listTotal: 0,
  124. table_chooseGoods: [],
  125. materialCategoryTree: []
  126. }
  127. },
  128. created() {
  129. // 获取小类筛选
  130. materialCategoryTree({ state: 'ON' }).then(res2 => {
  131. this.materialCategoryTree = res2.data.filter(item => item.child && item.child.length > 0)
  132. })
  133. // 获取列表数据
  134. this.getGoodsList()
  135. },
  136. methods: {
  137. selectable(row, index) {
  138. return !~this.guolvList.indexOf(row.goodsId)
  139. },
  140. // 获取商品列表
  141. getGoodsList() {
  142. newGetList({
  143. pageNum: this.table_currentPage,
  144. pageSize: this.table_pageSize,
  145. params: [
  146. ...(() => {
  147. if (this.tableScreenForm.goodsId) {
  148. return [{ param: 'a.goods_id', compare: 'like', value: this.tableScreenForm.goodsId }]
  149. } else {
  150. return []
  151. }
  152. })(),
  153. ...(() => {
  154. if (this.tableScreenForm.goodsName) {
  155. return [{ param: 'a.goods_name', compare: 'like', value: this.tableScreenForm.goodsName }]
  156. } else {
  157. return []
  158. }
  159. })(),
  160. ...(() => {
  161. if (this.tableScreenForm.goodsCode) {
  162. return [{ param: 'a.goods_code', compare: 'like', value: this.tableScreenForm.goodsCode }]
  163. } else {
  164. return []
  165. }
  166. })(),
  167. ...(() => {
  168. if (this.tableScreenForm.goodsSpecification) {
  169. return [
  170. { param: 'a.goods_specification', compare: 'like', value: this.tableScreenForm.goodsSpecification }
  171. ]
  172. } else {
  173. return []
  174. }
  175. })(),
  176. ...(() => {
  177. if (this.tableScreenForm.categoryId) {
  178. return [{ param: 'b.category_id', compare: '=', value: this.tableScreenForm.categoryId }]
  179. } else {
  180. return []
  181. }
  182. })()
  183. ]
  184. }).then(res => {
  185. this.goodsList = res.data.records
  186. console.log(res.data.records)
  187. this.table_listTotal = res.data.total
  188. })
  189. },
  190. chongzhi() {
  191. this.tableScreenForm = {
  192. goodsId: '',
  193. goodsName: '',
  194. goodsCode: '',
  195. categoryId: '',
  196. goodsSpecification: ''
  197. }
  198. this.getGoodsListByScreen()
  199. },
  200. // 搜索
  201. getGoodsListByScreen() {
  202. this.handleTableCurrentChange(1)
  203. },
  204. // 更改列表当前页
  205. handleTableCurrentChange(val) {
  206. if (this.table_chooseGoods.length > 0) {
  207. return this.$errorMsg('当前已选择商品')
  208. }
  209. this.table_currentPage = val
  210. this.getGoodsList()
  211. },
  212. // id
  213. getRowKeys(row) {
  214. return row.goodsId
  215. },
  216. // table点击选择商品
  217. handleChooseGoods(val) {
  218. this.table_chooseGoods = val
  219. },
  220. selGoods() {
  221. console.log(this.table_chooseGoods)
  222. this.$emit('confirm', this.table_chooseGoods)
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped></style>