schemeAdd.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" title="方案信息"
  4. @clickLeft="back">
  5. </uni-nav-bar>
  6. <u-cell-group>
  7. <u-cell title="项目" arrow-direction="down">
  8. <uni-data-picker v-model="form.typeId" slot="value" :clear-icon='false' placeholder="请选择"
  9. :localdata="typeIdList" @change="typeOnchange">
  10. </uni-data-picker>
  11. </u-cell>
  12. <u-cell title="编码" arrow-direction="down">
  13. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  14. v-model="form.code">
  15. </u--input>
  16. <view class="labels" slot="value" v-if="form.typeId == '2'">
  17. {{ form.code }}
  18. </view>
  19. </u-cell>
  20. <u-cell title="名称" arrow-direction="down">
  21. <u--input v-if="form.typeId == '2'" @click.native="selectProduct" slot="value" placeholder="请选择"
  22. border="surround" v-model="form.name">
  23. </u--input>
  24. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  25. v-model="form.name"></u--input>
  26. </u-cell>
  27. <u-cell title="型号" arrow-direction="down">
  28. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  29. v-model="form.categoryModel"></u--input>
  30. <view class="labels" slot="value" v-if="form.typeId == '2'">
  31. {{ form.categoryModel }}
  32. </view>
  33. </u-cell>
  34. <u-cell title="规格" arrow-direction="down">
  35. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  36. v-model="form.specification"></u--input>
  37. <view class="labels" slot="value" v-if="form.typeId == '2'">
  38. {{ form.specification }}
  39. </view>
  40. </u-cell>
  41. <u-cell title="仓库" arrow-direction="down">
  42. <template v-if="obtain == '主数据'">
  43. <!-- <uni-data-picker v-if="form.typeId != '2'" v-model="form.warehouseId" slot="value"
  44. :clear-icon='false' placeholder="请选择" :localdata="warehouseList" @change="warehouseOnchange">
  45. </uni-data-picker> -->
  46. <uni-data-select v-if="form.typeId == '2'" slot="value" v-model="form.warehouseId"
  47. @change="warehouseOnchange" :clear="false" :localdata="warehouseList">
  48. </uni-data-select>
  49. <u--input v-if="form.typeId != '2'" slot="value" placeholder="请输入" border="surround"
  50. v-model="form.warehouseName" disabled></u--input>
  51. </template>
  52. <template v-else>
  53. <u--input slot="value" placeholder="请输入仓库" border="surround" v-model="form.warehouseName"
  54. disabled></u--input>
  55. </template>
  56. </u-cell>
  57. <u-cell title="库存" arrow-direction="down">
  58. <!-- <u--input slot="value" placeholder="请输入" border="surround" v-model="form.warehouseNum"></u--input> -->
  59. <view class="labels" slot="value">
  60. {{ form.warehouseNum }}
  61. </view>
  62. </u-cell>
  63. <u-cell title="单位" arrow-direction="down">
  64. <u--input slot="value" v-if="form.typeId != '2'" placeholder="请输入" border="surround"
  65. v-model="form.measureUnit"></u--input>
  66. <view class="labels" slot="value" v-if="form.typeId == '2'">
  67. {{ form.measureUnit }}
  68. </view>
  69. </u-cell>
  70. <u-cell title="数量" arrow-direction="down">
  71. <u--input slot="value" type="number" @input=" (val) =>inputChange(val,'totalCount')" placeholder="请输入"
  72. border="surround" v-model="form.totalCount"></u--input>
  73. </u-cell>
  74. <u-cell title="单价" arrow-direction="down">
  75. <u--input type="number" slot="value" @input="(val) =>inputChange(val,'singlePrice')" placeholder="请输入"
  76. border="surround" v-model="form.singlePrice"></u--input>
  77. </u-cell>
  78. <u-cell title="合计" arrow-direction="down">
  79. <view class="labels" slot="value">
  80. {{ form.settlementPrice }}
  81. </view>
  82. </u-cell>
  83. <u-cell title="详细内容" arrow-direction="down">
  84. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.content"></u--input>
  85. </u-cell>
  86. <view class="footerButton">
  87. <u-button type="default" text="返回" @click="back"></u-button>
  88. <u-button type="primary" @click="save" text="保存"></u-button>
  89. </view>
  90. </u-cell-group>
  91. <u-toast ref="uToast"></u-toast>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. getIdWarehouseList
  97. } from '@/api/salesServiceManagement/workOrder/index.js'
  98. import {
  99. getByCode
  100. } from '@/api/pda/common.js'
  101. export default {
  102. data() {
  103. return {
  104. form: {
  105. typeId: '2',
  106. code: '',
  107. name: '',
  108. categoryModel: '', // 型号
  109. specification: '', // 规格
  110. content: '', // 详细内容
  111. warehouseId: '', // 仓库id\
  112. warehouseNum: '', // 库存
  113. totalCount: '', // 数量
  114. measureUnit: '', // 单位
  115. singlePrice: '', // 单价
  116. settlementPrice: '', // 合计
  117. },
  118. typeIdList: [],
  119. obtain: '主数据',
  120. warehouseList: [], // 仓库数据
  121. oldTypeId: '2', // 旧的项目选择
  122. }
  123. },
  124. onLoad(params) {
  125. let data = JSON.parse(params.data);
  126. if (data.name) {
  127. this.form = data;
  128. }
  129. console.log(data, 'params')
  130. this.obtain = params.obtain || '主数据'
  131. },
  132. created() {
  133. this.getLevelCode('after_sales_project')
  134. uni.$off('updateScheme');
  135. uni.$on('updateScheme', async (data) => {
  136. this.form = {
  137. ...this.form,
  138. ...data
  139. };
  140. console.log(this.form, 'data ----')
  141. if (this.obtain == '主数据') {
  142. const res = await getIdWarehouseList({
  143. categoryId: ''
  144. })
  145. res && res.map((el) => {
  146. el.text = el.warehouseName;
  147. el.value = el.warehouseId;
  148. })
  149. this.warehouseList = res || [];
  150. }
  151. })
  152. },
  153. methods: {
  154. async getLevelCode(code) {
  155. try {
  156. const res = await getByCode(code);
  157. if (res) {
  158. let list = Object.values(res).map((el) => {
  159. let k = Object.keys(el)[0];
  160. let v = Object.values(el)[0];
  161. return {
  162. text: v,
  163. value: k
  164. };
  165. });
  166. this.typeIdList = list;
  167. }
  168. } catch (err) {
  169. }
  170. },
  171. // 如果新的选择跟旧的一样 不做数据更改
  172. typeOnchange(e) {
  173. if (this.form.typeId == this.oldTypeId) {
  174. return;
  175. }
  176. this.oldTypeId = this.form.typeId;
  177. this.form = {
  178. typeId: this.form.typeId,
  179. code: '',
  180. name: '',
  181. categoryModel: '', // 型号
  182. specification: '', // 规格
  183. content: '', // 详细内容
  184. warehouseId: '', // 仓库
  185. warehouseNum: '', // 库存
  186. totalCount: '', // 数量
  187. measureUnit: '', // 单位
  188. singlePrice: '', // 单价
  189. settlementPrice: '', // 合计
  190. }
  191. },
  192. warehouseOnchange(e) {
  193. let name = this.warehouseList.find(item => item.warehouseId == e).warehouseName;
  194. this.form.warehouseName = name;
  195. },
  196. selectProduct() {
  197. uni.navigateTo({
  198. url: `/pages/salesServiceManagement/workOrder/components/selectProduct?obtain=${this.obtain}`
  199. })
  200. },
  201. save() {
  202. if (!this.form.name) {
  203. this.$refs.uToast.show({
  204. type: "warning",
  205. message: "请填写名称",
  206. })
  207. return;
  208. }
  209. uni.$emit('updateInfo', this.form);
  210. this.back();
  211. },
  212. inputChange(e, field) {
  213. // let value = e.replace(/[^\d]/g, '');
  214. // if (value.startsWith('0') && value.length > 1) {
  215. // value = value.replace(/^0+/, '');
  216. // }
  217. console.log(123)
  218. let value = '';
  219. if (field == 'singlePrice') {
  220. value = e.replace(/\./g, ''); // 如果不允许小数点,就移除所有小数点
  221. } else {
  222. value = e.replace(/[^\d]/g, '')
  223. if (value.startsWith('0') && value.length > 1) {
  224. value = value.replace(/^0+/, '');
  225. }
  226. }
  227. console.log(value, 'value')
  228. this.form[field] = value;
  229. let num1 = this.form.totalCount ? this.form.totalCount - 0 : 0;
  230. let num2 = this.form.singlePrice ? this.form.singlePrice - 0 : 0;
  231. this.form.settlementPrice = num1 * num2;
  232. },
  233. }
  234. }
  235. </script>
  236. <style scoped lang="scss">
  237. /deep/.u-cell__body__content {
  238. flex: none;
  239. margin-right: 16rpx;
  240. }
  241. .mainBox {
  242. padding-bottom: 84rpx;
  243. .labels {
  244. padding-left: 18rpx;
  245. }
  246. }
  247. .footerButton {
  248. width: 100%;
  249. height: 84rpx;
  250. display: flex;
  251. position: fixed;
  252. bottom: 0;
  253. /deep/.u-button {
  254. height: 100%;
  255. }
  256. >view {
  257. flex: 1;
  258. }
  259. }
  260. </style>