procurementMixins.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. export default {
  2. data() {
  3. return{
  4. imageUrl: require('@/static/procurement/default.png'),
  5. }
  6. },
  7. filters: {
  8. subText(str, index) {
  9. if(str) {
  10. if (str.length <= index) {
  11. return str
  12. }
  13. return str.substring(0, index) + '...'
  14. }
  15. return str
  16. }
  17. },
  18. methods: {
  19. // 校验 只能输入数字和小数点
  20. fpNumInput(e, str, name) {
  21. const o = e.target
  22. const inputRule = /[^\d.]/g //修改inputRule 的值
  23. this.$nextTick(() => {
  24. this[str][name] = o.value.replace(inputRule, '')
  25. if (o.value[0] == '.') {
  26. this[str][name] = ''
  27. } else if (o.value[0] == '0' && o.value[1] == '0') {
  28. this[str][name] = '0'
  29. }
  30. this[str][name] = this[str][name].replace('.', '$#$').replace(/\./g, '').replace('$#$', '.') // 只能输入一个小数点
  31. })
  32. },
  33. // 校验 只能输入数字
  34. NumberInput(e, str, name) {
  35. const o = e.target
  36. const inputRule = /[^\d]/g //修改inputRule 的值
  37. this.$nextTick(() => {
  38. this[str][name] = o.value.replace(inputRule, '')
  39. if (o.value[0] == '0') {
  40. this[str][name] = ''
  41. }
  42. })
  43. },
  44. // 状态
  45. procurementStatus(str, res) {
  46. const form = {
  47. isDelFlag: () => res == 1, // 是否删除
  48. isAchieve: () => res == 1, // 是否实现
  49. isAllTab: () => res === 0, // 是否在全部的tab栏下
  50. isSelfParticipationTab: () => res > 0, // 是否在已参与tab栏 是否在自已发布的tab中
  51. isInvolved: () => res === 2, // 是否我创建的
  52. isAdd: () => res === 1, // 是否参与
  53. }
  54. return form[str]()
  55. },
  56. // 图片是否上传
  57. isImageUrl: (url) => {
  58. if (url) return url.indexOf('none.jpg') > 0
  59. else return true
  60. },
  61. // 全部集采
  62. async procurementAllAddList() {
  63. const form = {
  64. pageNo: 1,
  65. userId: this.userInfo.userId,
  66. pageSize: this.pageInfo.pageNo * this.pageInfo.pageSize,
  67. status: this.currentTab
  68. }
  69. try {
  70. const { data } = await this.ProcurementService.procurementAllList(form)
  71. this.procurementList = data.list
  72. this.isLastPage = data.total === this.procurementList.length
  73. this.loadding = !this.isLastPage
  74. this.pullUpOn = !this.isLastPage
  75. } catch (error) {
  76. console.log(error)
  77. }
  78. },
  79. // 我要参与
  80. async procurementParticipate($event, callback) {
  81. if ($event.price === '') return this.$util.msg('请输入期望单价', 2000)
  82. if ($event.number === '') return this.$util.msg('请输入采购数量', 2000)
  83. const form = {
  84. userId: this.userInfo.userId,
  85. productImage: $event.productImage,
  86. productName: $event.productName,
  87. price: $event.price,
  88. number: $event.number,
  89. status: 0,
  90. id: $event.id,
  91. userName: this.userInfo.name
  92. }
  93. if ($event.isInvolved === 1) {
  94. form.id = $event.id
  95. form.status = 1 // 0参与 1 修改
  96. }
  97. try {
  98. await this.ProcurementService.procurementParticipate(form)
  99. callback && callback()
  100. uni.showToast({
  101. title: `${$event.isInvolved === 0 ? '参与' : '修改'}成功`,
  102. icon: 'success'
  103. })
  104. this.popupShow=false
  105. } catch (error) {
  106. console.log(error)
  107. }
  108. },
  109. // 参与集采详情
  110. async procurementEditData() {
  111. const form = {
  112. id: `${this.procurement.sid}`,
  113. userId: this.userInfo.userId,
  114. procurementType: 0
  115. }
  116. try {
  117. const { data } = await this.ProcurementService.procurementEditData(form)
  118. this.joinData = data
  119. this.popupShow = true
  120. } catch (error) {
  121. console.log(error)
  122. }
  123. },
  124. // 删除 退出
  125. async procurementUpdate(type, callback) {
  126. const form = {
  127. id: `${type === 0 ? this.procurement.id : this.procurement.sid}`,
  128. userId: this.userInfo.userId,
  129. procurementType: type
  130. }
  131. try {
  132. await this.ProcurementService.procurementUpdate(form)
  133. callback && callback()
  134. uni.showToast({
  135. title: `${type === 0 ? '删除' : '退出'}成功`,
  136. icon: 'success'
  137. })
  138. } catch (error) {
  139. console.log(error)
  140. }
  141. },
  142. }
  143. }