editShelfHw.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="content flex flex_column" v-if="nowData">
  3. <view class="form-body">
  4. <u-form :model="nowData" label-width="180rpx" :error-type="['toast']" ref="uForm">
  5. <view style="padding: 20upx 0;" v-if="nowData.shelfProductApi" >
  6. <view class="placeCode">
  7. {{nowData.shelfPlaceCode}}
  8. </view>
  9. <view class="flex flex_1 align_center">
  10. <view class="pimgs">
  11. <u-image :src="nowData.product.images?nowData.product.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  12. </view>
  13. <view class="pinfo flex_1">
  14. <view class="ptxt flex align_center justify_between">
  15. <text>{{nowData.productCode}}</text>
  16. <text class="pkuc">
  17. 可用库存:<text>{{nowData.shelfProductApi.qty}}</text>{{nowData.product.unit}}
  18. </text>
  19. </view>
  20. <view class="pname">
  21. {{nowData.product.productName}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view style="padding: 20upx 0;" v-else>
  27. <u-form-item label="货位号" required prop="shelfPlaceCode">
  28. <u-input v-model="nowData.shelfPlaceCode" @input="placeCodeBlur" :maxlength="30" placeholder="请输入货位号(字母+数字的格式)"/>
  29. </u-form-item>
  30. <u-gap height="10" bg-color="#f8f8f8"></u-gap>
  31. <u-form-item label="绑定产品" required prop="productSn">
  32. <view class="pinfo" style="width: 100%;">
  33. <view class="ptxt flex align_center justify_between">
  34. <text>{{nowData.productCode}}</text>
  35. <text class="pcode" @click="toBindProduct">
  36. <u-icon name='reload'></u-icon>
  37. 更换产品
  38. </text>
  39. </view>
  40. </view>
  41. </u-form-item>
  42. <u-form-item label="">
  43. <view class="flex flex_1 align_center">
  44. <view class="pimgs">
  45. <u-image :src="nowData.product.images?nowData.product.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  46. </view>
  47. <view class="pinfo flex_1">
  48. <view class="pname">
  49. {{nowData.product.productName}}
  50. </view>
  51. </view>
  52. </view>
  53. </u-form-item>
  54. </view>
  55. <u-gap height="10" bg-color="#f8f8f8"></u-gap>
  56. <u-form-item label="本次上架数量" required prop="qty">
  57. <view style="width: 100%;" class="flex justify_end">
  58. <view class="u-ninput">
  59. <u-number-box :min="1" :max="999999" positive-integer v-model="nowData.qty" color="#000" bg-color="#fff" size="30" :input-height="70" :input-width="150"></u-number-box>
  60. </view>
  61. </view>
  62. </u-form-item>
  63. </u-form>
  64. </view>
  65. <view class="flex footer-btn">
  66. <u-button class="delbtn" :loading='loading' @click="handleDel" type='primary' shape="circle" size="medium">删除</u-button>
  67. <u-button :style="{width:type=='bind'?'45%':'100%'}" class="newbtn" :loading='loading' @click="formSubmit" type='primary' shape="circle" size="medium">保存</u-button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { clzConfirm, numberToFixed } from '@/libs/tools';
  73. import { shelfCartSave, shelfCartDelete} from '@/api/shelfCart.js'
  74. export default {
  75. data() {
  76. return {
  77. nowData: {
  78. shelfPlaceCode: '',
  79. productSn: '',
  80. qty: '',
  81. },
  82. rules: {
  83. shelfPlaceCode:[
  84. { required: true, message: '请输入货位号', trigger: 'change' },
  85. {
  86. pattern: /^[a-zA-Z]{1}[0-9]{1,29}$/g,
  87. message: '必须字母开头且后面紧跟数字'
  88. }
  89. ],
  90. productSn: [{ required: true, message: '请选择绑定产品', trigger: 'change' }],
  91. qty: [{ required: true,type:'number', message: '请输入上架数量', trigger: 'change' }],
  92. },
  93. shelfSn: null,
  94. customerSn: '',
  95. shelfName: null,
  96. loading: false,
  97. type:"",
  98. }
  99. },
  100. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  101. onReady() {
  102. this.$refs.uForm.setRules(this.rules);
  103. },
  104. onLoad(opts) {
  105. const _this = this
  106. this.nowData = JSON.parse(JSON.stringify(this.$store.state.vuex_tempData));
  107. console.log(this.nowData)
  108. this.shelfName = opts.shelfName
  109. this.shelfSn = opts.shelfSn
  110. this.customerSn = opts.customerSn
  111. this.type = this.nowData.shelfProductApi ? 'edit' : 'new'
  112. // 选在产品
  113. uni.$on('addProductToHw',function(data){
  114. console.log(data)
  115. _this.nowData.product.images = data.productMsg
  116. _this.nowData.product.productName = data.name
  117. _this.nowData.product.unit = data.unit
  118. _this.nowData.price = Number(data.price)
  119. _this.nowData.cost = Number(data.cost)
  120. _this.nowData.productCode = data.code
  121. _this.nowData.productSn = data.productSn
  122. })
  123. },
  124. onUnload(){
  125. uni.$off("addProductToHw")
  126. this.$store.state.vuex_tempData = null
  127. },
  128. methods: {
  129. placeCodeBlur(v){
  130. this.$nextTick(() => {
  131. this.nowData.shelfPlaceCode = this.nowData.shelfPlaceCode.toLocaleUpperCase()
  132. })
  133. },
  134. // 更换产品
  135. toBindProduct(){
  136. uni.navigateTo({
  137. url: "/pages/shelfSetting/bindProduct?customerSn="+this.customerSn+"&shelfSn="+this.shelfSn
  138. })
  139. },
  140. // 删除
  141. handleDel(){
  142. const _this = this
  143. clzConfirm({
  144. title: '提示',
  145. content: '确认删除此货位和产品吗?',
  146. success (ret) {
  147. if (ret.confirm || ret.index == 0) {
  148. uni.showLoading({
  149. title: '正在删除...'
  150. })
  151. shelfCartDelete({ shelfCartSn: _this.nowData.shelfCartSn }).then(res => {
  152. console.log(res)
  153. if (res.status == 200) {
  154. _this.toashMsg(res.message)
  155. uni.navigateBack()
  156. }
  157. uni.hideLoading()
  158. })
  159. }
  160. }
  161. })
  162. },
  163. // 表单提交
  164. formSubmit(){
  165. const _this = this
  166. this.$refs.uForm.validate(valid => {
  167. if (valid) {
  168. const row = _this.nowData
  169. uni.showLoading({
  170. title: '正在保存...'
  171. })
  172. _this.loading = true
  173. const params = {
  174. shelfSn: this.shelfSn,
  175. shelfName: this.shelfName,
  176. shelfTierCode: row.shelfTierCode,
  177. shelfPlaceSn: row.shelfPlaceSn||undefined,
  178. shelfPlaceCode: row.shelfPlaceCode,
  179. productSn: row.productSn,
  180. productCode: row.productCode,
  181. qty: row.qty,
  182. price: row.price,
  183. cost: row.terminalPrice,
  184. shelfCartSn: row.shelfCartSn
  185. }
  186. console.log(params)
  187. shelfCartSave(params).then(res => {
  188. if(res.status == 200){
  189. this.toashMsg(res.message)
  190. uni.navigateBack()
  191. }
  192. uni.hideLoading()
  193. _this.loading = false
  194. })
  195. } else {
  196. console.log('验证失败');
  197. }
  198. });
  199. },
  200. }
  201. }
  202. </script>
  203. <style lang="less">
  204. .content{
  205. height: 100vh;
  206. width: 100%;
  207. .placeCode{
  208. text-align: center;
  209. border-radius: 20rpx;
  210. background-color: #eee;
  211. padding: 10upx 20upx;
  212. margin-bottom: 15upx;
  213. }
  214. .form-body{
  215. > view{
  216. background-color: #fff;
  217. padding: 0 1.5rem;
  218. }
  219. .pimgs{
  220. padding:0.1rem;
  221. background:#f8f8f8;
  222. border-radius:0.3rem;
  223. padding-right: 20rpx;
  224. }
  225. .pinfo{
  226. line-height:normal;
  227. color: #666;
  228. padding-left: 15rpx;
  229. .pcode{
  230. color:rgb(0, 170, 255);
  231. }
  232. .pname{
  233. font-weight: bold;
  234. }
  235. .pkuc{
  236. width: 200rpx;
  237. color: #999;
  238. text{
  239. color: #333;
  240. }
  241. }
  242. }
  243. .noproduct{
  244. padding: 40rpx 20rpx;
  245. text-align: center;
  246. color: #999;
  247. >view{
  248. padding: 10rpx 0;
  249. }
  250. text{
  251. color: #00aaff;
  252. margin-left: 10rpx;
  253. }
  254. }
  255. .u-ninput{
  256. border: 2rpx solid #eee;
  257. border-radius: 50rpx;
  258. padding: 0 6rpx;
  259. }
  260. ::v-deep .u-icon-disabled{
  261. background: #fff!important;
  262. }
  263. ::v-deep .u-number-input{
  264. margin: 0 0;
  265. border: 2rpx solid #eee;
  266. border-top: 0;
  267. border-bottom: 0;
  268. }
  269. ::v-deep .u-icon-plus, ::v-deep .u-icon-minus{
  270. border-radius: 50rpx;
  271. }
  272. }
  273. .footer-btn{
  274. padding: 2.5rem 1rem 0.5rem;
  275. justify-content: space-between;
  276. button{
  277. min-width: 45%;
  278. margin: 0 20upx;
  279. }
  280. .newbtn{
  281. background-color: rgb(51, 95, 182);
  282. color: #fff;
  283. }
  284. .delbtn{
  285. background-color: #fff;
  286. color: red;
  287. }
  288. }
  289. }
  290. </style>