list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <a-card size="small" :bordered="false" class="productInfoList-wrap">
  3. <!-- 搜索条件 -->
  4. <div class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="产品编码">
  9. <a-input id="productInfoList-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="产品名称">
  14. <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="原厂编码">
  19. <a-input id="productInfoList-origCode" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
  20. </a-form-item>
  21. </a-col>
  22. <template v-if="advanced">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品品牌">
  25. <a-select
  26. placeholder="请选择产品品牌"
  27. id="productInfoList-productBrandSn"
  28. allowClear
  29. v-model="queryParam.productBrandSn"
  30. :showSearch="true"
  31. option-filter-prop="children"
  32. :filter-option="filterOption">
  33. <a-select-option v-for="item in productBrandList" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  34. </a-select>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="6" :sm="24">
  38. <a-form-item label="产品分类">
  39. <a-cascader
  40. @change="changeProductType"
  41. change-on-select
  42. v-model="productType"
  43. :options="productTypeList"
  44. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  45. id="productInfoList-productType"
  46. placeholder="请选择产品分类"
  47. allowClear />
  48. </a-form-item>
  49. </a-col>
  50. <a-col :md="6" :sm="24">
  51. <a-form-item label="状态">
  52. <v-select code="ENABLE_FLAG" id="productInfoList-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  53. </a-form-item>
  54. </a-col>
  55. </template>
  56. <a-col :md="6" :sm="24">
  57. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
  58. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
  59. <!-- <a-button
  60. style="margin: 0 0 18px 8px"
  61. type="danger"
  62. @click="handleExport"
  63. :disabled="disabled"
  64. :loading="exportLoading"
  65. id="inventoryQueryList-export">导出</a-button> -->
  66. <a @click="advanced=!advanced" style="margin-left: 8px">
  67. {{ advanced ? '收起' : '展开' }}
  68. <a-icon :type="advanced ? 'up' : 'down'"/>
  69. </a>
  70. </a-col>
  71. </a-row>
  72. </a-form>
  73. </div>
  74. <!-- 操作按钮 -->
  75. <div class="table-operator">
  76. <a-button v-if="$hasPermissions('B_product_dealerProduct_add')" id="productInfoList-add" type="primary" @click="handleEdit()">新增产品</a-button>
  77. <!-- <a-button id="productInfoList-import" @click="handleImport" style="margin: 0 15px;">批量导入产品</a-button> -->
  78. </div>
  79. <!-- 列表 -->
  80. <s-table
  81. class="sTable"
  82. ref="table"
  83. size="default"
  84. :rowKey="(record) => record.id"
  85. :columns="columns"
  86. :data="loadData"
  87. :scroll="{ x: 1500 }"
  88. bordered>
  89. <!-- 产品分类 -->
  90. <template slot="productType" slot-scope="text, record">
  91. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  92. <span v-else>--</span>
  93. </template>
  94. <!-- 状态 -->
  95. <template slot="enabledFlag" slot-scope="text, record">
  96. <a-switch
  97. id="productInfoList-enable"
  98. checkedChildren="启用"
  99. unCheckedChildren="禁用"
  100. v-if="$hasPermissions('B_product_dealerProduct_enable')"
  101. @change="changeStatus(record)"
  102. :checked="record.enabledFlag == 1 ? true : false" />
  103. <span v-else> {{ record.enabledFlag==1? '已启用': '已禁用' }} </span>
  104. </template>
  105. <!-- 操作 -->
  106. <template slot="action" slot-scope="text, record">
  107. <a-button
  108. size="small"
  109. v-if="$hasPermissions('B_product_dealerProduct_edit')"
  110. type="primary"
  111. class="button-info"
  112. @click="handleEdit(record)"
  113. id="productInfoList-edit-btn">编辑</a-button>
  114. <a-button
  115. v-if="$hasPermissions('B_product_dealerProduct_detail')"
  116. size="small"
  117. type="primary"
  118. class="button-success"
  119. @click="handleDetail(record)"
  120. id="productInfoList-detail-btn">详情</a-button>
  121. </template>
  122. </s-table>
  123. <!-- 产品详情 -->
  124. <product-info-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  125. </a-card>
  126. </template>
  127. <script>
  128. import moment from 'moment'
  129. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  130. import { dealerProductTypeList } from '@/api/dealerProductType'
  131. import { dealerProductList, dealerProductUpdate, dealerProductExport } from '@/api/dealerProduct'
  132. import { STable, VSelect } from '@/components'
  133. import productInfoDetailModal from './detailModal.vue'
  134. export default {
  135. components: { STable, VSelect, productInfoDetailModal },
  136. data () {
  137. return {
  138. advanced: false, // 高级搜索 展开/关闭
  139. productType: [],
  140. queryParam: { // 查询条件
  141. code: '', // 产品编码
  142. name: '', // 产品名称
  143. origCode: '', // 原厂编码
  144. sysFlag: '0',
  145. productBrandSn: undefined, // 产品品牌
  146. productTypeSn1: '', // 产品一级分类
  147. productTypeSn2: '', // 产品二级分类
  148. productTypeSn3: '', // 产品三级分类
  149. enabledFlag: undefined // 状态
  150. },
  151. disabled: false, // 查询、重置按钮是否可操作
  152. exportLoading: false, // 导出loading
  153. columns: [
  154. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  155. { title: '产品编码', dataIndex: 'code', width: 140, align: 'center' },
  156. { title: '产品名称', dataIndex: 'name', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  157. { title: '原厂编码', dataIndex: 'origCode', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  158. { title: '产品品牌', dataIndex: 'productBrandName', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  159. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  160. { title: '终端价', dataIndex: 'terminalPrice', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  161. { title: '创建时间', dataIndex: 'createDate', width: 160, align: 'center' },
  162. { title: '状态', scopedSlots: { customRender: 'enabledFlag' }, width: 140, align: 'center' },
  163. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center', fixed: 'right' }
  164. ],
  165. // 加载数据方法 必须为 Promise 对象
  166. loadData: parameter => {
  167. this.disabled = true
  168. return dealerProductList(Object.assign(parameter, this.queryParam)).then(res => {
  169. const data = res.data
  170. const no = (data.pageNo - 1) * data.pageSize
  171. for (var i = 0; i < data.list.length; i++) {
  172. data.list[i].no = no + i + 1
  173. const productTypeName1 = data.list[i].productTypeName1 ? data.list[i].productTypeName1 : ''
  174. const productTypeName2 = data.list[i].productTypeName2 ? ' > ' + data.list[i].productTypeName2 : ''
  175. const productTypeName3 = data.list[i].productTypeName3 ? ' > ' + data.list[i].productTypeName3 : ''
  176. data.list[i].productTypeName = productTypeName1 + productTypeName2 + productTypeName3
  177. }
  178. this.disabled = false
  179. return data
  180. })
  181. },
  182. openModal: false, // 查看客户详情 弹框
  183. itemId: '', // 当前产品id
  184. productBrandList: [], // 品牌下拉数据
  185. productTypeList: [] // 分类下拉数据
  186. }
  187. },
  188. methods: {
  189. // 重置
  190. resetSearchForm () {
  191. this.queryParam.code = ''
  192. this.queryParam.name = ''
  193. this.queryParam.origCode = ''
  194. this.queryParam.productBrandSn = undefined
  195. this.queryParam.productTypeSn1 = ''
  196. this.queryParam.productTypeSn2 = ''
  197. this.queryParam.productTypeSn3 = ''
  198. this.queryParam.enabledFlag = undefined
  199. this.productType = []
  200. this.$refs.table.refresh(true)
  201. },
  202. // 新增/编辑
  203. handleEdit (row) {
  204. if (row) { // 编辑
  205. this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}` })
  206. } else { // 新增
  207. this.$router.push({ path: '/productManagement/productInfo/add' })
  208. }
  209. },
  210. // 批量导入
  211. handleImport () {
  212. },
  213. filterOption (input, option) {
  214. console.log(option.componentOptions.children[0].text, 'option')
  215. return (
  216. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  217. )
  218. },
  219. // 详情
  220. handleDetail (row) {
  221. this.itemId = row.id
  222. this.openModal = true
  223. },
  224. // 关闭弹框
  225. closeModal () {
  226. this.itemId = ''
  227. this.openModal = false
  228. },
  229. // 产品分类 change
  230. changeProductType (val, opt) {
  231. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  232. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  233. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  234. },
  235. // 启用 禁用
  236. changeStatus (record) {
  237. if (record.enabledFlag == '1') {
  238. this.$confirm({
  239. title: '提示',
  240. content: '产品被禁用后,不能再销售,确定禁用吗?',
  241. centered: true,
  242. onOk: () => {
  243. this.setEnable(record)
  244. }
  245. })
  246. } else {
  247. this.setEnable(record)
  248. }
  249. },
  250. // 启用 禁用
  251. setEnable (record) {
  252. const params = {
  253. id: record.id,
  254. enabledFlag: record.enabledFlag == 1 ? '0' : '1'
  255. }
  256. dealerProductUpdate(params).then(res => {
  257. if (res.status == 200) {
  258. this.$message.success(res.message)
  259. this.$refs.table.refresh()
  260. } else {
  261. this.$refs.table.refresh()
  262. }
  263. })
  264. },
  265. // 导出
  266. handleExport () {
  267. this.exportLoading = true
  268. dealerProductExport(this.queryParam).then(res => {
  269. this.exportLoading = false
  270. this.download(res)
  271. })
  272. },
  273. download (data) {
  274. if (!data) { return }
  275. const url = window.URL.createObjectURL(new Blob([data]))
  276. const link = document.createElement('a')
  277. link.style.display = 'none'
  278. link.href = url
  279. const a = moment().format('YYYYMMDDHHmmss')
  280. const fname = '自建产品列表' + a
  281. link.setAttribute('download', fname + '.xlsx')
  282. document.body.appendChild(link)
  283. link.click()
  284. },
  285. // 产品品牌 列表
  286. getProductBrand () {
  287. dealerProductBrandQuery({ 'sysFlag': '0' }).then(res => {
  288. if (res.status == 200) {
  289. this.productBrandList = res.data
  290. } else {
  291. this.productBrandList = []
  292. }
  293. })
  294. },
  295. // 产品分类 列表
  296. getProductType () {
  297. dealerProductTypeList({ 'sysFlag': '0' }).then(res => {
  298. if (res.status == 200) {
  299. this.productTypeList = res.data
  300. } else {
  301. this.productTypeList = []
  302. }
  303. })
  304. }
  305. },
  306. beforeRouteEnter (to, from, next) {
  307. next(vm => {
  308. vm.getProductBrand()
  309. vm.getProductType()
  310. })
  311. }
  312. }
  313. </script>