creatReplenishmentOrder.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <a-modal
  3. centered
  4. class="creatReplenish-confirm-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancel="isShow = false"
  10. width="70%">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <!-- 搜索条件 -->
  13. <div class="table-page-search-wrapper">
  14. <a-form-model
  15. ref="ruleForm"
  16. class="form-model-con"
  17. layout="inline"
  18. :model="queryParam"
  19. @keyup.enter.native="$refs.table.refresh(true)" >
  20. <a-row :gutter="5">
  21. <a-col :md="6" :sm="24">
  22. <a-form-model-item label="产品编码">
  23. <a-input id="crmo-code" ref="searchProductCode" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="产品名称">
  28. <a-input id="crmo-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="12" :sm="24">
  32. <a-form-model-item label="门店库存情况">
  33. <a-checkbox-group :options="options" v-model="queryParam.stockStateList" @change="onStockChange" />
  34. <a-button style="margin-left: 15px" type="primary" @click="$refs.table.refresh(true)" id="crmo-refresh">查询</a-button>
  35. <a-button style="margin-left: 5px" @click="resetSearchForm" id="crmo-reset">重置</a-button>
  36. </a-form-model-item>
  37. </a-col>
  38. </a-row>
  39. </a-form-model>
  40. </div>
  41. <div>
  42. <div class="table-operator">
  43. <div>
  44. <a-button id="crmo-creat-order" type="primary" @click="handleSave">创建补货单</a-button>
  45. <span style="margin-left:10px;" v-if="totalCategory||totalQty">
  46. 已选 {{ totalCategory }} 款产品,共 {{ totalQty }} 件
  47. </span>
  48. </div>
  49. <div style="margin-left:20px;" v-if="totalCategory||totalQty">
  50. <a-checkbox id="crmo-check-show" @change="changeShowChecked">
  51. 仅显示已选产品
  52. </a-checkbox>
  53. </div>
  54. </div>
  55. <!-- 列表 -->
  56. <s-table
  57. class="sTable"
  58. ref="table"
  59. size="small"
  60. :rowKey="(record) => record.id"
  61. :row-selection="{columnWidth: 40}"
  62. @rowSelection="rowSelectionFun"
  63. :columns="columns"
  64. :data="loadData"
  65. :style="{ height: '480px' }"
  66. :scroll="{ y: 450 }"
  67. :showPagination="false"
  68. bordered>
  69. <template slot="action" slot-scope="text, record">
  70. <a-input-number
  71. :id="'crmo-replenishQty-'+record.id"
  72. size="small"
  73. :readonly="hasChecked(record.id)"
  74. v-model="record.replenishQty"
  75. @change="changeNums(record)"
  76. :precision="0"
  77. :min="1"
  78. placeholder="请输入"
  79. style="width: 100%" />
  80. </template>
  81. </s-table>
  82. </div>
  83. </a-spin>
  84. </a-modal>
  85. </template>
  86. <script>
  87. import { commonMixin } from '@/utils/mixin'
  88. import { STable, VSelect } from '@/components'
  89. import { queryProductListForReplenish } from '@/api/shelf'
  90. import { saveMainAndDetail } from '@/api/shelfReplenish'
  91. export default {
  92. name: 'CreatReplenishmentOrder',
  93. components: { STable, VSelect },
  94. mixins: [commonMixin],
  95. props: {
  96. openModal: { // 弹框显示状态
  97. type: Boolean,
  98. default: false
  99. },
  100. nowData: { // 当前操作数据
  101. type: Object,
  102. default: () => {
  103. return {}
  104. }
  105. }
  106. },
  107. computed: {
  108. // 弹框标题
  109. modalTit () {
  110. const hjName = this.nowData ? this.nowData.shelfName : ''
  111. return '待补货产品 —— ' + hjName
  112. },
  113. // 列
  114. columns () {
  115. const arr = [
  116. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  117. { title: '货位号', dataIndex: 'shelfPlaceCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  118. { title: '产品编码', dataIndex: 'productCode', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  119. { title: '产品名称', dataIndex: 'productName', width: '18%', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  120. { title: '最大库容', dataIndex: 'maxQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  121. { title: '货架库存', dataIndex: 'qty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  122. { title: '补货在途', dataIndex: 'replenishBillQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  123. { title: '调回在途', dataIndex: 'recallBillQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  124. { title: '待补货数量', dataIndex: 'replenishBillWaitQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  125. { title: '门店库存数量', dataIndex: 'qplsStockQty', width: '8%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  126. { title: '单位', dataIndex: 'productUnit', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  127. { title: '本次补货数量', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  128. ]
  129. return arr
  130. },
  131. // 总款数
  132. totalCategory () {
  133. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.length
  134. },
  135. // 总补货数量
  136. totalQty () {
  137. let ret = 0
  138. this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.map(item => {
  139. ret = ret + item.replenishQty
  140. })
  141. return ret
  142. }
  143. },
  144. data () {
  145. return {
  146. spinning: false,
  147. isShow: this.openModal, // 是否打开弹框
  148. options: [ // 门店库存情况选项
  149. { label: '库存充足', value: 'stockEnough' },
  150. { label: '部分缺货', value: 'portionStockout' },
  151. { label: '全部缺货', value: 'allStockout' }
  152. ],
  153. queryParam: {
  154. productCode: '', // 产品编码
  155. productName: '', // 产品名称
  156. stockStateList: [] // 门店库存情况
  157. },
  158. allData: [], // 所有数据
  159. // 加载数据方法 必须为 Promise 对象
  160. loadData: parameter => {
  161. this.spinning = true
  162. this.disabled = true
  163. this.queryParam.shelfSn = this.nowData.shelfSn
  164. this.queryParam.enableFlag = 1
  165. return queryProductListForReplenish(this.queryParam).then(res => {
  166. let data
  167. if (res.status == 200) {
  168. data = res.data
  169. if (this.showChecked) {
  170. data = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  171. }
  172. for (var i = 0; i < data.length; i++) {
  173. data[i].no = i + 1
  174. const row = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  175. const cur = row.find(item => item.id == data[i].id)
  176. data[i].replenishQty = cur ? cur.replenishQty : (data[i].replenishBillWaitQty || 1)
  177. data[i].checked = !cur
  178. }
  179. this.disabled = false
  180. }
  181. this.spinning = false
  182. this.allData = data
  183. return data
  184. })
  185. },
  186. rowSelectionInfo: null,
  187. showChecked: false
  188. }
  189. },
  190. methods: {
  191. // 选择门店库存情况
  192. onStockChange (val) {
  193. this.queryParam.stockStateList = val
  194. },
  195. // 显示已选产品
  196. changeShowChecked (e) {
  197. this.showChecked = e.target.checked
  198. this.$refs.table.refresh(true)
  199. },
  200. // 表格选中项
  201. rowSelectionFun (obj) {
  202. this.rowSelectionInfo = obj || null
  203. },
  204. // 是否已选
  205. hasChecked: function (value) {
  206. const row = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  207. const cur = row.find(item => item.id == value)
  208. return !cur
  209. },
  210. // 补货数量修改
  211. changeNums (data) {
  212. const row = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  213. const cur = row.find(item => item.id == data.id)
  214. if (cur) {
  215. cur.replenishQty = data.replenishQty
  216. }
  217. row.splice()
  218. },
  219. // 重置
  220. resetSearchForm () {
  221. this.queryParam = {
  222. productCode: '', // 产品编码
  223. productName: '', // 产品名称
  224. stockStateList: []
  225. }
  226. this.$refs.table.refresh(true)
  227. },
  228. // 确认补货
  229. handleSave () {
  230. if (this.totalCategory) {
  231. const data = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows || []
  232. const dataList = []
  233. data.map(item => {
  234. dataList.push({
  235. shelfPlaceSn: item.shelfPlaceSn,
  236. shelfPlaceCode: item.shelfPlaceCode,
  237. productSn: item.productSn,
  238. productCode: item.productCode,
  239. qty: item.replenishQty
  240. })
  241. })
  242. // 开始提交
  243. this.spinning = true
  244. saveMainAndDetail({
  245. shelfSn: this.nowData.shelfSn,
  246. dealerSn: this.nowData.dealerSn,
  247. detailList: dataList
  248. }).then(res => {
  249. if (res.status == 200) {
  250. this.$message.success(res.message)
  251. this.$emit('ok')
  252. this.$emit('close')
  253. }
  254. this.spinning = false
  255. })
  256. } else {
  257. this.$message.info('请选择产品')
  258. }
  259. }
  260. },
  261. watch: {
  262. // 父页面传过来的弹框状态
  263. openModal (newValue, oldValue) {
  264. this.isShow = newValue
  265. },
  266. // 重定义的弹框状态
  267. isShow (newValue, oldValue) {
  268. if (!newValue) {
  269. this.$emit('close')
  270. } else {
  271. this.$nextTick(() => {
  272. // 重置
  273. this.resetSearchForm()
  274. this.$refs.table.clearSelected()
  275. this.showChecked = false
  276. })
  277. }
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="less">
  283. .creatReplenish-confirm-modal {
  284. .table-operator {
  285. padding:0 10px 10px 0;
  286. display:flex;
  287. align-items: center;
  288. }
  289. }
  290. </style>