chooseProductModal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <a-drawer
  3. :zIndex="zIndex"
  4. :title="title"
  5. placement="right"
  6. :visible="visible"
  7. :width="width"
  8. :get-container="false"
  9. :wrap-style="{ position: 'absolute' }"
  10. @close="onClose"
  11. wrapClassName="chooseProduct-drawer jg-drawer-wrap">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <div class="chooseProduct-drawer-box">
  14. <!-- 搜索条件 -->
  15. <div ref="searchBox" class="table-page-search-wrapper">
  16. <a-form layout="inline" @keyup.enter.native="searchForm">
  17. <a-row :gutter="12">
  18. <a-col :md="6" :sm="24">
  19. <a-form-model-item label="产品编码">
  20. <a-input id="purchaseOrderEdit-code" ref="searchProductCode" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  21. </a-form-model-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24">
  24. <a-form-model-item label="产品名称">
  25. <a-input id="purchaseOrderEdit-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  26. </a-form-model-item>
  27. </a-col>
  28. <!-- <a-col :flex="2">
  29. <a-form-model-item label="原厂编码">
  30. <a-input id="purchaseOrderEdit-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  31. </a-form-model-item>
  32. </a-col> -->
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="产品分类">
  35. <ProductType id="purchaseOrderEdit-productType" :isDealer="true" :tenantId="$route.params.dealerSn" @change="changeProductType" v-model="productType"></ProductType>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24">
  39. <a-form-item label="产品品牌">
  40. <ProductBrand id="purchaseOrderEdit-productBrand" :tenantId="$route.params.dealerSn" v-model="queryParam.productBrandSn"></ProductBrand>
  41. </a-form-item>
  42. </a-col>
  43. <a-col :md="6" :sm="24">
  44. <a-form-item label="可用库存小于等于">
  45. <a-input-number
  46. style="width:100%;"
  47. id="purchaseOrderEdit-stockQty"
  48. v-model.trim="queryParam.stockQty"
  49. :min="0"
  50. :step="1"
  51. :precision="0"
  52. :max="99999999"
  53. placeholder="请输入库存数量"/>
  54. </a-form-item>
  55. </a-col>
  56. <a-col :md="6" :sm="24">
  57. <a-button type="primary" @click="searchForm" id="purchaseOrderEdit-refresh">查询</a-button>
  58. <a-button style="margin-left: 5px" @click="resetSearchForm" id="purchaseOrderEdit-reset">重置</a-button>
  59. </a-col>
  60. </a-row>
  61. </a-form>
  62. </div>
  63. <!-- 列表 -->
  64. <s-table
  65. v-if="hasVaild&&showTable"
  66. class="sTable"
  67. ref="table"
  68. size="small"
  69. :rowKey="(record) => record.id"
  70. :columns="columns"
  71. :data="loadData"
  72. :scroll="{ x: tableWidth , y:tableHeight }"
  73. @dblclick="handleAdd"
  74. :pageSize="30"
  75. bordered>
  76. <!-- 产品图片 -->
  77. <template slot="imageUrl" slot-scope="text, record">
  78. <img
  79. :src="record.productMainPic && record.productMainPic.imageUrl?(record.productMainPic.imageUrl+'?x-oss-process=image/resize,h_30,m_lfit'):defImg"
  80. width="30"
  81. height="30"
  82. :id="'purchaseOrderEdit-imgview-'+record.id"
  83. style="cursor: pointer;"
  84. @click="handlePicDetail(record)" />
  85. </template>
  86. <!-- 包装数 -->
  87. <template slot="baozh" slot-scope="text, record">
  88. {{ record.packQty||'--' }}{{ record.packQty ? record.unit : '' }}/{{ record.packQtyUnit||'--' }}
  89. </template>
  90. <!-- 产品编码 -->
  91. <template slot="code" slot-scope="text, record">
  92. <a-tooltip placement="top" v-if="record.stockState=='NOT_ENOUGH'">
  93. <template slot="title">
  94. 该产品暂时缺货!
  95. </template>
  96. <span class="noStock">{{ record.code || '--' }}</span>
  97. </a-tooltip>
  98. <span v-else>{{ record.code || '--' }}</span>
  99. </template>
  100. <!-- 采购数量 -->
  101. <template slot="storageQuantity" slot-scope="text, record">
  102. <div @dblclick.stop>
  103. <a-input-number
  104. size="small"
  105. :id="'purchaseOrderEdit-cQty-'+record.id"
  106. v-model="record.qty"
  107. :precision="0"
  108. :min="0"
  109. :max="999999"
  110. style="width: 100%;"
  111. placeholder="请输入数量" />
  112. </div>
  113. </template>
  114. <!-- 操作 -->
  115. <template slot="action" slot-scope="text, record">
  116. <a-button
  117. size="small"
  118. type="link"
  119. :id="'purchaseOrderEdit-cadd-'+record.id"
  120. class="button-primary"
  121. :loading="addLoading"
  122. @click="handleAdd(record)"
  123. >添加</a-button>
  124. </template>
  125. </s-table>
  126. <div v-else>
  127. <a-empty :image="simpleImage" :image-style="{height: '60px'}">
  128. <span style="color:red" slot="description">请输入查询条件</span>
  129. </a-empty>
  130. </div>
  131. </div>
  132. </a-spin>
  133. </a-drawer>
  134. </template>
  135. <script>
  136. import { Empty } from 'ant-design-vue'
  137. import { commonMixin } from '@/utils/mixin'
  138. import { STable, VSelect } from '@/components'
  139. import ProductType from '../../common/productType.js'
  140. import ProductBrand from '../../common/productBrand.js'
  141. import defImg from '@/assets/def_img@2x.png'
  142. import { productListPurchase } from '@/api/product'
  143. export default {
  144. mixins: [commonMixin],
  145. components: {
  146. STable, VSelect, ProductType, ProductBrand
  147. },
  148. props: {
  149. showModal: { // 显示隐藏弹框
  150. type: Boolean,
  151. default: false
  152. },
  153. width: { // 弹框宽度
  154. type: [String, Number],
  155. default: '80%'
  156. },
  157. zIndex: { // 弹框层级
  158. type: Number,
  159. default: 100
  160. },
  161. isDealerUp: { // 是否上级经销商
  162. type: Boolean,
  163. default: false
  164. },
  165. purchaseBillSn: { // 采购单sn
  166. type: String,
  167. default: ''
  168. }
  169. },
  170. watch: {
  171. showModal (newValue, oldValue) {
  172. this.visible = newValue
  173. if (newValue) {
  174. // 初始化页面
  175. this.resetSearchForm()
  176. this.$refs.searchProductCode.focus()
  177. this.setTableH()
  178. }
  179. },
  180. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  181. this.setTableH()
  182. }
  183. },
  184. data () {
  185. return {
  186. visible: this.showModal, // 显示弹框
  187. title: '添加产品', // 标题
  188. tableHeight: 0, // 表格高度
  189. simpleImage: Empty.PRESENTED_IMAGE_SIMPLE, // 默认图片
  190. // 选择产品
  191. addLoading: false, // 添加按钮loading
  192. spinning: false,
  193. productType: [], // 产品分类默认值
  194. queryParam: {
  195. productBrandSn: undefined, // 产品品牌
  196. code: '', // 产品编码
  197. name: '', // 产品名称
  198. origCode: '', // 原厂编码
  199. productTypeSn1: '', // 产品一级分类
  200. productTypeSn2: '', // 产品二级分类
  201. productTypeSn3: '', // 产品三级分类
  202. stockQty: undefined
  203. },
  204. advanced: false, // 高级搜索 展开/关闭
  205. disabled: false, // 查询、重置按钮是否可操作
  206. showTable: false, // 是否显示表格
  207. // 加载数据方法 必须为 Promise 对象
  208. loadData: parameter => {
  209. this.disabled = true
  210. return productListPurchase(Object.assign(parameter, this.queryParam, { purchaseBillSn: this.purchaseBillSn })).then(res => {
  211. const data = res.data
  212. const no = (data.pageNo - 1) * data.pageSize
  213. for (var i = 0; i < data.list.length; i++) {
  214. data.list[i].no = no + i + 1
  215. data.list[i].qty = 1
  216. data.list[i].qtyBackups = data.list[i].qty
  217. }
  218. this.disabled = false
  219. this.setTableH()
  220. return data
  221. })
  222. },
  223. defImg // 默认图片
  224. }
  225. },
  226. computed: {
  227. // 是否有筛选条件,至少一个
  228. hasVaild () {
  229. return this.queryParam.code || this.queryParam.name || this.queryParam.productBrandSn || this.queryParam.productTypeSn1 || this.queryParam.stockQty || this.queryParam.stockQty == 0
  230. },
  231. // 动态计算表格宽度
  232. tableWidth () {
  233. let w = 1380
  234. if (!this.isDealerUp) {
  235. w -= 80
  236. }
  237. if (!this.$hasPermissions('M_ShowAllCost')) {
  238. w -= 80
  239. }
  240. return w
  241. },
  242. // 列定义
  243. columns () {
  244. const _this = this
  245. const arr = [
  246. { title: '序号', dataIndex: 'no', width: '50px', align: 'center' },
  247. { title: '产品名称', dataIndex: 'name', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  248. { title: '原厂编码', dataIndex: 'origCode', width: '150px', align: 'center', customRender: function (text) { return text && text != ' ' ? text : '--' } },
  249. { title: '在途数', dataIndex: 'transitQty', width: '60px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  250. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '60px', align: 'center' },
  251. { title: '单位', dataIndex: 'unit', width: '60px', align: 'center', customRender: function (text) { return text || '--' } },
  252. { title: '包装数', scopedSlots: { customRender: 'baozh' }, width: '60px', align: 'center' },
  253. { title: '终端会员价', dataIndex: 'terminalPrice', width: '80px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  254. { title: '车主零售价', dataIndex: 'carOwnersPrice', width: '80px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  255. { title: '可用库存', dataIndex: 'currentStockQty', width: '70px', align: 'center', fixed: 'right', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  256. { title: '采购数量', dataIndex: 'qty', scopedSlots: { customRender: 'storageQuantity' }, width: '80px', align: 'center', fixed: 'right' },
  257. { title: '操作', scopedSlots: { customRender: 'action' }, width: '80px', align: 'center', fixed: 'right' }
  258. ]
  259. // 产品来源,如果时上级
  260. if (this.isDealerUp) {
  261. arr.splice(1, 0, { title: '产品编码', scopedSlots: { customRender: 'code' }, width: '120px', align: 'center' })
  262. arr.splice(2, 0, { title: '产品来源', dataIndex: 'sysFlagDictValue', width: '80px', align: 'center', customRender: function (text) { return text || '--' } })
  263. } else {
  264. arr.splice(1, 0, { title: '产品编码', dataIndex: 'code', width: '120px', align: 'center', customRender: function (text) { return text || '--' }, sorter: true })
  265. }
  266. // 成本价权限
  267. if (this.$hasPermissions('M_ShowAllCost')) {
  268. arr.splice(this.isDealerUp ? 12 : 11, 0, { title: '成本价', dataIndex: 'purchasePrice', width: '80px', align: 'right', fixed: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  269. }
  270. return arr
  271. }
  272. },
  273. methods: {
  274. // 查看产品
  275. handlePicDetail (row) {
  276. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  277. },
  278. // 产品分类 change
  279. changeProductType (val, opt) {
  280. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  281. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  282. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  283. },
  284. // 查询列表
  285. searchForm () {
  286. if (this.hasVaild) {
  287. this.showTable = true
  288. if (this.$refs.table) {
  289. this.$refs.table.refresh(true)
  290. }
  291. } else {
  292. this.$message.info('请输入查询条件')
  293. }
  294. },
  295. // 重置产品库
  296. resetSearchForm () {
  297. this.queryParam = {
  298. productBrandSn: undefined,
  299. code: '', // 产品编码
  300. name: '', // 产品名称
  301. origCode: '', // 原厂编码
  302. productTypeSn1: '', // 产品一级分类
  303. productTypeSn2: '', // 产品二级分类
  304. productTypeSn3: '', // 产品三级分类
  305. stockQty: undefined
  306. }
  307. this.productType = []
  308. this.showTable = false
  309. },
  310. // 关闭弹框
  311. onClose () {
  312. this.$emit('close')
  313. },
  314. // 添加产品
  315. handleAdd (record) {
  316. this.spinning = true
  317. this.$emit('add', record, 0)
  318. },
  319. // 计算表格高度
  320. setTableH () {
  321. this.$nextTick(() => {
  322. const searchBoxH = this.$refs.searchBox.offsetHeight
  323. this.tableHeight = window.innerHeight - searchBoxH - 225
  324. })
  325. }
  326. }
  327. }
  328. </script>
  329. <style lang="less" scoped>
  330. .chooseProduct-drawer {
  331. .ant-drawer-header{
  332. padding: 13px 20px;
  333. }
  334. .ant-drawer-body {
  335. padding: 15px 20px;
  336. height: calc(100% - 50px);
  337. display: flex;
  338. flex-direction: column;
  339. overflow: auto;
  340. > div {
  341. height: 100%;
  342. }
  343. .noStock{
  344. text-decoration: line-through;
  345. color: red;
  346. }
  347. .ant-input-number-sm input{
  348. text-align: center;
  349. }
  350. }
  351. }
  352. .chooseProduct-drawer-box{
  353. /deep/.ant-input-number{
  354. border: 0;
  355. -webkit-box-shadow: none !important;
  356. box-shadow: none !important;
  357. }
  358. }
  359. </style>