offer.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. this.info = JSON.parse(decodeURIComponent(options.info))
  88. this.worker = this.info.maintenancerName || ''
  89. this.phone = this.info.maintenancerPhone || ''
  90. if (options.type) {
  91. this.goodList = this.info.goodsList || []
  92. this.type = options.type
  93. uni.setNavigationBarTitle({
  94. title: '改价'
  95. })
  96. }
  97. uni.$on('addConsumable', this.addConsumable)
  98. },
  99. onUnload() {
  100. uni.$off()
  101. },
  102. methods: {
  103. // 单价输入框输入回调
  104. handleChangePrice(e, item) {
  105. this.isScroll = true
  106. // 验证输入单价格式 只能是数字,小数点最多两位
  107. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
  108. if (!reg.test(e.detail.value)) {
  109. uni.showToast({
  110. title: '请确定单价为数字,并且只能保留两位小数点',
  111. icon: 'none'
  112. })
  113. item.price = 0
  114. }
  115. },
  116. // 价格输入框聚焦回调
  117. handleFocus() {
  118. this.isScroll = false
  119. },
  120. // 确认提交按钮回调
  121. handleSub() {
  122. if (!this.goodList.length) {
  123. uni.showToast({
  124. title: '请添加耗材',
  125. icon: 'none'
  126. })
  127. return
  128. }
  129. if (this.countMoney <= 0) {
  130. uni.showToast({
  131. title: '合计费用不能小于0元',
  132. icon: 'none'
  133. })
  134. return
  135. }
  136. uni.showModal({
  137. title: '提示',
  138. content: '确认提交吗?',
  139. success: async (res) => {
  140. if (res.confirm) {
  141. if (this.type) {
  142. const res = await this.$myRequest_repairs({
  143. url: '/repairConsumables/changeMaintenanceConsumables',
  144. method: 'post',
  145. data: {
  146. recordId: this.info.id,
  147. totalPrice: this.countMoney,
  148. consumes: this.goodList
  149. }
  150. })
  151. // console.log(res)
  152. if (res.code === '200') {
  153. uni.showToast({
  154. title: '改价成功',
  155. icon: 'success'
  156. })
  157. setTimeout(() => {
  158. uni.reLaunch({
  159. url: '/pagesRepairs/box/box'
  160. })
  161. }, 1500)
  162. }
  163. } else {
  164. const res = await this.$myRequest_repairs({
  165. url: '/repairConsumables/insertMaintenanceConsumables',
  166. method: 'post',
  167. data: {
  168. recordId: this.info.id,
  169. totalPrice: this.countMoney,
  170. consumes: this.goodList
  171. }
  172. })
  173. // console.log(res)
  174. if (res.code === '200') {
  175. uni.showToast({
  176. title: '提交成功',
  177. icon: 'success'
  178. })
  179. setTimeout(() => {
  180. uni.reLaunch({
  181. url: '/pagesRepairs/box/box'
  182. })
  183. }, 1500)
  184. }
  185. }
  186. }
  187. }
  188. })
  189. },
  190. // 全局自定义事件
  191. addConsumable(e) {
  192. // 判断是否存在相同的耗材
  193. let flag = this.goodList.some((ele) => {
  194. return ele.consumeName === e.data.name
  195. })
  196. if (!flag) {
  197. this.$set(e.data, 'number', 1)
  198. this.$set(e.data, 'consumeName', e.data.name)
  199. this.$set(e.data, 'consumeId', e.data.id)
  200. this.$set(e.data, 'articleId', e.articleId)
  201. // this.$delete(e.data, 'name')
  202. // this.$delete(e.data, 'id')
  203. this.goodList.push(e.data)
  204. }
  205. },
  206. // 耗材数量计数器改变回调
  207. bindChange(e, index) {
  208. // console.log(e)
  209. // console.log(index)
  210. if (e === 0) {
  211. this.goodList.splice(index, 1)
  212. }
  213. },
  214. // 添加耗材按钮回调
  215. handleAdd() {
  216. let temList = JSON.stringify(this.goodList.map((ele) => ele.consumeId))
  217. uni.navigateTo({
  218. url: `/pagesRepairs/addGoods/addGoods?activeList=${temList}`
  219. })
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="scss" scoped>
  225. .container {
  226. box-sizing: border-box;
  227. padding: 0 30rpx;
  228. width: 100vw;
  229. .title {
  230. height: 109rpx;
  231. line-height: 109rpx;
  232. font-size: 36rpx;
  233. font-weight: bold;
  234. }
  235. .detail_box {
  236. box-sizing: border-box;
  237. margin-bottom: 46rpx;
  238. padding: 5rpx 30rpx 0;
  239. width: 690rpx;
  240. height: 284rpx;
  241. border-radius: 9rpx;
  242. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
  243. .detail_box_item {
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: center;
  247. height: 92rpx;
  248. font-size: 32rpx;
  249. border-bottom: 1rpx solid #e5e5e5;
  250. .item_key {
  251. width: 150rpx;
  252. color: #808080;
  253. }
  254. .item_value {
  255. font-weight: bold;
  256. ::v-deep .is-input-border {
  257. text-align: right;
  258. border: none;
  259. }
  260. ::v-deep .uni-easyinput__content-input {
  261. font-size: 32rpx;
  262. }
  263. }
  264. }
  265. }
  266. .add {
  267. display: flex;
  268. justify-content: center;
  269. align-items: center;
  270. width: 690rpx;
  271. height: 90rpx;
  272. color: #6fb6b8;
  273. font-size: 32rpx;
  274. border-radius: 9rpx;
  275. background-color: #ebf2f2;
  276. text {
  277. margin-right: 10rpx;
  278. font-size: 48rpx;
  279. }
  280. }
  281. .total {
  282. display: flex;
  283. justify-content: space-between;
  284. align-items: center;
  285. margin: auto;
  286. width: 622rpx;
  287. height: 100rpx;
  288. font-size: 32rpx;
  289. font-weight: bold;
  290. border-bottom: 1rpx solid #e5e5e5;
  291. }
  292. .box {
  293. display: flex;
  294. align-items: center;
  295. height: 94rpx;
  296. font-size: 32rpx;
  297. border-radius: 10rpx;
  298. border: 1rpx solid #cccccc;
  299. img {
  300. margin: 0 14rpx 0 30rpx;
  301. width: 40rpx;
  302. height: 40rpx;
  303. }
  304. }
  305. .title2 {
  306. height: 126rpx;
  307. line-height: 126rpx;
  308. font-size: 36rpx;
  309. font-weight: bold;
  310. }
  311. .btn {
  312. display: flex;
  313. justify-content: center;
  314. align-items: center;
  315. margin: 194rpx 0 60rpx;
  316. height: 100rpx;
  317. color: #fff;
  318. font-size: 32rpx;
  319. border-radius: 12rpx;
  320. background-color: #6fb6b8;
  321. }
  322. }
  323. </style>