chooseProductModal.vue 13 KB

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