add.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="associatedProduct-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" class="associatedProduct-head" @back="handleBack" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="salesEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <span style="margin: 0 15px;color: #666;">供应商名称:{{ decodeURI($route.params.name) }}</span>
  8. </template>
  9. <!-- 操作区,位于 title 行的行尾 -->
  10. <template slot="extra">
  11. <a-button key="2" type="primary" @click="choosePModal" class="button-error" id="associatedProduct-addProduct-btn">增加产品</a-button>
  12. <a-button key="1" type="primary" class="button-success" id="associatedProduct-import-btn">批量导入</a-button>
  13. </template>
  14. </a-page-header>
  15. <!-- 列表 -->
  16. <a-card size="small" :bordered="false">
  17. <!-- 搜索条件 -->
  18. <div class="table-page-search-wrapper">
  19. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  20. <a-row :gutter="15">
  21. <a-col :md="6" :sm="24">
  22. <a-form-item label="产品名称">
  23. <a-input id="associatedProduct-name" v-model.trim="queryParam.product.name" allowClear placeholder="请输入产品名称"/>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-item label="产品编码/原厂编码">
  28. <a-input id="associatedProduct-queryWord" v-model.trim="queryParam.product.queryWord" allowClear placeholder="请输入产品编码/原厂编码"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-item label="品牌">
  33. <ProductBrand id="associatedProduct-productBrandSn" v-model="queryParam.product.productBrandSn"></ProductBrand>
  34. </a-form-item>
  35. </a-col>
  36. <template v-if="advanced">
  37. <a-col :md="6" :sm="24">
  38. <a-form-item label="产品分类">
  39. <ProductType id="associatedProduct-productType" v-model="productType" @change="changeProductType"></ProductType>
  40. </a-form-item>
  41. </a-col>
  42. </template>
  43. <a-col :md="6" :sm="24">
  44. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="associatedProduct-refresh">查询</a-button>
  45. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="associatedProduct-reset">重置</a-button>
  46. <a @click="advanced=!advanced" style="margin-left: 8px">
  47. {{ advanced ? '收起' : '展开' }}
  48. <a-icon :type="advanced ? 'up' : 'down'"/>
  49. </a>
  50. </a-col>
  51. </a-row>
  52. </a-form>
  53. </div>
  54. <!-- 列表 -->
  55. <s-table
  56. class="sTable"
  57. ref="table"
  58. size="default"
  59. :rowKey="(record) => record.id"
  60. :columns="columns"
  61. :data="loadData"
  62. :scroll="{ x: 1410, y: tableHeight }"
  63. bordered>
  64. <!-- 产品分类 -->
  65. <template slot="productType" slot-scope="text, record">
  66. <span v-if="record.product.productTypeName2 || record.product.productTypeName3">{{ record.product.productTypeName2 }} {{ record.product.productTypeName3 ? '>' : '' }} {{ record.product.productTypeName3 }}</span>
  67. <span v-else>--</span>
  68. </template>
  69. <!-- 操作 -->
  70. <template slot="action" slot-scope="text, record">
  71. <a-button
  72. size="small"
  73. type="link"
  74. class="button-info"
  75. @click="handleSetPrice(record)"
  76. id="associatedProduct-setCostPrice-btn">设置成本价</a-button>
  77. <a-button
  78. size="small"
  79. type="link"
  80. class="button-error"
  81. @click="handleDel(record)"
  82. id="associatedProduct-del-btn">删除</a-button>
  83. </template>
  84. </s-table>
  85. </a-card>
  86. <!-- 设置成本价 -->
  87. <SettingCost ref="settingCost" :openModal="openModal" @ok="$refs.table.refresh()" @close="openModal=false"></SettingCost>
  88. <!-- 选择产品 -->
  89. <chooseProductsModal type="supplier" :openModal="newProduct" :chooseData="chooseProducts" @close="newProduct=false" @ok="handleProductsOk" />
  90. </div>
  91. </template>
  92. <script>
  93. import { STable, VSelect } from '@/components'
  94. import { supplierProductList, deleteProduct, addProduct, supplierProductSnList } from '@/api/supplier'
  95. import ProductType from '@/views/common/productType.js'
  96. import ProductBrand from '@/views/common/productBrand.js'
  97. import SettingCost from './settingCost.vue'
  98. import ChooseProductsModal from '@/views/common/chooseProductsModal.vue'
  99. export default {
  100. components: { STable, VSelect, ProductBrand, ProductType, SettingCost, ChooseProductsModal },
  101. data () {
  102. return {
  103. disabled: false,
  104. advanced: false,
  105. tableHeight: 0,
  106. openModal: false, // 设置价格 弹框
  107. newProduct: false, // 选择产品 弹框
  108. queryParam: { // 查询条件
  109. product: {
  110. name: '', // 产品名称
  111. queryWord: '', // 产品编码/原厂编码
  112. productBrandSn: undefined, // 产品品牌
  113. productTypeSn1: '', // 产品一级分类
  114. productTypeSn2: '', // 产品二级分类
  115. productTypeSn3: '' // 产品三级分类
  116. }
  117. },
  118. productType: [],
  119. columns: [
  120. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  121. { title: '产品品牌', dataIndex: 'product.productBrandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  122. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  123. { title: '产品名称', dataIndex: 'product.name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  124. { title: '产品编码', dataIndex: 'product.code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  125. { title: '原厂编码', dataIndex: 'product.origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '成本价', dataIndex: 'cost', width: 100, align: 'center', customRender: function (text) { return '¥' + (text || 0) } },
  127. { title: '操作', scopedSlots: { customRender: 'action' }, width: 170, align: 'center', fixed: 'right' }
  128. ],
  129. // 加载数据方法 必须为 Promise 对象
  130. loadData: parameter => {
  131. this.disabled = true
  132. if (this.tableHeight == 0) {
  133. this.tableHeight = window.innerHeight - 380
  134. }
  135. this.queryParam.supplierSn = this.$route.params.sn
  136. return supplierProductList(Object.assign(parameter, this.queryParam)).then(res => {
  137. const data = res.data
  138. const no = (data.pageNo - 1) * data.pageSize
  139. for (var i = 0; i < data.list.length; i++) {
  140. data.list[i].no = no + i + 1
  141. }
  142. this.disabled = false
  143. return data
  144. })
  145. },
  146. chooseProducts: [] // 所选产品
  147. }
  148. },
  149. methods: {
  150. // 返回
  151. handleBack () {
  152. this.$router.push({ name: 'supplierInfoList' })
  153. },
  154. // 产品分类 change
  155. changeProductType (val, opt) {
  156. this.queryParam.product.productTypeSn1 = val[0] ? val[0] : ''
  157. this.queryParam.product.productTypeSn2 = val[1] ? val[1] : ''
  158. this.queryParam.product.productTypeSn3 = val[2] ? val[2] : ''
  159. },
  160. // 重置
  161. resetSearchForm () {
  162. this.queryParam.product.name = ''
  163. this.queryParam.product.queryWord = ''
  164. this.queryParam.product.productBrandSn = undefined
  165. this.queryParam.product.productTypeSn1 = ''
  166. this.queryParam.product.productTypeSn2 = ''
  167. this.queryParam.product.productTypeSn3 = ''
  168. this.productType = []
  169. this.$refs.table.refresh(true)
  170. },
  171. // 删除
  172. handleDel (row) {
  173. const _this = this
  174. this.$confirm({
  175. title: '提示',
  176. content: '确认要删除吗?',
  177. centered: true,
  178. closable: true,
  179. onOk () {
  180. deleteProduct({ sn: row.supplierProductSn }).then(res => {
  181. if (res.status == 200) {
  182. _this.$message.success(res.message)
  183. _this.$refs.table.refresh()
  184. }
  185. })
  186. }
  187. })
  188. },
  189. // 设置成本价
  190. handleSetPrice (row) {
  191. this.openModal = true
  192. this.$refs.settingCost.setData(row)
  193. },
  194. // 增加产品
  195. choosePModal () {
  196. // 查询所有已选sn
  197. supplierProductSnList({ sn: this.$route.params.sn }).then(res => {
  198. if (res.status == 200) {
  199. this.chooseProducts = res.data // 包含先前所选产品
  200. this.newProduct = true
  201. }
  202. })
  203. },
  204. // 产品
  205. handleProductsOk (obj) {
  206. this.chooseProducts = obj
  207. if (obj.length > 0) {
  208. this.addProduct()
  209. }
  210. },
  211. // 添加产品 数据处理
  212. addProduct () {
  213. addProduct({
  214. supplierSn: this.$route.params.sn,
  215. productSnList: this.chooseProducts
  216. }).then(res => {
  217. if (res.status == 200) {
  218. this.$message.success(res.message)
  219. this.$refs.table.refresh()
  220. this.newProduct = false
  221. }
  222. })
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="less">
  228. .associatedProduct-wrap{
  229. .associatedProduct-head{
  230. margin-bottom: 10px;
  231. }
  232. }
  233. </style>