list.vue 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <div class="subPage" :style="{ padding: '20px' }">
  3. <div>
  4. <el-form inline>
  5. <el-form-item label="案场">
  6. <el-select v-model="caseId" size="medium" placeholder="请选择案场">
  7. <el-option
  8. v-for="item in cases"
  9. :key="item.CaseId"
  10. :label="item.CaseName"
  11. :value="item.CaseId"
  12. ></el-option>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="条码">
  16. <el-input v-model="bookBarcode"></el-input>
  17. </el-form-item>
  18. <el-form-item label="书名">
  19. <el-input v-model="bookName"></el-input>
  20. </el-form-item>
  21. <el-form-item :style="{ float: 'right' }">
  22. <el-button type="primary" size="medium" @click="filterList">搜索</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. <div>
  27. <el-button plain @click="editBook()" size="medium">图书录入</el-button>
  28. <el-button plain @click="showBatchInput()" size="medium">批量导入</el-button>
  29. <div :style="{ margin: '10px 0' }">
  30. <el-table :data="list" border style="width: 100%">
  31. <el-table-column label="图片" width="128">
  32. <template slot-scope="scope">
  33. <img width="64" :src="scope.row.BookImg" alt>
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="BookBarcode" label="条码"></el-table-column>
  37. <el-table-column prop="BookName" label="书名"></el-table-column>
  38. <el-table-column label="案场">
  39. <template slot-scope="scope">
  40. <span>{{ getCaseName(scope.row.CaseId) }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="分类">
  44. <template slot-scope="scope">
  45. <span>{{ getTypeName(scope.row.BookTypeId) }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="价格">
  49. <template slot-scope="scope">
  50. <span>{{ formatPrice(scope.row.Price) }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="BorrowDays" label="借阅(天)"></el-table-column>
  54. <el-table-column prop="InStock" label="总数量"></el-table-column>
  55. <el-table-column prop="BorrowNum" label="借出"></el-table-column>
  56. <el-table-column label="预约">
  57. <template slot-scope="scope">
  58. <span>{{ getReserveNum(scope.row) }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="录入时间">
  62. <template slot-scope="scope">
  63. <span>{{ toolClass.dateFormat(scope.row.CreateDate) }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column fixed="right" label="操作" width="150">
  67. <template slot-scope="scope">
  68. <div>
  69. <el-button type="text" @click="changeStock(scope.row)" size="small">盘点</el-button>
  70. <el-button @click="setRecommend(scope.row)" type="text" size="small">{{ scope.row.IsRecommend === 1 ? '取消推荐' : '设为推荐' }}</el-button>
  71. </div>
  72. <div>
  73. <el-button @click="editBook(scope.row)" type="text" size="small">编辑</el-button>
  74. <el-button @click="removeBook(scope.row)" type="text" size="small">删除</el-button>
  75. </div>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <el-pagination
  80. layout="prev, pager, next"
  81. :current-page="page"
  82. :total="pagenum"
  83. @current-change="pageChange"
  84. ></el-pagination>
  85. </div>
  86. </div>
  87. <el-dialog
  88. title="批量导入"
  89. :visible.sync="showDialog"
  90. width="50%">
  91. <div :style="{ margin: 'auto', width: '80%' }">
  92. <div><el-button @click="inputRef.click()" :style="{ width: '100%' }">上传文件</el-button></div>
  93. <div :style="{ textAlign: 'right', paddingTop: '20px' }"><a href="https://jinchengjiaye.oss-cn-beijing.aliyuncs.com/excel/books-batch-import.xlsx" download="书籍导入模板" :style="{ color: '#409EFF' }">下载导入模板</a></div>
  94. </div>
  95. <span slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="showDialog = false">确 定</el-button>
  97. <el-button @click="showDialog = false">取 消</el-button>
  98. </span>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { createNamespacedHelpers, mapState } from 'vuex'
  104. import { Loading } from 'element-ui'
  105. const { mapState: mapLibSate, mapActions, mapMutations } = createNamespacedHelpers('library')
  106. export default {
  107. name: 'bookList',
  108. data() {
  109. return {
  110. caseId: '',
  111. bookBarcode: '',
  112. bookName: '',
  113. inputRef: window.document.createElement('input'),
  114. showDialog: false,
  115. }
  116. },
  117. computed: {
  118. ...mapState({
  119. cases: x => x.app.cases.list,
  120. defaultCase: x => x.app.cases.default,
  121. orgid: x => x.app.user.OrgId
  122. }),
  123. ...mapLibSate({
  124. list: s => s.list,
  125. page: s => s.page,
  126. pagenum: s => s.pagenum,
  127. types: s => s.type.list
  128. })
  129. },
  130. watch: {
  131. defaultCase(nv) {
  132. if (nv && !this.caseId) {
  133. this.caseId = nv
  134. this.filterList()
  135. }
  136. },
  137. },
  138. created() {
  139. this.inputRef.type = 'file'
  140. // https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
  141. this.inputRef.accept = 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  142. this.inputRef.addEventListener('change', this.importBatch.bind(this))
  143. // this.filterList()
  144. },
  145. beforeRouteLeave (to, from, next) {
  146. this.resetStore('list')
  147. next()
  148. },
  149. methods: {
  150. ...mapMutations({
  151. resetStore: 'clearData',
  152. }),
  153. ...mapActions({
  154. getList: 'getBookList',
  155. getTypeList: 'getTypeList',
  156. deleteBook: 'deleteBook',
  157. setBookRecommend: 'updateBookDetail',
  158. batchImport: 'batchImport',
  159. }),
  160. // 查询过滤
  161. filterList({ page = 0 } = {}) {
  162. const caseId = this.caseId || this.defaultCase
  163. if (!caseId) {
  164. this.$message({
  165. showClose: true,
  166. message: '请选择案场',
  167. type: 'error'
  168. })
  169. return
  170. }
  171. this.getTypeList({ page: 0, pagesize: 1000, caseid: caseId })
  172. this.getList({
  173. page,
  174. caseid: caseId,
  175. barcode: this.bookBarcode,
  176. name: this.bookName
  177. }).catch(err => {
  178. this.$message({
  179. showClose: true,
  180. message: err,
  181. type: 'error'
  182. })
  183. })
  184. },
  185. // 分页过滤
  186. pageChange(page) {
  187. this.filterList({ page })
  188. },
  189. // 删除图书
  190. removeBook({ BookId: id }) {
  191. this.$confirm('确认删除此数据?', '提示', {
  192. confirmButtonText: '确定',
  193. cancelButtonText: '取消',
  194. type: 'warning'
  195. })
  196. .then(() => {
  197. this.deleteBook({
  198. BookId: id
  199. })
  200. .then(() => {
  201. this.$message({
  202. showClose: true,
  203. message: '删除成功',
  204. type: 'success'
  205. })
  206. })
  207. .catch(err => {
  208. this.$message({
  209. showClose: true,
  210. message: err,
  211. type: 'error'
  212. })
  213. })
  214. })
  215. .catch(x => x)
  216. },
  217. // 跳转到编辑
  218. editBook({ BookId: id } = {}) {
  219. this.$router.push({ name: 'libraryEdit', params: { id } })
  220. },
  221. // 设为/取消推荐
  222. setRecommend(book) {
  223. const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
  224. book.IsRecommend = Math.abs(book.IsRecommend - 1)
  225. this.$confirm(tipMsg, '提示', {
  226. confirmButtonText: '是',
  227. cancelButtonText: '否',
  228. type: 'warning'
  229. })
  230. .then(() => {
  231. this.setBookRecommend(book)
  232. .then(() => {
  233. this.$message({
  234. showClose: true,
  235. message: '设置成功',
  236. type: 'success'
  237. })
  238. })
  239. .catch(err => {
  240. this.$message({
  241. showClose: true,
  242. message: err,
  243. type: 'error'
  244. })
  245. })
  246. })
  247. .catch(x => x)
  248. },
  249. // 批量导入
  250. showBatchInput() {
  251. if (!this.caseId) {
  252. this.showDialog = false
  253. this.$message({
  254. showClose: true,
  255. message: '请选择案场',
  256. type: 'error'
  257. })
  258. return
  259. }
  260. this.showDialog = true
  261. },
  262. importBatch(e) {
  263. this.showDialog = false
  264. // 需要指定案场
  265. const caseName = this.getCaseName(this.caseId)
  266. const file = e.target.files[0]
  267. if (!file) {
  268. this.$message({
  269. showClose: true,
  270. message: '请选择导入文件',
  271. type: 'error'
  272. })
  273. }
  274. this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
  275. confirmButtonText: '确定',
  276. cancelButtonText: '取消',
  277. type: 'warning'
  278. })
  279. .then(() => {
  280. const loadding = Loading.service({
  281. lock: true,
  282. text: '数据导入中, 可能耗时较长, 请耐心等候...'
  283. })
  284. const data = {
  285. caseId: this.caseId,
  286. excel: file,
  287. }
  288. this.batchImport(data).then(() => {
  289. loadding.close()
  290. this.$confirm(`数据导入完成, 点击【确定】刷新页面`, '提示', {
  291. confirmButtonText: '确定',
  292. cancelButtonText: '取消',
  293. type: 'warning'
  294. }).then(() => {
  295. window.location.reload()
  296. })
  297. }).catch((err) => {
  298. loadding.close()
  299. this.$message({
  300. showClose: true,
  301. message: err,
  302. type: 'error'
  303. })
  304. })
  305. })
  306. .catch(x => x)
  307. },
  308. getCaseName(id) {
  309. return (this.cases.filter(x => x.CaseId === id)[0] || {}).CaseName
  310. },
  311. getTypeName(id) {
  312. return (this.types.filter(x => x.BookTypeId === id)[0] || {}).BookTypeName
  313. },
  314. formatPrice(price) {
  315. return window.Number(price).toFixed(2)
  316. },
  317. getReserveNum({ InStock, LeftNum, BorrowNum } = {}) {
  318. return InStock - LeftNum - BorrowNum
  319. },
  320. changeStock({ BookId: id }) {
  321. this.$router.push({ name: 'stockChange', params: { id } })
  322. },
  323. }
  324. }
  325. </script>