chooseProductModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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">
  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="$refs.table.refresh(true)">
  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" :disabled="disabled" id="purchaseOrderEdit-refresh">查询</a-button>
  45. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="purchaseOrderEdit-reset">重置</a-button>
  46. </a-col>
  47. </a-row>
  48. </a-form>
  49. </div>
  50. <!-- 列表 -->
  51. <s-table
  52. v-if="hasVaild"
  53. class="sTable"
  54. ref="table"
  55. size="small"
  56. :rowKey="(record) => record.id"
  57. :columns="columns"
  58. :data="loadData"
  59. :defaultLoadData="false"
  60. :scroll="{ x: tableWidth , y:tableHeight }"
  61. @dblclick="handleAdd"
  62. :pageSize="30"
  63. bordered>
  64. <!-- 产品图片 -->
  65. <template slot="imageUrl" slot-scope="text, record">
  66. <img
  67. :src="record.productMainPic && record.productMainPic.imageUrl?(record.productMainPic.imageUrl+'?x-oss-process=image/resize,h_30,m_lfit'):defImg"
  68. width="30"
  69. height="30"
  70. style="cursor: pointer;"
  71. @click="handlePicDetail(record)" />
  72. </template>
  73. <!-- 包装数 -->
  74. <template slot="baozh" slot-scope="text, record">
  75. <span v-if="record.packQty&&record.packQtyUnit">
  76. {{ record.packQty||'--' }}{{ record.unit }}/{{ record.packQtyUnit||'--' }}
  77. </span>
  78. <span v-else>--</span>
  79. </template>
  80. <!-- 产品编码 -->
  81. <template slot="code" slot-scope="text, record">
  82. <a-tooltip placement="top" v-if="record.stockState=='NOT_ENOUGH'">
  83. <template slot="title">
  84. 该产品暂时缺货!
  85. </template>
  86. <span class="noStock">{{ record.code || '--' }}</span>
  87. </a-tooltip>
  88. <span v-else>{{ record.code || '--' }}</span>
  89. </template>
  90. <!-- 采购数量 -->
  91. <template slot="storageQuantity" slot-scope="text, record">
  92. <div @dblclick.stop>
  93. <a-input-number
  94. size="small"
  95. v-model="record.qty"
  96. :precision="0"
  97. :min="0"
  98. :max="999999"
  99. style="width: 100%;"
  100. placeholder="请输入数量" />
  101. </div>
  102. </template>
  103. <!-- 操作 -->
  104. <template slot="action" slot-scope="text, record">
  105. <a-button
  106. size="small"
  107. type="link"
  108. class="button-primary"
  109. :loading="addLoading"
  110. @click="handleAdd(record)"
  111. v-if="record.purchasePrice>0"
  112. id="purchaseOrderEdit-add-btn">添加</a-button>
  113. <span v-else>--</span>
  114. </template>
  115. </s-table>
  116. <div v-else>
  117. <a-empty
  118. :image="simpleImage"
  119. :image-style="{
  120. height: '60px',
  121. }"
  122. >
  123. <span style="color:red" slot="description">请输入查询条件</span>
  124. </a-empty>
  125. </div>
  126. </div>
  127. </a-spin>
  128. </a-drawer>
  129. </template>
  130. <script>
  131. import { Empty } from 'ant-design-vue'
  132. import { commonMixin } from '@/utils/mixin'
  133. import { STable, VSelect } from '@/components'
  134. import ProductType from '../../common/productType.js'
  135. import ProductBrand from '../../common/productBrand.js'
  136. import defImg from '@/assets/def_img@2x.png'
  137. import { productListPurchase } from '@/api/product'
  138. export default {
  139. mixins: [commonMixin],
  140. components: {
  141. STable, VSelect, ProductType, ProductBrand
  142. },
  143. props: {
  144. showModal: {
  145. type: Boolean,
  146. default: false
  147. },
  148. width: {
  149. type: [String, Number],
  150. default: '70%'
  151. },
  152. zIndex: {
  153. type: Number,
  154. default: 1050
  155. },
  156. isDealerUp: {
  157. type: Boolean
  158. },
  159. purchaseBillSn: {
  160. type: String
  161. }
  162. },
  163. watch: {
  164. showModal (newValue, oldValue) {
  165. this.visible = newValue
  166. if (newValue) {
  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,
  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. // 加载数据方法 必须为 Promise 对象
  198. loadData: parameter => {
  199. this.disabled = true
  200. return productListPurchase(Object.assign(parameter, this.queryParam, { purchaseBillSn: this.purchaseBillSn })).then(res => {
  201. const data = res.data
  202. const no = (data.pageNo - 1) * data.pageSize
  203. for (var i = 0; i < data.list.length; i++) {
  204. data.list[i].no = no + i + 1
  205. data.list[i].qty = 1
  206. }
  207. this.disabled = false
  208. return data
  209. })
  210. },
  211. defImg
  212. }
  213. },
  214. computed: {
  215. hasVaild () {
  216. return this.queryParam.code || this.queryParam.name || this.queryParam.productBrandSn || this.queryParam.productTypeSn1
  217. },
  218. tableWidth () {
  219. let w = 1100
  220. if (this.isDealerUp) {
  221. w = 1200
  222. }
  223. if (this.$hasPermissions('M_ShowAllCost')) {
  224. w = this.isDealerUp ? 1200 : 1100
  225. }
  226. return w
  227. },
  228. columns () {
  229. const _this = this
  230. const arr = [
  231. { title: '产品编码', scopedSlots: { customRender: 'code' }, width: '150px', align: 'center', fixed: 'left' },
  232. { title: '产品名称', dataIndex: 'name', width: '250px', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  233. // { title: '原厂编码', dataIndex: 'origCode', width: '14%', align: 'center', customRender: function (text) { return text && text != ' ' ? text : '--' } },
  234. { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '80px', align: 'center' },
  235. { title: '单位', dataIndex: 'unit', width: '60px', align: 'center', customRender: function (text) { return text || '--' } },
  236. { title: '包装数', scopedSlots: { customRender: 'baozh' }, width: '60px', align: 'center' },
  237. { title: '终端会员价', dataIndex: 'terminalPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  238. { title: '车主零售价', dataIndex: 'carOwnersPrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } },
  239. { title: '采购数量', dataIndex: 'qty', scopedSlots: { customRender: 'storageQuantity' }, width: '100px', align: 'center', fixed: 'right' },
  240. { title: '操作', scopedSlots: { customRender: 'action' }, width: '100px', align: 'center', fixed: 'right' }
  241. ]
  242. // 产品来源
  243. if (this.isDealerUp) {
  244. arr.splice(2, 0, { title: '产品来源', dataIndex: 'sysFlagDictValue', width: '100px', align: 'center', customRender: function (text) { return text || '--' } })
  245. }
  246. if (this.$hasPermissions('M_ShowAllCost')) {
  247. arr.splice(this.isDealerUp ? 3 : 2, 0, { title: '成本价', dataIndex: 'purchasePrice', width: '100px', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text, 2) : '--') } })
  248. }
  249. return arr
  250. }
  251. },
  252. methods: {
  253. // 查看产品
  254. handlePicDetail (row) {
  255. this.$router.push({ name: 'viewProduct', params: { sn: row.productSn } })
  256. },
  257. // 产品分类 change
  258. changeProductType (val, opt) {
  259. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  260. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  261. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  262. },
  263. // 查询
  264. searchForm () {
  265. if (this.hasVaild) {
  266. this.$refs.table.refresh(true)
  267. } else {
  268. this.$message.info('请输入查询条件')
  269. }
  270. },
  271. // 重置产品库
  272. resetSearchForm () {
  273. this.queryParam = {
  274. productBrandSn: undefined,
  275. code: '', // 产品编码
  276. name: '', // 产品名称
  277. origCode: '', // 原厂编码
  278. productTypeSn1: '', // 产品一级分类
  279. productTypeSn2: '', // 产品二级分类
  280. productTypeSn3: '' // 产品三级分类
  281. }
  282. this.productType = []
  283. if (this.hasVaild) {
  284. this.$refs.table.refresh(true)
  285. }
  286. },
  287. onClose () {
  288. this.$emit('close')
  289. },
  290. handleAdd (record) {
  291. this.spinning = true
  292. this.$emit('add', record, 0)
  293. },
  294. setTableH () {
  295. this.$nextTick(() => {
  296. const searchBoxH = this.$refs.searchBox.offsetHeight
  297. this.tableHeight = window.innerHeight - searchBoxH - 285
  298. })
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="less">
  304. .chooseProduct-drawer {
  305. .ant-drawer-header{
  306. padding: 13px 20px;
  307. }
  308. .ant-drawer-body {
  309. padding: 15px 20px;
  310. height: calc(100% - 50px);
  311. display: flex;
  312. flex-direction: column;
  313. overflow: auto;
  314. > div {
  315. height: 100%;
  316. }
  317. .noStock{
  318. text-decoration: line-through;
  319. color: red;
  320. }
  321. .ant-input-number-sm input{
  322. text-align: center;
  323. }
  324. }
  325. }
  326. </style>