offer.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <scroll-view class="container" :scroll-y="isScroll">
  3. <view class="title">关联耗材</view>
  4. <!-- 每一个耗材盒子区域 -->
  5. <view class="detail_box" v-for="(item, index) in goodList" :key="index">
  6. <view class="detail_box_item">
  7. <view class="item_key">耗材名称</view>
  8. <view class="item_value">{{ item.consumeName }}</view>
  9. </view>
  10. <view class="detail_box_item">
  11. <view class="item_key">耗材数量</view>
  12. <view class="item_value">
  13. <uni-number-box v-model="item.number" :min="0" @change="bindChange($event, index)"></uni-number-box>
  14. </view>
  15. </view>
  16. <view class="detail_box_item">
  17. <view class="item_key">耗材单价</view>
  18. <view class="item_value">
  19. <uni-easyinput
  20. type="number"
  21. :clearable="false"
  22. v-model="item.price"
  23. placeholder="请输入耗材单价"
  24. placeholderStyle="font-size:16px"
  25. @focus="handleFocus"
  26. @blur="handleChangePrice($event, item)"
  27. ></uni-easyinput>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 添加耗材区域 -->
  32. <view class="add" @click="handleAdd">
  33. <text>+</text>
  34. 添加耗材
  35. </view>
  36. <!-- 合计费用区域 -->
  37. <view class="total">
  38. <view>合计费用</view>
  39. <view>{{ countMoney }}元</view>
  40. </view>
  41. <view class="title">维修师傅</view>
  42. <view class="box">
  43. <img src="../../static/images/repairsImg/people.png" />
  44. {{ worker }}
  45. </view>
  46. <view class="title2">手机</view>
  47. <view class="box">
  48. <img src="../../static/images/repairsImg/phone2.png" />
  49. {{ phone }}
  50. </view>
  51. <view class="btn" @click="handleSub">确认提交</view>
  52. </scroll-view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. // 维修师傅
  59. worker: '',
  60. // 手机号码
  61. phone: '',
  62. // 耗材列表
  63. goodList: [],
  64. // 订单信息
  65. info: {},
  66. // 是否允许页面滚动
  67. isScroll: true,
  68. // 区别报价还是改价
  69. type: ''
  70. }
  71. },
  72. computed: {
  73. // 合计费用
  74. countMoney() {
  75. let countMoney = 0
  76. this.goodList.forEach((ele) => {
  77. countMoney += Number(ele.number) * Number(ele.price)
  78. })
  79. if (countMoney) {
  80. return countMoney
  81. } else {
  82. return 0
  83. }
  84. }
  85. },
  86. onLoad(options) {
  87. // console.log(options)
  88. this.info = JSON.parse(decodeURIComponent(options.info))
  89. // console.log(this.info.goodsList)
  90. this.worker = this.info.maintenancerName || ''
  91. this.phone = this.info.maintenancerPhone || ''
  92. if (options.type) {
  93. this.goodList = this.info.goodsList || []
  94. this.type = options.type
  95. uni.setNavigationBarTitle({
  96. title: '改价'
  97. })
  98. }
  99. uni.$on('addConsumable', this.addConsumable)
  100. },
  101. onUnload() {
  102. uni.$off()
  103. },
  104. methods: {
  105. // 单价输入框输入回调
  106. handleChangePrice(e, item) {
  107. this.isScroll = true
  108. // 验证输入单价格式 只能是数字,小数点最多两位
  109. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  110. if (!reg.test(e.detail.value)) {
  111. uni.showToast({
  112. title: '请确定单价为数字,并且只能保留两位小数点',
  113. icon: 'none'
  114. })
  115. item.price = 0
  116. }
  117. },
  118. // 价格输入框聚焦回调
  119. handleFocus() {
  120. this.isScroll = false
  121. },
  122. // 确认提交按钮回调
  123. handleSub() {
  124. if (!this.goodList.length) {
  125. uni.showToast({
  126. title: '请添加耗材',
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. if (this.countMoney <= 0) {
  132. uni.showToast({
  133. title: '合计费用不能小于0元',
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. uni.showModal({
  139. title: '提示',
  140. content: '确认提交吗?',
  141. success: async (res) => {
  142. if (res.confirm) {
  143. if (this.type) {
  144. this.goodList.forEach((ele) => {
  145. if (ele.new) {
  146. ele.id = null
  147. }
  148. })
  149. const res = await this.$myRequest_repairs({
  150. url: '/repairConsumables/changeMaintenanceConsumables',
  151. method: 'post',
  152. data: {
  153. recordId: this.info.id,
  154. totalPrice: this.countMoney,
  155. consumes: this.goodList
  156. }
  157. })
  158. // console.log(res)
  159. if (res.code === '200') {
  160. uni.showToast({
  161. title: '改价成功',
  162. icon: 'success'
  163. })
  164. setTimeout(() => {
  165. uni.reLaunch({
  166. url: '/pagesRepairs/box/box'
  167. })
  168. }, 1500)
  169. }
  170. } else {
  171. const res = await this.$myRequest_repairs({
  172. url: '/repairConsumables/insertMaintenanceConsumables',
  173. method: 'post',
  174. data: {
  175. recordId: this.info.id,
  176. totalPrice: this.countMoney,
  177. consumes: this.goodList
  178. }
  179. })
  180. // console.log(res)
  181. if (res.code === '200') {
  182. uni.showToast({
  183. title: '提交成功',
  184. icon: 'success'
  185. })
  186. setTimeout(() => {
  187. uni.reLaunch({
  188. url: '/pagesRepairs/box/box'
  189. })
  190. }, 1500)
  191. }
  192. }
  193. }
  194. }
  195. })
  196. },
  197. // 全局自定义事件
  198. addConsumable(e) {
  199. // console.log(e)
  200. // 判断是否存在相同的耗材
  201. let flag = this.goodList.some((ele) => {
  202. return ele.consumeName === e.data.name
  203. })
  204. if (!flag) {
  205. this.$set(e.data, 'number', 1)
  206. this.$set(e.data, 'consumeName', e.data.name)
  207. this.$set(e.data, 'consumeId', e.data.id)
  208. this.$set(e.data, 'articleId', e.articleId)
  209. // 添加标识
  210. this.$set(e.data, 'new', true)
  211. // this.$delete(e.data, 'name')
  212. // this.$delete(e.data, 'id')
  213. this.goodList.push(e.data)
  214. }
  215. },
  216. // 耗材数量计数器改变回调
  217. bindChange(e, index) {
  218. // console.log(e)
  219. // console.log(index)
  220. if (e === 0) {
  221. this.goodList.splice(index, 1)
  222. }
  223. },
  224. // 添加耗材按钮回调
  225. handleAdd() {
  226. let temList = JSON.stringify(this.goodList.map((ele) => ele.consumeId))
  227. uni.navigateTo({
  228. url: `/pagesRepairs/addGoods/addGoods?activeList=${temList}`
  229. })
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss" scoped>
  235. .container {
  236. box-sizing: border-box;
  237. padding: 0 30rpx;
  238. width: 100vw;
  239. .title {
  240. height: 109rpx;
  241. line-height: 109rpx;
  242. font-size: 36rpx;
  243. font-weight: bold;
  244. }
  245. .detail_box {
  246. box-sizing: border-box;
  247. margin-bottom: 46rpx;
  248. padding: 5rpx 30rpx 0;
  249. width: 690rpx;
  250. height: 284rpx;
  251. border-radius: 9rpx;
  252. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  253. .detail_box_item {
  254. display: flex;
  255. justify-content: space-between;
  256. align-items: center;
  257. height: 92rpx;
  258. font-size: 32rpx;
  259. border-bottom: 1rpx solid #e5e5e5;
  260. .item_key {
  261. width: 150rpx;
  262. color: #808080;
  263. }
  264. .item_value {
  265. font-weight: bold;
  266. ::v-deep .is-input-border {
  267. text-align: right;
  268. border: none;
  269. }
  270. ::v-deep .uni-easyinput__content-input {
  271. font-size: 32rpx;
  272. }
  273. }
  274. }
  275. }
  276. .add {
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. width: 690rpx;
  281. height: 90rpx;
  282. color: #6fb6b8;
  283. font-size: 32rpx;
  284. border-radius: 9rpx;
  285. background-color: #ebf2f2;
  286. text {
  287. margin-right: 10rpx;
  288. font-size: 48rpx;
  289. }
  290. }
  291. .total {
  292. display: flex;
  293. justify-content: space-between;
  294. align-items: center;
  295. margin: auto;
  296. width: 622rpx;
  297. height: 100rpx;
  298. font-size: 32rpx;
  299. font-weight: bold;
  300. border-bottom: 1rpx solid #e5e5e5;
  301. }
  302. .box {
  303. display: flex;
  304. align-items: center;
  305. height: 94rpx;
  306. font-size: 32rpx;
  307. border-radius: 10rpx;
  308. border: 1rpx solid #cccccc;
  309. img {
  310. margin: 0 14rpx 0 30rpx;
  311. width: 40rpx;
  312. height: 40rpx;
  313. }
  314. }
  315. .title2 {
  316. height: 126rpx;
  317. line-height: 126rpx;
  318. font-size: 36rpx;
  319. font-weight: bold;
  320. }
  321. .btn {
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. margin: 194rpx 0 60rpx;
  326. height: 100rpx;
  327. color: #fff;
  328. font-size: 32rpx;
  329. border-radius: 12rpx;
  330. background-color: #6fb6b8;
  331. }
  332. }
  333. </style>