offer.vue 6.6 KB

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