| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <template>
- <scroll-view class="container" :scroll-y="isScroll">
- <view class="title">关联耗材</view>
- <!-- 每一个耗材盒子区域 -->
- <view class="detail_box" v-for="(item, index) in goodList" :key="index">
- <view class="detail_box_item">
- <view class="item_key">耗材名称</view>
- <view class="item_value">{{ item.consumeName }}</view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材数量</view>
- <view class="item_value">
- <uni-number-box v-model="item.number" :min="0" @change="bindChange($event, index)"></uni-number-box>
- </view>
- </view>
- <view class="detail_box_item">
- <view class="item_key">耗材单价</view>
- <view class="item_value">
- <uni-easyinput
- type="number"
- :clearable="false"
- v-model="item.price"
- placeholder="请输入耗材单价"
- placeholderStyle="font-size:16px"
- @focus="handleFocus"
- @blur="handleChangePrice($event, item)"
- ></uni-easyinput>
- </view>
- </view>
- </view>
- <!-- 添加耗材区域 -->
- <view class="add" @click="handleAdd">
- <text>+</text>
- 添加耗材
- </view>
- <!-- 合计费用区域 -->
- <view class="total">
- <view>合计费用</view>
- <view>{{ countMoney }}元</view>
- </view>
- <view class="title">维修师傅</view>
- <view class="box">
- <img src="../../static/images/repairsImg/people.png" />
- {{ worker }}
- </view>
- <view class="title2">手机</view>
- <view class="box">
- <img src="../../static/images/repairsImg/phone2.png" />
- {{ phone }}
- </view>
- <view class="btn" @click="handleSub">确认提交</view>
- </scroll-view>
- </template>
- <script>
- export default {
- data() {
- return {
- // 维修师傅
- worker: '',
- // 手机号码
- phone: '',
- // 耗材列表
- goodList: [],
- // 订单信息
- info: {},
- // 是否允许页面滚动
- isScroll: true,
- // 区别报价还是改价
- type: ''
- }
- },
- computed: {
- // 合计费用
- countMoney() {
- let countMoney = 0
- this.goodList.forEach((ele) => {
- countMoney += Number(ele.number) * Number(ele.price)
- })
- if (countMoney) {
- return countMoney
- } else {
- return 0
- }
- }
- },
- onLoad(options) {
- // console.log(options)
- this.info = JSON.parse(decodeURIComponent(options.info))
- // console.log(this.info.goodsList)
- this.worker = this.info.maintenancerName || ''
- this.phone = this.info.maintenancerPhone || ''
- if (options.type) {
- this.goodList = this.info.goodsList || []
- this.type = options.type
- uni.setNavigationBarTitle({
- title: '改价'
- })
- }
- uni.$on('addConsumable', this.addConsumable)
- },
- onUnload() {
- uni.$off()
- },
- methods: {
- // 单价输入框输入回调
- handleChangePrice(e, item) {
- this.isScroll = true
- // 验证输入单价格式 只能是数字,小数点最多两位
- const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
- if (!reg.test(e.detail.value)) {
- uni.showToast({
- title: '请确定单价为数字,并且只能保留两位小数点',
- icon: 'none'
- })
- item.price = 0
- }
- },
- // 价格输入框聚焦回调
- handleFocus() {
- this.isScroll = false
- },
- // 确认提交按钮回调
- handleSub() {
- if (!this.goodList.length) {
- uni.showToast({
- title: '请添加耗材',
- icon: 'none'
- })
- return
- }
- if (this.countMoney <= 0) {
- uni.showToast({
- title: '合计费用不能小于0元',
- icon: 'none'
- })
- return
- }
- uni.showModal({
- title: '提示',
- content: '确认提交吗?',
- success: async (res) => {
- if (res.confirm) {
- if (this.type) {
- this.goodList.forEach((ele) => {
- if (ele.new) {
- ele.id = null
- }
- })
- const res = await this.$myRequest_repairs({
- url: '/repairConsumables/changeMaintenanceConsumables',
- method: 'post',
- data: {
- recordId: this.info.id,
- totalPrice: this.countMoney,
- consumes: this.goodList
- }
- })
- // console.log(res)
- if (res.code === '200') {
- uni.showToast({
- title: '改价成功',
- icon: 'success'
- })
- setTimeout(() => {
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- }, 1500)
- }
- } else {
- const res = await this.$myRequest_repairs({
- url: '/repairConsumables/insertMaintenanceConsumables',
- method: 'post',
- data: {
- recordId: this.info.id,
- totalPrice: this.countMoney,
- consumes: this.goodList
- }
- })
- // console.log(res)
- if (res.code === '200') {
- uni.showToast({
- title: '提交成功',
- icon: 'success'
- })
- setTimeout(() => {
- uni.reLaunch({
- url: '/pagesRepairs/box/box'
- })
- }, 1500)
- }
- }
- }
- }
- })
- },
- // 全局自定义事件
- addConsumable(e) {
- // console.log(e)
- // 判断是否存在相同的耗材
- let flag = this.goodList.some((ele) => {
- return ele.consumeName === e.data.name
- })
- if (!flag) {
- this.$set(e.data, 'number', 1)
- this.$set(e.data, 'consumeName', e.data.name)
- this.$set(e.data, 'consumeId', e.data.id)
- this.$set(e.data, 'articleId', e.articleId)
- // 添加标识
- this.$set(e.data, 'new', true)
- // this.$delete(e.data, 'name')
- // this.$delete(e.data, 'id')
- this.goodList.push(e.data)
- }
- },
- // 耗材数量计数器改变回调
- bindChange(e, index) {
- // console.log(e)
- // console.log(index)
- if (e === 0) {
- this.goodList.splice(index, 1)
- }
- },
- // 添加耗材按钮回调
- handleAdd() {
- let temList = JSON.stringify(this.goodList.map((ele) => ele.consumeId))
- uni.navigateTo({
- url: `/pagesRepairs/addGoods/addGoods?activeList=${temList}`
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- box-sizing: border-box;
- padding: 0 30rpx;
- width: 100vw;
- .title {
- height: 109rpx;
- line-height: 109rpx;
- font-size: 36rpx;
- font-weight: bold;
- }
- .detail_box {
- box-sizing: border-box;
- margin-bottom: 46rpx;
- padding: 5rpx 30rpx 0;
- width: 690rpx;
- height: 284rpx;
- border-radius: 9rpx;
- box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);
- .detail_box_item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 92rpx;
- font-size: 32rpx;
- border-bottom: 1rpx solid #e5e5e5;
- .item_key {
- width: 150rpx;
- color: #808080;
- }
- .item_value {
- font-weight: bold;
- ::v-deep .is-input-border {
- text-align: right;
- border: none;
- }
- ::v-deep .uni-easyinput__content-input {
- font-size: 32rpx;
- }
- }
- }
- }
- .add {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 690rpx;
- height: 90rpx;
- color: #6fb6b8;
- font-size: 32rpx;
- border-radius: 9rpx;
- background-color: #ebf2f2;
- text {
- margin-right: 10rpx;
- font-size: 48rpx;
- }
- }
- .total {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin: auto;
- width: 622rpx;
- height: 100rpx;
- font-size: 32rpx;
- font-weight: bold;
- border-bottom: 1rpx solid #e5e5e5;
- }
- .box {
- display: flex;
- align-items: center;
- height: 94rpx;
- font-size: 32rpx;
- border-radius: 10rpx;
- border: 1rpx solid #cccccc;
- img {
- margin: 0 14rpx 0 30rpx;
- width: 40rpx;
- height: 40rpx;
- }
- }
- .title2 {
- height: 126rpx;
- line-height: 126rpx;
- font-size: 36rpx;
- font-weight: bold;
- }
- .btn {
- display: flex;
- justify-content: center;
- align-items: center;
- margin: 194rpx 0 60rpx;
- height: 100rpx;
- color: #fff;
- font-size: 32rpx;
- border-radius: 12rpx;
- background-color: #6fb6b8;
- }
- }
- </style>
|