procurementMixins.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. if (this.procurementList.length === 0) {
  76. this.isEmpty = true
  77. }
  78. } catch (error) {
  79. console.log(error)
  80. }
  81. },
  82. // 我要参与
  83. async procurementParticipate($event, callback) {
  84. if ($event.price === '') return this.$util.msg('请输入期望单价', 2000)
  85. if ($event.number === '') return this.$util.msg('请输入采购数量', 2000)
  86. const form = {
  87. userId: this.userInfo.userId,
  88. productImage: $event.productImage,
  89. productName: $event.productName,
  90. price: $event.price,
  91. number: $event.number,
  92. status: 0,
  93. id: $event.id,
  94. userName: this.userInfo.name
  95. }
  96. if ($event.isInvolved === 1) {
  97. form.id = $event.id
  98. form.status = 1 // 0参与 1 修改
  99. }
  100. try {
  101. await this.ProcurementService.procurementParticipate(form)
  102. callback && callback()
  103. uni.showToast({
  104. title: `${$event.isInvolved === 0 ? '参与' : '修改'}成功`,
  105. icon: 'success'
  106. })
  107. this.popupShow=false
  108. } catch (error) {
  109. console.log(error)
  110. }
  111. },
  112. // 参与集采详情
  113. async procurementEditData() {
  114. const form = {
  115. id: `${this.procurement.sid}`,
  116. userId: this.userInfo.userId,
  117. procurementType: 0
  118. }
  119. try {
  120. const { data } = await this.ProcurementService.procurementEditData(form)
  121. this.joinData = data
  122. this.popupShow = true
  123. } catch (error) {
  124. console.log(error)
  125. }
  126. },
  127. // 删除 退出
  128. async procurementUpdate(type, callback) {
  129. const form = {
  130. id: `${type === 0 ? this.procurement.id : this.procurement.sid}`,
  131. userId: this.userInfo.userId,
  132. procurementType: type
  133. }
  134. try {
  135. await this.ProcurementService.procurementUpdate(form)
  136. callback && callback()
  137. uni.showToast({
  138. title: `${type === 0 ? '删除' : '退出'}成功`,
  139. icon: 'success'
  140. })
  141. } catch (error) {
  142. console.log(error)
  143. }
  144. },
  145. }
  146. }