offer.vue 6.5 KB

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