chooseProductModal.vue 12 KB

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