offer.vue 6.2 KB

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