VenderGoodsArea.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div style="padding: 20px">
  3. <el-form ref="dataForm" :model="dataForm" :rules="dataFormRules" label-position="left" label-width="120px">
  4. <el-form-item v-if="!(inputParam.openType === 'add')" label="单据编号" prop="sheetId">
  5. <el-input autocomplete="off" placeholder="单据编号" :disabled="true" :value="dataForm.sheetId" />
  6. </el-form-item>
  7. <el-form-item label="供应商" prop="venderId">
  8. <el-select
  9. v-model="dataForm.venderId"
  10. :disabled="inputParam.openType === 'view'"
  11. placeholder="请选择供应商"
  12. style="width: 100%"
  13. filterable
  14. >
  15. <el-option
  16. v-for="(item, index) in venderList"
  17. :key="index"
  18. :label="item.venderName"
  19. :value="item.venderId"
  20. :disabled="item.status !== 'ON'"
  21. />
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="备注" prop="notes">
  25. <el-input
  26. v-model="dataForm.notes"
  27. autocomplete="off"
  28. placeholder="备注"
  29. :disabled="inputParam.openType === 'view'"
  30. />
  31. </el-form-item>
  32. <el-row>
  33. <el-col>
  34. <el-button size="small" :disabled="inputParam.openType === 'view'" @click="innerVisible = true"
  35. >添加商品</el-button
  36. >
  37. </el-col>
  38. <el-col>
  39. <el-table
  40. ref="goodsTable"
  41. :data="dataForm.items"
  42. height="300"
  43. size="mini"
  44. border
  45. header-cell-class-name="headerRowColor"
  46. style="width: 100%; margin: 15px 0"
  47. >
  48. <el-table-column prop="goodsId" label="辅材编号" width="80" />
  49. <el-table-column prop="goodsName" label="辅材名称" width="180" />
  50. <el-table-column prop="goodsSpecification" label="规格" />
  51. <el-table-column prop="cost" label="进价">
  52. <template slot-scope="scope">
  53. <el-input v-model="scope.row.cost" :disabled="inputParam.openType === 'view'" />
  54. </template>
  55. </el-table-column>
  56. <el-table-column prop="status" label="状态">
  57. <template slot-scope="scope">
  58. <el-select
  59. v-model="scope.row.status"
  60. placeholder="请选择状态"
  61. style="width: 100%"
  62. :disabled="inputParam.openType === 'view'"
  63. >
  64. <el-option
  65. v-for="(item, index) in select_item_flag"
  66. :key="index"
  67. :label="item.label"
  68. :value="item.value"
  69. />
  70. </el-select>
  71. </template>
  72. </el-table-column>
  73. <el-table-column v-if="!(inputParam.openType === 'view')" align="center" label="" min-width="50">
  74. <template slot-scope="scope">
  75. <el-button type="text" @click="delItem(scope.$index)">删除</el-button>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <el-row>
  80. <el-col :span="24"
  81. ><div>共 {{ goodsTotalCount }} 条记录</div></el-col
  82. >
  83. </el-row>
  84. </el-col>
  85. </el-row>
  86. </el-form>
  87. <el-dialog
  88. width="60%"
  89. title="商品列表"
  90. :visible.sync="innerVisible"
  91. append-to-body
  92. :close-on-click-modal="false"
  93. @close="
  94. $refs.goodsTable.clearSelection()
  95. searchGoods = ''
  96. "
  97. >
  98. <el-input
  99. v-model="searchGoods"
  100. size="mini"
  101. placeholder="输入关键字搜索"
  102. style="margin-bottom: 5px"
  103. :clearable="true"
  104. />
  105. <el-table
  106. ref="goodsTable"
  107. :data="
  108. goodsList.filter(
  109. data =>
  110. !searchGoods ||
  111. data.goodsName.toLowerCase().includes(searchGoods.toLowerCase()) ||
  112. data.categoryName.toLowerCase().includes(searchGoods.toLowerCase())
  113. )
  114. "
  115. :row-key="getRowKeys"
  116. height="400"
  117. size="mini"
  118. border
  119. header-cell-class-name="headerRowColor"
  120. style="width: 100%"
  121. >
  122. <el-table-column type="selection" width="55" :reserve-selection="true" />
  123. <el-table-column prop="goodsId" label="辅材编号" width="80" />
  124. <el-table-column prop="goodsName" label="辅材名称" width="280" />
  125. <el-table-column prop="goodsCode" label="辅材代码" />
  126. <el-table-column prop="categoryName" label="小类名称" />
  127. <el-table-column prop="goodsSpecification" label="规格" />
  128. </el-table>
  129. <div slot="footer" class="dialog-footer">
  130. <el-button type="primary" @click="selGoods">确 定</el-button>
  131. </div>
  132. </el-dialog>
  133. <div style="text-align: right">
  134. <el-button @click="cancelForm">取 消</el-button>
  135. <el-button v-if="!(inputParam.openType === 'view')" type="primary" @click="submitForm">保 存</el-button>
  136. </div>
  137. </div>
  138. </template>
  139. <script>
  140. import { addVenderGoodsSheet, editVenderGoodsSheet, getVenderGoodsSheet } from '@/api/material-system/vender'
  141. import { listPageV2 } from '@/api/auxiliaryFittings/supplier'
  142. import { materialNormList } from '@/api/auxiliaryPriceManagement'
  143. export default {
  144. name: 'VenderGoodsArea',
  145. props: {
  146. inputParam: {
  147. type: Object,
  148. default: function () {
  149. return {
  150. openType: 'add',
  151. sheetId: ''
  152. }
  153. }
  154. }
  155. },
  156. data() {
  157. return {
  158. loading: true,
  159. dataForm: {
  160. sheetId: '', // 单据ID
  161. venderId: '', // 供应商ID
  162. venderName: '',
  163. notes: '', // 备注
  164. items: [] // 关系辅材列表
  165. },
  166. goodsList: [], // 商品列表
  167. venderList: [], // 供应商列表
  168. select_item_flag: [
  169. { label: '有效', value: 'ON' },
  170. { label: '无效', value: 'OFF' }
  171. ],
  172. dataFormRules: {
  173. venderId: [{ required: true, message: '请选择供应商', trigger: 'change' }]
  174. },
  175. innerVisible: false,
  176. searchGoods: ''
  177. }
  178. },
  179. computed: {
  180. goodsTotalCount: function () {
  181. return this.dataForm && this.dataForm.items ? this.dataForm.items.length : 0
  182. }
  183. },
  184. mounted() {
  185. this.getDetail()
  186. this.getVenderList()
  187. if (this.inputParam.openType === 'add') {
  188. this.getMaterialList()
  189. }
  190. },
  191. methods: {
  192. getDetail(id) {
  193. this.loading = true
  194. const openType = this.inputParam.openType
  195. if (openType !== 'add') {
  196. getVenderGoodsSheet({ id: id || this.inputParam.sheetId }).then(res => {
  197. this.setDataForm(res.data)
  198. this.loading = false
  199. })
  200. } else {
  201. this.loading = false
  202. }
  203. },
  204. setDataForm(data) {
  205. this.dataForm = {
  206. sheetId: data.sheetId, // 单据编号
  207. venderId: data.venderId, // 供应商Id
  208. notes: data.notes, // 备注
  209. items: data.items // 关系商品列表
  210. }
  211. },
  212. cancelForm() {
  213. this.$emit('getList')
  214. this.$emit('update:isOpen', false)
  215. },
  216. // 获取辅材列表
  217. getMaterialList() {
  218. materialNormList({
  219. pageNum: 1,
  220. pageSize: -1,
  221. params: [{ param: 'a.status', compare: '=', value: 'ON' }]
  222. }).then(res => {
  223. this.goodsList = res.data.records
  224. console.log(res.data.records)
  225. })
  226. },
  227. // 获取供应商列表
  228. getVenderList() {
  229. listPageV2({
  230. pageNum: 1,
  231. pageSize: -1,
  232. params: [
  233. { param: 'a.status', compare: '=', value: 'ON' },
  234. { param: 'a.vender_type', compare: 'like', value: '辅材' }
  235. ]
  236. }).then(res => {
  237. this.venderList = res.data.records
  238. })
  239. },
  240. // 提交 新增编辑 供应商关系商品维护单
  241. submitForm() {
  242. this.$refs.dataForm.validate(valid => {
  243. if (valid) {
  244. this.dataForm.venderName = this.venderList?.find(item => item.venderId === this.dataForm.venderId)?.venderName
  245. if (this.inputParam.openType === 'edit') {
  246. editVenderGoodsSheet(this.dataForm).then(() => {
  247. this.cancelForm()
  248. this.$successMsg('编辑成功')
  249. })
  250. } else {
  251. addVenderGoodsSheet(this.dataForm).then(() => {
  252. this.cancelForm()
  253. this.$successMsg('新增成功')
  254. })
  255. }
  256. }
  257. })
  258. },
  259. // 选中辅材添加到表单中
  260. selGoods() {
  261. this.$refs.goodsTable.selection.forEach(value => {
  262. const index = this.dataForm.items.findIndex(item => {
  263. return item.goodsId === value.goodsId
  264. })
  265. // 添加不在列表的商品
  266. if (index < 0) {
  267. this.dataForm.items.push({
  268. goodsId: value.goodsId,
  269. goodsName: value.goodsName,
  270. goodsSpecification: value.goodsSpecification,
  271. cost: 0,
  272. status: 'ON'
  273. })
  274. }
  275. })
  276. this.$refs.goodsTable.clearSelection()
  277. this.innerVisible = false
  278. },
  279. // 删除明细
  280. delItem(index) {
  281. this.dataForm.items.splice(index, 1)
  282. },
  283. getRowKeys(row) {
  284. return row.id
  285. }
  286. }
  287. }
  288. </script>
  289. <style scoped></style>