editShelfHw.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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.$emit("updateTempHw")
  156. uni.navigateBack()
  157. }
  158. uni.hideLoading()
  159. })
  160. }
  161. }
  162. })
  163. },
  164. // 表单提交
  165. formSubmit(){
  166. const _this = this
  167. this.$refs.uForm.validate(valid => {
  168. if (valid) {
  169. const row = _this.nowData
  170. uni.showLoading({
  171. title: '正在保存...'
  172. })
  173. _this.loading = true
  174. const params = {
  175. shelfSn: this.shelfSn,
  176. shelfName: this.shelfName,
  177. shelfTierCode: row.shelfTierCode,
  178. shelfPlaceSn: row.shelfPlaceSn||undefined,
  179. shelfPlaceCode: row.shelfPlaceCode,
  180. productSn: row.productSn,
  181. productCode: row.productCode,
  182. qty: row.qty,
  183. price: row.price,
  184. cost: row.terminalPrice,
  185. shelfCartSn: row.shelfCartSn
  186. }
  187. console.log(params)
  188. shelfCartSave(params).then(res => {
  189. if(res.status == 200){
  190. this.toashMsg(res.message)
  191. uni.$emit("updateTempHw")
  192. uni.navigateBack()
  193. }
  194. uni.hideLoading()
  195. _this.loading = false
  196. })
  197. } else {
  198. console.log('验证失败');
  199. }
  200. });
  201. },
  202. }
  203. }
  204. </script>
  205. <style lang="less">
  206. .content{
  207. height: 100vh;
  208. width: 100%;
  209. .placeCode{
  210. text-align: center;
  211. border-radius: 20rpx;
  212. background-color: #eee;
  213. padding: 10upx 20upx;
  214. margin-bottom: 15upx;
  215. }
  216. .form-body{
  217. > view{
  218. background-color: #fff;
  219. padding: 0 1.5rem;
  220. }
  221. .pimgs{
  222. padding:0.1rem;
  223. background:#f8f8f8;
  224. border-radius:0.3rem;
  225. padding-right: 20rpx;
  226. }
  227. .pinfo{
  228. line-height:normal;
  229. color: #666;
  230. padding-left: 15rpx;
  231. .pcode{
  232. color:rgb(0, 170, 255);
  233. }
  234. .pname{
  235. font-weight: bold;
  236. }
  237. .pkuc{
  238. width: 200rpx;
  239. color: #999;
  240. text{
  241. color: #333;
  242. }
  243. }
  244. }
  245. .noproduct{
  246. padding: 40rpx 20rpx;
  247. text-align: center;
  248. color: #999;
  249. >view{
  250. padding: 10rpx 0;
  251. }
  252. text{
  253. color: #00aaff;
  254. margin-left: 10rpx;
  255. }
  256. }
  257. .u-ninput{
  258. border: 2rpx solid #eee;
  259. border-radius: 50rpx;
  260. padding: 0 6rpx;
  261. }
  262. /deep/ .u-icon-disabled{
  263. background: #fff!important;
  264. }
  265. /deep/ .u-number-input{
  266. margin: 0 0;
  267. border: 2rpx solid #eee;
  268. border-top: 0;
  269. border-bottom: 0;
  270. }
  271. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  272. border-radius: 50rpx;
  273. }
  274. }
  275. .footer-btn{
  276. padding: 2.5rem 1rem 0.5rem;
  277. justify-content: space-between;
  278. button{
  279. min-width: 45%;
  280. margin: 0 20upx;
  281. }
  282. .newbtn{
  283. background-color: rgb(51, 95, 182);
  284. color: #fff;
  285. }
  286. .delbtn{
  287. background-color: #fff;
  288. color: red;
  289. }
  290. }
  291. }
  292. </style>